Skip to content

Commit

Permalink
fixup! chore(core): hardcode ETH and Gwei units in ETH send summary
Browse files Browse the repository at this point in the history
  • Loading branch information
grdddj committed Nov 27, 2023
1 parent 4e8c68d commit b428d53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
32 changes: 20 additions & 12 deletions core/src/apps/ethereum/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions core/tests/test_apps.ethereum.layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b428d53

Please sign in to comment.