mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-21 22:08:08 +00:00
chore(core): make minor improvements
This commit is contained in:
parent
45168f730e
commit
523fdd8157
@ -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
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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:
|
||||||
|
@ -189,7 +189,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
|
||||||
@ -200,7 +199,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:
|
||||||
@ -408,12 +406,12 @@ async def show_address(
|
|||||||
xpubs: Sequence[str] = (),
|
xpubs: Sequence[str] = (),
|
||||||
) -> None:
|
) -> None:
|
||||||
send_button_request = True
|
send_button_request = True
|
||||||
|
title = (
|
||||||
|
"RECEIVE ADDRESS\n(MULTISIG)"
|
||||||
|
if multisig_index is not None
|
||||||
|
else "RECEIVE ADDRESS"
|
||||||
|
)
|
||||||
while True:
|
while True:
|
||||||
title = (
|
|
||||||
"RECEIVE ADDRESS\n(MULTISIG)"
|
|
||||||
if multisig_index is not None
|
|
||||||
else "RECEIVE ADDRESS"
|
|
||||||
)
|
|
||||||
layout = RustLayout(
|
layout = RustLayout(
|
||||||
trezorui2.confirm_address(
|
trezorui2.confirm_address(
|
||||||
title=title,
|
title=title,
|
||||||
@ -825,7 +823,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,
|
||||||
@ -1052,7 +1050,7 @@ async def confirm_coinjoin(
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
"coinjoin_final",
|
"coinjoin_final",
|
||||||
ButtonRequestType.Other,
|
BR_TYPE_OTHER,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1067,7 +1065,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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -1087,7 +1085,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(
|
||||||
@ -1096,7 +1094,7 @@ async def confirm_signverify(
|
|||||||
title,
|
title,
|
||||||
message,
|
message,
|
||||||
"Confirm 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,
|
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
|
assert isinstance(result, str)
|
||||||
assert isinstance(result, str)
|
return result
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class RustProgress:
|
class RustProgress:
|
||||||
|
@ -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):
|
||||||
|
@ -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 = str(exc)
|
||||||
|
else:
|
||||||
|
message = "Firmware error"
|
||||||
|
return Failure(code=FailureType.FirmwareError, message=message)
|
||||||
|
|
||||||
|
|
||||||
def unexpected_message() -> Failure:
|
def unexpected_message() -> Failure:
|
||||||
|
Loading…
Reference in New Issue
Block a user