From 107c2226310caf55079882229de1eec47a047daa Mon Sep 17 00:00:00 2001 From: grdddj Date: Wed, 21 Sep 2022 12:35:17 +0200 Subject: [PATCH] chore(core): decrease TT_v2 UI size by 390 bytes --- core/src/trezor/ui/__init__.py | 10 +- core/src/trezor/ui/layouts/tt_v2/__init__.py | 153 ++++++++++--------- core/src/trezor/ui/layouts/tt_v2/altcoin.py | 10 +- core/src/trezor/ui/layouts/tt_v2/recovery.py | 39 +++-- core/src/trezor/ui/layouts/tt_v2/reset.py | 131 ++++++++-------- core/src/trezor/ui/layouts/tt_v2/webauthn.py | 6 +- 6 files changed, 189 insertions(+), 160 deletions(-) diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py index ed8943fd7..b9eb9b38b 100644 --- a/core/src/trezor/ui/__init__.py +++ b/core/src/trezor/ui/__init__.py @@ -17,11 +17,11 @@ if TYPE_CHECKING: display = Display() # re-export constants from modtrezorui -NORMAL = Display.FONT_NORMAL -BOLD = Display.FONT_BOLD -MONO = Display.FONT_MONO -WIDTH = Display.WIDTH -HEIGHT = Display.HEIGHT +NORMAL: int = Display.FONT_NORMAL +BOLD: int = Display.FONT_BOLD +MONO: int = Display.FONT_MONO +WIDTH: int = Display.WIDTH +HEIGHT: int = Display.HEIGHT # viewport margins VIEWX = const(6) diff --git a/core/src/trezor/ui/layouts/tt_v2/__init__.py b/core/src/trezor/ui/layouts/tt_v2/__init__.py index 039b22e2c..361b450d3 100644 --- a/core/src/trezor/ui/layouts/tt_v2/__init__.py +++ b/core/src/trezor/ui/layouts/tt_v2/__init__.py @@ -1,8 +1,8 @@ from typing import TYPE_CHECKING -from ubinascii import hexlify -from trezor import io, log, loop, ui, wire, workflow +from trezor import io, log, loop, ui from trezor.enums import ButtonRequestType +from trezor.wire import ActionCancelled import trezorui2 @@ -11,11 +11,18 @@ from ..common import button_request, interact if TYPE_CHECKING: from typing import Any, Awaitable, Iterable, NoReturn, Sequence, TypeVar + from trezor.wire import GenericContext, Context from ..common import PropertyType, ExceptionType T = TypeVar("T") +CONFIRMED = trezorui2.CONFIRMED # global_import_cache +CANCELLED = trezorui2.CANCELLED # global_import_cache +INFO = trezorui2.INFO # global_import_cache +BR_TYPE_OTHER = ButtonRequestType.Other # global_import_cache + + class _RustLayout(ui.Layout): # pylint: disable=super-init-not-called def __init__(self, layout: Any, is_backup: bool = False): @@ -132,6 +139,8 @@ class _RustLayout(ui.Layout): ui.backlight_fade(self.BACKLIGHT_LEVEL) def handle_input_and_rendering(self) -> loop.Task: # type: ignore [awaitable-is-generator] + from trezor import workflow + touch = loop.wait(io.TOUCH) self._before_render() # self.layout.bounds() @@ -160,7 +169,7 @@ class _RustLayout(ui.Layout): return self.layout.page_count() -async def raise_if_not_confirmed(a: Awaitable[T], exc: Any = wire.ActionCancelled) -> T: +async def raise_if_not_confirmed(a: Awaitable[T], exc: Any = ActionCancelled) -> T: result = await a if result is not trezorui2.CONFIRMED: raise exc @@ -168,7 +177,7 @@ async def raise_if_not_confirmed(a: Awaitable[T], exc: Any = wire.ActionCancelle async def confirm_action( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, action: str | None = None, @@ -183,8 +192,8 @@ async def confirm_action( icon_color: int | None = None, reverse: bool = False, larger_vspace: bool = False, - exc: ExceptionType = wire.ActionCancelled, - br_code: ButtonRequestType = ButtonRequestType.Other, + exc: ExceptionType = ActionCancelled, + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> None: if isinstance(verb, bytes) or isinstance(verb_cancel, bytes): raise NotImplementedError @@ -220,7 +229,7 @@ async def confirm_action( async def confirm_reset_device( - ctx: wire.GenericContext, prompt: str, recovery: bool = False + ctx: GenericContext, prompt: str, recovery: bool = False ) -> None: if recovery: title = "RECOVERY MODE" @@ -245,7 +254,7 @@ async def confirm_reset_device( # TODO cleanup @ redesign -async def confirm_backup(ctx: wire.GenericContext) -> bool: +async def confirm_backup(ctx: GenericContext) -> bool: result = await interact( ctx, _RustLayout( @@ -260,7 +269,7 @@ async def confirm_backup(ctx: wire.GenericContext) -> bool: "backup_device", ButtonRequestType.ResetDevice, ) - if result is trezorui2.CONFIRMED: + if result is CONFIRMED: return True result = await interact( @@ -277,11 +286,11 @@ async def confirm_backup(ctx: wire.GenericContext) -> bool: "backup_device", ButtonRequestType.ResetDevice, ) - return result is trezorui2.CONFIRMED + return result is CONFIRMED async def confirm_path_warning( - ctx: wire.GenericContext, path: str, path_type: str = "Path" + ctx: GenericContext, path: str, path_type: str = "Path" ) -> None: await raise_if_not_confirmed( interact( @@ -309,9 +318,7 @@ def _show_xpub(xpub: str, title: str, cancel: str) -> ui.Layout: return content -async def show_xpub( - ctx: wire.GenericContext, xpub: str, title: str, cancel: str -) -> None: +async def show_xpub(ctx: GenericContext, xpub: str, title: str, cancel: str) -> None: await raise_if_not_confirmed( interact( ctx, @@ -323,7 +330,7 @@ async def show_xpub( async def show_address( - ctx: wire.GenericContext, + ctx: GenericContext, address: str, *, address_qr: str | None = None, @@ -351,7 +358,7 @@ async def show_address( "show_address", ButtonRequestType.Address, ) - if result is trezorui2.CONFIRMED: + if result is CONFIRMED: break result = await interact( @@ -367,7 +374,7 @@ async def show_address( "show_qr", ButtonRequestType.Address, ) - if result is trezorui2.CONFIRMED: + if result is CONFIRMED: break if is_multisig: @@ -381,12 +388,12 @@ async def show_address( "show_xpub", ButtonRequestType.PublicKey, ) - if result is trezorui2.CONFIRMED: + if result is CONFIRMED: return def show_pubkey( - ctx: wire.Context, pubkey: str, title: str = "Confirm public key" + ctx: Context, pubkey: str, title: str = "Confirm public key" ) -> Awaitable[None]: return confirm_blob( ctx, @@ -399,14 +406,14 @@ def show_pubkey( async def show_error_and_raise( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, content: str, header: str = "Error", subheader: str | None = None, button: str = "CLOSE", red: bool = False, - exc: ExceptionType = wire.ActionCancelled, + exc: ExceptionType = ActionCancelled, ) -> NoReturn: await interact( ctx, @@ -419,13 +426,13 @@ async def show_error_and_raise( ) ), br_type, - ButtonRequestType.Other, + BR_TYPE_OTHER, ) raise exc async def show_warning( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, content: str, header: str = "Warning", @@ -453,7 +460,7 @@ async def show_warning( async def show_success( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, content: str, subheader: str | None = None, @@ -477,7 +484,7 @@ async def show_success( async def confirm_output( - ctx: wire.GenericContext, + ctx: GenericContext, address: str, amount: str, font_amount: int = ui.NORMAL, # TODO cleanup @ redesign @@ -517,7 +524,7 @@ async def confirm_output( async def confirm_payment_request( - ctx: wire.GenericContext, + ctx: GenericContext, recipient_name: str, amount: str, memos: list[str], @@ -537,21 +544,21 @@ async def confirm_payment_request( "confirm_payment_request", ButtonRequestType.ConfirmOutput, ) - if result is trezorui2.CONFIRMED: + if result is CONFIRMED: return confirm.CONFIRMED - elif result is trezorui2.INFO: + elif result is INFO: return confirm.INFO else: - raise wire.ActionCancelled + raise ActionCancelled async def should_show_more( - ctx: wire.GenericContext, + ctx: GenericContext, title: str, para: Iterable[tuple[int, str]], button_text: str = "Show all", br_type: str = "should_show_more", - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, icon: str = ui.ICON_DEFAULT, icon_color: int = ui.ORANGE_ICON, confirm: str | bytes | None = None, @@ -583,27 +590,29 @@ async def should_show_more( br_code, ) - if result is trezorui2.CONFIRMED: + if result is CONFIRMED: return False - elif result is trezorui2.INFO: + elif result is INFO: return True else: - assert result is trezorui2.CANCELLED - raise wire.ActionCancelled + assert result is CANCELLED + raise ActionCancelled async def confirm_blob( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, data: bytes | str, description: str | None = None, hold: bool = False, - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, icon: str = ui.ICON_SEND, # TODO cleanup @ redesign icon_color: int = ui.GREEN, # TODO cleanup @ redesign ask_pagination: bool = False, ) -> None: + from ubinascii import hexlify + if isinstance(data, bytes): data = hexlify(data).decode() @@ -626,12 +635,12 @@ async def confirm_blob( def confirm_address( - ctx: wire.GenericContext, + ctx: GenericContext, title: str, address: str, description: str | None = "Address:", br_type: str = "confirm_address", - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, icon: str = ui.ICON_SEND, # TODO cleanup @ redesign icon_color: int = ui.GREEN, # TODO cleanup @ redesign ) -> Awaitable[None]: @@ -647,12 +656,12 @@ def confirm_address( async def confirm_text( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, data: str, description: str | None = None, - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, icon: str = ui.ICON_SEND, # TODO cleanup @ redesign icon_color: int = ui.GREEN, # TODO cleanup @ redesign ) -> None: @@ -668,12 +677,12 @@ async def confirm_text( def confirm_amount( - ctx: wire.GenericContext, + ctx: GenericContext, title: str, amount: str, description: str = "Amount:", br_type: str = "confirm_amount", - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, icon: str = ui.ICON_SEND, # TODO cleanup @ redesign icon_color: int = ui.GREEN, # TODO cleanup @ redesign ) -> Awaitable[None]: @@ -689,7 +698,7 @@ def confirm_amount( def confirm_value( - ctx: wire.GenericContext, + ctx: GenericContext, title: str, value: str, description: str, @@ -723,7 +732,7 @@ def confirm_value( async def confirm_properties( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, props: Iterable[PropertyType], @@ -733,6 +742,8 @@ async def confirm_properties( br_code: ButtonRequestType = ButtonRequestType.ConfirmOutput, ) -> None: def handle_bytes(prop): + from ubinascii import hexlify + if isinstance(prop[1], bytes): return (prop[0], hexlify(prop[1]).decode(), True) else: @@ -751,11 +762,11 @@ async def confirm_properties( br_code, ) if result is not trezorui2.CONFIRMED: - raise wire.ActionCancelled + raise ActionCancelled async def confirm_total( - ctx: wire.GenericContext, + ctx: GenericContext, total_amount: str, fee_amount: str, fee_rate_amount: str | None = None, @@ -788,7 +799,7 @@ async def confirm_total( async def confirm_joint_total( - ctx: wire.GenericContext, spending_amount: str, total_amount: str + ctx: GenericContext, spending_amount: str, total_amount: str ) -> None: await raise_if_not_confirmed( @@ -807,7 +818,7 @@ async def confirm_joint_total( async def confirm_metadata( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, content: str, @@ -856,9 +867,7 @@ async def confirm_metadata( ) -async def confirm_replacement( - ctx: wire.GenericContext, description: str, txid: str -) -> None: +async def confirm_replacement(ctx: GenericContext, description: str, txid: str) -> None: await confirm_blob( ctx, title=description.upper(), @@ -870,7 +879,7 @@ async def confirm_replacement( async def confirm_modify_output( - ctx: wire.GenericContext, + ctx: GenericContext, address: str, sign: int, amount_change: str, @@ -894,7 +903,7 @@ async def confirm_modify_output( async def confirm_modify_fee( - ctx: wire.GenericContext, + ctx: GenericContext, sign: int, user_fee_change: str, total_fee_new: str, @@ -917,7 +926,7 @@ async def confirm_modify_fee( async def confirm_coinjoin( - ctx: wire.GenericContext, max_rounds: int, max_fee_per_vbyte: str + ctx: GenericContext, max_rounds: int, max_fee_per_vbyte: str ) -> None: await raise_if_not_confirmed( interact( @@ -940,7 +949,7 @@ def show_coinjoin() -> None: # TODO cleanup @ redesign async def confirm_sign_identity( - ctx: wire.GenericContext, proto: str, identity: str, challenge_visual: str | None + ctx: GenericContext, proto: str, identity: str, challenge_visual: str | None ) -> None: await confirm_blob( ctx, @@ -953,7 +962,7 @@ async def confirm_sign_identity( async def confirm_signverify( - ctx: wire.GenericContext, coin: str, message: str, address: str, verify: bool + ctx: GenericContext, coin: str, message: str, address: str, verify: bool ) -> None: if verify: title = f"VERIFY {coin} MESSAGE" @@ -964,19 +973,19 @@ async def confirm_signverify( await confirm_blob( ctx, - title=title, - data=address, - description="Confirm address:", - br_type=br_type, + br_type, + title, + address, + "Confirm address:", br_code=ButtonRequestType.Other, ) await confirm_blob( ctx, - title=title, - data=message, - description="Confirm message:", - br_type=br_type, + br_type, + title, + message, + "Confirm message:", br_code=ButtonRequestType.Other, ) @@ -1004,7 +1013,7 @@ def draw_simple_text(title: str, description: str = "") -> None: log.error(__name__, "draw_simple_text not implemented") -async def request_passphrase_on_device(ctx: wire.GenericContext, max_len: int) -> str: +async def request_passphrase_on_device(ctx: GenericContext, max_len: int) -> str: await button_request( ctx, "passphrase_device", code=ButtonRequestType.PassphraseEntry ) @@ -1013,19 +1022,21 @@ async def request_passphrase_on_device(ctx: wire.GenericContext, max_len: int) - trezorui2.request_passphrase(prompt="Enter passphrase", max_len=max_len) ) result = await ctx.wait(keyboard) - if result is trezorui2.CANCELLED: - raise wire.ActionCancelled("Passphrase entry cancelled") + if result is CANCELLED: + raise ActionCancelled("Passphrase entry cancelled") assert isinstance(result, str) return result async def request_pin_on_device( - ctx: wire.GenericContext, + ctx: GenericContext, prompt: str, attempts_remaining: int | None, allow_cancel: bool, ) -> str: + from trezor.wire import PinCancelled + await button_request(ctx, "pin_device", code=ButtonRequestType.PinEntry) warning = "Wrong PIN" if "Wrong" in prompt else None @@ -1049,7 +1060,7 @@ async def request_pin_on_device( ) while True: result = await ctx.wait(dialog) - if result is trezorui2.CANCELLED: - raise wire.PinCancelled + if result is CANCELLED: + raise PinCancelled assert isinstance(result, str) return result diff --git a/core/src/trezor/ui/layouts/tt_v2/altcoin.py b/core/src/trezor/ui/layouts/tt_v2/altcoin.py index 7af879624..444dd1681 100644 --- a/core/src/trezor/ui/layouts/tt_v2/altcoin.py +++ b/core/src/trezor/ui/layouts/tt_v2/altcoin.py @@ -1,6 +1,5 @@ from typing import TYPE_CHECKING -from trezor import wire from trezor.enums import ButtonRequestType from trezor.ui.layouts import ( confirm_amount, @@ -11,12 +10,13 @@ from trezor.ui.layouts import ( if TYPE_CHECKING: from typing import Sequence + from trezor.wire import GenericContext pass async def confirm_total_ethereum( - ctx: wire.GenericContext, total_amount: str, gas_price: str, fee_max: str + ctx: GenericContext, total_amount: str, gas_price: str, fee_max: str ) -> None: await confirm_amount( ctx, @@ -34,7 +34,7 @@ async def confirm_total_ethereum( async def confirm_total_ripple( - ctx: wire.GenericContext, + ctx: GenericContext, address: str, amount: str, ) -> None: @@ -42,7 +42,7 @@ async def confirm_total_ripple( async def confirm_transfer_binance( - ctx: wire.GenericContext, inputs_outputs: Sequence[tuple[str, str, str]] + ctx: GenericContext, inputs_outputs: Sequence[tuple[str, str, str]] ) -> None: for title, amount, address in inputs_outputs: await confirm_blob( @@ -55,7 +55,7 @@ async def confirm_transfer_binance( async def confirm_decred_sstx_submission( - ctx: wire.GenericContext, + ctx: GenericContext, address: str, amount: str, ) -> None: diff --git a/core/src/trezor/ui/layouts/tt_v2/recovery.py b/core/src/trezor/ui/layouts/tt_v2/recovery.py index 2ec5b3b04..d4a0b85c2 100644 --- a/core/src/trezor/ui/layouts/tt_v2/recovery.py +++ b/core/src/trezor/ui/layouts/tt_v2/recovery.py @@ -1,22 +1,24 @@ from typing import TYPE_CHECKING -from trezor import strings, wire -from trezor.crypto.slip39 import MAX_SHARE_COUNT from trezor.enums import ButtonRequestType +from trezor.wire import ActionCancelled import trezorui2 -from ..common import button_request, interact +from ..common import interact from . import _RustLayout if TYPE_CHECKING: from typing import Iterable, Callable, Any + from trezor.wire import GenericContext - pass + +CONFIRMED = trezorui2.CONFIRMED # global_import_cache +INFO = trezorui2.INFO # global_import_cache async def _is_confirmed_info( - ctx: wire.GenericContext, + ctx: GenericContext, dialog: _RustLayout, info_func: Callable, ) -> bool: @@ -26,10 +28,10 @@ async def _is_confirmed_info( if result is trezorui2.INFO: await info_func(ctx) else: - return result is trezorui2.CONFIRMED + return result is CONFIRMED -async def request_word_count(ctx: wire.GenericContext, dry_run: bool) -> int: +async def request_word_count(ctx: GenericContext, dry_run: bool) -> int: selector = _RustLayout(trezorui2.select_word_count(dry_run=dry_run)) count = await interact( ctx, selector, "word_count", ButtonRequestType.MnemonicWordCount @@ -38,7 +40,7 @@ async def request_word_count(ctx: wire.GenericContext, dry_run: bool) -> int: async def request_word( - ctx: wire.GenericContext, word_index: int, word_count: int, is_slip39: bool + ctx: GenericContext, word_index: int, word_count: int, is_slip39: bool ) -> str: if is_slip39: keyboard: Any = _RustLayout( @@ -58,11 +60,14 @@ async def request_word( async def show_remaining_shares( - ctx: wire.GenericContext, + ctx: GenericContext, groups: Iterable[tuple[int, tuple[str, ...]]], # remaining + list 3 words shares_remaining: list[int], group_threshold: int, ) -> None: + from trezor import strings + from trezor.crypto.slip39 import MAX_SHARE_COUNT + pages: list[tuple[str, str]] = [] for remaining, group in groups: if 0 < remaining < MAX_SHARE_COUNT: @@ -87,12 +92,12 @@ async def show_remaining_shares( "show_shares", ButtonRequestType.Other, ) - if result is not trezorui2.CONFIRMED: - raise wire.ActionCancelled + if result is not CONFIRMED: + raise ActionCancelled async def show_group_share_success( - ctx: wire.GenericContext, share_index: int, group_index: int + ctx: GenericContext, share_index: int, group_index: int ) -> None: result = await interact( ctx, @@ -109,18 +114,20 @@ async def show_group_share_success( "share_success", ButtonRequestType.Other, ) - if result is not trezorui2.CONFIRMED: - raise wire.ActionCancelled + if result is not CONFIRMED: + raise ActionCancelled async def continue_recovery( - ctx: wire.GenericContext, + ctx: GenericContext, button_label: str, text: str, subtext: str | None, info_func: Callable | None, dry_run: bool, ) -> bool: + from ..common import button_request + title = text if subtext: title += "\n" @@ -156,4 +163,4 @@ async def continue_recovery( "recovery", ButtonRequestType.RecoveryHomepage, ) - return result is trezorui2.CONFIRMED + return result is CONFIRMED diff --git a/core/src/trezor/ui/layouts/tt_v2/reset.py b/core/src/trezor/ui/layouts/tt_v2/reset.py index b3fc1c490..56cf1bfac 100644 --- a/core/src/trezor/ui/layouts/tt_v2/reset.py +++ b/core/src/trezor/ui/layouts/tt_v2/reset.py @@ -1,7 +1,7 @@ from typing import TYPE_CHECKING -from trezor import wire -from trezor.enums import BackupType, ButtonRequestType +from trezor.enums import ButtonRequestType +from trezor.wire import ActionCancelled import trezorui2 @@ -10,8 +10,11 @@ from . import _RustLayout if TYPE_CHECKING: from typing import Callable, Sequence, List + from trezor.enums import BackupType + from trezor.wire import GenericContext - pass + +CONFIRMED = trezorui2.CONFIRMED # global_import_cache def _split_share_into_pages(share_words: Sequence[str], per_page: int = 4) -> List[str]: @@ -34,7 +37,7 @@ def _split_share_into_pages(share_words: Sequence[str], per_page: int = 4) -> Li async def show_share_words( - ctx: wire.GenericContext, + ctx: GenericContext, share_words: Sequence[str], share_index: int | None = None, group_index: int | None = None, @@ -58,8 +61,8 @@ async def show_share_words( # "confirm_backup_words", # ButtonRequestType.ResetDevice, # ) - # if result != trezorui2.CONFIRMED: - # raise wire.ActionCancelled + # if result != CONFIRMED: + # raise ActionCancelled pages = _split_share_into_pages(share_words) @@ -75,12 +78,12 @@ async def show_share_words( "backup_words", ButtonRequestType.ResetDevice, ) - if result != trezorui2.CONFIRMED: - raise wire.ActionCancelled + if result != CONFIRMED: + raise ActionCancelled async def select_word( - ctx: wire.GenericContext, + ctx: GenericContext, words: Sequence[str], share_index: int | None, checked_index: int, @@ -111,17 +114,25 @@ async def select_word( async def slip39_show_checklist( - ctx: wire.GenericContext, step: int, backup_type: BackupType + ctx: GenericContext, step: int, backup_type: BackupType ) -> None: - items = [] - if backup_type is BackupType.Slip39_Basic: - items.append("Set number of shares") - items.append("Set threshold") - items.append("Write down and check all recovery shares") - elif backup_type is BackupType.Slip39_Advanced: - items.append("Set number of groups") - items.append("Set group threshold") - items.append("Set size and threshold for each group") + from trezor.enums import BackupType + + assert backup_type in (BackupType.Slip39_Basic, BackupType.Slip39_Advanced) + + items = ( + ( + "Set number of shares", + "Set threshold", + "Write down and check all recovery shares", + ) + if backup_type == BackupType.Slip39_Basic + else ( + "Set number of groups", + "Set number of shares", + "Set size and threshold for each group", + ) + ) result = await interact( ctx, @@ -136,12 +147,12 @@ async def slip39_show_checklist( "slip39_checklist", ButtonRequestType.ResetDevice, ) - if result != trezorui2.CONFIRMED: - raise wire.ActionCancelled + if result != CONFIRMED: + raise ActionCancelled async def _prompt_number( - ctx: wire.GenericContext, + ctx: GenericContext, title: str, description: Callable[[int], str], info: Callable[[int], str], @@ -174,7 +185,7 @@ async def _prompt_number( result = (result, count) status, value = result - if status == trezorui2.CONFIRMED: + if status == CONFIRMED: assert isinstance(value, int) return value @@ -189,7 +200,7 @@ async def _prompt_number( async def slip39_prompt_threshold( - ctx: wire.GenericContext, num_of_shares: int, group_id: int | None = None + ctx: GenericContext, num_of_shares: int, group_id: int | None = None ) -> int: count = num_of_shares // 2 + 1 # min value of share threshold is 2 unless the number of shares is 1 @@ -197,7 +208,7 @@ async def slip39_prompt_threshold( min_count = min(2, num_of_shares) max_count = num_of_shares - def description(count: int): + def description(count: int) -> str: if group_id is None: if count == 1: return "For recovery you need 1 share." @@ -208,7 +219,7 @@ async def slip39_prompt_threshold( else: return f"The required number of shares to form Group {group_id + 1}." - def info(count: int): + def info(count: int) -> str: text = "The threshold sets the number of shares " if group_id is None: text += "needed to recover your wallet. " @@ -233,18 +244,18 @@ async def slip39_prompt_threshold( return await _prompt_number( ctx, - title="SET THRESHOLD", - description=description, - info=info, - count=count, - min_count=min_count, - max_count=max_count, - br_name="slip39_threshold", + "SET THRESHOLD", + description, + info, + count, + min_count, + max_count, + "slip39_threshold", ) async def slip39_prompt_number_of_shares( - ctx: wire.GenericContext, group_id: int | None = None + ctx: GenericContext, group_id: int | None = None ) -> int: count = 5 min_count = 1 @@ -266,17 +277,17 @@ async def slip39_prompt_number_of_shares( return await _prompt_number( ctx, - title="SET NUMBER OF SHARES", - description=description, - info=lambda i: info, - count=count, - min_count=min_count, - max_count=max_count, - br_name="slip39_shares", + "SET NUMBER OF SHARES", + description, + lambda i: info, + count, + min_count, + max_count, + "slip39_shares", ) -async def slip39_advanced_prompt_number_of_groups(ctx: wire.GenericContext) -> int: +async def slip39_advanced_prompt_number_of_groups(ctx: GenericContext) -> int: count = 5 min_count = 2 max_count = 16 @@ -285,18 +296,18 @@ async def slip39_advanced_prompt_number_of_groups(ctx: wire.GenericContext) -> i return await _prompt_number( ctx, - title="SET NUMBER OF GROUPS", - description=lambda i: description, - info=lambda i: info, - count=count, - min_count=min_count, - max_count=max_count, - br_name="slip39_groups", + "SET NUMBER OF GROUPS", + lambda i: description, + lambda i: info, + count, + min_count, + max_count, + "slip39_groups", ) async def slip39_advanced_prompt_group_threshold( - ctx: wire.GenericContext, num_of_groups: int + ctx: GenericContext, num_of_groups: int ) -> int: count = num_of_groups // 2 + 1 min_count = 1 @@ -306,17 +317,17 @@ async def slip39_advanced_prompt_group_threshold( return await _prompt_number( ctx, - title="SET GROUP THRESHOLD", - description=lambda i: description, - info=lambda i: info, - count=count, - min_count=min_count, - max_count=max_count, - br_name="slip39_group_threshold", + "SET GROUP THRESHOLD", + lambda i: description, + lambda i: info, + count, + min_count, + max_count, + "slip39_group_threshold", ) -async def show_warning_backup(ctx: wire.GenericContext, slip39: bool) -> None: +async def show_warning_backup(ctx: GenericContext, slip39: bool) -> None: if slip39: description = ( "Never make a digital copy of your shares and never upload them online." @@ -337,5 +348,5 @@ async def show_warning_backup(ctx: wire.GenericContext, slip39: bool) -> None: "backup_warning", ButtonRequestType.ResetDevice, ) - if result != trezorui2.CONFIRMED: - raise wire.ActionCancelled + if result != CONFIRMED: + raise ActionCancelled diff --git a/core/src/trezor/ui/layouts/tt_v2/webauthn.py b/core/src/trezor/ui/layouts/tt_v2/webauthn.py index d989403c5..4a0e09eae 100644 --- a/core/src/trezor/ui/layouts/tt_v2/webauthn.py +++ b/core/src/trezor/ui/layouts/tt_v2/webauthn.py @@ -1,15 +1,15 @@ from typing import TYPE_CHECKING -from trezor import wire - from ...components.common.webauthn import ConfirmInfo if TYPE_CHECKING: + from trezor.wire import GenericContext + Pageable = object async def confirm_webauthn( - ctx: wire.GenericContext | None, + ctx: GenericContext | None, info: ConfirmInfo, pageable: Pageable | None = None, ) -> bool: