1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-27 00:48:12 +00:00

core/src: random small improvements

This commit is contained in:
grdddj 2023-03-30 17:42:52 +02:00
parent 1ffbd410b5
commit d26aa6d7d4
9 changed files with 34 additions and 28 deletions

View File

@ -9,6 +9,7 @@ from trezor.enums import (
) )
from trezor.strings import format_amount from trezor.strings import format_amount
from trezor.ui import layouts from trezor.ui import layouts
from trezor.ui.layouts import confirm_metadata, confirm_properties
from apps.common.paths import address_n_to_str from apps.common.paths import address_n_to_str
@ -21,9 +22,6 @@ from .helpers.utils import (
format_stake_pool_id, format_stake_pool_id,
) )
confirm_metadata = layouts.confirm_metadata # global_import_cache
confirm_properties = layouts.confirm_properties # global_import_cache
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Literal from typing import Literal

View File

@ -7,6 +7,7 @@ from trezor.wire import DataError
if TYPE_CHECKING: if TYPE_CHECKING:
from trezor.wire import Context from trezor.wire import Context
_MAX_PASSPHRASE_LEN = const(50) _MAX_PASSPHRASE_LEN = const(50)

View File

@ -122,9 +122,11 @@ if __debug__:
if debuglink_decision_chan.putters: if debuglink_decision_chan.putters:
log.warning(__name__, "DebugLinkDecision queue is not empty") log.warning(__name__, "DebugLinkDecision queue is not empty")
x = msg.x # local_cache_attribute x = msg.x # local_cache_attribute
y = msg.y # local_cache_attribute y = msg.y # local_cache_attribute
# TT click on specific coordinates, with possible hold
if x is not None and y is not None: if x is not None and y is not None:
evt_down = io.TOUCH_START, x, y evt_down = io.TOUCH_START, x, y
evt_up = io.TOUCH_END, x, y evt_up = io.TOUCH_END, x, y
@ -133,6 +135,7 @@ if __debug__:
loop.schedule(touch_hold(x, y, msg.hold_ms)) loop.schedule(touch_hold(x, y, msg.hold_ms))
else: else:
loop.synthetic_events.append((io.TOUCH, evt_up)) loop.synthetic_events.append((io.TOUCH, evt_up))
# Something more general
else: else:
debuglink_decision_chan.publish(msg) debuglink_decision_chan.publish(msg)

Binary file not shown.

View File

@ -26,8 +26,8 @@ _WELCOME_SCREEN_MS = 1200 # how long do we want to show welcome screen (minimum
def enforce_welcome_screen_duration() -> None: def enforce_welcome_screen_duration() -> None:
"""Make sure we will show the welcome screen for appropriate amount of time.""" """Make sure we will show the welcome screen for appropriate amount of time."""
# Not wasting the time in debug builds (saves time during emulator debugging) # Not wasting the time in emulator debug builds (debugging and development)
if __debug__: if __debug__ and utils.EMULATOR:
return return
while utime.ticks_ms() - welcome_screen_start_ms < _WELCOME_SCREEN_MS: while utime.ticks_ms() - welcome_screen_start_ms < _WELCOME_SCREEN_MS:
utime.sleep_ms(100) utime.sleep_ms(100)

View File

@ -38,6 +38,7 @@ async def interact(
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = ButtonRequestType.Other,
) -> Any: ) -> Any:
if hasattr(layout, "page_count") and layout.page_count() > 1: # type: ignore [Cannot access member "page_count" for type "LayoutType"] if hasattr(layout, "page_count") and layout.page_count() > 1: # type: ignore [Cannot access member "page_count" for type "LayoutType"]
# We know for certain how many pages the layout will have
await button_request(ctx, br_type, br_code, pages=layout.page_count()) # type: ignore [Cannot access member "page_count" for type "LayoutType"] await button_request(ctx, br_type, br_code, pages=layout.page_count()) # type: ignore [Cannot access member "page_count" for type "LayoutType"]
return await ctx.wait(layout) return await ctx.wait(layout)
else: else:

View File

