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

feat(core): improve ethereum tokens ui (fixes #800)

This commit is contained in:
matejcik 2020-06-24 09:24:14 +02:00 committed by Tomas Susanka
parent b311bd4d4a
commit 7abe70e484
5 changed files with 24 additions and 5 deletions

View File

@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- CoinJoin preauthorization and signing flow. [#1053]
- Value of the `safety-checks` setting to the `Features` message. [#1193]
- ERC20 tokens show contract address for confirmation. Unknown ERC20 tokens show wei amount. [#800]
### Changed
- The `safety-checks` setting gained new possible value `PromptTemporarily` which overrides safety checks until device reboot. [#1133]

View File

@ -40,6 +40,14 @@ async def require_confirm_fee(
await require_hold_to_confirm(ctx, text, ButtonRequestType.SignTx)
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()
text.mono(*split_data(contract_address_hex))
await require_confirm(ctx, text, ButtonRequestType.SignTx)
def split_data(data):
return chunks(data, 18)
@ -56,9 +64,10 @@ async def require_confirm_data(ctx, data, data_total):
def format_ethereum_amount(value: int, token, chain_id: int, tx_type=None):
if token:
if token is tokens.UNKNOWN_TOKEN:
return "Unknown token value"
if token is tokens.UNKNOWN_TOKEN:
suffix = "Wei UNKN"
decimals = 0
elif token:
suffix = token[2]
decimals = token[3]
else:

View File

@ -11,7 +11,12 @@ from apps.common import paths
from . import address, tokens
from .keychain import with_keychain_from_chain_id
from .layout import require_confirm_data, require_confirm_fee, require_confirm_tx
from .layout import (
require_confirm_data,
require_confirm_fee,
require_confirm_tx,
require_confirm_unknown_token,
)
# maximum supported chain id
MAX_CHAIN_ID = 2147483629
@ -41,6 +46,9 @@ async def sign_tx(ctx, msg, keychain):
recipient = msg.data_initial_chunk[16:36]
value = int.from_bytes(msg.data_initial_chunk[36:68], "big")
if token is tokens.UNKNOWN_TOKEN:
await require_confirm_unknown_token(ctx, address_bytes)
await require_confirm_tx(ctx, recipient, value, msg.chain_id, token, msg.tx_type)
if token is None and msg.data_length > 0:
await require_confirm_data(ctx, msg.data_initial_chunk, data_total)

View File

@ -119,6 +119,7 @@ class TestMsgEthereumSigntx:
with client:
client.set_expected_responses(
[
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
messages.EthereumTxRequest(data_length=None),

View File

@ -139,7 +139,7 @@
"test_msg_ethereum_signtx.py-test_ethereum_signtx_message": "f15bfcd910b3a315515a07babc1f1bbfb30a78a9304b0fa4646cfc91911a638c",
"test_msg_ethereum_signtx.py-test_ethereum_signtx_newcontract": "b8672006a9590fa69b4a882830810734ddbf120327780d59e51dd894afa383cc",
"test_msg_ethereum_signtx.py-test_ethereum_signtx_nodata": "9d69b61aee19c42c22651cd9912d8a29b2ac6987b552966a6659e3505d4869e7",
"test_msg_ethereum_signtx.py-test_ethereum_signtx_unknown_erc20_token": "74ccd107e69bfd5d08355636f4d5814a9e4f2d2153f63a4a10bfab39c4ff60a1",
"test_msg_ethereum_signtx.py-test_ethereum_signtx_unknown_erc20_token": "1c35295d3216ba377a73e152d506033896c7d958775f4c9cfd13dd3cd5e3cfd2",
"test_msg_ethereum_signtx.py-test_ethereum_signtx_wanchain": "4abb87c2b2836601971af8483fb95ff0f5913bdf912ff3e17a20c8c34872470a",
"test_msg_ethereum_signtx_eip155.py::test_chain_ids[1-60-sig0]": "4fb0b0b8fb5f803132a422d8b26d51e46ee6976c04ad0de29230adfc63d0e44c",
"test_msg_ethereum_signtx_eip155.py::test_chain_ids[2018-2018-sig4]": "1eaf3c481d105f3c5da45e3455f6af13ac7c77a3796a9b69fdd38adae89a0401",