From 2d0d360944f86a0cb9a5d97ef886b4b0f2936ae9 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Thu, 10 May 2018 13:35:28 +0200 Subject: [PATCH 1/2] eth: unknown token transfer is recognized and displayed as unknown updates #198 --- src/apps/ethereum/layout.py | 3 +++ src/apps/ethereum/tokens.py | 6 +++--- tests/test_apps.ethereum.tokens.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/apps/ethereum/layout.py b/src/apps/ethereum/layout.py index 5ad457c5a..9d17e0de0 100644 --- a/src/apps/ethereum/layout.py +++ b/src/apps/ethereum/layout.py @@ -1,4 +1,5 @@ from apps.common.confirm import * +from apps.ethereum import tokens from trezor import ui from trezor.utils import chunks, format_amount from trezor.messages import ButtonRequestType @@ -53,6 +54,8 @@ def split_address(address): 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' suffix = token[2] decimals = token[3] else: diff --git a/src/apps/ethereum/tokens.py b/src/apps/ethereum/tokens.py index 88a1c465b..1aaa7ef11 100644 --- a/src/apps/ethereum/tokens.py +++ b/src/apps/ethereum/tokens.py @@ -1,12 +1,12 @@ def token_by_chain_address(chain_id, address): - if not address: - return None for token in tokens: if chain_id == token[0] and address == token[1]: return token - return None + return UNKNOWN_TOKEN +UNKNOWN_TOKEN = True + # rest of the file is generated using trezor-common/ethereum_tokens-gen.py # DO NOT EDIT MANUALLY! tokens = [ diff --git a/tests/test_apps.ethereum.tokens.py b/tests/test_apps.ethereum.tokens.py index e91a58def..222e76855 100644 --- a/tests/test_apps.ethereum.tokens.py +++ b/tests/test_apps.ethereum.tokens.py @@ -22,7 +22,7 @@ class TestEthereumTokens(unittest.TestCase): # invalid adress, invalid chain token = tokens.token_by_chain_address(999, b'\x00\xFF') - self.assertEqual(token, None) + self.assertEqual(token, tokens.UNKNOWN_TOKEN) if __name__ == '__main__': From 55de110ee92942d96e0545bc55928c7349a0966a Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Thu, 10 May 2018 14:50:56 +0200 Subject: [PATCH 2/2] eth: unknown token changed to (None, None..) --- src/apps/ethereum/tokens.py | 2 +- tests/test_apps.ethereum.tokens.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/ethereum/tokens.py b/src/apps/ethereum/tokens.py index 1aaa7ef11..222ecef4e 100644 --- a/src/apps/ethereum/tokens.py +++ b/src/apps/ethereum/tokens.py @@ -5,7 +5,7 @@ def token_by_chain_address(chain_id, address): return UNKNOWN_TOKEN -UNKNOWN_TOKEN = True +UNKNOWN_TOKEN = (None, None, None, None) # rest of the file is generated using trezor-common/ethereum_tokens-gen.py # DO NOT EDIT MANUALLY! diff --git a/tests/test_apps.ethereum.tokens.py b/tests/test_apps.ethereum.tokens.py index 222e76855..c5576d65b 100644 --- a/tests/test_apps.ethereum.tokens.py +++ b/tests/test_apps.ethereum.tokens.py @@ -22,7 +22,7 @@ class TestEthereumTokens(unittest.TestCase): # invalid adress, invalid chain token = tokens.token_by_chain_address(999, b'\x00\xFF') - self.assertEqual(token, tokens.UNKNOWN_TOKEN) + self.assertIs(token, tokens.UNKNOWN_TOKEN) if __name__ == '__main__':