Skip to content

Commit

Permalink
feat(core): improve ethereum tokens ui (fixes #800)
Browse files Browse the repository at this point in the history
  • Loading branch information
matejcik authored and tsusanka committed Nov 20, 2020
1 parent b311bd4 commit 7abe70e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 12 additions & 3 deletions core/src/apps/ethereum/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion core/src/apps/ethereum/sign_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/device_tests/test_msg_ethereum_signtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def test_ethereum_signtx_unknown_erc20_token(self, client):
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),
Expand Down
2 changes: 1 addition & 1 deletion tests/ui_tests/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7abe70e

Please sign in to comment.