1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

feat(core): auto-hexlify in confirm_properties

This commit is contained in:
matejcik 2021-06-22 15:14:15 +02:00 committed by matejcik
parent 74bd26b160
commit da4442bbd7
3 changed files with 29 additions and 14 deletions

View File

@ -1,5 +1,3 @@
from ubinascii import hexlify
from trezor import ui from trezor import ui
from trezor.enums import ButtonRequestType, CardanoAddressType, CardanoCertificateType from trezor.enums import ButtonRequestType, CardanoAddressType, CardanoCertificateType
from trezor.strings import format_amount from trezor.strings import format_amount
@ -197,7 +195,7 @@ async def show_warning_tx_staking_key_hash(
) -> None: ) -> None:
props = [ props = [
("Change address staking rights do not match the current account.\n\n", None), ("Change address staking rights do not match the current account.\n\n", None),
("Staking key hash:", hexlify(staking_key_hash).decode()), ("Staking key hash:", staking_key_hash),
("Change amount:", format_coin_amount(amount)), ("Change amount:", format_coin_amount(amount)),
] ]
@ -365,7 +363,7 @@ async def confirm_stake_pool_metadata(
title="Confirm transaction", title="Confirm transaction",
props=[ props=[
("Pool metadata url:", metadata.url), ("Pool metadata url:", metadata.url),
("Pool metadata hash:", hexlify(metadata.hash).decode()), ("Pool metadata hash:", metadata.hash),
], ],
br_code=ButtonRequestType.Other, br_code=ButtonRequestType.Other,
) )
@ -458,7 +456,7 @@ async def show_auxiliary_data_hash(
ctx, ctx,
"confirm_auxiliary_data", "confirm_auxiliary_data",
title="Confirm transaction", title="Confirm transaction",
props=[("Auxiliary data hash:", hexlify(auxiliary_data_hash).decode())], props=[("Auxiliary data hash:", auxiliary_data_hash)],
br_code=ButtonRequestType.Other, br_code=ButtonRequestType.Other,
) )
@ -486,7 +484,7 @@ async def show_warning_address_foreign_staking_key(
) )
else: else:
assert staking_key_hash is not None # _validate_base_address_staking_info assert staking_key_hash is not None # _validate_base_address_staking_info
props.append(("Staking key:", hexlify(staking_key_hash).decode())) props.append(("Staking key:", staking_key_hash))
props.append(("Continue?", None)) props.append(("Continue?", None))
await confirm_properties( await confirm_properties(

View File

@ -1,5 +1,3 @@
from ubinascii import hexlify
from trezor import ui from trezor import ui
from trezor.enums import ButtonRequestType from trezor.enums import ButtonRequestType
from trezor.ui.layouts import confirm_properties from trezor.ui.layouts import confirm_properties
@ -290,7 +288,7 @@ async def confirm_action_unknown(
props=[ props=[
("Contract:", helpers.eos_name_to_string(action.account)), ("Contract:", helpers.eos_name_to_string(action.account)),
("Action Name:", helpers.eos_name_to_string(action.name)), ("Action Name:", helpers.eos_name_to_string(action.name)),
("Checksum:", hexlify(checksum).decode("ascii")), ("Checksum:", checksum),
], ],
icon=ui.ICON_WIPE, icon=ui.ICON_WIPE,
icon_color=ui.RED, icon_color=ui.RED,

View File

@ -1,5 +1,7 @@
from micropython import const from micropython import const
from ubinascii import hexlify
from trezor import ui, wire from trezor import ui, wire
from trezor.enums import ButtonRequestType from trezor.enums import ButtonRequestType
from trezor.ui.container import Container from trezor.ui.container import Container
@ -11,7 +13,13 @@ from ..components.common import break_path_to_lines
from ..components.common.confirm import is_confirmed, raise_if_cancelled from ..components.common.confirm import is_confirmed, raise_if_cancelled
from ..components.tt.button import ButtonCancel, ButtonDefault from ..components.tt.button import ButtonCancel, ButtonDefault
from ..components.tt.confirm import Confirm, HoldToConfirm from ..components.tt.confirm import Confirm, HoldToConfirm
from ..components.tt.scroll import Paginated, paginate_paragraphs, paginate_text, PAGINATED_LINE_WIDTH, PAGEBREAK from ..components.tt.scroll import (
Paginated,
paginate_paragraphs,
paginate_text,
PAGINATED_LINE_WIDTH,
PAGEBREAK,
)
from ..components.tt.text import Span, Text from ..components.tt.text import Span, Text
from ..constants.tt import ( from ..constants.tt import (
MONO_ADDR_PER_LINE, MONO_ADDR_PER_LINE,
@ -36,7 +44,7 @@ if False:
) )
ExceptionType = Union[BaseException, Type[BaseException]] ExceptionType = Union[BaseException, Type[BaseException]]
PropertyType = Tuple[Optional[str], Optional[str]] PropertyType = Tuple[Optional[str], Union[str, bytes, None]]
__all__ = ( __all__ = (
@ -597,8 +605,14 @@ async def confirm_properties(
for key, val in props: for key, val in props:
span.reset(key or "", 0, ui.NORMAL, line_width=PAGINATED_LINE_WIDTH) span.reset(key or "", 0, ui.NORMAL, line_width=PAGINATED_LINE_WIDTH)
key_lines = span.count_lines() key_lines = span.count_lines()
span.reset(val or "", 0, ui.BOLD, line_width=PAGINATED_LINE_WIDTH)
val_lines = span.count_lines() if isinstance(val, str):
span.reset(val, 0, ui.BOLD, line_width=PAGINATED_LINE_WIDTH)
val_lines = span.count_lines()
elif isinstance(val, bytes):
val_lines = (len(val) * 2 + MONO_HEX_PER_LINE - 1) // MONO_HEX_PER_LINE
else:
val_lines = 0
remaining_lines = TEXT_MAX_LINES - used_lines remaining_lines = TEXT_MAX_LINES - used_lines
used_lines = (used_lines + key_lines + val_lines) % TEXT_MAX_LINES used_lines = (used_lines + key_lines + val_lines) % TEXT_MAX_LINES
@ -627,7 +641,12 @@ async def confirm_properties(
if key: if key:
para.append((ui.NORMAL, key)) para.append((ui.NORMAL, key))
if val: if isinstance(val, bytes):
para.extend(
(ui.MONO, line)
for line in chunks(hexlify(val).decode(), MONO_HEX_PER_LINE - 2)
)
elif isinstance(val, str):
para.append((ui.BOLD, val)) para.append((ui.BOLD, val))
content = paginate_paragraphs( content = paginate_paragraphs(
para, title, icon, icon_color, confirm=HoldToConfirm if hold else Confirm para, title, icon, icon_color, confirm=HoldToConfirm if hold else Confirm