1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-04 05:42:34 +00:00

refactor(core): convert parts of apps.webauthn to layouts

This commit is contained in:
Martin Milata 2021-02-12 23:15:10 +01:00
parent ffe6d65f72
commit 01900b8536
3 changed files with 21 additions and 20 deletions

View File

@ -1,8 +1,8 @@
import storage.device import storage.device
from trezor import ui, wire from trezor import wire
from trezor.messages.Success import Success from trezor.messages.Success import Success
from trezor.messages.WebAuthnAddResidentCredential import WebAuthnAddResidentCredential 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 from apps.common.confirm import require_confirm
@ -41,14 +41,16 @@ async def add_resident_credential(
try: try:
cred = Fido2Credential.from_cred_id(bytes(msg.credential_id), None) cred = Fido2Credential.from_cred_id(bytes(msg.credential_id), None)
except Exception: except Exception:
text = Text("Import credential", ui.ICON_WRONG, ui.RED) await require(
text.normal( show_error(
"The credential you are", ctx,
"trying to import does", "warning_credential",
"not belong to this", header="Import credential",
"authenticator.", 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 raise wire.ActionCancelled
content = ConfirmContent(ConfirmAddCredential(cred)) content = ConfirmContent(ConfirmAddCredential(cred))

View File

@ -4,9 +4,7 @@ from trezor.messages.WebAuthnCredentials import WebAuthnCredentials
from trezor.messages.WebAuthnListResidentCredentials import ( from trezor.messages.WebAuthnListResidentCredentials import (
WebAuthnListResidentCredentials, WebAuthnListResidentCredentials,
) )
from trezor.ui.components.tt.text import Text from trezor.ui.layouts import confirm_action, require
from apps.common.confirm import require_confirm
from . import resident_credentials from . import resident_credentials
@ -14,14 +12,14 @@ from . import resident_credentials
async def list_resident_credentials( async def list_resident_credentials(
ctx: wire.Context, msg: WebAuthnListResidentCredentials ctx: wire.Context, msg: WebAuthnListResidentCredentials
) -> WebAuthnCredentials: ) -> WebAuthnCredentials:
text = Text("List credentials") await require(
text.normal( confirm_action(
"Do you want to export", ctx,
"information about the", "credentials_list",
"resident credentials", title="List credentials",
"stored on this device?", description="Do you want to export information about the resident credentials stored on this device?",
)
) )
await require_confirm(ctx, text)
creds = [ creds = [
WebAuthnCredential( WebAuthnCredential(
index=cred.index, index=cred.index,

View File

@ -358,6 +358,7 @@ def show_error(
header: str = "Error", header: str = "Error",
subheader: Optional[str] = None, subheader: Optional[str] = None,
button: str = "Close", button: str = "Close",
red: bool = False,
) -> Awaitable[bool]: ) -> Awaitable[bool]:
return _show_modal( return _show_modal(
ctx, ctx,
@ -369,7 +370,7 @@ def show_error(
button_confirm=None, button_confirm=None,
button_cancel=button, button_cancel=button,
icon=ui.ICON_WRONG, icon=ui.ICON_WRONG,
icon_color=ui.ORANGE_ICON, icon_color=ui.RED if red else ui.ORANGE_ICON,
) )