From 01900b8536dd1697e01ab6757e655335f1a3ed3a Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Fri, 12 Feb 2021 23:15:10 +0100 Subject: [PATCH] refactor(core): convert parts of apps.webauthn to layouts --- .../apps/webauthn/add_resident_credential.py | 20 ++++++++++--------- .../webauthn/list_resident_credentials.py | 18 ++++++++--------- core/src/trezor/ui/layouts/tt.py | 3 ++- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/core/src/apps/webauthn/add_resident_credential.py b/core/src/apps/webauthn/add_resident_credential.py index 08135cbe4..822f26f09 100644 --- a/core/src/apps/webauthn/add_resident_credential.py +++ b/core/src/apps/webauthn/add_resident_credential.py @@ -1,8 +1,8 @@ import storage.device -from trezor import ui, wire +from trezor import wire from trezor.messages.Success import Success from trezor.messages.WebAuthnAddResidentCredential import WebAuthnAddResidentCredential -from trezor.ui.components.tt.text import Text +from trezor.ui.layouts import require, show_error from apps.common.confirm import require_confirm @@ -41,14 +41,16 @@ async def add_resident_credential( try: cred = Fido2Credential.from_cred_id(bytes(msg.credential_id), None) except Exception: - text = Text("Import credential", ui.ICON_WRONG, ui.RED) - text.normal( - "The credential you are", - "trying to import does", - "not belong to this", - "authenticator.", + await require( + show_error( + ctx, + "warning_credential", + header="Import credential", + button="Close", + content="The credential you are trying to import does\nnot belong to this authenticator.", + red=True, + ) ) - await require_confirm(ctx, text, confirm=None, cancel="Close") raise wire.ActionCancelled content = ConfirmContent(ConfirmAddCredential(cred)) diff --git a/core/src/apps/webauthn/list_resident_credentials.py b/core/src/apps/webauthn/list_resident_credentials.py index 4b1576232..8d7fa405c 100644 --- a/core/src/apps/webauthn/list_resident_credentials.py +++ b/core/src/apps/webauthn/list_resident_credentials.py @@ -4,9 +4,7 @@ from trezor.messages.WebAuthnCredentials import WebAuthnCredentials from trezor.messages.WebAuthnListResidentCredentials import ( WebAuthnListResidentCredentials, ) -from trezor.ui.components.tt.text import Text - -from apps.common.confirm import require_confirm +from trezor.ui.layouts import confirm_action, require from . import resident_credentials @@ -14,14 +12,14 @@ from . import resident_credentials async def list_resident_credentials( ctx: wire.Context, msg: WebAuthnListResidentCredentials ) -> WebAuthnCredentials: - text = Text("List credentials") - text.normal( - "Do you want to export", - "information about the", - "resident credentials", - "stored on this device?", + await require( + confirm_action( + ctx, + "credentials_list", + title="List credentials", + description="Do you want to export information about the resident credentials stored on this device?", + ) ) - await require_confirm(ctx, text) creds = [ WebAuthnCredential( index=cred.index, diff --git a/core/src/trezor/ui/layouts/tt.py b/core/src/trezor/ui/layouts/tt.py index d013b933f..d06b3990b 100644 --- a/core/src/trezor/ui/layouts/tt.py +++ b/core/src/trezor/ui/layouts/tt.py @@ -358,6 +358,7 @@ def show_error( header: str = "Error", subheader: Optional[str] = None, button: str = "Close", + red: bool = False, ) -> Awaitable[bool]: return _show_modal( ctx, @@ -369,7 +370,7 @@ def show_error( button_confirm=None, button_cancel=button, icon=ui.ICON_WRONG, - icon_color=ui.ORANGE_ICON, + icon_color=ui.RED if red else ui.ORANGE_ICON, )