diff --git a/core/src/apps/management/recovery_device/homescreen.py b/core/src/apps/management/recovery_device/homescreen.py index ed25e62533..046802497c 100644 --- a/core/src/apps/management/recovery_device/homescreen.py +++ b/core/src/apps/management/recovery_device/homescreen.py @@ -5,6 +5,7 @@ import storage.recovery as storage_recovery import storage.recovery_shares as storage_recovery_shares from trezor import TR, wire from trezor.messages import Success +from trezor.ui.layouts.recovery import show_invalid_mnemonic from apps.common import backup_types from apps.management.recovery_device.recover import RecoveryAborted @@ -126,7 +127,7 @@ async def _continue_recovery_process() -> Success: # that the first step is complete. is_first_step = False except MnemonicError: - await layout.show_invalid_mnemonic(word_count) + await show_invalid_mnemonic(word_count) assert backup_type is not None if recovery_type == RecoveryType.DryRun: @@ -211,7 +212,7 @@ async def _finish_recovery_unlock_repeated_backup( async def _finish_recovery(secret: bytes, backup_type: BackupType) -> Success: - from trezor.ui.layouts import show_success + from trezor.ui.layouts.recovery import show_recovery_success if backup_type is None: raise RuntimeError @@ -234,7 +235,7 @@ async def _finish_recovery(secret: bytes, backup_type: BackupType) -> Success: storage_recovery.end_progress() - await show_success("success_recovery", TR.recovery__wallet_recovered) + await show_recovery_success() return Success(message="Device recovered") diff --git a/core/src/apps/management/recovery_device/layout.py b/core/src/apps/management/recovery_device/layout.py index c86246e8e3..c8760e949a 100644 --- a/core/src/apps/management/recovery_device/layout.py +++ b/core/src/apps/management/recovery_device/layout.py @@ -3,7 +3,10 @@ from typing import TYPE_CHECKING from trezor import TR from trezor.ui.layouts.recovery import ( # noqa: F401 request_word_count, + show_already_added, show_group_share_success, + show_group_thresholod, + show_identifier_mismatch, show_recovery_warning, ) @@ -66,27 +69,15 @@ async def request_mnemonic( word_validity.check(backup_type, non_empty_words) except word_validity.AlreadyAdded: # show_share_already_added - await show_recovery_warning( - "warning_known_share", - TR.recovery__share_already_entered, - TR.recovery__enter_different_share, - ) + await show_already_added() return None except word_validity.IdentifierMismatch: # show_identifier_mismatch - await show_recovery_warning( - "warning_mismatched_share", - "", - TR.recovery__share_from_another_multi_share_backup, - ) + await show_identifier_mismatch() return None except word_validity.ThresholdReached: # show_group_threshold_reached - await show_recovery_warning( - "warning_group_threshold", - TR.recovery__group_threshold_reached, - TR.recovery__enter_share_from_diff_group, - ) + await show_group_thresholod() return None return " ".join(words) @@ -111,21 +102,6 @@ async def show_dry_run_result(result: bool, is_slip39: bool) -> None: ) -async def show_invalid_mnemonic(word_count: int) -> None: - if backup_types.is_slip39_word_count(word_count): - await show_recovery_warning( - "warning_invalid_share", - TR.words__please_try_again, - TR.recovery__invalid_share_entered, - ) - else: - await show_recovery_warning( - "warning_invalid_seed", - TR.words__please_try_again, - TR.recovery__invalid_wallet_backup_entered, - ) - - def enter_share( word_count: int | None = None, entered_remaining: tuple[int, int] | None = None, diff --git a/core/src/trezor/ui/layouts/bolt/recovery.py b/core/src/trezor/ui/layouts/bolt/recovery.py index 1258feb331..4c968319a4 100644 --- a/core/src/trezor/ui/layouts/bolt/recovery.py +++ b/core/src/trezor/ui/layouts/bolt/recovery.py @@ -4,6 +4,8 @@ import trezorui_api from trezor import TR, ui from trezor.enums import ButtonRequestType +from apps.common import backup_types + from ..common import interact if TYPE_CHECKING: @@ -188,6 +190,45 @@ async def continue_recovery( return False +async def show_invalid_mnemonic(word_count: int) -> None: + if backup_types.is_slip39_word_count(word_count): + await show_recovery_warning( + "warning_invalid_share", + TR.words__please_try_again, + TR.recovery__invalid_share_entered, + ) + else: + await show_recovery_warning( + "warning_invalid_seed", + TR.words__please_try_again, + TR.recovery__invalid_wallet_backup_entered, + ) + + +async def show_identifier_mismatch() -> None: + await show_recovery_warning( + "warning_mismatched_share", + "", + TR.recovery__share_from_another_multi_share_backup, + ) + + +async def show_already_added() -> None: + await show_recovery_warning( + "warning_known_share", + TR.recovery__share_already_entered, + TR.recovery__enter_different_share, + ) + + +async def show_group_thresholod() -> None: + await show_recovery_warning( + "warning_group_threshold", + TR.recovery__group_threshold_reached, + TR.recovery__enter_share_from_diff_group, + ) + + def show_recovery_warning( br_name: str, content: str, @@ -207,3 +248,9 @@ def show_recovery_warning( br_name, br_code, ) + + +async def show_recovery_success() -> None: + from trezor.ui.layouts import show_success + + return await show_success("success_recovery", TR.recovery__wallet_recovered) diff --git a/core/src/trezor/ui/layouts/caesar/recovery.py b/core/src/trezor/ui/layouts/caesar/recovery.py index a1c8c8e3a5..8baf5d7594 100644 --- a/core/src/trezor/ui/layouts/caesar/recovery.py +++ b/core/src/trezor/ui/layouts/caesar/recovery.py @@ -4,6 +4,8 @@ import trezorui_api from trezor import TR, ui from trezor.enums import ButtonRequestType, RecoveryType +from apps.common import backup_types + from ..common import interact from . import show_warning @@ -149,6 +151,45 @@ async def continue_recovery( return False +async def show_invalid_mnemonic(word_count: int) -> None: + if backup_types.is_slip39_word_count(word_count): + await show_recovery_warning( + "warning_invalid_share", + TR.words__please_try_again, + TR.recovery__invalid_share_entered, + ) + else: + await show_recovery_warning( + "warning_invalid_seed", + TR.words__please_try_again, + TR.recovery__invalid_wallet_backup_entered, + ) + + +async def show_identifier_mismatch() -> None: + await show_recovery_warning( + "warning_mismatched_share", + "", + TR.recovery__share_from_another_multi_share_backup, + ) + + +async def show_already_added() -> None: + await show_recovery_warning( + "warning_known_share", + TR.recovery__share_already_entered, + TR.recovery__enter_different_share, + ) + + +async def show_group_thresholod() -> None: + await show_recovery_warning( + "warning_group_threshold", + TR.recovery__group_threshold_reached, + TR.recovery__enter_share_from_diff_group, + ) + + def show_recovery_warning( br_name: str, content: str, @@ -158,3 +199,9 @@ def show_recovery_warning( ) -> Awaitable[ui.UiResult]: button = button or TR.buttons__try_again # def_arg return show_warning(br_name, content, subheader, button, br_code=br_code) + + +async def show_recovery_success() -> None: + from trezor.ui.layouts import show_success + + await show_success("success_recovery", TR.recovery__wallet_recovered) diff --git a/core/src/trezor/ui/layouts/delizia/recovery.py b/core/src/trezor/ui/layouts/delizia/recovery.py index 82019bff4d..146fa3fe7a 100644 --- a/core/src/trezor/ui/layouts/delizia/recovery.py +++ b/core/src/trezor/ui/layouts/delizia/recovery.py @@ -4,6 +4,8 @@ import trezorui_api from trezor import TR from trezor.enums import ButtonRequestType, RecoveryType +from apps.common import backup_types + from ..common import interact from . import raise_if_not_confirmed @@ -130,6 +132,45 @@ async def continue_recovery( return result is CONFIRMED +async def show_invalid_mnemonic(word_count: int) -> None: + if backup_types.is_slip39_word_count(word_count): + await show_recovery_warning( + "warning_invalid_share", + TR.words__please_try_again, + TR.recovery__invalid_share_entered, + ) + else: + await show_recovery_warning( + "warning_invalid_seed", + TR.words__please_try_again, + TR.recovery__invalid_wallet_backup_entered, + ) + + +async def show_identifier_mismatch() -> None: + await show_recovery_warning( + "warning_mismatched_share", + "", + TR.recovery__share_from_another_multi_share_backup, + ) + + +async def show_already_added() -> None: + await show_recovery_warning( + "warning_known_share", + TR.recovery__share_already_entered, + TR.recovery__enter_different_share, + ) + + +async def show_group_thresholod() -> None: + await show_recovery_warning( + "warning_group_threshold", + TR.recovery__group_threshold_reached, + TR.recovery__enter_share_from_diff_group, + ) + + async def show_recovery_warning( br_name: str, content: str, @@ -149,3 +190,9 @@ async def show_recovery_warning( br_name, br_code, ) + + +async def show_recovery_success() -> None: + from trezor.ui.layouts import show_success + + return await show_success("success_recovery", TR.recovery__wallet_recovered) diff --git a/core/src/trezor/ui/layouts/eckhart/recovery.py b/core/src/trezor/ui/layouts/eckhart/recovery.py index 410ff53a7d..b9b2126896 100644 --- a/core/src/trezor/ui/layouts/eckhart/recovery.py +++ b/core/src/trezor/ui/layouts/eckhart/recovery.py @@ -4,6 +4,8 @@ import trezorui_api from trezor import TR from trezor.enums import ButtonRequestType, RecoveryType +from apps.common import backup_types + from ..common import interact from . import raise_if_not_confirmed @@ -126,22 +128,77 @@ async def continue_recovery( return result is CONFIRMED +async def show_invalid_mnemonic(word_count: int) -> None: + if backup_types.is_slip39_word_count(word_count): + await show_recovery_warning( + "warning_invalid_share", + TR.words__pay_attention, + TR.recovery__invalid_share_entered, + TR.words__try_again, + ) + else: + await show_recovery_warning( + "warning_invalid_seed", + TR.words__pay_attention, + TR.recovery__invalid_wallet_backup_entered, + TR.buttons__continue, + ) + + +async def show_identifier_mismatch() -> None: + await show_recovery_warning( + "warning_mismatched_share", + TR.words__pay_attention, + TR.recovery__share_from_another_multi_share_backup, + TR.buttons__continue, + ) + + +async def show_already_added() -> None: + await show_recovery_warning( + "warning_known_share", + TR.words__pay_attention, + f"{TR.recovery__share_already_entered}. {TR.recovery__enter_different_share}.", + TR.buttons__continue, + ) + + +async def show_group_thresholod() -> None: + await show_recovery_warning( + "warning_group_threshold", + TR.words__pay_attention, + TR.recovery__group_threshold_reached, + TR.recovery__enter_share_from_diff_group, + ) + + async def show_recovery_warning( br_name: str, - content: str, + content: str | None = None, subheader: str | None = None, button: str | None = None, br_code: ButtonRequestType = ButtonRequestType.Warning, ) -> None: - button = button or TR.buttons__try_again # def_arg await raise_if_not_confirmed( trezorui_api.show_warning( - title=content or TR.words__warning, + title=content or TR.words__pay_attention, value=subheader or "", - button=button, + button=button or TR.buttons__continue, description="", danger=True, + allow_cancel=False, ), br_name, br_code, ) + + +async def show_recovery_success() -> None: + from trezor.ui.layouts import show_success + + return await show_success( + "success_recovery", + TR.recovery__wallet_recovered, + TR.words__title_done, + TR.instructions__continue_in_app, + )