1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-18 05:28:40 +00:00

refactor(core/ui): more consistent layout parameter names

This commit is contained in:
Martin Milata 2021-03-04 01:02:17 +01:00 committed by matejcik
parent d33c61bbe7
commit ffb400180d
10 changed files with 40 additions and 34 deletions

View File

@ -18,7 +18,7 @@ async def get_address(ctx, msg: BinanceGetAddress, keychain: Keychain):
pubkey = node.public_key()
address = address_from_public_key(pubkey, HRP)
if msg.show_display:
desc = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address, desc=desc)
title = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address, title=title)
return BinanceAddress(address=address)

View File

@ -82,19 +82,19 @@ async def get_address(
pubnodes = [hd.node for hd in msg.multisig.pubkeys]
multisig_index = multisig_pubkey_index(msg.multisig, node.public_key())
desc = "Multisig %d of %d" % (msg.multisig.m, len(pubnodes))
title = "Multisig %d of %d" % (msg.multisig.m, len(pubnodes))
await show_address(
ctx,
address=address_short,
address_qr=address_qr,
desc=desc,
title=title,
multisig_index=multisig_index,
xpubs=_get_xpubs(coin, multisig_xpub_magic, pubnodes),
)
else:
desc = address_n_to_str(msg.address_n)
title = address_n_to_str(msg.address_n)
await show_address(
ctx, address=address_short, address_qr=address_qr, desc=desc
ctx, address=address_short, address_qr=address_qr, title=title
)
return Address(address=address)

View File

@ -27,7 +27,7 @@ async def get_address(ctx, msg, keychain):
address = address_from_bytes(address_bytes, network)
if msg.show_display:
desc = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address, desc=desc)
title = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address, title=title)
return EthereumAddress(address=address)

View File

@ -18,7 +18,7 @@ async def get_address(ctx, msg, keychain):
address = get_address_from_public_key(pubkey)
if msg.show_display:
desc = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address, desc=desc)
title = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address, title=title)
return LiskAddress(address=address)

View File

@ -41,12 +41,12 @@ async def get_address(ctx, msg, keychain):
)
if msg.show_display:
desc = address_n_to_str(msg.address_n)
title = address_n_to_str(msg.address_n)
await show_address(
ctx,
address=addr.decode(),
address_qr="monero:" + addr.decode(),
desc=desc,
title=title,
)
return MoneroAddress(address=addr)

View File

@ -21,12 +21,12 @@ async def get_address(ctx, msg, keychain):
address = node.nem_address(network)
if msg.show_display:
desc = address_n_to_str(msg.address_n)
title = address_n_to_str(msg.address_n)
await show_address(
ctx,
address=address,
address_qr=address.upper(),
desc=desc,
title=title,
network=get_network_str(network),
)

View File

@ -17,7 +17,7 @@ async def get_address(ctx, msg: RippleGetAddress, keychain):
address = address_from_public_key(pubkey)
if msg.show_display:
desc = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address, desc=desc)
title = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address, title=title)
return RippleAddress(address=address)

View File

@ -17,7 +17,9 @@ async def get_address(ctx, msg: StellarGetAddress, keychain):
address = helpers.address_from_public_key(pubkey)
if msg.show_display:
desc = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address.upper(), desc=desc)
title = address_n_to_str(msg.address_n)
await show_address(
ctx, address=address, address_qr=address.upper(), title=title
)
return StellarAddress(address=address)

View File

@ -22,7 +22,7 @@ async def get_address(ctx, msg, keychain):
)
if msg.show_display:
desc = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address, desc=desc)
title = address_n_to_str(msg.address_n)
await show_address(ctx, address=address, address_qr=address, title=title)
return TezosAddress(address=address)

View File

@ -199,12 +199,12 @@ async def confirm_path_warning(ctx: wire.GenericContext, path: str) -> None:
def _show_qr(
address: str,
desc: str,
title: str,
cancel: str = "Address",
) -> Confirm:
QR_COEF = const(4) if len(address) < QR_SIZE_THRESHOLD else const(3)
qr = Qr(address, QR_X, QR_Y, QR_COEF)
text = Text(desc, ui.ICON_RECEIVE, ui.GREEN)
text = Text(title, ui.ICON_RECEIVE, ui.GREEN)
return Confirm(Container(qr, text), cancel=cancel, cancel_style=ButtonDefault)
@ -235,7 +235,7 @@ def _truncate_hex(
def _show_address(
address: str,
desc: str,
title: str,
network: str | None = None,
) -> Confirm | Paginated:
para = [(ui.NORMAL, "%s network" % network)] if network is not None else []
@ -244,17 +244,17 @@ def _show_address(
)
return paginate_paragraphs(
para,
header=desc,
header=title,
header_icon=ui.ICON_RECEIVE,
icon_color=ui.GREEN,
confirm_kwargs={"cancel": "QR", "cancel_style": ButtonDefault},
)
def _show_xpub(xpub: str, desc: str, cancel: str) -> Paginated:
def _show_xpub(xpub: str, title: str, cancel: str) -> Paginated:
pages: list[ui.Component] = []
for lines in chunks(list(chunks_intersperse(xpub, 16)), TEXT_MAX_LINES * 2):
text = Text(desc, ui.ICON_RECEIVE, ui.GREEN, new_lines=False)
text = Text(title, ui.ICON_RECEIVE, ui.GREEN, new_lines=False)
text.mono(*lines)
pages.append(text)
@ -270,12 +270,12 @@ def _show_xpub(xpub: str, desc: str, cancel: str) -> Paginated:
async def show_xpub(
ctx: wire.GenericContext, xpub: str, desc: str, cancel: str
ctx: wire.GenericContext, xpub: str, title: str, cancel: str
) -> None:
await raise_if_cancelled(
interact(
ctx,
_show_xpub(xpub, desc, cancel),
_show_xpub(xpub, title, cancel),
"show_xpub",
ButtonRequestType.PublicKey,
)
@ -286,7 +286,7 @@ async def show_address(
ctx: wire.GenericContext,
address: str,
address_qr: str | None = None,
desc: str = "Confirm address",
title: str = "Confirm address",
network: str | None = None,
multisig_index: int | None = None,
xpubs: Sequence[str] = [],
@ -296,7 +296,11 @@ async def show_address(
if is_confirmed(
await interact(
ctx,
_show_address(address, desc, network),
_show_address(
address,
title,
network,
),
"show_address",
ButtonRequestType.Address,
)
@ -307,7 +311,7 @@ async def show_address(
ctx,
_show_qr(
address if address_qr is None else address_qr,
desc,
title,
cancel="XPUBs" if is_multisig else "Address",
),
"show_qr",
@ -319,12 +323,12 @@ async def show_address(
if is_multisig:
for i, xpub in enumerate(xpubs):
cancel = "Next" if i < len(xpubs) - 1 else "Address"
desc_xpub = "XPUB #%d" % (i + 1)
desc_xpub += " (yours)" if i == multisig_index else " (cosigner)"
title_xpub = "XPUB #%d" % (i + 1)
title_xpub += " (yours)" if i == multisig_index else " (cosigner)"
if is_confirmed(
await interact(
ctx,
_show_xpub(xpub, desc=desc_xpub, cancel=cancel),
_show_xpub(xpub, title=title_xpub, cancel=cancel),
"show_xpub",
ButtonRequestType.PublicKey,
)