diff --git a/core/src/apps/ethereum/layout.py b/core/src/apps/ethereum/layout.py index 34b014f1daf..b300d6823d5 100644 --- a/core/src/apps/ethereum/layout.py +++ b/core/src/apps/ethereum/layout.py @@ -38,10 +38,10 @@ async def require_confirm_tx( to_str = "new contract?" chunkify = False - total_amount = format_ethereum_amount(value, token, network, force_unit_eth=True) - maximum_fee = format_ethereum_amount(gas_price * gas_limit, None, network, force_unit_eth=True) + total_amount = format_ethereum_amount(value, token, network) + maximum_fee = format_ethereum_amount(gas_price * gas_limit, None, network) gas_limit_str = f"{gas_limit} units" - gas_price_str = format_ethereum_amount(gas_price, None, network, force_unit_gwei=True) + gas_price_str = format_ethereum_amount(gas_price, None, network, force_unit_gwei=True, hide_symbol=True) items = ( ("Gas limit:", gas_limit_str), @@ -70,11 +70,11 @@ async def require_confirm_tx_eip1559( to_str = "new contract?" chunkify = False - total_amount = format_ethereum_amount(value, token, network, force_unit_eth=True) - maximum_fee = format_ethereum_amount(max_gas_fee * gas_limit, None, network, force_unit_eth=True) + total_amount = format_ethereum_amount(value, token, network) + maximum_fee = format_ethereum_amount(max_gas_fee * gas_limit, None, network) gas_limit_str = f"{gas_limit} units" - max_gas_fee_str = format_ethereum_amount(max_gas_fee, None, network, force_unit_gwei=True) - max_priority_fee_str = format_ethereum_amount(max_priority_fee, None, network, force_unit_gwei=True) + max_gas_fee_str = format_ethereum_amount(max_gas_fee, None, network, force_unit_gwei=True, hide_symbol=True) + max_priority_fee_str = format_ethereum_amount(max_priority_fee, None, network, force_unit_gwei=True, hide_symbol=True) items = ( ("Gas limit:", gas_limit_str), @@ -245,27 +245,35 @@ def format_ethereum_amount( network: EthereumNetworkInfo, force_unit_eth: bool = False, force_unit_gwei: bool = False, + hide_symbol: bool = False, ) -> str: from trezor.strings import format_amount + unit = "" + if token: - suffix = token.symbol + symbol = token.symbol decimals = token.decimals else: - suffix = network.symbol + symbol = network.symbol decimals = 18 if force_unit_eth: pass elif force_unit_gwei: decimals = decimals - 9 - suffix = "Gwei " + suffix + unit = "Gwei" elif decimals > 9 and value < 10 ** (decimals - 9): # Don't want to display wei values for tokens with small decimal numbers - suffix = "Wei " + suffix + unit = "Wei" decimals = 0 - return f"{format_amount(value, decimals)} {suffix}" + amount = format_amount(value, decimals) + amount_unit = f"{amount} {unit}" if unit else amount + if hide_symbol: + return amount_unit + else: + return f"{amount_unit} {symbol}" def limit_str(s: str, limit: int = 16) -> str: diff --git a/core/tests/test_apps.ethereum.layout.py b/core/tests/test_apps.ethereum.layout.py index 3d40552be0e..0720c4ceb96 100644 --- a/core/tests/test_apps.ethereum.layout.py +++ b/core/tests/test_apps.ethereum.layout.py @@ -58,6 +58,8 @@ def test_force_units(self): self.assertEqual(text, "0.0000000001 ETH") text = format_ethereum_amount(wei_amount, None, ETH, force_unit_gwei=True) self.assertEqual(text, "0.1 Gwei ETH") + text = format_ethereum_amount(wei_amount, None, ETH, force_unit_gwei=True, hide_symbol=True) + self.assertEqual(text, "0.1 Gwei") def test_precision(self): text = format_ethereum_amount(1000000000000000001, None, ETH)