mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 12:00:59 +00:00
refactor(core): sync layout code
Refactor mercury layout code according to recent changes in model_t layout code. [no changelog]
This commit is contained in:
parent
936fe1aea9
commit
d4b854a95e
@ -281,7 +281,7 @@ async def raise_if_not_confirmed(
|
||||
raise exc
|
||||
|
||||
|
||||
async def confirm_action(
|
||||
def confirm_action(
|
||||
br_type: str,
|
||||
title: str,
|
||||
action: str | None = None,
|
||||
@ -297,11 +297,11 @@ async def confirm_action(
|
||||
br_code: ButtonRequestType = BR_TYPE_OTHER,
|
||||
prompt_screen: bool = False,
|
||||
prompt_title: str | None = None,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
if description is not None and description_param is not None:
|
||||
description = description.format(description_param)
|
||||
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.confirm_action(
|
||||
@ -325,13 +325,13 @@ async def confirm_action(
|
||||
)
|
||||
|
||||
|
||||
async def confirm_single(
|
||||
def confirm_single(
|
||||
br_type: str,
|
||||
title: str,
|
||||
description: str,
|
||||
description_param: str | None = None,
|
||||
verb: str | None = None,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
description_param = description_param or ""
|
||||
|
||||
# Placeholders are coming from translations in form of {0}
|
||||
@ -340,7 +340,7 @@ async def confirm_single(
|
||||
template_str = "{}"
|
||||
|
||||
begin, _separator, end = description.partition(template_str)
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.confirm_emphasized(
|
||||
@ -355,13 +355,13 @@ async def confirm_single(
|
||||
)
|
||||
|
||||
|
||||
async def confirm_reset_device(_title: str, recovery: bool = False) -> None:
|
||||
def confirm_reset_device(_title: str, recovery: bool = False) -> Awaitable[None]:
|
||||
if recovery:
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
RustLayout(trezorui2.flow_confirm_reset_recover()),
|
||||
)
|
||||
else:
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
RustLayout(trezorui2.flow_confirm_reset_create()),
|
||||
)
|
||||
|
||||
@ -386,16 +386,16 @@ async def prompt_backup() -> bool:
|
||||
return result is CONFIRMED
|
||||
|
||||
|
||||
async def confirm_path_warning(
|
||||
def confirm_path_warning(
|
||||
path: str,
|
||||
path_type: str | None = None,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
description = (
|
||||
TR.addr_mismatch__wrong_derivation_path
|
||||
if not path_type
|
||||
else f"{TR.words__unknown} {path_type.lower()}."
|
||||
)
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.flow_warning_hi_prio(
|
||||
@ -408,8 +408,8 @@ async def confirm_path_warning(
|
||||
)
|
||||
|
||||
|
||||
async def confirm_multisig_warning() -> None:
|
||||
await raise_if_not_confirmed(
|
||||
def confirm_multisig_warning() -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.flow_warning_hi_prio(
|
||||
@ -423,10 +423,10 @@ async def confirm_multisig_warning() -> None:
|
||||
)
|
||||
|
||||
|
||||
async def confirm_homescreen(
|
||||
def confirm_homescreen(
|
||||
image: bytes,
|
||||
) -> None:
|
||||
await raise_if_not_confirmed(
|
||||
) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.confirm_homescreen(
|
||||
@ -531,15 +531,15 @@ async def show_error_and_raise(
|
||||
raise exc
|
||||
|
||||
|
||||
async def show_warning(
|
||||
def show_warning(
|
||||
br_type: str,
|
||||
content: str,
|
||||
subheader: str | None = None,
|
||||
button: str | None = None,
|
||||
br_code: ButtonRequestType = ButtonRequestType.Warning,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
button = button or TR.buttons__continue # def_arg
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.show_warning(
|
||||
@ -554,18 +554,18 @@ async def show_warning(
|
||||
)
|
||||
|
||||
|
||||
async def show_success(
|
||||
def show_success(
|
||||
br_type: str,
|
||||
content: str,
|
||||
subheader: str | None = None,
|
||||
button: str | None = None,
|
||||
) -> None:
|
||||
await raise_if_not_confirmed(
|
||||
) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.show_success(
|
||||
title=content,
|
||||
description=subheader,
|
||||
description=subheader if subheader else "",
|
||||
)
|
||||
),
|
||||
br_type,
|
||||
@ -721,7 +721,7 @@ async def _confirm_ask_pagination(
|
||||
assert False
|
||||
|
||||
|
||||
async def confirm_blob(
|
||||
def confirm_blob(
|
||||
br_type: str,
|
||||
title: str,
|
||||
data: bytes | str,
|
||||
@ -733,7 +733,7 @@ async def confirm_blob(
|
||||
ask_pagination: bool = False,
|
||||
chunkify: bool = False,
|
||||
prompt_screen: bool = True,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
layout = RustLayout(
|
||||
trezorui2.confirm_blob(
|
||||
title=title,
|
||||
@ -750,10 +750,10 @@ async def confirm_blob(
|
||||
|
||||
if ask_pagination and layout.page_count() > 1:
|
||||
assert not hold
|
||||
await _confirm_ask_pagination(br_type, title, data, description or "", br_code)
|
||||
return _confirm_ask_pagination(br_type, title, data, description or "", br_code)
|
||||
|
||||
else:
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
layout,
|
||||
br_type,
|
||||
@ -762,14 +762,14 @@ async def confirm_blob(
|
||||
)
|
||||
|
||||
|
||||
async def confirm_address(
|
||||
def confirm_address(
|
||||
title: str,
|
||||
address: str,
|
||||
description: str | None = None,
|
||||
br_type: str = "confirm_address",
|
||||
br_code: ButtonRequestType = BR_TYPE_OTHER,
|
||||
) -> None:
|
||||
return await confirm_value(
|
||||
) -> Awaitable[None]:
|
||||
return confirm_value(
|
||||
title,
|
||||
address,
|
||||
description or "",
|
||||
@ -779,14 +779,14 @@ async def confirm_address(
|
||||
)
|
||||
|
||||
|
||||
async def confirm_text(
|
||||
def confirm_text(
|
||||
br_type: str,
|
||||
title: str,
|
||||
data: str,
|
||||
description: str | None = None,
|
||||
br_code: ButtonRequestType = BR_TYPE_OTHER,
|
||||
) -> None:
|
||||
return await confirm_value(
|
||||
) -> Awaitable[None]:
|
||||
return confirm_value(
|
||||
title,
|
||||
data,
|
||||
description or "",
|
||||
@ -864,17 +864,17 @@ def confirm_value(
|
||||
)
|
||||
|
||||
|
||||
async def confirm_properties(
|
||||
def confirm_properties(
|
||||
br_type: str,
|
||||
title: str,
|
||||
props: Iterable[PropertyType],
|
||||
hold: bool = False,
|
||||
br_code: ButtonRequestType = ButtonRequestType.ConfirmOutput,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
# Monospace flag for values that are bytes.
|
||||
items = [(prop[0], prop[1], isinstance(prop[1], bytes)) for prop in props]
|
||||
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.confirm_properties(
|
||||
@ -889,7 +889,7 @@ async def confirm_properties(
|
||||
)
|
||||
|
||||
|
||||
async def confirm_total(
|
||||
def confirm_total(
|
||||
total_amount: str,
|
||||
fee_amount: str,
|
||||
title: str | None = None,
|
||||
@ -900,7 +900,7 @@ async def confirm_total(
|
||||
fee_rate_amount: str | None = None,
|
||||
br_type: str = "confirm_total",
|
||||
br_code: ButtonRequestType = ButtonRequestType.SignTx,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
title = title or TR.words__title_summary # def_arg
|
||||
total_label = total_label or TR.send__total_amount # def_arg
|
||||
fee_label = fee_label or TR.send__incl_transaction_fee # def_arg
|
||||
@ -918,7 +918,7 @@ async def confirm_total(
|
||||
if fee_rate_amount:
|
||||
fee_items.append((TR.confirm_total__fee_rate, fee_rate_amount))
|
||||
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
RustLayout(
|
||||
trezorui2.flow_confirm_summary(
|
||||
title=title,
|
||||
@ -932,18 +932,18 @@ async def confirm_total(
|
||||
)
|
||||
|
||||
|
||||
async def confirm_summary(
|
||||
def confirm_summary(
|
||||
items: Iterable[tuple[str, str]],
|
||||
title: str | None = None,
|
||||
info_items: Iterable[tuple[str, str]] | None = None,
|
||||
info_title: str | None = None,
|
||||
br_type: str = "confirm_total",
|
||||
br_code: ButtonRequestType = ButtonRequestType.SignTx,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
# TODO: info_title
|
||||
title = title or TR.words__title_summary # def_arg
|
||||
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
RustLayout(
|
||||
trezorui2.flow_confirm_summary(
|
||||
title=title,
|
||||
@ -1051,7 +1051,7 @@ if not utils.BITCOIN_ONLY:
|
||||
br_code=br_code,
|
||||
)
|
||||
|
||||
async def confirm_solana_tx(
|
||||
def confirm_solana_tx(
|
||||
amount: str,
|
||||
fee: str,
|
||||
items: Iterable[tuple[str, str]],
|
||||
@ -1059,12 +1059,12 @@ if not utils.BITCOIN_ONLY:
|
||||
fee_title: str | None = None,
|
||||
br_type: str = "confirm_solana_tx",
|
||||
br_code: ButtonRequestType = ButtonRequestType.SignTx,
|
||||
):
|
||||
) -> Awaitable[None]:
|
||||
amount_title = (
|
||||
amount_title if amount_title is not None else f"{TR.words__amount}:"
|
||||
) # def_arg
|
||||
fee_title = fee_title or TR.words__fee # def_arg
|
||||
await confirm_summary(
|
||||
return confirm_summary(
|
||||
((amount_title, amount), (fee_title, fee)),
|
||||
info_items=items,
|
||||
br_type=br_type,
|
||||
@ -1072,8 +1072,8 @@ if not utils.BITCOIN_ONLY:
|
||||
)
|
||||
|
||||
|
||||
async def confirm_joint_total(spending_amount: str, total_amount: str) -> None:
|
||||
await confirm_summary(
|
||||
def confirm_joint_total(spending_amount: str, total_amount: str) -> Awaitable[None]:
|
||||
return confirm_summary(
|
||||
items=[
|
||||
(TR.send__you_are_contributing, spending_amount),
|
||||
(TR.send__to_the_total_amount, total_amount),
|
||||
@ -1084,7 +1084,7 @@ async def confirm_joint_total(spending_amount: str, total_amount: str) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def confirm_metadata(
|
||||
def confirm_metadata(
|
||||
br_type: str,
|
||||
title: str,
|
||||
content: str,
|
||||
@ -1092,9 +1092,9 @@ async def confirm_metadata(
|
||||
br_code: ButtonRequestType = ButtonRequestType.SignTx,
|
||||
hold: bool = False,
|
||||
verb: str | None = None,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
verb = verb or TR.buttons__continue # def_arg
|
||||
await confirm_action(
|
||||
return confirm_action(
|
||||
br_type,
|
||||
title=title,
|
||||
action="",
|
||||
@ -1106,8 +1106,8 @@ async def confirm_metadata(
|
||||
)
|
||||
|
||||
|
||||
async def confirm_replacement(title: str, txid: str) -> None:
|
||||
await confirm_blob(
|
||||
def confirm_replacement(title: str, txid: str) -> Awaitable[None]:
|
||||
return confirm_blob(
|
||||
"confirm_replacement",
|
||||
title,
|
||||
txid,
|
||||
@ -1187,13 +1187,13 @@ async def with_info(
|
||||
return result
|
||||
|
||||
|
||||
async def confirm_modify_fee(
|
||||
def confirm_modify_fee(
|
||||
title: str,
|
||||
sign: int,
|
||||
user_fee_change: str,
|
||||
total_fee_new: str,
|
||||
fee_rate_amount: str | None = None,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
fee_layout = RustLayout(
|
||||
trezorui2.confirm_modify_fee(
|
||||
title=title,
|
||||
@ -1212,13 +1212,13 @@ async def confirm_modify_fee(
|
||||
items=items,
|
||||
)
|
||||
)
|
||||
await raise_if_not_confirmed(
|
||||
return raise_if_not_confirmed(
|
||||
with_info(fee_layout, info_layout, "modify_fee", ButtonRequestType.SignTx)
|
||||
)
|
||||
|
||||
|
||||
async def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> None:
|
||||
await raise_if_not_confirmed(
|
||||
def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.confirm_coinjoin(
|
||||
@ -1233,10 +1233,10 @@ async def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> None:
|
||||
|
||||
|
||||
# TODO cleanup @ redesign
|
||||
async def confirm_sign_identity(
|
||||
def confirm_sign_identity(
|
||||
proto: str, identity: str, challenge_visual: str | None
|
||||
) -> None:
|
||||
await confirm_blob(
|
||||
) -> Awaitable[None]:
|
||||
return confirm_blob(
|
||||
"sign_identity",
|
||||
f"{TR.words__sign} {proto}",
|
||||
identity,
|
||||
@ -1326,7 +1326,7 @@ async def confirm_signverify(
|
||||
address_layout.request_complete_repaint()
|
||||
|
||||
|
||||
async def show_error_popup(
|
||||
def show_error_popup(
|
||||
title: str,
|
||||
description: str,
|
||||
subtitle: str | None = None,
|
||||
@ -1334,13 +1334,13 @@ async def show_error_popup(
|
||||
*,
|
||||
button: str = "",
|
||||
timeout_ms: int = 0,
|
||||
) -> None:
|
||||
) -> Awaitable[None]:
|
||||
if not button and not timeout_ms:
|
||||
raise ValueError("Either button or timeout_ms must be set")
|
||||
|
||||
if subtitle:
|
||||
title += f"\n{subtitle}"
|
||||
await RustLayout(
|
||||
return RustLayout(
|
||||
trezorui2.show_error(
|
||||
title=title,
|
||||
description=description.format(description_param),
|
||||
@ -1417,7 +1417,7 @@ async def request_pin_on_device(
|
||||
async def confirm_reenter_pin(
|
||||
is_wipe_code: bool = False,
|
||||
) -> None:
|
||||
"""Not supported for TT."""
|
||||
"""Not supported for Mercury."""
|
||||
pass
|
||||
|
||||
|
||||
@ -1444,14 +1444,14 @@ async def wipe_code_same_as_pin_popup() -> None:
|
||||
)
|
||||
|
||||
|
||||
async def confirm_set_new_pin(
|
||||
def confirm_set_new_pin(
|
||||
br_type: str,
|
||||
title: str,
|
||||
description: str,
|
||||
information: str,
|
||||
br_code: ButtonRequestType = BR_TYPE_OTHER,
|
||||
) -> None:
|
||||
await raise_if_not_confirmed(
|
||||
) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.flow_confirm_set_new_pin(title=title, description=description)
|
||||
@ -1462,8 +1462,8 @@ async def confirm_set_new_pin(
|
||||
)
|
||||
|
||||
|
||||
async def confirm_firmware_update(description: str, fingerprint: str) -> None:
|
||||
await raise_if_not_confirmed(
|
||||
def confirm_firmware_update(description: str, fingerprint: str) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
interact(
|
||||
RustLayout(
|
||||
trezorui2.confirm_firmware_update(
|
||||
|
Loading…
Reference in New Issue
Block a user