From da72482c2f152542366431f136eb922d29aa8f7c Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Tue, 16 Mar 2021 13:37:34 +0100 Subject: [PATCH] refactor(core/ui): get rid of confirm_wipe --- core/src/apps/management/wipe_device.py | 19 +++++++++++++++++-- core/src/trezor/ui/layouts/tt.py | 23 +++++------------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/core/src/apps/management/wipe_device.py b/core/src/apps/management/wipe_device.py index f0cfae21d..d5b2dc189 100644 --- a/core/src/apps/management/wipe_device.py +++ b/core/src/apps/management/wipe_device.py @@ -1,12 +1,27 @@ import storage +from trezor import ui +from trezor.messages import ButtonRequestType from trezor.messages.Success import Success -from trezor.ui.layouts import confirm_wipe +from trezor.ui.layouts import confirm_action from .apply_settings import reload_settings_from_storage async def wipe_device(ctx, msg): - await confirm_wipe(ctx) + await confirm_action( + ctx, + "confirm_wipe", + title="Wipe device", + description="Do you really want to\nwipe the device?\n", + action="All data will be lost.", + reverse=True, + verb="Hold to confirm", + hold=True, + hold_danger=True, + icon=ui.ICON_WIPE, + icon_color=ui.RED, + br_code=ButtonRequestType.WipeDevice, + ) storage.wipe() reload_settings_from_storage() diff --git a/core/src/trezor/ui/layouts/tt.py b/core/src/trezor/ui/layouts/tt.py index 52d8b82ad..5dbb39460 100644 --- a/core/src/trezor/ui/layouts/tt.py +++ b/core/src/trezor/ui/layouts/tt.py @@ -43,7 +43,6 @@ if False: __all__ = ( "confirm_action", - "confirm_wipe", "confirm_reset_device", "confirm_backup", "confirm_path_warning", @@ -79,13 +78,13 @@ async def confirm_action( verb: Union[str, bytes, None] = Confirm.DEFAULT_CONFIRM, verb_cancel: Union[str, bytes, None] = Confirm.DEFAULT_CANCEL, hold: bool = False, + hold_danger: bool = False, icon: str = None, # TODO cleanup @ redesign icon_color: int = None, # TODO cleanup @ redesign reverse: bool = False, # TODO cleanup @ redesign larger_vspace: bool = False, # TODO cleanup @ redesign exc: ExceptionType = wire.ActionCancelled, br_code: EnumTypeButtonRequestType = ButtonRequestType.Other, - **kwargs: Any, ) -> None: text = Text( title, @@ -118,10 +117,13 @@ async def confirm_action( ) cls = HoldToConfirm if hold else Confirm + kwargs = {} + if hold_danger: + kwargs = {"loader_style": LoaderDanger, "confirm_style": ButtonCancel} await raise_if_cancelled( interact( ctx, - cls(text, confirm=verb, cancel=verb_cancel), + cls(text, confirm=verb, cancel=verb_cancel, **kwargs), br_type, br_code, ), @@ -129,21 +131,6 @@ async def confirm_action( ) -# TODO cleanup @ redesign -async def confirm_wipe(ctx: wire.GenericContext) -> None: - text = Text("Wipe device", ui.ICON_WIPE, ui.RED) - text.normal("Do you really want to", "wipe the device?", "") - text.bold("All data will be lost.") - await raise_if_cancelled( - interact( - ctx, - HoldToConfirm(text, confirm_style=ButtonCancel, loader_style=LoaderDanger), - "wipe_device", - ButtonRequestType.WipeDevice, - ) - ) - - async def confirm_reset_device(ctx: wire.GenericContext, prompt: str) -> None: text = Text("Create new wallet", ui.ICON_RESET, new_lines=False) text.bold(prompt)