diff --git a/src/apps/ethereum/networks.py b/src/apps/ethereum/networks.py new file mode 100644 index 0000000000..c21b24d58a --- /dev/null +++ b/src/apps/ethereum/networks.py @@ -0,0 +1,16 @@ +suffixes = { + 1: 'ETH', # Ethereum Mainnet + 2: 'EXP', # Expanse + 3: 'tETH', # Ethereum Testnet: Ropsten + 4: 'tETH', # Ethereum Testnet: Rinkeby + 8: 'UBQ', # UBIQ + 30: 'RSK', # Rootstock Mainnet + 31: 'tRSK', # Rootstock Testnet + 42: 'tETH', # Ethereum Testnet: Kovan + 61: 'ETC', # Ethereum Classic Mainnet + 62: 'tETC', # Ethereum Classic Testnet +} + + +def suffix_by_chain_id(chain_id): + return suffixes.get(chain_id, 'UNKN') diff --git a/src/apps/ethereum/sign_tx.py b/src/apps/ethereum/sign_tx.py index f0b79ea961..e20ef94596 100644 --- a/src/apps/ethereum/sign_tx.py +++ b/src/apps/ethereum/sign_tx.py @@ -8,7 +8,7 @@ from apps.common.confirm import confirm from apps.common.hash_writer import HashWriter from trezor.ui.text import Text from trezor.crypto import rlp -from apps.ethereum import tokens +from apps.ethereum import networks, tokens # maximum supported chain id @@ -26,8 +26,11 @@ async def ethereum_sign_tx(ctx, msg): # detect ERC - 20 token token = None - if len(msg.to) == 20 and len(msg.value) == 0 and data_total == 68 and len(msg.data_initial_chunk) == 68 \ - and msg.data_initial_chunk[:16] == b'a9059cbb000000000000000000000000': #todo x? + if len(msg.to) == 20 and \ + len(msg.value) == 0 and \ + data_total == 68 and \ + len(msg.data_initial_chunk) == 68 and \ + msg.data_initial_chunk[:16] == b'\xa9\x05\x9c\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00': token = tokens.token_by_chain_address(msg.chain_id, msg.to) if token is not None: @@ -198,31 +201,10 @@ def format_amount(value, token, chain_id): suffix = token.ticker decimals = token.decimals elif value < 1e18: - suffix = " Wei" + suffix = 'Wei' decimals = 0 else: decimals = 18 - if chain_id == 1: - suffix = " ETH" # Ethereum Mainnet - elif chain_id == 61: - suffix = " ETC" # Ethereum Classic Mainnet - elif chain_id == 62: - suffix = " tETC" # Ethereum Classic Testnet - elif chain_id == 30: - suffix = " RSK" # Rootstock Mainnet - elif chain_id == 31: - suffix = " tRSK" # Rootstock Testnet - elif chain_id == 3: - suffix = " tETH" # Ethereum Testnet: Ropsten - elif chain_id == 4: - suffix = " tETH" # Ethereum Testnet: Rinkeby - elif chain_id == 42: - suffix = " tETH" # Ethereum Testnet: Kovan - elif chain_id == 2: - suffix = " EXP" # Expanse - elif chain_id == 8: - suffix = " UBQ" # UBIQ - else: - suffix = " UNKN" # unknown chain + suffix = networks.suffix_by_chain_id(chain_id) - return '%s%s' % (value // 10**decimals, suffix) + return '%s %s' % (value // 10 ** decimals, suffix) diff --git a/src/apps/ethereum/tokens.py b/src/apps/ethereum/tokens.py index 806b86199f..3debb7daa1 100644 --- a/src/apps/ethereum/tokens.py +++ b/src/apps/ethereum/tokens.py @@ -1,4 +1,3 @@ - def token_by_chain_address(chain_id, address): if not address: return 0