1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-24 15:38:22 +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.ui import layouts
from trezor.ui.layouts import confirm_metadata, confirm_properties
from apps.common.paths import address_n_to_str
@ -21,9 +22,6 @@ from .helpers.utils import (
format_stake_pool_id,
)
confirm_metadata = layouts.confirm_metadata # global_import_cache
confirm_properties = layouts.confirm_properties # global_import_cache
if TYPE_CHECKING:
from typing import Literal

View File

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

View File

@ -122,9 +122,11 @@ if __debug__:
if debuglink_decision_chan.putters:
log.warning(__name__, "DebugLinkDecision queue is not empty")
x = msg.x # 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:
evt_down = io.TOUCH_START, x, y
evt_up = io.TOUCH_END, x, y
@ -133,6 +135,7 @@ if __debug__:
loop.schedule(touch_hold(x, y, msg.hold_ms))
else:
loop.synthetic_events.append((io.TOUCH, evt_up))
# Something more general
else:
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:
"""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)
if __debug__:
# Not wasting the time in emulator debug builds (debugging and development)
if __debug__ and utils.EMULATOR:
return
while utime.ticks_ms() - welcome_screen_start_ms < _WELCOME_SCREEN_MS:
utime.sleep_ms(100)

View File

@ -38,6 +38,7 @@ async def interact(
br_code: ButtonRequestType = ButtonRequestType.Other,
) -> Any:
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"]
return await ctx.wait(layout)
else:

View File

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

View File

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

View File

@ -466,7 +466,13 @@ def failure(exc: BaseException) -> Failure:
elif isinstance(exc, InvalidSessionError):
return Failure(code=FailureType.InvalidSession, message="Invalid session")
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: