1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-30 20:02:34 +00:00

WIP - fixes after rebase

This commit is contained in:
grdddj 2022-12-30 12:59:42 +01:00
parent 3c38d74a76
commit cf3687263f
19 changed files with 97 additions and 554 deletions

View File

@ -313,10 +313,6 @@ impl Rect {
self.bottom_left().center(self.bottom_right()) 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 { pub const fn left_center(&self) -> Point {
self.bottom_left().center(self.top_left()) self.bottom_left().center(self.top_left())
} }

View File

@ -149,50 +149,6 @@ trezor.ui
import trezor.ui import trezor.ui
trezor.ui.components.common.confirm trezor.ui.components.common.confirm
import 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 trezor.ui.layouts
import trezor.ui.layouts import trezor.ui.layouts
trezor.ui.layouts.common trezor.ui.layouts.common
@ -209,18 +165,12 @@ trezor.ui.layouts.tr
import trezor.ui.layouts.tr import trezor.ui.layouts.tr
trezor.ui.layouts.tr.altcoin trezor.ui.layouts.tr.altcoin
import 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 trezor.ui.layouts.tr.recovery
import trezor.ui.layouts.tr.recovery import trezor.ui.layouts.tr.recovery
trezor.ui.layouts.tr.reset trezor.ui.layouts.tr.reset
import 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 trezor.ui.layouts.tt_v2
import trezor.ui.layouts.tt_v2 import trezor.ui.layouts.tt_v2
trezor.ui.layouts.tt_v2.fido trezor.ui.layouts.tt_v2.fido
@ -357,18 +307,6 @@ apps.debug.load_device
import apps.debug.load_device import apps.debug.load_device
apps.homescreen apps.homescreen
import 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 apps.management
import apps.management import apps.management
apps.management.apply_flags apps.management.apply_flags
@ -477,18 +415,6 @@ if not utils.BITCOIN_ONLY:
import trezor.enums.TezosBallotType import trezor.enums.TezosBallotType
trezor.enums.TezosContractType trezor.enums.TezosContractType
import 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 apps.binance
import apps.binance import apps.binance
apps.binance.get_address apps.binance.get_address

View File

@ -38,12 +38,9 @@ async def get(ctx: Context) -> str:
async def _request_on_host(ctx: Context) -> str: async def _request_on_host(ctx: Context) -> str:
from trezor.messages import PassphraseAck, PassphraseRequest 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 request_passphrase_on_host()
draw_simple_text(
"Passphrase entry", "Please type your\npassphrase on the\nconnected host."
)
request = PassphraseRequest() request = PassphraseRequest()
ack = await ctx.call(request, PassphraseAck) ack = await ctx.call(request, PassphraseAck)
@ -83,9 +80,3 @@ async def _request_on_host(ctx: Context) -> str:
) )
return passphrase return passphrase
def _entry_dialog() -> None:
from trezor.ui.layouts import request_passphrase_on_host
request_passphrase_on_host()

View File

@ -11,7 +11,6 @@ from trezor.ui.layouts import (
should_show_more, should_show_more,
) )
from ..management import text_r
from . import networks from . import networks
from .helpers import decode_typed_data from .helpers import decode_typed_data

View File

