From b54ff6247c6c156edae873cf94973a9052606b82 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 ++ 8 files changed, 77 insertions(+), 12 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,