From a08a1a5e2aa72e78c93f6c10440faf2b05837bd2 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Fri, 24 Aug 2018 16:33:21 +0200 Subject: [PATCH] apps: split_address moved to show only (#307) --- src/apps/common/show.py | 7 ++++--- src/apps/ethereum/layout.py | 5 +---- src/apps/lisk/layout.py | 6 +----- src/apps/nem/get_address.py | 19 ++----------------- src/apps/nem/layout.py | 6 +----- src/apps/nem/mosaic/layout.py | 3 ++- src/apps/nem/multisig/layout.py | 3 ++- src/apps/nem/transfer/layout.py | 3 ++- 8 files changed, 15 insertions(+), 37 deletions(-) diff --git a/src/apps/common/show.py b/src/apps/common/show.py index ac1d8fdfc..c2af10df6 100644 --- a/src/apps/common/show.py +++ b/src/apps/common/show.py @@ -11,10 +11,11 @@ from trezor.utils import chunks from apps.common.confirm import confirm, require_confirm -async def show_address(ctx, address: str): - lines = split_address(address) +async def show_address(ctx, address: str, network: str = None): text = Text("Confirm address", ui.ICON_RECEIVE, icon_color=ui.GREEN) - text.mono(*lines) + if network: + text.normal("%s network" % network) + text.mono(*split_address(address)) return await confirm( ctx, text, code=ButtonRequestType.Address, cancel="QR", cancel_style=ui.BTN_KEY ) diff --git a/src/apps/ethereum/layout.py b/src/apps/ethereum/layout.py index b96c7f4d1..ccb730291 100644 --- a/src/apps/ethereum/layout.py +++ b/src/apps/ethereum/layout.py @@ -6,6 +6,7 @@ from trezor.ui.text import Text from trezor.utils import chunks, format_amount from apps.common.confirm import require_confirm, require_hold_to_confirm +from apps.common.show import split_address from apps.ethereum import networks, tokens from apps.ethereum.get_address import _ethereum_address_hex @@ -50,10 +51,6 @@ async def require_confirm_data(ctx, data, data_total): await require_confirm(ctx, text, ButtonRequestType.SignTx) -def split_address(address): - return chunks(address, 17) - - def format_ethereum_amount(value: int, token, chain_id: int, tx_type=None): if token: if token is tokens.UNKNOWN_TOKEN: diff --git a/src/apps/lisk/layout.py b/src/apps/lisk/layout.py index e39e671bc..d33ef65e8 100644 --- a/src/apps/lisk/layout.py +++ b/src/apps/lisk/layout.py @@ -6,7 +6,7 @@ from trezor.utils import chunks from .helpers import get_vote_tx_text from apps.common.confirm import require_confirm, require_hold_to_confirm -from apps.common.show import show_pubkey +from apps.common.show import show_pubkey, split_address async def require_confirm_tx(ctx, to, value): @@ -53,7 +53,3 @@ async def require_confirm_fee(ctx, value, fee): def format_amount(value): return "%s LSK" % (int(value) / 100000000) - - -def split_address(address): - return chunks(address, 16) diff --git a/src/apps/nem/get_address.py b/src/apps/nem/get_address.py index 8bf1c0000..f00553a40 100644 --- a/src/apps/nem/get_address.py +++ b/src/apps/nem/get_address.py @@ -1,15 +1,10 @@ -from trezor import ui -from trezor.messages import ButtonRequestType from trezor.messages.NEMAddress import NEMAddress -from trezor.ui.text import Text from .helpers import NEM_CURVE, get_network_str -from .layout import split_address from .validators import validate_network from apps.common import seed -from apps.common.confirm import confirm -from apps.common.show import show_qr +from apps.common.show import show_address, show_qr async def get_address(ctx, msg): @@ -19,19 +14,9 @@ async def get_address(ctx, msg): if msg.show_display: while True: - if await _show_address(ctx, address, network): + if await show_address(ctx, address, get_network_str(network)): break if await show_qr(ctx, address.upper()): break return NEMAddress(address=address) - - -async def _show_address(ctx, address: str, network: int): - lines = split_address(address) - text = Text("Confirm address", ui.ICON_RECEIVE, icon_color=ui.GREEN) - text.normal("%s network" % get_network_str(network)) - text.mono(*lines) - return await confirm( - ctx, text, code=ButtonRequestType.Address, cancel="QR", cancel_style=ui.BTN_KEY - ) diff --git a/src/apps/nem/layout.py b/src/apps/nem/layout.py index 52edde84e..502e9fe16 100644 --- a/src/apps/nem/layout.py +++ b/src/apps/nem/layout.py @@ -1,7 +1,7 @@ from trezor import ui from trezor.messages import ButtonRequestType from trezor.ui.text import Text -from trezor.utils import chunks, format_amount, split_words +from trezor.utils import format_amount, split_words from .helpers import NEM_MAX_DIVISIBILITY @@ -38,10 +38,6 @@ async def require_confirm_final(ctx, fee: int): await require_hold_to_confirm(ctx, text, ButtonRequestType.SignTx) -def split_address(address: str): - return chunks(address, 17) - - def trim(payload: str, length: int) -> str: if len(payload) > length: return payload[:length] + ".." diff --git a/src/apps/nem/mosaic/layout.py b/src/apps/nem/mosaic/layout.py index 1ebbea533..0259997af 100644 --- a/src/apps/nem/mosaic/layout.py +++ b/src/apps/nem/mosaic/layout.py @@ -19,10 +19,11 @@ from ..layout import ( require_confirm_fee, require_confirm_final, require_confirm_text, - split_address, trim, ) +from apps.common.show import split_address + async def ask_mosaic_creation( ctx, common: NEMTransactionCommon, creation: NEMMosaicCreation diff --git a/src/apps/nem/multisig/layout.py b/src/apps/nem/multisig/layout.py index 66493afd4..f0c47bc6a 100644 --- a/src/apps/nem/multisig/layout.py +++ b/src/apps/nem/multisig/layout.py @@ -14,9 +14,10 @@ from ..layout import ( require_confirm_fee, require_confirm_final, require_confirm_text, - split_address, ) +from apps.common.show import split_address + async def ask_multisig(ctx, msg: NEMSignTx): address = nem.compute_address(msg.multisig.signer, msg.transaction.network) diff --git a/src/apps/nem/transfer/layout.py b/src/apps/nem/transfer/layout.py index 1eef6e80f..3ce32f541 100644 --- a/src/apps/nem/transfer/layout.py +++ b/src/apps/nem/transfer/layout.py @@ -16,10 +16,11 @@ from ..helpers import ( NEM_MAX_DIVISIBILITY, NEM_MOSAIC_AMOUNT_DIVISOR, ) -from ..layout import require_confirm_final, require_confirm_text, split_address +from ..layout import require_confirm_final, require_confirm_text from ..mosaic.helpers import get_mosaic_definition, is_nem_xem_mosaic from apps.common.confirm import require_confirm +from apps.common.show import split_address async def ask_transfer(