@ -1046,7 +1046,7 @@ def _networks_iterator() -> Iterator[NetworkInfoTuple]:
1246, # chain_id 1246, # chain_id
60, # slip44 60, # slip44
"OM", # shortcut "OM", # shortcut
"OM Platform", # name "OM Chain", # name
False, # rskip60 False, # rskip60
) )
yield ( yield (
@ -1819,13 +1819,6 @@ def _networks_iterator() -> Iterator[NetworkInfoTuple]:
"OpenChain", # name "OpenChain", # name
False, # rskip60 False, # rskip60
) )
yield (
846000, # chain_id
60, # slip44
"APTA", # shortcut
"4GoodNetwork", # name
False, # rskip60
)
yield ( yield (
888888, # chain_id 888888, # chain_id
60, # slip44 60, # slip44

View File

@ -45,11 +45,6 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int]]:
"$TEAK", "$TEAK",
18, 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 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", b"\xb6\xed\x76\x44\xc6\x94\x16\xd6\x7b\x52\x2e\x20\xbc\x29\x4a\x9a\x9b\x40\x5b\x31",
"0xBTC", "0xBTC",
@ -4760,11 +4755,6 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int]]:
"OGN", "OGN",
18, 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 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", b"\x21\xe1\x3c\xb3\xf3\xf2\x6f\x92\xa6\x2a\xc7\xad\xab\x40\x93\xe8\x99\x7d\x1f\xb1",
"OIKOS", "OIKOS",
@ -8325,11 +8315,6 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int]]:
"VENUS", "VENUS",
3, 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 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", b"\x8f\x34\x70\xa7\x38\x8c\x05\xee\x4e\x7a\xf3\xd0\x1d\x8c\x72\x2b\x0f\xf5\x23\x74",
"VERI", "VERI",
@ -8605,11 +8590,6 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int]]:
"WOC", "WOC",
0, 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 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", b"\x62\x08\x72\x45\x08\x71\x25\xd3\xdb\x5b\x9a\x3d\x71\x3d\x78\xe7\xbb\xc3\x1e\x54",
"WPC", "WPC",

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -65,9 +65,7 @@ async def _continue_recovery_process(ctx: GenericContext) -> Success:
if is_first_step: if is_first_step:
# If we are starting recovery, ask for word count first... # If we are starting recovery, ask for word count first...
# _request_word_count # _request_word_count
await layout.homescreen_dialog( await layout.homescreen_dialog(ctx, "Select", "Select the number of words")
ctx, "Select", "Select the number of words"
)
# ask for the number of words # ask for the number of words
word_count = await layout.request_word_count(ctx, dry_run) word_count = await layout.request_word_count(ctx, dry_run)
# ...and only then show the starting screen with word count. # ...and only then show the starting screen with word count.

View File

@ -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

View File

@ -1,3 +1,5 @@
from trezor import utils
if utils.MODEL in ("T",): if utils.MODEL in ("T",):
from .tt_v2.recovery import * # noqa: F401,F403 from .tt_v2.recovery import * # noqa: F401,F403
elif utils.MODEL in ("R",): elif utils.MODEL in ("R",):

View File

@ -1,3 +1,5 @@
from trezor import utils
if utils.MODEL in ("T",): if utils.MODEL in ("T",):
from .tt_v2.reset import * # noqa: F401,F403 from .tt_v2.reset import * # noqa: F401,F403
elif utils.MODEL in ("R",): elif utils.MODEL in ("R",):

View File

