src/apps/ethereum: fix get_address ui

This commit is contained in:
Pavol Rusnak 2018-02-28 00:56:16 +01:00
parent 27f9f986c5
commit 9549ef9865
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 9 additions and 27 deletions

View File

@ -1,4 +1,4 @@
from trezor import ui
from apps.wallet.get_address import _show_address, _show_qr
async def ethereum_get_address(ctx, msg):
@ -16,31 +16,16 @@ async def ethereum_get_address(ctx, msg):
address = sha3_256(public_key[1:]).digest(True)[12:] # Keccak
if msg.show_display:
await _show_address(ctx, address)
hex_addr = _ethereum_address_hex(address)
while True:
if await _show_address(ctx, hex_addr):
break
if await _show_qr(ctx, hex_addr):
break
return EthereumAddress(address=address)
async def _show_address(ctx, address):
from trezor.messages.ButtonRequestType import Address
from trezor.ui.text import Text
from trezor.ui.qr import Qr
from trezor.ui.container import Container
from ..common.confirm import require_confirm
address = _ethereum_address_hex(address)
lines = _split_address(address)
content = Container(
Qr(address, (120, 135), 3),
Text('Confirm address', ui.ICON_DEFAULT, ui.MONO, *lines))
await require_confirm(ctx, content, code=Address)
def _split_address(address):
from trezor.utils import chunks
return chunks(address, 21)
def _ethereum_address_hex(address):
from ubinascii import hexlify
from trezor.crypto.hashlib import sha3_256

View File

@ -22,7 +22,7 @@ async def get_address(ctx, msg):
while True:
if await _show_address(ctx, address):
break
if await _show_qr(ctx, address, msg.script_type):
if await _show_qr(ctx, address.upper() if msg.script_type == InputScriptType.SPENDWITNESS else address):
break
return Address(address=address)
@ -39,14 +39,11 @@ async def _show_address(ctx, address: str):
cancel_style=ui.BTN_KEY)
async def _show_qr(ctx, address: str, script_type: int):
async def _show_qr(ctx, address: str):
qr_x = const(120)
qr_y = const(115)
qr_coef = const(4)
if script_type == InputScriptType.SPENDWITNESS:
address = address.upper()
content = Container(
Qr(address, (qr_x, qr_y), qr_coef),
Text('Confirm address', ui.ICON_RECEIVE, ui.MONO, icon_color=ui.GREEN))