src/apps: use address_n as description to show_address/show_qr dialogs

pull/25/head core/v2.0.8
Pavol Rusnak 6 years ago
parent 90868702ba
commit 939a932219
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -12,9 +12,10 @@ from apps.common import HARDENED
from apps.common.confirm import confirm, require_confirm from apps.common.confirm import confirm, require_confirm
async def show_address(ctx, address: str, address_n: list, network: str = None): async def show_address(ctx, address: str, desc: str = None, network: str = None):
text = Text("Confirm address", ui.ICON_RECEIVE, icon_color=ui.GREEN) text = Text(
# TODO: print address_n via address_n_to_str(address_n) desc if desc else "Confirm address", ui.ICON_RECEIVE, icon_color=ui.GREEN
)
if network: if network:
text.normal("%s network" % network) text.normal("%s network" % network)
text.mono(*split_address(address)) text.mono(*split_address(address))
@ -23,13 +24,15 @@ async def show_address(ctx, address: str, address_n: list, network: str = None):
) )
async def show_qr(ctx, address: str): async def show_qr(ctx, address: str, desc: str = None):
qr_x = const(120) qr_x = const(120)
qr_y = const(115) qr_y = const(115)
qr_coef = const(4) qr_coef = const(4)
qr = Qr(address, (qr_x, qr_y), qr_coef) qr = Qr(address, (qr_x, qr_y), qr_coef)
text = Text("Confirm address", ui.ICON_RECEIVE, icon_color=ui.GREEN) text = Text(
desc if desc else "Confirm address", ui.ICON_RECEIVE, icon_color=ui.GREEN
)
content = Container(qr, text) content = Container(qr, text)
return await confirm( return await confirm(
ctx, ctx,
@ -58,4 +61,7 @@ def address_n_to_str(address_n: list) -> str:
else: else:
return str(i) return str(i)
if not address_n:
return "m"
return "m/" + "/".join([path_item(i) for i in address_n]) return "m/" + "/".join([path_item(i) for i in address_n])

@ -1,4 +1,4 @@
from apps.common.layout import show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.ethereum import networks from apps.ethereum import networks
@ -22,11 +22,11 @@ async def get_address(ctx, msg):
else: else:
network = None network = None
hex_addr = _ethereum_address_hex(address, network) hex_addr = _ethereum_address_hex(address, network)
desc = address_n_to_str(address_n)
while True: while True:
if await show_address(ctx, hex_addr, address_n): if await show_address(ctx, hex_addr, desc=desc):
break break
if await show_qr(ctx, hex_addr): if await show_qr(ctx, hex_addr, desc=desc):
break break
return EthereumAddress(address=address) return EthereumAddress(address=address)

@ -3,7 +3,7 @@ from trezor.messages.LiskAddress import LiskAddress
from .helpers import LISK_CURVE, get_address_from_public_key from .helpers import LISK_CURVE, get_address_from_public_key
from apps.common import seed from apps.common import seed
from apps.common.layout import show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
async def get_address(ctx, msg): async def get_address(ctx, msg):
@ -15,10 +15,11 @@ async def get_address(ctx, msg):
address = get_address_from_public_key(pubkey) address = get_address_from_public_key(pubkey)
if msg.show_display: if msg.show_display:
desc = address_n_to_str(address_n)
while True: while True:
if await show_address(ctx, address, address_n): if await show_address(ctx, address, desc=desc):
break break
if await show_qr(ctx, address): if await show_qr(ctx, address, desc=desc):
break break
return LiskAddress(address=address) return LiskAddress(address=address)

@ -1,6 +1,6 @@
from trezor.messages.MoneroAddress import MoneroAddress from trezor.messages.MoneroAddress import MoneroAddress
from apps.common.layout import show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.monero import misc from apps.monero import misc
@ -8,10 +8,11 @@ async def get_address(ctx, msg):
creds = await misc.get_creds(ctx, msg.address_n, msg.network_type) creds = await misc.get_creds(ctx, msg.address_n, msg.network_type)
if msg.show_display: if msg.show_display:
desc = address_n_to_str(msg.address_n)
while True: while True:
if await show_address(ctx, creds.address.decode("ascii"), msg.address_n): if await show_address(ctx, creds.address.decode(), desc=desc):
break break
if await show_qr(ctx, creds.address.decode("ascii")): if await show_qr(ctx, creds.address.decode(), desc=desc):
break break
return MoneroAddress(address=creds.address) return MoneroAddress(address=creds.address)

@ -4,7 +4,7 @@ from .helpers import NEM_CURVE, get_network_str
from .validators import validate_network from .validators import validate_network
from apps.common import seed from apps.common import seed
from apps.common.layout import show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
async def get_address(ctx, msg): async def get_address(ctx, msg):
@ -13,12 +13,13 @@ async def get_address(ctx, msg):
address = node.nem_address(network) address = node.nem_address(network)
if msg.show_display: if msg.show_display:
desc = address_n_to_str(msg.address_n)
while True: while True:
if await show_address( if await show_address(
ctx, address, msg.address_n, network=get_network_str(network) ctx, address, desc=desc, network=get_network_str(network)
): ):
break break
if await show_qr(ctx, address.upper()): if await show_qr(ctx, address.upper(), desc=desc):
break break
return NEMAddress(address=address) return NEMAddress(address=address)

@ -4,7 +4,7 @@ from trezor.messages.RippleGetAddress import RippleGetAddress
from . import helpers from . import helpers
from apps.common import seed from apps.common import seed
from apps.common.layout import show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
async def get_address(ctx, msg: RippleGetAddress): async def get_address(ctx, msg: RippleGetAddress):
@ -13,10 +13,11 @@ async def get_address(ctx, msg: RippleGetAddress):
address = helpers.address_from_public_key(pubkey) address = helpers.address_from_public_key(pubkey)
if msg.show_display: if msg.show_display:
desc = address_n_to_str(msg.address_n)
while True: while True:
if await show_address(ctx, address, msg.address_n): if await show_address(ctx, address, desc=desc):
break break
if await show_qr(ctx, address.upper()): if await show_qr(ctx, address.upper(), desc=desc):
break break
return RippleAddress(address=address) return RippleAddress(address=address)

@ -2,7 +2,7 @@ from trezor.messages.StellarAddress import StellarAddress
from trezor.messages.StellarGetAddress import StellarGetAddress from trezor.messages.StellarGetAddress import StellarGetAddress
from apps.common import seed from apps.common import seed
from apps.common.layout import show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.stellar import helpers from apps.stellar import helpers
@ -12,10 +12,11 @@ async def get_address(ctx, msg: StellarGetAddress):
address = helpers.address_from_public_key(pubkey) address = helpers.address_from_public_key(pubkey)
if msg.show_display: if msg.show_display:
desc = address_n_to_str(msg.address_n)
while True: while True:
if await show_address(ctx, address, msg.address_n): if await show_address(ctx, address, desc=desc):
break break
if await show_qr(ctx, address.upper()): if await show_qr(ctx, address.upper(), desc=desc):
break break
return StellarAddress(address=address) return StellarAddress(address=address)

@ -2,7 +2,7 @@ from trezor.crypto import hashlib
from trezor.messages.TezosAddress import TezosAddress from trezor.messages.TezosAddress import TezosAddress
from apps.common import seed from apps.common import seed
from apps.common.layout import show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.tezos.helpers import ( from apps.tezos.helpers import (
TEZOS_CURVE, TEZOS_CURVE,
TEZOS_ED25519_ADDRESS_PREFIX, TEZOS_ED25519_ADDRESS_PREFIX,
@ -19,10 +19,11 @@ async def get_address(ctx, msg):
address = base58_encode_check(pkh, prefix=TEZOS_ED25519_ADDRESS_PREFIX) address = base58_encode_check(pkh, prefix=TEZOS_ED25519_ADDRESS_PREFIX)
if msg.show_display: if msg.show_display:
desc = address_n_to_str(msg.address_n)
while True: while True:
if await show_address(ctx, address, address_n): if await show_address(ctx, address, desc=desc):
break break
if await show_qr(ctx, address): if await show_qr(ctx, address, desc=desc):
break break
return TezosAddress(address=address) return TezosAddress(address=address)

@ -2,7 +2,7 @@ from trezor.messages import InputScriptType
from trezor.messages.Address import Address from trezor.messages.Address import Address
from apps.common import coins, seed from apps.common import coins, seed
from apps.common.layout import show_address, show_qr from apps.common.layout import address_n_to_str, show_address, show_qr
from apps.wallet.sign_tx import addresses from apps.wallet.sign_tx import addresses
@ -15,14 +15,19 @@ async def get_address(ctx, msg):
address_short = addresses.address_short(coin, address) address_short = addresses.address_short(coin, address)
if msg.show_display: if msg.show_display:
if msg.multisig:
desc = "Multisig %d of %d" % (msg.multisig.m, len(msg.multisig.pubkeys))
else:
desc = address_n_to_str(msg.address_n)
while True: while True:
if await show_address(ctx, address_short, msg.address_n): if await show_address(ctx, address_short, desc=desc):
break break
if await show_qr( if await show_qr(
ctx, ctx,
address.upper() address.upper()
if msg.script_type == InputScriptType.SPENDWITNESS if msg.script_type == InputScriptType.SPENDWITNESS
else address, else address,
desc=desc,
): ):
break break

Loading…
Cancel
Save