@ -1,19 +1,17 @@
from typing import TYPE_CHECKING, Sequence from typing import TYPE_CHECKING, Sequence
from ubinascii import hexlify
from trezor import io, log, loop, ui, wire, workflow from trezor import io, log, loop, ui, wire, workflow
from trezor.enums import ButtonRequestType from trezor.enums import ButtonRequestType
from trezor.utils import DISABLE_ANIMATION from trezor.utils import DISABLE_ANIMATION
from trezor.ui.popup import Popup
import trezorui2 import trezorui2
from ...components.tr.text import Text
from ..common import button_request, interact from ..common import button_request, interact
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Any, NoReturn, Type, Awaitable, Iterable, TypeVar from typing import Any, NoReturn, Type, Awaitable, Iterable, TypeVar
from trezor.wire import GenericContext, Context
from ..common import PropertyType from ..common import PropertyType
T = TypeVar("T") T = TypeVar("T")
@ -21,6 +19,9 @@ if TYPE_CHECKING:
ExceptionType = BaseException | Type[BaseException] ExceptionType = BaseException | Type[BaseException]
BR_TYPE_OTHER = ButtonRequestType.Other # global_import_cache
if __debug__: if __debug__:
trezorui2.disable_animation(bool(DISABLE_ANIMATION)) trezorui2.disable_animation(bool(DISABLE_ANIMATION))
@ -282,7 +283,7 @@ class RustLayout(ui.Layout):
Only `UP` and `DOWN` directions are supported. Only `UP` and `DOWN` directions are supported.
""" """
from trezor.ui.components.common import ( from trezor.ui import (
SWIPE_UP, SWIPE_UP,
SWIPE_DOWN, SWIPE_DOWN,
) )
@ -305,7 +306,7 @@ class RustLayout(ui.Layout):
Waits for `swipe_signal` and carries it out. Waits for `swipe_signal` and carries it out.
""" """
from apps.debug import swipe_signal 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: while True:
direction = await swipe_signal() direction = await swipe_signal()
@ -396,12 +397,12 @@ class RustLayout(ui.Layout):
# Temporary function, so we know where it is used # Temporary function, so we know where it is used
# Should be gradually replaced by custom designs/layouts # Should be gradually replaced by custom designs/layouts
async def _placeholder_confirm( async def _placeholder_confirm(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
title: str, title: str,
data: str, data: str,
description: str | None = None, description: str | None = None,
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> Any: ) -> Any:
return await raise_if_cancelled( return await raise_if_cancelled(
confirm_text( confirm_text(
@ -416,7 +417,7 @@ async def _placeholder_confirm(
async def get_bool( async def get_bool(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
title: str, title: str,
data: str | None = None, data: str | None = None,
@ -425,7 +426,7 @@ async def get_bool(
verb_cancel: str | None = "", verb_cancel: str | None = "",
hold: bool = False, hold: bool = False,
reverse: bool = False, reverse: bool = False,
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> bool: ) -> bool:
result = await interact( result = await interact(
ctx, 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 # `description` strings for model R, as those for model T
# have newlines at random places (suitable for T). # have newlines at random places (suitable for T).
async def confirm_action( async def confirm_action(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
title: str, title: str,
action: str | None = None, action: str | None = None,
@ -470,7 +471,7 @@ async def confirm_action(
hold: bool = False, hold: bool = False,
reverse: bool = False, reverse: bool = False,
exc: ExceptionType = wire.ActionCancelled, exc: ExceptionType = wire.ActionCancelled,
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> None: ) -> None:
if verb_cancel is not None: if verb_cancel is not None:
verb_cancel = verb_cancel.upper() verb_cancel = verb_cancel.upper()
@ -513,7 +514,7 @@ async def confirm_action(
async def confirm_reset_device( async def confirm_reset_device(
ctx: wire.GenericContext, ctx: GenericContext,
prompt: str, prompt: str,
recovery: bool = False, recovery: bool = False,
show_tutorial: bool = True, show_tutorial: bool = True,
@ -545,7 +546,7 @@ async def confirm_reset_device(
# TODO cleanup @ redesign # TODO cleanup @ redesign
async def confirm_backup(ctx: wire.GenericContext) -> bool: async def confirm_backup(ctx: GenericContext) -> bool:
if await get_bool( if await get_bool(
ctx=ctx, ctx=ctx,
title="SUCCESS", title="SUCCESS",
@ -571,7 +572,7 @@ async def confirm_backup(ctx: wire.GenericContext) -> bool:
async def confirm_path_warning( async def confirm_path_warning(
ctx: wire.GenericContext, path: str, path_type: str = "Path" ctx: GenericContext, path: str, path_type: str = "Path"
) -> None: ) -> None:
return await _placeholder_confirm( return await _placeholder_confirm(
ctx=ctx, ctx=ctx,
@ -595,9 +596,7 @@ def _show_xpub(xpub: str, title: str, cancel: str) -> ui.Layout:
return content return content
async def show_xpub( async def show_xpub(ctx: GenericContext, xpub: str, title: str, cancel: str) -> None:
ctx: wire.GenericContext, xpub: str, title: str, cancel: str
) -> None:
await raise_if_cancelled( await raise_if_cancelled(
interact( interact(
ctx, ctx,
@ -609,7 +608,7 @@ async def show_xpub(
async def show_address( async def show_address(
ctx: wire.GenericContext, ctx: GenericContext,
address: str, address: str,
*, *,
case_sensitive: bool = True, case_sensitive: bool = True,
@ -680,7 +679,7 @@ async def show_address(
def show_pubkey( def show_pubkey(
ctx: wire.Context, pubkey: str, title: str = "Confirm public key" ctx: Context, pubkey: str, title: str = "Confirm public key"
) -> Awaitable[None]: ) -> Awaitable[None]:
return confirm_blob( return confirm_blob(
ctx, ctx,
@ -692,7 +691,7 @@ def show_pubkey(
async def _show_modal( async def _show_modal(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
br_code: ButtonRequestType, br_code: ButtonRequestType,
header: str, header: str,
@ -700,8 +699,6 @@ async def _show_modal(
content: str, content: str,
button_confirm: str | None, button_confirm: str | None,
button_cancel: str | None, button_cancel: str | None,
icon: str,
icon_color: int,
exc: ExceptionType = wire.ActionCancelled, exc: ExceptionType = wire.ActionCancelled,
) -> None: ) -> None:
await confirm_action( await confirm_action(
@ -718,7 +715,7 @@ async def _show_modal(
async def show_error_and_raise( async def show_error_and_raise(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
content: str, content: str,
header: str = "Error", header: str = "Error",
@ -730,29 +727,25 @@ async def show_error_and_raise(
await _show_modal( await _show_modal(
ctx=ctx, ctx=ctx,
br_type=br_type, br_type=br_type,
br_code=ButtonRequestType.Other, br_code=BR_TYPE_OTHER,
header=header, header=header,
subheader=subheader, subheader=subheader,
content=content, content=content,
button_confirm=None, button_confirm=None,
button_cancel=button, button_cancel=button,
icon=ui.ICON_WRONG,
icon_color=ui.RED if red else ui.ORANGE_ICON,
exc=exc, exc=exc,
) )
raise exc raise exc
def show_warning( def show_warning(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
content: str, content: str,
header: str = "Warning", header: str = "Warning",
subheader: str | None = None, subheader: str | None = None,
button: str = "Try again", button: str = "Try again",
br_code: ButtonRequestType = ButtonRequestType.Warning, br_code: ButtonRequestType = ButtonRequestType.Warning,
icon: str = ui.ICON_WRONG,
icon_color: int = ui.RED,
) -> Awaitable[None]: ) -> Awaitable[None]:
return _show_modal( return _show_modal(
ctx, ctx,
@ -763,13 +756,11 @@ def show_warning(
content=content, content=content,
button_confirm=button, button_confirm=button,
button_cancel=None, button_cancel=None,
icon=icon,
icon_color=icon_color,
) )
def show_success( def show_success(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
content: str, content: str,
subheader: str | None = None, subheader: str | None = None,
@ -784,13 +775,11 @@ def show_success(
content=content, content=content,
button_confirm=button, button_confirm=button,
button_cancel=None, button_cancel=None,
icon=ui.ICON_CONFIRM,
icon_color=ui.GREEN,
) )
async def confirm_output( async def confirm_output(
ctx: wire.GenericContext, ctx: GenericContext,
address: str, address: str,
amount: str, amount: str,
subtitle: str = "", subtitle: str = "",
@ -827,8 +816,8 @@ async def confirm_output(
async def tutorial( async def tutorial(
ctx: wire.GenericContext, ctx: GenericContext,
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> None: ) -> None:
"""Showing users how to interact with the device.""" """Showing users how to interact with the device."""
await interact( await interact(
@ -840,7 +829,7 @@ async def tutorial(
async def confirm_payment_request( async def confirm_payment_request(
ctx: wire.GenericContext, ctx: GenericContext,
recipient_name: str, recipient_name: str,
amount: str, amount: str,
memos: list[str], memos: list[str],
@ -857,16 +846,13 @@ async def confirm_payment_request(
async def should_show_more( async def should_show_more(
ctx: wire.GenericContext, ctx: GenericContext,
title: str, title: str,
para: Iterable[tuple[int, str]], para: Iterable[tuple[int, str]],
button_text: str = "Show all", button_text: str = "Show all",
confirm: str = "Show all",
br_type: str = "should_show_more", br_type: str = "should_show_more",
major_confirm: bool = True, br_code: ButtonRequestType = BR_TYPE_OTHER,
br_code: ButtonRequestType = ButtonRequestType.Other, confirm: str | bytes | None = None,
icon: str = ui.ICON_DEFAULT,
icon_color: int = ui.ORANGE_ICON,
) -> bool: ) -> bool:
return await get_bool( return await get_bool(
ctx=ctx, ctx=ctx,
@ -878,13 +864,13 @@ async def should_show_more(
async def confirm_blob( async def confirm_blob(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
title: str, title: str,
data: bytes | str, data: bytes | str,
description: str | None = None, description: str | None = None,
hold: bool = False, hold: bool = False,
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = BR_TYPE_OTHER,
ask_pagination: bool = False, ask_pagination: bool = False,
) -> None: ) -> None:
await _placeholder_confirm( await _placeholder_confirm(
@ -898,14 +884,12 @@ async def confirm_blob(
async def confirm_address( async def confirm_address(
ctx: wire.GenericContext, ctx: GenericContext,
title: str, title: str,
address: str, address: str,
description: str | None = "Address:", description: str | None = "Address:",
br_type: str = "confirm_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]: ) -> Awaitable[None]:
return confirm_blob( return confirm_blob(
ctx=ctx, ctx=ctx,
@ -918,14 +902,12 @@ async def confirm_address(
async def confirm_text( async def confirm_text(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
title: str, title: str,
data: str, data: str,
description: str | None = None, 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
) -> Any: ) -> Any:
return await interact( return await interact(
ctx, ctx,
@ -942,14 +924,12 @@ async def confirm_text(
def confirm_amount( def confirm_amount(
ctx: wire.GenericContext, ctx: GenericContext,
title: str, title: str,
amount: str, amount: str,
description: str = "Amount:", description: str = "Amount:",
br_type: str = "confirm_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]: ) -> Awaitable[None]:
return _placeholder_confirm( return _placeholder_confirm(
ctx=ctx, ctx=ctx,
@ -962,20 +942,14 @@ def confirm_amount(
async def confirm_properties( async def confirm_properties(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
title: str, title: str,
props: Iterable[PropertyType], props: Iterable[PropertyType],
icon: str = ui.ICON_SEND, # TODO cleanup @ redesign
icon_color: int = ui.GREEN, # TODO cleanup @ redesign
hold: bool = False, hold: bool = False,
br_code: ButtonRequestType = ButtonRequestType.ConfirmOutput, br_code: ButtonRequestType = ButtonRequestType.ConfirmOutput,
) -> None: ) -> None:
def handle_bytes(prop: PropertyType): items = [(prop[0], prop[1], isinstance(prop[1], bytes)) for prop in props]
if isinstance(prop[1], bytes):
return (prop[0], hexlify(prop[1]).decode(), True)
else:
return (prop[0], prop[1], False)
await raise_if_cancelled( await raise_if_cancelled(
interact( interact(
@ -983,7 +957,7 @@ async def confirm_properties(
RustLayout( RustLayout(
trezorui2.confirm_properties( trezorui2.confirm_properties(
title=title.upper(), title=title.upper(),
items=map(handle_bytes, props), items=items,
hold=hold, hold=hold,
) )
), ),
@ -994,7 +968,7 @@ async def confirm_properties(
async def confirm_total( async def confirm_total(
ctx: wire.GenericContext, ctx: GenericContext,
total_amount: str, total_amount: str,
fee_amount: str, fee_amount: str,
fee_rate_amount: str | None = None, fee_rate_amount: str | None = None,
@ -1025,7 +999,7 @@ async def confirm_total(
async def confirm_joint_total( async def confirm_joint_total(
ctx: wire.GenericContext, spending_amount: str, total_amount: str ctx: GenericContext, spending_amount: str, total_amount: str
) -> None: ) -> None:
await _placeholder_confirm( await _placeholder_confirm(
ctx=ctx, ctx=ctx,
@ -1038,7 +1012,7 @@ async def confirm_joint_total(
async def confirm_metadata( async def confirm_metadata(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
title: str, title: str,
content: str, content: str,
@ -1062,9 +1036,7 @@ async def confirm_metadata(
) )
async def confirm_replacement( async def confirm_replacement(ctx: GenericContext, description: str, txid: str) -> None:
ctx: wire.GenericContext, description: str, txid: str
) -> None:
await _placeholder_confirm( await _placeholder_confirm(
ctx=ctx, ctx=ctx,
br_type="confirm_replacement", br_type="confirm_replacement",
@ -1076,7 +1048,7 @@ async def confirm_replacement(
async def confirm_modify_output( async def confirm_modify_output(
ctx: wire.GenericContext, ctx: GenericContext,
address: str, address: str,
sign: int, sign: int,
amount_change: str, amount_change: str,
@ -1100,7 +1072,7 @@ async def confirm_modify_output(
async def confirm_modify_fee( async def confirm_modify_fee(
ctx: wire.GenericContext, ctx: GenericContext,
sign: int, sign: int,
user_fee_change: str, user_fee_change: str,
total_fee_new: str, total_fee_new: str,
@ -1130,7 +1102,7 @@ async def confirm_modify_fee(
async def confirm_coinjoin( 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: ) -> None:
await _placeholder_confirm( await _placeholder_confirm(
ctx=ctx, ctx=ctx,
@ -1138,7 +1110,7 @@ async def confirm_coinjoin(
title="AUTHORIZE COINJOIN", title="AUTHORIZE COINJOIN",
data=f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte}", data=f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte}",
description="", description="",
br_code=ButtonRequestType.Other, br_code=BR_TYPE_OTHER,
) )
@ -1148,7 +1120,7 @@ def show_coinjoin() -> None:
# TODO cleanup @ redesign # TODO cleanup @ redesign
async def confirm_sign_identity( 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: ) -> None:
text = "" text = ""
if challenge_visual: if challenge_visual:
@ -1161,12 +1133,12 @@ async def confirm_sign_identity(
title=f"Sign {proto}".upper(), title=f"Sign {proto}".upper(),
data=text, data=text,
description="", description="",
br_code=ButtonRequestType.Other, br_code=BR_TYPE_OTHER,
) )
async def confirm_signverify( 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: ) -> None:
if verify: if verify:
header = f"Verify {coin} message" header = f"Verify {coin} message"
@ -1181,7 +1153,7 @@ async def confirm_signverify(
title=header.upper(), title=header.upper(),
data=f"Confirm address:\n{address}", data=f"Confirm address:\n{address}",
description="", description="",
br_code=ButtonRequestType.Other, br_code=BR_TYPE_OTHER,
) )
await _placeholder_confirm( await _placeholder_confirm(
@ -1190,7 +1162,7 @@ async def confirm_signverify(
title=header.upper(), title=header.upper(),
data=f"Confirm message:\n{message}", data=f"Confirm message:\n{message}",
description="", description="",
br_code=ButtonRequestType.Other, br_code=BR_TYPE_OTHER,
) )
@ -1200,33 +1172,11 @@ async def show_popup(
subtitle: str | None = None, subtitle: str | None = None,
description_param: str = "", description_param: str = "",
timeout_ms: int = 3000, timeout_ms: int = 3000,
icon: str = ui.ICON_WRONG,
) -> None: ) -> None:
text = Text(title, icon) raise NotImplementedError
# 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)
def draw_simple_text( async def request_passphrase_on_device(ctx: GenericContext, max_len: int) -> str:
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:
await button_request( await button_request(
ctx, "passphrase_device", code=ButtonRequestType.PassphraseEntry 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( async def request_pin_on_device(
ctx: wire.GenericContext, ctx: GenericContext,
prompt: str, prompt: str,
attempts_remaining: int | None, attempts_remaining: int | None,
allow_cancel: bool, allow_cancel: bool,
@ -1278,9 +1228,9 @@ async def request_pin_on_device(
async def confirm_reenter_pin( async def confirm_reenter_pin(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str = "set_pin", br_type: str = "set_pin",
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> None: ) -> None:
return await confirm_action( return await confirm_action(
ctx, ctx,
@ -1293,9 +1243,9 @@ async def confirm_reenter_pin(
async def pin_mismatch( async def pin_mismatch(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str = "set_pin", br_type: str = "set_pin",
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> None: ) -> None:
return await confirm_action( return await confirm_action(
ctx, ctx,
@ -1309,12 +1259,12 @@ async def pin_mismatch(
async def confirm_pin_action( async def confirm_pin_action(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
title: str, title: str,
action: str | None, action: str | None,
description: str | None = "Do you really want to", description: str | None = "Do you really want to",
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> None: ) -> None:
return await confirm_action( return await confirm_action(
ctx, ctx,
@ -1326,13 +1276,13 @@ async def confirm_pin_action(
async def confirm_set_new_pin( async def confirm_set_new_pin(
ctx: wire.GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
title: str, title: str,
action: str, action: str,
information: list[str], information: list[str],
description: str = "Do you want to", description: str = "Do you want to",
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> None: ) -> None:
await confirm_action( await confirm_action(
ctx, ctx,

View File

@ -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

View File

@ -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

View File

@ -1039,7 +1039,6 @@ async def show_popup(
subtitle: str | None = None, subtitle: str | None = None,
description_param: str = "", description_param: str = "",
timeout_ms: int = 3000, timeout_ms: int = 3000,
icon: str = ui.ICON_WRONG,
) -> None: ) -> None:
if subtitle: if subtitle:
title += f"\n{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: def request_passphrase_on_host() -> None:
draw_simple( draw_simple(
trezorui2.show_info( trezorui2.show_info(

View File

@ -31,7 +31,6 @@ from typing import (
Iterable, Iterable,
Iterator, Iterator,
List, List,
NamedTuple,
Optional, Optional,
Sequence, Sequence,
Tuple, Tuple,

View File

@ -224,8 +224,7 @@ def test_invalid_seed_core(client: Client):
client.debug.press_right() client.debug.press_right()
yield yield
layout = client.debug.wait_layout() assert "WORD ENTERING" in layout().text
assert "WORD ENTERING" in layout.text
client.debug.press_yes() client.debug.press_yes()
yield yield