1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-21 13:58:08 +00:00

chore(core): make minor improvements

This commit is contained in:
grdddj 2023-05-04 14:44:24 +02:00 committed by Martin Milata
parent 45168f730e
commit 523fdd8157
6 changed files with 29 additions and 27 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

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

@ -189,7 +189,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
@ -200,7 +199,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:
@ -408,12 +406,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,
@ -825,7 +823,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,
@ -1052,7 +1050,7 @@ async def confirm_coinjoin(
)
),
"coinjoin_final",
ButtonRequestType.Other,
BR_TYPE_OTHER,
)
)
@ -1067,7 +1065,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,
)
@ -1087,7 +1085,7 @@ async def confirm_signverify(
title,
address,
"Confirm address:",
br_code=ButtonRequestType.Other,
br_code=BR_TYPE_OTHER,
)
await confirm_blob(
@ -1096,7 +1094,7 @@ async def confirm_signverify(
title,
message,
"Confirm message:",
br_code=ButtonRequestType.Other,
br_code=BR_TYPE_OTHER,
)
@ -1170,12 +1168,11 @@ 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
class RustProgress:

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 = str(exc)
else:
message = "Firmware error"
return Failure(code=FailureType.FirmwareError, message=message)
def unexpected_message() -> Failure: