1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 23:08:14 +00:00

nem: get address formatting

This commit is contained in:
Tomas Susanka 2018-03-27 14:30:57 +02:00 committed by Jan Pochyla
parent 93ff3f074b
commit 105ba853af
2 changed files with 37 additions and 5 deletions

View File

@ -1,7 +1,11 @@
from apps.wallet.get_address import _show_address
from apps.common import seed
from trezor.messages.NEMAddress import NEMAddress
from .validators import * from .validators import *
from apps.common import seed
from apps.common.confirm import confirm
from trezor import ui
from trezor.messages.NEMAddress import NEMAddress
from trezor.messages import ButtonRequestType
from trezor.ui.text import Text
from trezor.utils import chunks
async def nem_get_address(ctx, msg): async def nem_get_address(ctx, msg):
@ -11,7 +15,35 @@ async def nem_get_address(ctx, msg):
if msg.show_display: if msg.show_display:
while True: while True:
if await _show_address(ctx, address): if await _show_address(ctx, address, network):
break break
return NEMAddress(address=address) return NEMAddress(address=address)
async def _show_address(ctx, address: str, network: int):
lines = _split_address(address)
print(network)
content = Text('Export NEM address', ui.ICON_RECEIVE,
ui.MONO, _get_network_str(network) + ' network',
ui.MONO, *lines,
icon_color=ui.GREEN)
return await confirm(
ctx,
content,
code=ButtonRequestType.Address,
cancel_style=ui.BTN_KEY)
def _split_address(address: str):
return chunks(address, 17)
def _get_network_str(network: int) -> str:
if network == NEM_NETWORK_MAINNET:
return 'Mainnet'
elif network == NEM_NETWORK_TESTNET:
return 'Testnet'
elif network == NEM_NETWORK_MIJIN:
return 'Mijin'

View File

@ -18,7 +18,7 @@ def validate(msg: NEMSignTx):
if msg.provision_namespace or msg.mosaic_creation or msg.supply_change or msg.aggregate_modification \ if msg.provision_namespace or msg.mosaic_creation or msg.supply_change or msg.aggregate_modification \
or msg.importance_transfer: or msg.importance_transfer:
raise ValueError('Not yet implemented') raise ValueError('Not yet implemented') # todo
_validate_single_tx(msg) _validate_single_tx(msg)
_validate_common(msg.transaction) _validate_common(msg.transaction)