From e5f67fff3e4048c61d2deab831b880e3fab7409e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ioan=20Biz=C4=83u?= Date: Thu, 12 Sep 2024 15:56:07 +0200 Subject: [PATCH] feat(core): show account info in ETH send/stake flow --- core/.changelog.d/3536.fixed | 1 + .../ui/model_mercury/flow/confirm_output.rs | 1 + core/src/apps/ethereum/helpers.py | 16 +++++++ core/src/apps/ethereum/layout.py | 42 +++++++++++++++---- core/src/apps/ethereum/sign_tx.py | 9 +++- .../src/trezor/ui/layouts/mercury/__init__.py | 12 ++++-- core/src/trezor/ui/layouts/tr/__init__.py | 4 ++ core/src/trezor/ui/layouts/tt/__init__.py | 4 ++ tests/ui_tests/fixtures.json | 24 +++++------ 9 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 core/.changelog.d/3536.fixed diff --git a/core/.changelog.d/3536.fixed b/core/.changelog.d/3536.fixed new file mode 100644 index 00000000000..f52cef49076 --- /dev/null +++ b/core/.changelog.d/3536.fixed @@ -0,0 +1 @@ +[T3T1] Show account info in ETH send/stake flow. diff --git a/core/embed/rust/src/ui/model_mercury/flow/confirm_output.rs b/core/embed/rust/src/ui/model_mercury/flow/confirm_output.rs index 6c215eafdfa..09756d74951 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/confirm_output.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/confirm_output.rs @@ -163,6 +163,7 @@ impl FlowState for ConfirmOutputWithSummary { (Self::MainMenu, FlowMsg::Choice(MENU_ITEM_CANCEL)) => { Self::MainMenuCancel.swipe_left() } + (Self::AccountInfo, FlowMsg::Cancelled) => Self::MainMenu.swipe_right(), (Self::MainMenuCancel, FlowMsg::Cancelled) => Self::MainMenu.swipe_right(), (Self::AddressInfo, FlowMsg::Info) => Self::MainMenu.transit(), (Self::Summary, FlowMsg::Info) => Self::SummaryMenu.transit(), diff --git a/core/src/apps/ethereum/helpers.py b/core/src/apps/ethereum/helpers.py index 7ce265d1af1..08d3062f3b0 100644 --- a/core/src/apps/ethereum/helpers.py +++ b/core/src/apps/ethereum/helpers.py @@ -195,6 +195,22 @@ def format_ethereum_amount( return f"{amount} {suffix}" +def get_account_and_path(address_n: list[int]) -> tuple[str | None, str | None]: + from apps.common import paths + + from .keychain import PATTERNS_ADDRESS + + slip44_id = address_n[1] # it depends on the network (ETH vs ETC...) + account = ( + paths.get_account_name("ETH", address_n, PATTERNS_ADDRESS, slip44_id) + if address_n + else None + ) + account_path = paths.address_n_to_str(address_n) if address_n is not None else None + + return (account, account_path) + + def _from_bytes_bigendian_signed(b: bytes) -> int: negative = b[0] & 0x80 if negative: diff --git a/core/src/apps/ethereum/layout.py b/core/src/apps/ethereum/layout.py index 20bd76cb7f9..8f88d9f8020 100644 --- a/core/src/apps/ethereum/layout.py +++ b/core/src/apps/ethereum/layout.py @@ -9,7 +9,12 @@ should_show_more, ) -from .helpers import address_from_bytes, decode_typed_data, format_ethereum_amount +from .helpers import ( + address_from_bytes, + decode_typed_data, + format_ethereum_amount, + get_account_and_path, +) if TYPE_CHECKING: from typing import Awaitable, Iterable @@ -25,6 +30,7 @@ async def require_confirm_tx( to_bytes: bytes, value: int, + address_n: list[int], maximum_fee: str, fee_info_items: Iterable[tuple[str, str]], network: EthereumNetworkInfo, @@ -41,14 +47,23 @@ async def require_confirm_tx( total_amount = format_ethereum_amount(value, token, network) + account, account_path = get_account_and_path(address_n) + await confirm_ethereum_tx( - to_str, total_amount, maximum_fee, fee_info_items, chunkify=chunkify + to_str, + total_amount, + account, + account_path, + maximum_fee, + fee_info_items, + chunkify=chunkify, ) async def require_confirm_stake( addr_bytes: bytes, value: int, + address_n: list[int], maximum_fee: str, fee_info_items: Iterable[tuple[str, str]], network: EthereumNetworkInfo, @@ -57,12 +72,16 @@ async def require_confirm_stake( addr_str = address_from_bytes(addr_bytes, network) total_amount = format_ethereum_amount(value, None, network) + account, account_path = get_account_and_path(address_n) + await confirm_ethereum_staking_tx( TR.ethereum__staking_stake, # title TR.ethereum__staking_stake_intro, # intro_question TR.ethereum__staking_stake, # verb - total_amount, # total_amount - maximum_fee, # maximum_fee + total_amount, + account, + account_path, + maximum_fee, addr_str, # address TR.ethereum__staking_stake_address, # address_title fee_info_items, # info_items @@ -73,6 +92,7 @@ async def require_confirm_stake( async def require_confirm_unstake( addr_bytes: bytes, value: int, + address_n: list[int], maximum_fee: str, fee_info_items: Iterable[tuple[str, str]], network: EthereumNetworkInfo, @@ -81,13 +101,16 @@ async def require_confirm_unstake( addr_str = address_from_bytes(addr_bytes, network) total_amount = format_ethereum_amount(value, None, network) + account, account_path = get_account_and_path(address_n) await confirm_ethereum_staking_tx( TR.ethereum__staking_unstake, # title TR.ethereum__staking_unstake_intro, # intro_question TR.ethereum__staking_unstake, # verb - total_amount, # total_amount - maximum_fee, # maximum_fee + total_amount, + account, + account_path, + maximum_fee, addr_str, # address TR.ethereum__staking_stake_address, # address_title fee_info_items, # info_items @@ -97,6 +120,7 @@ async def require_confirm_unstake( async def require_confirm_claim( addr_bytes: bytes, + address_n: list[int], maximum_fee: str, fee_info_items: Iterable[tuple[str, str]], network: EthereumNetworkInfo, @@ -104,12 +128,16 @@ async def require_confirm_claim( ) -> None: addr_str = address_from_bytes(addr_bytes, network) + account, account_path = get_account_and_path(address_n) + await confirm_ethereum_staking_tx( TR.ethereum__staking_claim, # title TR.ethereum__staking_claim_intro, # intro_question TR.ethereum__staking_claim, # verb "", # total_amount - maximum_fee, # maximum_fee + account, + account_path, + maximum_fee, addr_str, # address TR.ethereum__staking_claim_address, # address_title fee_info_items, # info_items diff --git a/core/src/apps/ethereum/sign_tx.py b/core/src/apps/ethereum/sign_tx.py index c90f4d427d5..7e1dc3d0ae3 100644 --- a/core/src/apps/ethereum/sign_tx.py +++ b/core/src/apps/ethereum/sign_tx.py @@ -138,6 +138,7 @@ async def confirm_tx_data( await require_confirm_tx( recipient, value, + msg.address_n, maximum_fee, fee_items, defs.network, @@ -175,6 +176,7 @@ async def handle_staking( if func_sig == constants.SC_FUNC_SIG_CLAIM: await _handle_staking_tx_claim( data_reader, + msg, address_bytes, maximum_fee, fee_items, @@ -325,6 +327,7 @@ async def _handle_staking_tx_stake( await require_confirm_stake( address_bytes, int.from_bytes(msg.value, "big"), + msg.address_n, maximum_fee, fee_items, network, @@ -364,6 +367,7 @@ async def _handle_staking_tx_unstake( await require_confirm_unstake( address_bytes, value, + msg.address_n, maximum_fee, fee_items, network, @@ -373,6 +377,7 @@ async def _handle_staking_tx_unstake( async def _handle_staking_tx_claim( data_reader: BufferReader, + msg: MsgInSignTx, staking_addr: bytes, maximum_fee: str, fee_items: Iterable[tuple[str, str]], @@ -385,7 +390,9 @@ async def _handle_staking_tx_claim( if data_reader.remaining_count() != 0: raise DataError("Invalid staking transaction call") - await require_confirm_claim(staking_addr, maximum_fee, fee_items, network, chunkify) + await require_confirm_claim( + staking_addr, msg.address_n, maximum_fee, fee_items, network, chunkify + ) _progress_obj: ProgressLayout | None = None diff --git a/core/src/trezor/ui/layouts/mercury/__init__.py b/core/src/trezor/ui/layouts/mercury/__init__.py index 3a8385e2f07..96adf2e2edc 100644 --- a/core/src/trezor/ui/layouts/mercury/__init__.py +++ b/core/src/trezor/ui/layouts/mercury/__init__.py @@ -1027,6 +1027,8 @@ def _confirm_summary( async def confirm_ethereum_tx( recipient: str, total_amount: str, + account: str | None, + account_path: str | None, maximum_fee: str, fee_info_items: Iterable[tuple[str, str]], br_name: str = "confirm_ethereum_tx", @@ -1042,8 +1044,8 @@ async def confirm_ethereum_tx( amount=None, chunkify=chunkify, text_mono=True, - account=None, - account_path=None, + account=account, + account_path=account_path, address=None, address_title=None, br_code=ButtonRequestType.Other, @@ -1066,6 +1068,8 @@ async def confirm_ethereum_staking_tx( intro_question: str, verb: str, total_amount: str, + account: str | None, + account_path: str | None, maximum_fee: str, address: str, address_title: str, @@ -1090,8 +1094,8 @@ async def confirm_ethereum_staking_tx( amount=None, chunkify=False, text_mono=False, - account=None, - account_path=None, + account=account, + account_path=account_path, br_code=br_code, br_name=br_name, address=address, diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index 8d54956f911..ea82d30a6a1 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -1191,6 +1191,8 @@ async def confirm_ethereum_staking_tx( intro_question: str, verb: str, total_amount: str, + _account: str | None, + _account_path: str | None, maximum_fee: str, address: str, address_title: str, @@ -1268,6 +1270,8 @@ def confirm_solana_tx( async def confirm_ethereum_tx( recipient: str, total_amount: str, + _account: str, + _account_path: str, maximum_fee: str, fee_info_items: Iterable[tuple[str, str]], br_name: str = "confirm_ethereum_tx", diff --git a/core/src/trezor/ui/layouts/tt/__init__.py b/core/src/trezor/ui/layouts/tt/__init__.py index 93215a0e717..ed74a7d471c 100644 --- a/core/src/trezor/ui/layouts/tt/__init__.py +++ b/core/src/trezor/ui/layouts/tt/__init__.py @@ -1097,6 +1097,8 @@ def _confirm_summary( async def confirm_ethereum_tx( recipient: str, total_amount: str, + _account: str, + _account_path: str, maximum_fee: str, fee_info_items: Iterable[tuple[str, str]], br_name: str = "confirm_ethereum_tx", @@ -1145,6 +1147,8 @@ async def confirm_ethereum_staking_tx( intro_question: str, verb: str, total_amount: str, + _account: str | None, + _account_path: str | None, maximum_fee: str, address: str, address_title: str, diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index 290425db55b..6cde2519de2 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -22183,18 +22183,18 @@ "T3T1_en_ethereum-test_signtx.py::test_signtx_eip1559_access_list": "dd2790ac7fa5c240b051e85342d6368d0deac5a5cf8c7c8c4af1c09e3cf7182f", "T3T1_en_ethereum-test_signtx.py::test_signtx_eip1559_access_list_larger": "dd2790ac7fa5c240b051e85342d6368d0deac5a5cf8c7c8c4af1c09e3cf7182f", "T3T1_en_ethereum-test_signtx.py::test_signtx_fee_info": "b85b87c6946ad2074272ae7156fd6a5bfec4db17f12290c8b88d1bde1b551565", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-claim_holesky]": "c9ea54681f77d78b130719dec5be110ae0268f499466cc4656e96aa090c7f057", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-claim_mainnet]": "ef7330fe5b7ef7d9bef858d63bd78401ffacb39ee2b07134f74c25ca0ac057e2", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-stake_holesky]": "ee0a79a53b01e068bfee5ecc98597d4c6504b241ddff2eed22fadd0c4690913f", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-stake_main]": "28a8ede2baa9b729d626e128451452e335e3161dbc651867c9ed70a2192d4944", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-unstake_holesky]": "e5b6b99c47e6f5bf2d0dda1c317db61858ca42f5ab67ef268379770bc01ccc86", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-unstake_main]": "47ab2304a91cfbf820996c7514b5cc25d2f5fa317c294f6f7d60914836a1e25f", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-claim_holesky]": "c9ea54681f77d78b130719dec5be110ae0268f499466cc4656e96aa090c7f057", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-claim_mainnet]": "ef7330fe5b7ef7d9bef858d63bd78401ffacb39ee2b07134f74c25ca0ac057e2", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-stake_holesky]": "ee0a79a53b01e068bfee5ecc98597d4c6504b241ddff2eed22fadd0c4690913f", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-stake_main]": "28a8ede2baa9b729d626e128451452e335e3161dbc651867c9ed70a2192d4944", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-unstake_holesky]": "e5b6b99c47e6f5bf2d0dda1c317db61858ca42f5ab67ef268379770bc01ccc86", -"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-unstake_main]": "47ab2304a91cfbf820996c7514b5cc25d2f5fa317c294f6f7d60914836a1e25f", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-claim_holesky]": "eaca0e98888546de42dccfc6f08cb371f4bbb0b2683b9809a95abdf21d93d137", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-claim_mainnet]": "6864d04cd868e5c6140011d07bfbafc7b94a1947e817ec41dca99cce329f01ca", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-stake_holesky]": "8571b93330b2f8e1d0cfe5afa4ad4facc42c7ba15217b4aa4ee66fdf31fac767", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-stake_main]": "5c6ad16fa5749fc08af9e54c88044b723665fa7c5cc669ef7b086e96dc74bc09", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-unstake_holesky]": "d800aacbe852eb06a4dc3f077c24042058878fce5c35a7c75050e881484e0739", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[False-unstake_main]": "46c83ead0992edc76ca8452682ec1a7c35f5562eedfb89b27cdf4b7b27573b05", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-claim_holesky]": "eaca0e98888546de42dccfc6f08cb371f4bbb0b2683b9809a95abdf21d93d137", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-claim_mainnet]": "6864d04cd868e5c6140011d07bfbafc7b94a1947e817ec41dca99cce329f01ca", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-stake_holesky]": "8571b93330b2f8e1d0cfe5afa4ad4facc42c7ba15217b4aa4ee66fdf31fac767", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-stake_main]": "5c6ad16fa5749fc08af9e54c88044b723665fa7c5cc669ef7b086e96dc74bc09", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-unstake_holesky]": "d800aacbe852eb06a4dc3f077c24042058878fce5c35a7c75050e881484e0739", +"T3T1_en_ethereum-test_signtx.py::test_signtx_staking[True-unstake_main]": "46c83ead0992edc76ca8452682ec1a7c35f5562eedfb89b27cdf4b7b27573b05", "T3T1_en_ethereum-test_signtx.py::test_signtx_staking_bad_inputs[claim_bad_inputs_1]": "886a329a63547ee0f07547685dfc1c8677587c3471fe1bcba81c6a9363659185", "T3T1_en_ethereum-test_signtx.py::test_signtx_staking_bad_inputs[stake_bad_inputs_1]": "886a329a63547ee0f07547685dfc1c8677587c3471fe1bcba81c6a9363659185", "T3T1_en_ethereum-test_signtx.py::test_signtx_staking_bad_inputs[stake_bad_inputs_2]": "886a329a63547ee0f07547685dfc1c8677587c3471fe1bcba81c6a9363659185",