@ -131,7 +131,6 @@ class RustLayout(ui.Layout):
touch = loop.wait(io.TOUCH) touch = loop.wait(io.TOUCH)
self._first_paint() self._first_paint()
# self.layout.bounds()
while True: while True:
# Using `yield` instead of `await` to avoid allocations. # Using `yield` instead of `await` to avoid allocations.
event, x, y = yield touch event, x, y = yield touch
@ -142,7 +141,6 @@ class RustLayout(ui.Layout):
if msg is not None: if msg is not None:
raise ui.Result(msg) raise ui.Result(msg)
self._paint() self._paint()
# self.layout.bounds()
def handle_timers(self) -> loop.Task: # type: ignore [awaitable-is-generator] def handle_timers(self) -> loop.Task: # type: ignore [awaitable-is-generator]
while True: while True:
@ -357,12 +355,12 @@ async def show_address(
xpubs: Sequence[str] = (), xpubs: Sequence[str] = (),
) -> None: ) -> None:
send_button_request = True send_button_request = True
while True:
title = ( title = (
"RECEIVE ADDRESS\n(MULTISIG)" "RECEIVE ADDRESS\n(MULTISIG)"
if multisig_index is not None if multisig_index is not None
else "RECEIVE ADDRESS" else "RECEIVE ADDRESS"
) )
while True:
layout = RustLayout( layout = RustLayout(
trezorui2.confirm_address( trezorui2.confirm_address(
title=title, title=title,
@ -388,7 +386,7 @@ async def show_address(
# User pressed corner button or swiped left, go to address details. # User pressed corner button or swiped left, go to address details.
elif result is INFO: elif result is INFO:
def xpub_title(i: int): def xpub_title(i: int) -> str:
result = f"MULTISIG XPUB #{i + 1}\n" result = f"MULTISIG XPUB #{i + 1}\n"
result += "(YOURS)" if i == multisig_index else "(COSIGNER)" result += "(YOURS)" if i == multisig_index else "(COSIGNER)"
return result return result
@ -775,7 +773,7 @@ def confirm_value(
value: str, value: str,
description: str, description: str,
br_type: str, br_type: str,
br_code: ButtonRequestType = ButtonRequestType.Other, br_code: ButtonRequestType = BR_TYPE_OTHER,
*, *,
verb: str | None = None, verb: str | None = None,
subtitle: str | None = None, subtitle: str | None = None,
@ -1021,7 +1019,7 @@ async def confirm_coinjoin(
) )
), ),
"coinjoin_final", "coinjoin_final",
ButtonRequestType.Other, BR_TYPE_OTHER,
) )
) )
@ -1036,7 +1034,7 @@ async def confirm_sign_identity(
data=identity, data=identity,
description=challenge_visual + "\n" if challenge_visual else "", description=challenge_visual + "\n" if challenge_visual else "",
br_type="sign_identity", br_type="sign_identity",
br_code=ButtonRequestType.Other, br_code=BR_TYPE_OTHER,
) )
@ -1056,7 +1054,7 @@ async def confirm_signverify(
title, title,
address, address,
"Confirm address:", "Confirm address:",
br_code=ButtonRequestType.Other, br_code=BR_TYPE_OTHER,
) )
await confirm_blob( await confirm_blob(
@ -1065,7 +1063,7 @@ async def confirm_signverify(
title, title,
message, message,
"Confirm message:", "Confirm message:",
br_code=ButtonRequestType.Other, br_code=BR_TYPE_OTHER,
) )
@ -1139,7 +1137,6 @@ async def request_pin_on_device(
wrong_pin=wrong_pin, wrong_pin=wrong_pin,
) )
) )
while True:
result = await ctx.wait(dialog) result = await ctx.wait(dialog)
if result is CANCELLED: if result is CANCELLED:
raise PinCancelled raise PinCancelled

View File

@ -9,7 +9,7 @@ from ..common import interact
from . import RustLayout from . import RustLayout
if TYPE_CHECKING: if TYPE_CHECKING:
from typing import Callable, Sequence, List from typing import Callable, Sequence
from trezor.enums import BackupType from trezor.enums import BackupType
from trezor.wire import GenericContext from trezor.wire import GenericContext
@ -17,8 +17,8 @@ if TYPE_CHECKING:
CONFIRMED = trezorui2.CONFIRMED # global_import_cache CONFIRMED = trezorui2.CONFIRMED # global_import_cache
def _split_share_into_pages(share_words: Sequence[str], per_page: int = 4) -> List[str]: def _split_share_into_pages(share_words: Sequence[str], per_page: int = 4) -> list[str]:
pages = [] pages: list[str] = []
current = "" current = ""
for i, word in enumerate(share_words): for i, word in enumerate(share_words):

View File

@ -466,7 +466,13 @@ def failure(exc: BaseException) -> Failure:
elif isinstance(exc, InvalidSessionError): elif isinstance(exc, InvalidSessionError):
return Failure(code=FailureType.InvalidSession, message="Invalid session") return Failure(code=FailureType.InvalidSession, message="Invalid session")
else: else:
return Failure(code=FailureType.FirmwareError, message="Firmware error") # NOTE: when receiving generic `FirmwareError` on non-debug build,
# change the `if __debug__` to `if True` to get the full error message.
if __debug__:
message = f"Firmware error - {exc}"
else:
message = "Firmware error"
return Failure(code=FailureType.FirmwareError, message=message)
def unexpected_message() -> Failure: def unexpected_message() -> Failure: