|
|
@ -3,11 +3,7 @@ from ubinascii import hexlify
|
|
|
|
from trezor import ui
|
|
|
|
from trezor import ui
|
|
|
|
from trezor.enums import ButtonRequestType
|
|
|
|
from trezor.enums import ButtonRequestType
|
|
|
|
from trezor.strings import format_amount
|
|
|
|
from trezor.strings import format_amount
|
|
|
|
from trezor.ui.components.tt.text import Text
|
|
|
|
from trezor.ui.layouts import confirm_hex, confirm_output, confirm_total_ethereum
|
|
|
|
from trezor.utils import chunks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from apps.common.confirm import require_confirm, require_hold_to_confirm
|
|
|
|
|
|
|
|
from apps.common.layout import split_address
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from . import networks, tokens
|
|
|
|
from . import networks, tokens
|
|
|
|
from .address import address_from_bytes
|
|
|
|
from .address import address_from_bytes
|
|
|
@ -18,49 +14,55 @@ async def require_confirm_tx(ctx, to_bytes, value, chain_id, token=None, tx_type
|
|
|
|
to_str = address_from_bytes(to_bytes, networks.by_chain_id(chain_id))
|
|
|
|
to_str = address_from_bytes(to_bytes, networks.by_chain_id(chain_id))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
to_str = "new contract?"
|
|
|
|
to_str = "new contract?"
|
|
|
|
text = Text("Confirm sending", ui.ICON_SEND, ui.GREEN, new_lines=False)
|
|
|
|
await confirm_output(
|
|
|
|
text.bold(format_ethereum_amount(value, token, chain_id, tx_type))
|
|
|
|
ctx,
|
|
|
|
text.normal(ui.GREY, " to ", ui.FG)
|
|
|
|
address=to_str,
|
|
|
|
for to_line in split_address(to_str):
|
|
|
|
amount=format_ethereum_amount(value, token, chain_id, tx_type),
|
|
|
|
text.br()
|
|
|
|
font_amount=ui.BOLD,
|
|
|
|
text.mono(to_line)
|
|
|
|
color_to=ui.GREY,
|
|
|
|
# we use SignTx, not ConfirmOutput, for compatibility with T1
|
|
|
|
br_code=ButtonRequestType.SignTx,
|
|
|
|
await require_confirm(ctx, text, ButtonRequestType.SignTx)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def require_confirm_fee(
|
|
|
|
async def require_confirm_fee(
|
|
|
|
ctx, spending, gas_price, gas_limit, chain_id, token=None, tx_type=None
|
|
|
|
ctx, spending, gas_price, gas_limit, chain_id, token=None, tx_type=None
|
|
|
|
):
|
|
|
|
):
|
|
|
|
text = Text("Confirm transaction", ui.ICON_SEND, ui.GREEN, new_lines=False)
|
|
|
|
await confirm_total_ethereum(
|
|
|
|
text.bold(format_ethereum_amount(spending, token, chain_id, tx_type))
|
|
|
|
ctx,
|
|
|
|
text.normal(" ", ui.GREY, "Gas price:", ui.FG)
|
|
|
|
format_ethereum_amount(spending, token, chain_id, tx_type),
|
|
|
|
text.bold(format_ethereum_amount(gas_price, None, chain_id, tx_type))
|
|
|
|
format_ethereum_amount(gas_price, None, chain_id, tx_type),
|
|
|
|
text.normal(" ", ui.GREY, "Maximum fee:", ui.FG)
|
|
|
|
format_ethereum_amount(gas_price * gas_limit, None, chain_id, tx_type),
|
|
|
|
text.bold(format_ethereum_amount(gas_price * gas_limit, None, chain_id, tx_type))
|
|
|
|
)
|
|
|
|
await require_hold_to_confirm(ctx, text, ButtonRequestType.SignTx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def require_confirm_unknown_token(ctx, address_bytes):
|
|
|
|
async def require_confirm_unknown_token(ctx, address_bytes):
|
|
|
|
text = Text("Unknown token", ui.ICON_SEND, ui.ORANGE, new_lines=False)
|
|
|
|
|
|
|
|
text.normal(ui.GREY, "Contract:", ui.FG)
|
|
|
|
|
|
|
|
contract_address_hex = "0x" + hexlify(address_bytes).decode()
|
|
|
|
contract_address_hex = "0x" + hexlify(address_bytes).decode()
|
|
|
|
text.mono(*split_data(contract_address_hex))
|
|
|
|
await confirm_hex(
|
|
|
|
await require_confirm(ctx, text, ButtonRequestType.SignTx)
|
|
|
|
ctx,
|
|
|
|
|
|
|
|
"confirm_unknown",
|
|
|
|
|
|
|
|
title="Unknown token",
|
|
|
|
def split_data(data):
|
|
|
|
data=contract_address_hex,
|
|
|
|
return chunks(data, 18)
|
|
|
|
truncate=True,
|
|
|
|
|
|
|
|
description="Contract:",
|
|
|
|
|
|
|
|
color_description=ui.GREY,
|
|
|
|
|
|
|
|
icon_color=ui.ORANGE,
|
|
|
|
|
|
|
|
br_code=ButtonRequestType.SignTx,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def require_confirm_data(ctx, data, data_total):
|
|
|
|
async def require_confirm_data(ctx, data, data_total):
|
|
|
|
data_str = hexlify(data[:36]).decode()
|
|
|
|
data_str = hexlify(data[:36]).decode()
|
|
|
|
if data_total > 36:
|
|
|
|
if data_total > 36:
|
|
|
|
data_str = data_str[:-2] + ".."
|
|
|
|
data_str = data_str[:-2] + ".."
|
|
|
|
text = Text("Confirm data", ui.ICON_SEND, ui.GREEN)
|
|
|
|
await confirm_hex(
|
|
|
|
text.bold("Size: %d bytes" % data_total)
|
|
|
|
ctx,
|
|
|
|
text.mono(*split_data(data_str))
|
|
|
|
"confirm_data",
|
|
|
|
# we use SignTx, not ConfirmOutput, for compatibility with T1
|
|
|
|
title="Confirm data",
|
|
|
|
await require_confirm(ctx, text, ButtonRequestType.SignTx)
|
|
|
|
data=data_str,
|
|
|
|
|
|
|
|
truncate=True,
|
|
|
|
|
|
|
|
subtitle="Size: %d bytes" % data_total,
|
|
|
|
|
|
|
|
br_code=ButtonRequestType.SignTx,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_ethereum_amount(value: int, token, chain_id: int, tx_type=None):
|
|
|
|
def format_ethereum_amount(value: int, token, chain_id: int, tx_type=None):
|
|
|
|