From ffb400180d38830f8679c995e2570bc20efa89d5 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Thu, 4 Mar 2021 01:02:17 +0100 Subject: [PATCH] refactor(core/ui): more consistent layout parameter names --- core/src/apps/binance/get_address.py | 4 ++-- core/src/apps/bitcoin/get_address.py | 8 +++---- core/src/apps/ethereum/get_address.py | 4 ++-- core/src/apps/lisk/get_address.py | 4 ++-- core/src/apps/monero/get_address.py | 4 ++-- core/src/apps/nem/get_address.py | 4 ++-- core/src/apps/ripple/get_address.py | 4 ++-- core/src/apps/stellar/get_address.py | 6 +++-- core/src/apps/tezos/get_address.py | 4 ++-- core/src/trezor/ui/layouts/tt.py | 32 +++++++++++++++------------ 10 files changed, 40 insertions(+), 34 deletions(-) diff --git a/core/src/apps/binance/get_address.py b/core/src/apps/binance/get_address.py index d885fbff5..a9797ab7e 100644 --- a/core/src/apps/binance/get_address.py +++ b/core/src/apps/binance/get_address.py @@ -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) diff --git a/core/src/apps/bitcoin/get_address.py b/core/src/apps/bitcoin/get_address.py index fd2709803..50d535242 100644 --- a/core/src/apps/bitcoin/get_address.py +++ b/core/src/apps/bitcoin/get_address.py @@ -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) diff --git a/core/src/apps/ethereum/get_address.py b/core/src/apps/ethereum/get_address.py index a2ced53d5..57a8cb860 100644 --- a/core/src/apps/ethereum/get_address.py +++ b/core/src/apps/ethereum/get_address.py @@ -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) diff --git a/core/src/apps/lisk/get_address.py b/core/src/apps/lisk/get_address.py index c6824a0ce..7526b654f 100644 --- a/core/src/apps/lisk/get_address.py +++ b/core/src/apps/lisk/get_address.py @@ -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) diff --git a/core/src/apps/monero/get_address.py b/core/src/apps/monero/get_address.py index 275077f9f..70cbe35c9 100644 --- a/core/src/apps/monero/get_address.py +++ b/core/src/apps/monero/get_address.py @@ -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) diff --git a/core/src/apps/nem/get_address.py b/core/src/apps/nem/get_address.py index b1a08c31b..fccdb516d 100644 --- a/core/src/apps/nem/get_address.py +++ b/core/src/apps/nem/get_address.py @@ -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), ) diff --git a/core/src/apps/ripple/get_address.py b/core/src/apps/ripple/get_address.py index 405afae24..967189964 100644 --- a/core/src/apps/ripple/get_address.py +++ b/core/src/apps/ripple/get_address.py @@ -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) diff --git a/core/src/apps/stellar/get_address.py b/core/src/apps/stellar/get_address.py index 5a988fd3b..537303bb5 100644 --- a/core/src/apps/stellar/get_address.py +++ b/core/src/apps/stellar/get_address.py @@ -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) diff --git a/core/src/apps/tezos/get_address.py b/core/src/apps/tezos/get_address.py index 08a221dfc..ac676c1e6 100644 --- a/core/src/apps/tezos/get_address.py +++ b/core/src/apps/tezos/get_address.py @@ -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) diff --git a/core/src/trezor/ui/layouts/tt.py b/core/src/trezor/ui/layouts/tt.py index 9edc52326..09be0dc1c 100644 --- a/core/src/trezor/ui/layouts/tt.py +++ b/core/src/trezor/ui/layouts/tt.py @@ -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, )