Skip to content
Snippets Groups Projects
Commit 0d5a5298 authored by Mateusz Żebrak's avatar Mateusz Żebrak
Browse files

Remove WELCOME_PROFILE from TUI, set Profile to None when locked

parent c742a344
No related branches found
No related tags found
2 merge requests!600v1.27.5.21 Release,!558Remove welcome profile from TUIWorld, set TUIWorld profile during CreateProfile wizard instead
from __future__ import annotations
from typing import Final
WELCOME_PROFILE_NAME: Final[str] = "welcome"
...@@ -12,7 +12,6 @@ from clive.__private.cli.exceptions import CLINoProfileUnlockedError ...@@ -12,7 +12,6 @@ from clive.__private.cli.exceptions import CLINoProfileUnlockedError
from clive.__private.core.app_state import AppState, LockSource from clive.__private.core.app_state import AppState, LockSource
from clive.__private.core.commands.commands import CLICommands, Commands, TUICommands from clive.__private.core.commands.commands import CLICommands, Commands, TUICommands
from clive.__private.core.commands.get_unlocked_user_wallet import NoProfileUnlockedError from clive.__private.core.commands.get_unlocked_user_wallet import NoProfileUnlockedError
from clive.__private.core.constants.tui.profile import WELCOME_PROFILE_NAME
from clive.__private.core.known_exchanges import KnownExchanges from clive.__private.core.known_exchanges import KnownExchanges
from clive.__private.core.node import Node from clive.__private.core.node import Node
from clive.__private.core.profile import Profile from clive.__private.core.profile import Profile
...@@ -207,7 +206,7 @@ class World: ...@@ -207,7 +206,7 @@ class World:
await self.commands.unlock(profile_name=profile_name, password=password, permanent=True) await self.commands.unlock(profile_name=profile_name, password=password, permanent=True)
await self.load_profile_based_on_beekepeer() await self.load_profile_based_on_beekepeer()
async def switch_profile(self, new_profile: Profile) -> None: async def switch_profile(self, new_profile: Profile | None) -> None:
self._profile = new_profile self._profile = new_profile
await self._update_node() await self._update_node()
...@@ -276,7 +275,11 @@ class World: ...@@ -276,7 +275,11 @@ class World:
class TUIWorld(World, CliveDOMNode): class TUIWorld(World, CliveDOMNode):
profile_reactive: Profile = var(None, init=False) # type: ignore[assignment] profile_reactive: Profile = var(None, init=False) # type: ignore[assignment]
"""Should be used only after unlocking the profile so it will be available then."""
node_reactive: Node = var(None, init=False) # type: ignore[assignment] node_reactive: Node = var(None, init=False) # type: ignore[assignment]
"""Should be used only after unlocking the profile so it will be available then."""
app_state: AppState = var(None, init=False) # type: ignore[assignment] app_state: AppState = var(None, init=False) # type: ignore[assignment]
@override @override
...@@ -304,18 +307,13 @@ class TUIWorld(World, CliveDOMNode): ...@@ -304,18 +307,13 @@ class TUIWorld(World, CliveDOMNode):
try: try:
await self.load_profile_based_on_beekepeer() await self.load_profile_based_on_beekepeer()
except NoProfileUnlockedError: except NoProfileUnlockedError:
await self._switch_to_welcome_profile() await self.switch_profile(None)
return self return self
async def switch_profile(self, new_profile: Profile) -> None: async def switch_profile(self, new_profile: Profile | None) -> None:
await super().switch_profile(new_profile) await super().switch_profile(new_profile)
self._update_profile_related_reactive_attributes() self._update_profile_related_reactive_attributes()
async def _switch_to_welcome_profile(self) -> None:
"""Set the profile to default (welcome)."""
await self.create_new_profile(WELCOME_PROFILE_NAME)
self.profile.skip_saving()
def _watch_profile(self, profile: Profile) -> None: def _watch_profile(self, profile: Profile) -> None:
self.node.change_related_profile(profile) self.node.change_related_profile(profile)
...@@ -330,7 +328,7 @@ class TUIWorld(World, CliveDOMNode): ...@@ -330,7 +328,7 @@ class TUIWorld(World, CliveDOMNode):
self._add_welcome_modes() self._add_welcome_modes()
await self.app.switch_mode("unlock") await self.app.switch_mode("unlock")
await self._restart_dashboard_mode() await self._restart_dashboard_mode()
await self._switch_to_welcome_profile() await self.switch_profile(None)
self.app.run_worker(lock()) self.app.run_worker(lock())
...@@ -349,10 +347,14 @@ class TUIWorld(World, CliveDOMNode): ...@@ -349,10 +347,14 @@ class TUIWorld(World, CliveDOMNode):
self.app.add_mode("dashboard", Dashboard) self.app.add_mode("dashboard", Dashboard)
def _update_profile_related_reactive_attributes(self) -> None: def _update_profile_related_reactive_attributes(self) -> None:
if self._node is not None: # There's no proper way to add some proxy reactive property on textual reactives that could raise error if
self.node_reactive = self._node # not set yet, and still can be watched. See: https://github.com/Textualize/textual/discussions/4007
if self._profile is not None:
self.profile_reactive = self._profile if self._node is None or self._profile is None:
assert not self.app_state.is_unlocked, "Profile and node should never be None when unlocked"
self.node_reactive = self._node # type: ignore[assignment] # ignore that, node_reactive shouldn't be accessed before unlocking
self.profile_reactive = self._profile # type: ignore[assignment] # ignore that, profile_reactive shouldn't be accessed before unlocking
class CLIWorld(World): class CLIWorld(World):
......
...@@ -2,7 +2,6 @@ from __future__ import annotations ...@@ -2,7 +2,6 @@ from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from clive.__private.core.constants.tui.profile import WELCOME_PROFILE_NAME
from clive.__private.core.node import Node from clive.__private.core.node import Node
from clive.__private.core.profile import Profile from clive.__private.core.profile import Profile
from clive.__private.ui.forms.create_profile.context import CreateProfileContext from clive.__private.ui.forms.create_profile.context import CreateProfileContext
...@@ -31,5 +30,5 @@ class CreateProfileForm(Form[CreateProfileContext]): ...@@ -31,5 +30,5 @@ class CreateProfileForm(Form[CreateProfileContext]):
yield NewKeyAliasFormScreen yield NewKeyAliasFormScreen
def _rebuild_context(self) -> None: def _rebuild_context(self) -> None:
profile = Profile.create(WELCOME_PROFILE_NAME) profile = Profile.create("temp")
self.__context = CreateProfileContext(profile, Node(profile)) self.__context = CreateProfileContext(profile, Node(profile))
...@@ -4,7 +4,6 @@ from typing import TYPE_CHECKING, Final ...@@ -4,7 +4,6 @@ from typing import TYPE_CHECKING, Final
import pytest import pytest
from clive.__private.core.constants.tui.profile import WELCOME_PROFILE_NAME
from clive.__private.ui.app import Clive from clive.__private.ui.app import Clive
from clive.__private.ui.forms.create_profile.create_profile_form_screen import CreateProfileFormScreen from clive.__private.ui.forms.create_profile.create_profile_form_screen import CreateProfileFormScreen
from clive.__private.ui.forms.create_profile.new_key_alias_form_screen import NewKeyAliasFormScreen from clive.__private.ui.forms.create_profile.new_key_alias_form_screen import NewKeyAliasFormScreen
...@@ -115,8 +114,8 @@ async def assert_tui_key_alias_exists(pilot: ClivePilot) -> None: ...@@ -115,8 +114,8 @@ async def assert_tui_key_alias_exists(pilot: ClivePilot) -> None:
def assert_is_new_profile(pilot: ClivePilot) -> None: def assert_is_new_profile(pilot: ClivePilot) -> None:
assert pilot.app.world.profile, "Expected profile is not None" assert pilot.app.world.profile, "Expected profile to be set"
assert pilot.app.world.profile.name == WELCOME_PROFILE_NAME, f"Expected profile name to be {WELCOME_PROFILE_NAME}" assert pilot.app.world.profile.name == "temp_name", "Expected different profile name"
def assert_working_account(pilot: ClivePilot, name: str) -> None: def assert_working_account(pilot: ClivePilot, name: str) -> None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment