2018-01-04 13:08:21 +00:00
|
|
|
from apps.common.confirm import *
|
2018-02-27 02:05:15 +00:00
|
|
|
from trezor import ui
|
2018-02-06 17:35:14 +00:00
|
|
|
from trezor.utils import chunks, format_amount
|
2017-12-27 11:48:05 +00:00
|
|
|
from trezor.messages import ButtonRequestType
|
|
|
|
from trezor.ui.text import Text
|
2018-01-04 13:08:21 +00:00
|
|
|
from ubinascii import hexlify
|
2017-12-27 11:48:05 +00:00
|
|
|
from . import networks
|
2018-02-28 01:09:10 +00:00
|
|
|
from .get_address import _ethereum_address_hex
|
2017-12-27 11:48:05 +00:00
|
|
|
|
|
|
|
|
2018-02-28 19:20:39 +00:00
|
|
|
async def require_confirm_tx(ctx, to, value, chain_id, token=None):
|
2018-02-28 01:09:10 +00:00
|
|
|
if to:
|
|
|
|
str_to = _ethereum_address_hex(to)
|
|
|
|
else:
|
|
|
|
str_to = 'new contract?'
|
|
|
|
content = Text('Confirm sending', ui.ICON_SEND,
|
2018-02-06 17:35:14 +00:00
|
|
|
ui.BOLD, format_ethereum_amount(value, token, chain_id),
|
2017-12-27 11:48:05 +00:00
|
|
|
ui.NORMAL, 'to',
|
2018-02-28 01:09:10 +00:00
|
|
|
ui.MONO, *split_address(str_to),
|
|
|
|
icon_color=ui.GREEN)
|
2018-02-28 19:20:39 +00:00
|
|
|
await require_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
2017-12-27 11:48:05 +00:00
|
|
|
|
|
|
|
|
2018-02-28 19:20:39 +00:00
|
|
|
async def require_confirm_fee(ctx, spending, gas_price, gas_limit, chain_id, token=None):
|
2018-02-28 01:09:10 +00:00
|
|
|
content = Text('Confirm transaction', ui.ICON_SEND,
|
|
|
|
ui.BOLD, format_ethereum_amount(spending, token, chain_id),
|
2018-03-08 11:05:53 +00:00
|
|
|
ui.NORMAL, 'Gas price:',
|
|
|
|
ui.BOLD, format_ethereum_amount(gas_price, None, chain_id),
|
|
|
|
ui.NORMAL, 'Maximum fee:',
|
|
|
|
ui.BOLD, format_ethereum_amount(gas_price * gas_limit, None, chain_id),
|
2018-02-28 01:09:10 +00:00
|
|
|
icon_color=ui.GREEN)
|
2018-02-28 19:20:39 +00:00
|
|
|
await require_hold_to_confirm(ctx, content, ButtonRequestType.SignTx)
|
2017-12-27 11:48:05 +00:00
|
|
|
|
|
|
|
|
2018-02-28 01:09:10 +00:00
|
|
|
def split_data(data):
|
|
|
|
return chunks(data, 18)
|
|
|
|
|
|
|
|
|
2018-02-28 19:20:39 +00:00
|
|
|
async def require_confirm_data(ctx, data, data_total):
|
2018-02-28 01:09:10 +00:00
|
|
|
str_data = hexlify(data[:36]).decode()
|
|
|
|
if data_total > 36:
|
|
|
|
str_data = str_data[:-2] + '..'
|
|
|
|
content = Text('Confirm data', ui.ICON_SEND,
|
|
|
|
ui.BOLD, 'Size: %d bytes' % data_total,
|
|
|
|
ui.MONO, *split_data(str_data),
|
|
|
|
icon_color=ui.GREEN)
|
2018-02-28 19:20:39 +00:00
|
|
|
await require_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
2017-12-27 11:48:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
def split_address(address):
|
|
|
|
return chunks(address, 17)
|
|
|
|
|
|
|
|
|
2018-02-06 17:35:14 +00:00
|
|
|
def format_ethereum_amount(value, token, chain_id):
|
2017-12-27 11:48:05 +00:00
|
|
|
if token:
|
2018-02-28 01:36:43 +00:00
|
|
|
suffix = token[2]
|
|
|
|
decimals = token[3]
|
2017-12-27 11:48:05 +00:00
|
|
|
else:
|
|
|
|
suffix = networks.suffix_by_chain_id(chain_id)
|
2018-02-28 01:09:10 +00:00
|
|
|
decimals = 18
|
|
|
|
|
2018-03-03 22:37:21 +00:00
|
|
|
if value <= 1e9:
|
2018-02-28 01:09:10 +00:00
|
|
|
suffix = 'Wei ' + suffix
|
|
|
|
decimals = 0
|
2017-12-27 11:48:05 +00:00
|
|
|
|
2018-02-06 17:35:14 +00:00
|
|
|
return '%s %s' % (format_amount(value, decimals), suffix)
|