From cf3687263fc8dc0c83ad9f644a3944ebadac6ae6 Mon Sep 17 00:00:00 2001 From: grdddj Date: Fri, 30 Dec 2022 12:59:42 +0100 Subject: [PATCH] WIP - fixes after rebase --- core/embed/rust/src/ui/geometry.rs | 4 - core/src/all_modules.py | 78 +------- core/src/apps/common/passphrase.py | 13 +- core/src/apps/ethereum/layout.py | 1 - core/src/apps/ethereum/networks.py | 9 +- core/src/apps/ethereum/tokens.py | 20 -- core/src/apps/homescreen/t1.py | 50 ----- core/src/apps/homescreen/tr.py | 78 -------- core/src/apps/homescreen/tt.py | 116 ----------- .../management/recovery_device/homescreen.py | 4 +- core/src/trezor/ui/components/tr/text.py | 43 ----- core/src/trezor/ui/layouts/recovery.py | 2 + core/src/trezor/ui/layouts/reset.py | 2 + core/src/trezor/ui/layouts/tr/__init__.py | 180 +++++++----------- core/src/trezor/ui/layouts/tr/fido.py | 21 ++ core/src/trezor/ui/layouts/tr/webauthn.py | 19 -- core/src/trezor/ui/layouts/tt_v2/__init__.py | 7 - python/src/trezorlib/debuglink.py | 1 - .../test_recovery_bip39_dryrun.py | 3 +- 19 files changed, 97 insertions(+), 554 deletions(-) delete mode 100644 core/src/apps/homescreen/t1.py delete mode 100644 core/src/apps/homescreen/tr.py delete mode 100644 core/src/apps/homescreen/tt.py delete mode 100644 core/src/trezor/ui/components/tr/text.py create mode 100644 core/src/trezor/ui/layouts/tr/fido.py delete mode 100644 core/src/trezor/ui/layouts/tr/webauthn.py diff --git a/core/embed/rust/src/ui/geometry.rs b/core/embed/rust/src/ui/geometry.rs index 73cadc9044..cad6cb7ef5 100644 --- a/core/embed/rust/src/ui/geometry.rs +++ b/core/embed/rust/src/ui/geometry.rs @@ -313,10 +313,6 @@ impl Rect { self.bottom_left().center(self.bottom_right()) } - pub const fn top_center(&self) -> Point { - self.top_left().center(self.top_right()) - } - pub const fn left_center(&self) -> Point { self.bottom_left().center(self.top_left()) } diff --git a/core/src/all_modules.py b/core/src/all_modules.py index 2c7eae69f2..98e1a34694 100644 --- a/core/src/all_modules.py +++ b/core/src/all_modules.py @@ -149,50 +149,6 @@ trezor.ui import trezor.ui trezor.ui.components.common.confirm import trezor.ui.components.common.confirm -trezor.ui.components.common.text -import trezor.ui.components.common.text -trezor.ui.components.tr.text -import trezor.ui.components.tr.text -trezor.ui.components.tt.button -import trezor.ui.components.tt.button -trezor.ui.components.tt.checklist -import trezor.ui.components.tt.checklist -trezor.ui.components.tt.confirm -import trezor.ui.components.tt.confirm -trezor.ui.components.tt.info -import trezor.ui.components.tt.info -trezor.ui.components.tt.keyboard_bip39 -import trezor.ui.components.tt.keyboard_bip39 -trezor.ui.components.tt.keyboard_slip39 -import trezor.ui.components.tt.keyboard_slip39 -trezor.ui.components.tt.num_input -import trezor.ui.components.tt.num_input -trezor.ui.components.tt.passphrase -import trezor.ui.components.tt.passphrase -trezor.ui.components.tt.pin -import trezor.ui.components.tt.pin -trezor.ui.components.tt.recovery -import trezor.ui.components.tt.recovery -trezor.ui.components.tt.reset -import trezor.ui.components.tt.reset -trezor.ui.components.tt.scroll -import trezor.ui.components.tt.scroll -trezor.ui.components.tt.swipe -import trezor.ui.components.tt.swipe -trezor.ui.components.tt.text -import trezor.ui.components.tt.text -trezor.ui.components.tt.word_select -import trezor.ui.components.tt.word_select -trezor.ui.constants -import trezor.ui.constants -trezor.ui.constants.t1 -import trezor.ui.constants.t1 -trezor.ui.constants.tr -import trezor.ui.constants.tr -trezor.ui.constants.tt -import trezor.ui.constants.tt -trezor.ui.container -import trezor.ui.container trezor.ui.layouts import trezor.ui.layouts trezor.ui.layouts.common @@ -209,18 +165,12 @@ trezor.ui.layouts.tr import trezor.ui.layouts.tr trezor.ui.layouts.tr.altcoin import trezor.ui.layouts.tr.altcoin +trezor.ui.layouts.tr.fido +import trezor.ui.layouts.tr.fido trezor.ui.layouts.tr.recovery import trezor.ui.layouts.tr.recovery trezor.ui.layouts.tr.reset import trezor.ui.layouts.tr.reset -trezor.ui.layouts.tt -import trezor.ui.layouts.tt -trezor.ui.layouts.tt.altcoin -import trezor.ui.layouts.tt.altcoin -trezor.ui.layouts.tt.recovery -import trezor.ui.layouts.tt.recovery -trezor.ui.layouts.tt.reset -import trezor.ui.layouts.tt.reset trezor.ui.layouts.tt_v2 import trezor.ui.layouts.tt_v2 trezor.ui.layouts.tt_v2.fido @@ -357,18 +307,6 @@ apps.debug.load_device import apps.debug.load_device apps.homescreen import apps.homescreen -apps.homescreen.busyscreen -import apps.homescreen.busyscreen -apps.homescreen.homescreen -import apps.homescreen.homescreen -apps.homescreen.lockscreen -import apps.homescreen.lockscreen -apps.homescreen.t1 -import apps.homescreen.t1 -apps.homescreen.tr -import apps.homescreen.tr -apps.homescreen.tt -import apps.homescreen.tt apps.management import apps.management apps.management.apply_flags @@ -477,18 +415,6 @@ if not utils.BITCOIN_ONLY: import trezor.enums.TezosBallotType trezor.enums.TezosContractType import trezor.enums.TezosContractType - trezor.ui.components.common.webauthn - import trezor.ui.components.common.webauthn - trezor.ui.components.tt.webauthn - import trezor.ui.components.tt.webauthn - trezor.ui.layouts.tr.webauthn - import trezor.ui.layouts.tr.webauthn - trezor.ui.layouts.tt.webauthn - import trezor.ui.layouts.tt.webauthn - trezor.ui.layouts.tt_v2.webauthn - import trezor.ui.layouts.tt_v2.webauthn - trezor.ui.layouts.webauthn - import trezor.ui.layouts.webauthn apps.binance import apps.binance apps.binance.get_address diff --git a/core/src/apps/common/passphrase.py b/core/src/apps/common/passphrase.py index 7ffc1fcf2a..b3ee9159ab 100644 --- a/core/src/apps/common/passphrase.py +++ b/core/src/apps/common/passphrase.py @@ -38,12 +38,9 @@ async def get(ctx: Context) -> str: async def _request_on_host(ctx: Context) -> str: from trezor.messages import PassphraseAck, PassphraseRequest - from trezor.ui.layouts import draw_simple_text + from trezor.ui.layouts import request_passphrase_on_host - # _entry_dialog - draw_simple_text( - "Passphrase entry", "Please type your\npassphrase on the\nconnected host." - ) + request_passphrase_on_host() request = PassphraseRequest() ack = await ctx.call(request, PassphraseAck) @@ -83,9 +80,3 @@ async def _request_on_host(ctx: Context) -> str: ) return passphrase - - -def _entry_dialog() -> None: - from trezor.ui.layouts import request_passphrase_on_host - - request_passphrase_on_host() diff --git a/core/src/apps/ethereum/layout.py b/core/src/apps/ethereum/layout.py index fdc3937580..72513517f9 100644 --- a/core/src/apps/ethereum/layout.py +++ b/core/src/apps/ethereum/layout.py @@ -11,7 +11,6 @@ from trezor.ui.layouts import ( should_show_more, ) -from ..management import text_r from . import networks from .helpers import decode_typed_data diff --git a/core/src/apps/ethereum/networks.py b/core/src/apps/ethereum/networks.py index 26730b04b5..e8b5ecad37 100644 --- a/core/src/apps/ethereum/networks.py +++ b/core/src/apps/ethereum/networks.py @@ -1046,7 +1046,7 @@ def _networks_iterator() -> Iterator[NetworkInfoTuple]: 1246, # chain_id 60, # slip44 "OM", # shortcut - "OM Platform", # name + "OM Chain", # name False, # rskip60 ) yield ( @@ -1819,13 +1819,6 @@ def _networks_iterator() -> Iterator[NetworkInfoTuple]: "OpenChain", # name False, # rskip60 ) - yield ( - 846000, # chain_id - 60, # slip44 - "APTA", # shortcut - "4GoodNetwork", # name - False, # rskip60 - ) yield ( 888888, # chain_id 60, # slip44 diff --git a/core/src/apps/ethereum/tokens.py b/core/src/apps/ethereum/tokens.py index b0f66afb43..2c19620ab9 100644 --- a/core/src/apps/ethereum/tokens.py +++ b/core/src/apps/ethereum/tokens.py @@ -45,11 +45,6 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int]]: "$TEAK", 18, ) - yield ( # address, symbol, decimals - b"\x88\x1b\xa0\x5d\xe1\xe7\x8f\x54\x9c\xc6\x3a\x8f\x6c\xab\xb1\xd4\xad\x32\x25\x0d", - "00", - 18, - ) yield ( # address, symbol, decimals b"\xb6\xed\x76\x44\xc6\x94\x16\xd6\x7b\x52\x2e\x20\xbc\x29\x4a\x9a\x9b\x40\x5b\x31", "0xBTC", @@ -4760,11 +4755,6 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int]]: "OGN", 18, ) - yield ( # address, symbol, decimals - b"\x9c\x35\x45\x03\xc3\x84\x81\xa7\xa7\xa5\x16\x29\x14\x29\x63\xf9\x8e\xcc\x12\xd0", - "OGV", - 18, - ) yield ( # address, symbol, decimals b"\x21\xe1\x3c\xb3\xf3\xf2\x6f\x92\xa6\x2a\xc7\xad\xab\x40\x93\xe8\x99\x7d\x1f\xb1", "OIKOS", @@ -8325,11 +8315,6 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int]]: "VENUS", 3, ) - yield ( # address, symbol, decimals - b"\x0c\x45\x76\xca\x1c\x36\x58\x68\xe1\x62\x55\x4a\xf8\xe3\x85\xdc\x3e\x7c\x66\xd9", - "veOGV", - 18, - ) yield ( # address, symbol, decimals b"\x8f\x34\x70\xa7\x38\x8c\x05\xee\x4e\x7a\xf3\xd0\x1d\x8c\x72\x2b\x0f\xf5\x23\x74", "VERI", @@ -8605,11 +8590,6 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int]]: "WOC", 0, ) - yield ( # address, symbol, decimals - b"\xd2\xaf\x83\x0e\x8c\xbd\xfe\xd6\xcc\x11\xba\xb6\x97\xbb\x25\x49\x6e\xd6\xfa\x62", - "WOUSD", - 18, - ) yield ( # address, symbol, decimals b"\x62\x08\x72\x45\x08\x71\x25\xd3\xdb\x5b\x9a\x3d\x71\x3d\x78\xe7\xbb\xc3\x1e\x54", "WPC", diff --git a/core/src/apps/homescreen/t1.py b/core/src/apps/homescreen/t1.py deleted file mode 100644 index 4cd22231f3..0000000000 --- a/core/src/apps/homescreen/t1.py +++ /dev/null @@ -1,50 +0,0 @@ -import storage -import storage.cache -import storage.device -from trezor import loop, ui - -from . import HomescreenBase, render_header_and_refresh - - -class Homescreen(HomescreenBase): - """Homescreen for model 1.""" - - RENDER_INDICATOR = storage.cache.HOMESCREEN_ON - - def __init__(self) -> None: - super().__init__() - if not storage.device.is_initialized(): - self.label = "Go to trezor.io/start" - - def do_render(self) -> None: - with render_header_and_refresh(): - ui.display.icon(33, 14, self.get_avatar(), ui.style.FG, ui.style.BG) - ui.display.text_center(ui.WIDTH // 2, 60, self.label, ui.BOLD, ui.FG, ui.BG) - - -class Lockscreen(HomescreenBase): - """Lockscreen for model 1.""" - - BACKLIGHT_LEVEL = ui.BACKLIGHT_LOW - RENDER_SLEEP = loop.SLEEP_FOREVER - RENDER_INDICATOR = storage.cache.LOCKSCREEN_ON - - def __init__(self, bootscreen: bool = False) -> None: - if bootscreen: - self.BACKLIGHT_LEVEL = ui.BACKLIGHT_NORMAL - self.lock_label = "Not connected" - self.tap_label = "Click to connect" - else: - self.lock_label = "Locked" - self.tap_label = "Click to unlock" - - super().__init__() - - def do_render(self) -> None: - ui.header_warning(self.lock_label) - ui.display.icon(33, 14, self.get_avatar(), ui.style.FG, ui.style.BG) - ui.display.text_center(ui.WIDTH // 2, 60, self.label, ui.BOLD, ui.FG, ui.BG) - - def on_button_released(self, _x: int) -> None: - """Going to the PIN screen after pressing any button.""" - raise ui.Result(None) diff --git a/core/src/apps/homescreen/tr.py b/core/src/apps/homescreen/tr.py deleted file mode 100644 index 3090ab1c55..0000000000 --- a/core/src/apps/homescreen/tr.py +++ /dev/null @@ -1,78 +0,0 @@ -import storage -import storage.cache -import storage.device -from trezor import loop, ui - -from . import HomescreenBase, render_header_and_refresh - - -class Homescreen(HomescreenBase): - """Homescreen for model R.""" - - RENDER_INDICATOR = storage.cache.HOMESCREEN_ON - - def __init__(self) -> None: - super().__init__() - - def do_render(self) -> None: - with render_header_and_refresh(): - # When not initialized, showing the instruction text on two lines, - # as it cannot all fit on one line. In that case also putting - # the icon more on the top. - # Otherwise just showing the uppercase label in monospace. - if not storage.device.is_initialized(): - ui.display.icon(32, 5, self.get_avatar(), ui.style.FG, ui.style.BG) - ui.display.text_center( - ui.WIDTH // 2, 52, "Go to", ui.BOLD, ui.FG, ui.BG - ) - ui.display.text_center( - ui.WIDTH // 2, 60, "trezor.io/start", ui.BOLD, ui.FG, ui.BG - ) - else: - ui.display.icon(32, 11, self.get_avatar(), ui.style.FG, ui.style.BG) - ui.display.text_center( - ui.WIDTH // 2, 60, self.label.upper(), ui.MONO, ui.FG, ui.BG - ) - - -class Lockscreen(HomescreenBase): - """Lockscreen for model R.""" - - BACKLIGHT_LEVEL = ui.BACKLIGHT_LOW - RENDER_SLEEP = loop.SLEEP_FOREVER - RENDER_INDICATOR = storage.cache.LOCKSCREEN_ON - - def __init__(self, bootscreen: bool = False) -> None: - if bootscreen: - self.BACKLIGHT_LEVEL = ui.BACKLIGHT_NORMAL - self.lock_label = "Not connected" - self.tap_label = "Click to connect" - else: - self.lock_label = "Locked" - self.tap_label = "Click to unlock" - - super().__init__() - - def do_render(self) -> None: - ui.display.text_center( - ui.WIDTH // 2, 9, self.label.upper(), ui.MONO, ui.FG, ui.BG - ) - ui.display.icon(32, 11, self.get_avatar(), ui.style.FG, ui.style.BG) - - # Lock icon placement depends on the lock_label text - lock_icon = ui.res.load("trezor/res/model_r/lock.toif") - if self.lock_label == "Not connected": - ui.display.icon(13, 45, lock_icon, ui.style.FG, ui.style.BG) - else: - ui.display.icon(38, 45, lock_icon, ui.style.FG, ui.style.BG) - - ui.display.text_center( - ui.WIDTH // 2 + 10, 52, self.lock_label.upper(), ui.NORMAL, ui.FG, ui.BG - ) - ui.display.text_center( - ui.WIDTH // 2, 60, self.tap_label.upper(), ui.MONO, ui.FG, ui.BG - ) - - def on_button_released(self, _x: int) -> None: - """Going to the PIN screen after pressing any button.""" - raise ui.Result(None) diff --git a/core/src/apps/homescreen/tt.py b/core/src/apps/homescreen/tt.py deleted file mode 100644 index 00594ac5d0..0000000000 --- a/core/src/apps/homescreen/tt.py +++ /dev/null @@ -1,116 +0,0 @@ -import utime -from micropython import const - -import storage -import storage.cache -import storage.device -from trezor import config, loop, res, ui -from trezor.ui.loader import Loader, LoaderNeutral - -from . import HomescreenBase, render_header_and_refresh - -_LOADER_DELAY_MS = const(500) -_LOADER_TOTAL_MS = const(2500) - - -class Homescreen(HomescreenBase): - """Homescreen for model T.""" - - RENDER_INDICATOR = storage.cache.HOMESCREEN_ON - - def __init__(self) -> None: - super().__init__() - if not storage.device.is_initialized(): - self.label = "Go to trezor.io/start" - - self.loader = Loader( - style=LoaderNeutral, - target_ms=_LOADER_TOTAL_MS - _LOADER_DELAY_MS, - offset_y=-10, - reverse_speedup=3, - ) - self.touch_ms: int | None = None - - def do_render(self) -> None: - with render_header_and_refresh(): - ui.display.avatar(48, 48 - 10, self.get_avatar(), ui.WHITE, ui.BLACK) - ui.display.text_center( - ui.WIDTH // 2, 220, self.label, ui.BOLD, ui.FG, ui.BG - ) - - def on_touch_start(self, _x: int, _y: int) -> None: - if self.loader.start_ms is not None: - self.loader.start() - elif config.has_pin(): - self.touch_ms = utime.ticks_ms() - - def on_touch_end(self, _x: int, _y: int) -> None: - if self.loader.start_ms is not None: - self.set_repaint(True) - self.loader.stop() - self.touch_ms = None - - # raise here instead of self.loader.on_finish so as not to send TOUCH_END to the lockscreen - if self.loader.elapsed_ms() >= self.loader.target_ms: - raise ui.Result(None) - - def _loader_start(self) -> None: - ui.display.clear() - ui.display.text_center(ui.WIDTH // 2, 35, "Hold to lock", ui.BOLD, ui.FG, ui.BG) - self.loader.start() - - def dispatch(self, event: int, x: int, y: int) -> None: - if ( - self.touch_ms is not None - and self.touch_ms + _LOADER_DELAY_MS < utime.ticks_ms() - ): - self.touch_ms = None - self._loader_start() - - if event is ui.RENDER and self.loader.start_ms is not None: - self.loader.dispatch(event, x, y) - else: - super().dispatch(event, x, y) - - -class Lockscreen(HomescreenBase): - """Lockscreen for model T.""" - - BACKLIGHT_LEVEL = ui.BACKLIGHT_LOW - RENDER_SLEEP = loop.SLEEP_FOREVER - RENDER_INDICATOR = storage.cache.LOCKSCREEN_ON - - def __init__(self, bootscreen: bool = False) -> None: - if bootscreen: - self.BACKLIGHT_LEVEL = ui.BACKLIGHT_NORMAL - self.lock_label = "Not connected" - self.tap_label = "Tap to connect" - else: - self.lock_label = "Locked" - self.tap_label = "Tap to unlock" - - super().__init__() - - def do_render(self) -> None: - # homescreen with label text on top - ui.display.text_center( - ui.WIDTH // 2, 35, self.label, ui.BOLD, ui.TITLE_GREY, ui.BG - ) - ui.display.avatar(48, 48, self.get_avatar(), ui.WHITE, ui.BLACK) - - # lock bar - ui.display.bar_radius(40, 100, 160, 40, ui.TITLE_GREY, ui.BG, 4) - ui.display.bar_radius(42, 102, 156, 36, ui.BG, ui.TITLE_GREY, 4) - ui.display.text_center( - ui.WIDTH // 2, 128, self.lock_label, ui.BOLD, ui.TITLE_GREY, ui.BG - ) - - # "tap to unlock" - ui.display.text_center( - ui.WIDTH // 2 + 10, 220, self.tap_label, ui.BOLD, ui.TITLE_GREY, ui.BG - ) - ui.display.icon(45, 202, res.load(ui.ICON_CLICK), ui.TITLE_GREY, ui.BG) - - def on_touch_end(self, _x: int, _y: int) -> None: - """Going to the PIN screen after tapping the display.""" - raise ui.Result(None) diff --git a/core/src/apps/management/recovery_device/homescreen.py b/core/src/apps/management/recovery_device/homescreen.py index 7b5e3644aa..3328187d96 100644 --- a/core/src/apps/management/recovery_device/homescreen.py +++ b/core/src/apps/management/recovery_device/homescreen.py @@ -65,9 +65,7 @@ async def _continue_recovery_process(ctx: GenericContext) -> Success: if is_first_step: # If we are starting recovery, ask for word count first... # _request_word_count - await layout.homescreen_dialog( - ctx, "Select", "Select the number of words" - ) + await layout.homescreen_dialog(ctx, "Select", "Select the number of words") # ask for the number of words word_count = await layout.request_word_count(ctx, dry_run) # ...and only then show the starting screen with word count. diff --git a/core/src/trezor/ui/components/tr/text.py b/core/src/trezor/ui/components/tr/text.py deleted file mode 100644 index fb03007a84..0000000000 --- a/core/src/trezor/ui/components/tr/text.py +++ /dev/null @@ -1,43 +0,0 @@ -from trezor import res, ui -from trezor.ui import display, style - -from ..common.text import TEXT_HEADER_HEIGHT, TEXT_LINE_HEIGHT, TextBase, render_text - - -def header( - title: str, - icon: str = style.ICON_DEFAULT, - fg: int = style.FG, - bg: int = style.BG, - ifg: int = style.GREEN, -) -> None: - if icon is not None: - display.icon(2, 2, res.load(icon), ifg, bg) - display.text(35, 18, title, ui.BOLD, fg, bg) - - -class Text(TextBase): - def on_render(self) -> None: - if self.repaint: - offset_y = TEXT_LINE_HEIGHT - if self.header_text is not None: - header( - self.header_text, - self.header_icon, - ui.TITLE_GREY, - ui.BG, - self.icon_color, - ) - offset_y = TEXT_HEADER_HEIGHT + TEXT_LINE_HEIGHT - render_text( - self.content, - self.new_lines, - self.max_lines, - item_offset=self.content_offset, - char_offset=self.char_offset, - break_words=self.break_words, - line_width=self.line_width, - render_page_overflow=self.render_page_overflow, - offset_y=offset_y, - ) - self.repaint = False diff --git a/core/src/trezor/ui/layouts/recovery.py b/core/src/trezor/ui/layouts/recovery.py index 226335b6db..adcd40786d 100644 --- a/core/src/trezor/ui/layouts/recovery.py +++ b/core/src/trezor/ui/layouts/recovery.py @@ -1,3 +1,5 @@ +from trezor import utils + if utils.MODEL in ("T",): from .tt_v2.recovery import * # noqa: F401,F403 elif utils.MODEL in ("R",): diff --git a/core/src/trezor/ui/layouts/reset.py b/core/src/trezor/ui/layouts/reset.py index 81a01e2572..538af3ed54 100644 --- a/core/src/trezor/ui/layouts/reset.py +++ b/core/src/trezor/ui/layouts/reset.py @@ -1,3 +1,5 @@ +from trezor import utils + if utils.MODEL in ("T",): from .tt_v2.reset import * # noqa: F401,F403 elif utils.MODEL in ("R",): diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index bebb63282e..fa2846f573 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -1,19 +1,17 @@ from typing import TYPE_CHECKING, Sequence -from ubinascii import hexlify from trezor import io, log, loop, ui, wire, workflow from trezor.enums import ButtonRequestType from trezor.utils import DISABLE_ANIMATION -from trezor.ui.popup import Popup import trezorui2 -from ...components.tr.text import Text from ..common import button_request, interact if TYPE_CHECKING: from typing import Any, NoReturn, Type, Awaitable, Iterable, TypeVar + from trezor.wire import GenericContext, Context from ..common import PropertyType T = TypeVar("T") @@ -21,6 +19,9 @@ if TYPE_CHECKING: ExceptionType = BaseException | Type[BaseException] +BR_TYPE_OTHER = ButtonRequestType.Other # global_import_cache + + if __debug__: trezorui2.disable_animation(bool(DISABLE_ANIMATION)) @@ -282,7 +283,7 @@ class RustLayout(ui.Layout): Only `UP` and `DOWN` directions are supported. """ - from trezor.ui.components.common import ( + from trezor.ui import ( SWIPE_UP, SWIPE_DOWN, ) @@ -305,7 +306,7 @@ class RustLayout(ui.Layout): Waits for `swipe_signal` and carries it out. """ from apps.debug import swipe_signal - from trezor.ui.components.common import SWIPE_ALL_THE_WAY_UP, SWIPE_UP + from trezor.ui import SWIPE_ALL_THE_WAY_UP, SWIPE_UP while True: direction = await swipe_signal() @@ -396,12 +397,12 @@ class RustLayout(ui.Layout): # Temporary function, so we know where it is used # Should be gradually replaced by custom designs/layouts async def _placeholder_confirm( - 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, ) -> Any: return await raise_if_cancelled( confirm_text( @@ -416,7 +417,7 @@ async def _placeholder_confirm( async def get_bool( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, data: str | None = None, @@ -425,7 +426,7 @@ async def get_bool( verb_cancel: str | None = "", hold: bool = False, reverse: bool = False, - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> bool: result = await interact( ctx, @@ -458,7 +459,7 @@ async def raise_if_cancelled(a: Awaitable[T], exc: Any = wire.ActionCancelled) - # `description` strings for model R, as those for model T # have newlines at random places (suitable for T). async def confirm_action( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, action: str | None = None, @@ -470,7 +471,7 @@ async def confirm_action( hold: bool = False, reverse: bool = False, exc: ExceptionType = wire.ActionCancelled, - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> None: if verb_cancel is not None: verb_cancel = verb_cancel.upper() @@ -513,7 +514,7 @@ async def confirm_action( async def confirm_reset_device( - ctx: wire.GenericContext, + ctx: GenericContext, prompt: str, recovery: bool = False, show_tutorial: bool = True, @@ -545,7 +546,7 @@ async def confirm_reset_device( # TODO cleanup @ redesign -async def confirm_backup(ctx: wire.GenericContext) -> bool: +async def confirm_backup(ctx: GenericContext) -> bool: if await get_bool( ctx=ctx, title="SUCCESS", @@ -571,7 +572,7 @@ async def confirm_backup(ctx: wire.GenericContext) -> bool: async def confirm_path_warning( - ctx: wire.GenericContext, path: str, path_type: str = "Path" + ctx: GenericContext, path: str, path_type: str = "Path" ) -> None: return await _placeholder_confirm( ctx=ctx, @@ -595,9 +596,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_cancelled( interact( ctx, @@ -609,7 +608,7 @@ async def show_xpub( async def show_address( - ctx: wire.GenericContext, + ctx: GenericContext, address: str, *, case_sensitive: bool = True, @@ -680,7 +679,7 @@ async def show_address( 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, @@ -692,7 +691,7 @@ def show_pubkey( async def _show_modal( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, br_code: ButtonRequestType, header: str, @@ -700,8 +699,6 @@ async def _show_modal( content: str, button_confirm: str | None, button_cancel: str | None, - icon: str, - icon_color: int, exc: ExceptionType = wire.ActionCancelled, ) -> None: await confirm_action( @@ -718,7 +715,7 @@ async def _show_modal( async def show_error_and_raise( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, content: str, header: str = "Error", @@ -730,29 +727,25 @@ async def show_error_and_raise( await _show_modal( ctx=ctx, br_type=br_type, - br_code=ButtonRequestType.Other, + br_code=BR_TYPE_OTHER, header=header, subheader=subheader, content=content, button_confirm=None, button_cancel=button, - icon=ui.ICON_WRONG, - icon_color=ui.RED if red else ui.ORANGE_ICON, exc=exc, ) raise exc def show_warning( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, content: str, header: str = "Warning", subheader: str | None = None, button: str = "Try again", br_code: ButtonRequestType = ButtonRequestType.Warning, - icon: str = ui.ICON_WRONG, - icon_color: int = ui.RED, ) -> Awaitable[None]: return _show_modal( ctx, @@ -763,13 +756,11 @@ def show_warning( content=content, button_confirm=button, button_cancel=None, - icon=icon, - icon_color=icon_color, ) def show_success( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, content: str, subheader: str | None = None, @@ -784,13 +775,11 @@ def show_success( content=content, button_confirm=button, button_cancel=None, - icon=ui.ICON_CONFIRM, - icon_color=ui.GREEN, ) async def confirm_output( - ctx: wire.GenericContext, + ctx: GenericContext, address: str, amount: str, subtitle: str = "", @@ -827,8 +816,8 @@ async def confirm_output( async def tutorial( - ctx: wire.GenericContext, - br_code: ButtonRequestType = ButtonRequestType.Other, + ctx: GenericContext, + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> None: """Showing users how to interact with the device.""" await interact( @@ -840,7 +829,7 @@ async def tutorial( async def confirm_payment_request( - ctx: wire.GenericContext, + ctx: GenericContext, recipient_name: str, amount: str, memos: list[str], @@ -857,16 +846,13 @@ async def confirm_payment_request( async def should_show_more( - ctx: wire.GenericContext, + ctx: GenericContext, title: str, para: Iterable[tuple[int, str]], button_text: str = "Show all", - confirm: str = "Show all", br_type: str = "should_show_more", - major_confirm: bool = True, - br_code: ButtonRequestType = ButtonRequestType.Other, - icon: str = ui.ICON_DEFAULT, - icon_color: int = ui.ORANGE_ICON, + br_code: ButtonRequestType = BR_TYPE_OTHER, + confirm: str | bytes | None = None, ) -> bool: return await get_bool( ctx=ctx, @@ -878,13 +864,13 @@ async def should_show_more( 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, ask_pagination: bool = False, ) -> None: await _placeholder_confirm( @@ -898,14 +884,12 @@ async def confirm_blob( async 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, - icon: str = ui.ICON_SEND, # TODO cleanup @ redesign - icon_color: int = ui.GREEN, # TODO cleanup @ redesign + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> Awaitable[None]: return confirm_blob( ctx=ctx, @@ -918,14 +902,12 @@ async 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, - icon: str = ui.ICON_SEND, # TODO cleanup @ redesign - icon_color: int = ui.GREEN, # TODO cleanup @ redesign + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> Any: return await interact( ctx, @@ -942,14 +924,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, - icon: str = ui.ICON_SEND, # TODO cleanup @ redesign - icon_color: int = ui.GREEN, # TODO cleanup @ redesign + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> Awaitable[None]: return _placeholder_confirm( ctx=ctx, @@ -962,20 +942,14 @@ def confirm_amount( async def confirm_properties( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, props: Iterable[PropertyType], - icon: str = ui.ICON_SEND, # TODO cleanup @ redesign - icon_color: int = ui.GREEN, # TODO cleanup @ redesign hold: bool = False, br_code: ButtonRequestType = ButtonRequestType.ConfirmOutput, ) -> None: - def handle_bytes(prop: PropertyType): - if isinstance(prop[1], bytes): - return (prop[0], hexlify(prop[1]).decode(), True) - else: - return (prop[0], prop[1], False) + items = [(prop[0], prop[1], isinstance(prop[1], bytes)) for prop in props] await raise_if_cancelled( interact( @@ -983,7 +957,7 @@ async def confirm_properties( RustLayout( trezorui2.confirm_properties( title=title.upper(), - items=map(handle_bytes, props), + items=items, hold=hold, ) ), @@ -994,7 +968,7 @@ async def confirm_properties( async def confirm_total( - ctx: wire.GenericContext, + ctx: GenericContext, total_amount: str, fee_amount: str, fee_rate_amount: str | None = None, @@ -1025,7 +999,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 _placeholder_confirm( ctx=ctx, @@ -1038,7 +1012,7 @@ async def confirm_joint_total( async def confirm_metadata( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, content: str, @@ -1062,9 +1036,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 _placeholder_confirm( ctx=ctx, br_type="confirm_replacement", @@ -1076,7 +1048,7 @@ async def confirm_replacement( async def confirm_modify_output( - ctx: wire.GenericContext, + ctx: GenericContext, address: str, sign: int, amount_change: str, @@ -1100,7 +1072,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, @@ -1130,7 +1102,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 _placeholder_confirm( ctx=ctx, @@ -1138,7 +1110,7 @@ async def confirm_coinjoin( title="AUTHORIZE COINJOIN", data=f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte}", description="", - br_code=ButtonRequestType.Other, + br_code=BR_TYPE_OTHER, ) @@ -1148,7 +1120,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: text = "" if challenge_visual: @@ -1161,12 +1133,12 @@ async def confirm_sign_identity( title=f"Sign {proto}".upper(), data=text, description="", - br_code=ButtonRequestType.Other, + br_code=BR_TYPE_OTHER, ) 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: header = f"Verify {coin} message" @@ -1181,7 +1153,7 @@ async def confirm_signverify( title=header.upper(), data=f"Confirm address:\n{address}", description="", - br_code=ButtonRequestType.Other, + br_code=BR_TYPE_OTHER, ) await _placeholder_confirm( @@ -1190,7 +1162,7 @@ async def confirm_signverify( title=header.upper(), data=f"Confirm message:\n{message}", description="", - br_code=ButtonRequestType.Other, + br_code=BR_TYPE_OTHER, ) @@ -1200,33 +1172,11 @@ async def show_popup( subtitle: str | None = None, description_param: str = "", timeout_ms: int = 3000, - icon: str = ui.ICON_WRONG, ) -> None: - text = Text(title, icon) - # Need to add two newlines at the beginning of the text, - # so it is not colliding with the icon - if subtitle is not None: - subtitle = f"\n\n{subtitle}" - text.bold(subtitle) - text.br_half() - else: - description = f"\n\n{description}" - text.format_parametrized(description, description_param) - await Popup(text, timeout_ms) + raise NotImplementedError -def draw_simple_text( - title: str, description: str = "", icon: str = ui.ICON_CONFIG -) -> None: - text = Text(title, icon, new_lines=False) - # Need to add two newlines at the beginning of the text, - # so it is not colliding with the icon - description = f"\n\n{description}" - text.normal(description) - ui.draw_simple(text) - - -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 ) @@ -1247,7 +1197,7 @@ async def request_passphrase_on_device(ctx: wire.GenericContext, max_len: int) - async def request_pin_on_device( - ctx: wire.GenericContext, + ctx: GenericContext, prompt: str, attempts_remaining: int | None, allow_cancel: bool, @@ -1278,9 +1228,9 @@ async def request_pin_on_device( async def confirm_reenter_pin( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str = "set_pin", - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> None: return await confirm_action( ctx, @@ -1293,9 +1243,9 @@ async def confirm_reenter_pin( async def pin_mismatch( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str = "set_pin", - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> None: return await confirm_action( ctx, @@ -1309,12 +1259,12 @@ async def pin_mismatch( async def confirm_pin_action( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, action: str | None, description: str | None = "Do you really want to", - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> None: return await confirm_action( ctx, @@ -1326,13 +1276,13 @@ async def confirm_pin_action( async def confirm_set_new_pin( - ctx: wire.GenericContext, + ctx: GenericContext, br_type: str, title: str, action: str, information: list[str], description: str = "Do you want to", - br_code: ButtonRequestType = ButtonRequestType.Other, + br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> None: await confirm_action( ctx, diff --git a/core/src/trezor/ui/layouts/tr/fido.py b/core/src/trezor/ui/layouts/tr/fido.py new file mode 100644 index 0000000000..9a09006cfa --- /dev/null +++ b/core/src/trezor/ui/layouts/tr/fido.py @@ -0,0 +1,21 @@ +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from trezor.wire import GenericContext + + Pageable = object + + +async def confirm_fido( + ctx: GenericContext | None, + header: str, + app_name: str, + icon_name: str | None, + accounts: list[str | None], +) -> int: + """Webauthn confirmation for one or more credentials.""" + raise NotImplementedError + + +async def confirm_fido_reset() -> bool: + raise NotImplementedError diff --git a/core/src/trezor/ui/layouts/tr/webauthn.py b/core/src/trezor/ui/layouts/tr/webauthn.py deleted file mode 100644 index 6e684d3c68..0000000000 --- a/core/src/trezor/ui/layouts/tr/webauthn.py +++ /dev/null @@ -1,19 +0,0 @@ -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from ...components.common.webauthn import ConfirmInfo - from trezor import wire - - Pageable = object - - -async def confirm_webauthn( - ctx: wire.GenericContext | None, - info: ConfirmInfo, - pageable: Pageable | None = None, -) -> bool: - raise NotImplementedError - - -async def confirm_webauthn_reset() -> bool: - raise NotImplementedError diff --git a/core/src/trezor/ui/layouts/tt_v2/__init__.py b/core/src/trezor/ui/layouts/tt_v2/__init__.py index 5a29426d46..9025f8952b 100644 --- a/core/src/trezor/ui/layouts/tt_v2/__init__.py +++ b/core/src/trezor/ui/layouts/tt_v2/__init__.py @@ -1039,7 +1039,6 @@ async def show_popup( subtitle: str | None = None, description_param: str = "", timeout_ms: int = 3000, - icon: str = ui.ICON_WRONG, ) -> None: if subtitle: title += f"\n{subtitle}" @@ -1053,12 +1052,6 @@ async def show_popup( ) -def draw_simple_text( - title: str, description: str = "", icon: str = ui.ICON_CONFIG -) -> None: - log.error(__name__, "draw_simple_text not implemented") - - def request_passphrase_on_host() -> None: draw_simple( trezorui2.show_info( diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index 1bdb9b2676..085677b98c 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -31,7 +31,6 @@ from typing import ( Iterable, Iterator, List, - NamedTuple, Optional, Sequence, Tuple, diff --git a/tests/device_tests/reset_recovery/test_recovery_bip39_dryrun.py b/tests/device_tests/reset_recovery/test_recovery_bip39_dryrun.py index d1f3611aee..b58cc47734 100644 --- a/tests/device_tests/reset_recovery/test_recovery_bip39_dryrun.py +++ b/tests/device_tests/reset_recovery/test_recovery_bip39_dryrun.py @@ -224,8 +224,7 @@ def test_invalid_seed_core(client: Client): client.debug.press_right() yield - layout = client.debug.wait_layout() - assert "WORD ENTERING" in layout.text + assert "WORD ENTERING" in layout().text client.debug.press_yes() yield