Skip to content

Commit

Permalink
feat(core): show account info in ETH send/stake flow
Browse files Browse the repository at this point in the history
  • Loading branch information
ibz committed Sep 17, 2024
1 parent 24a15c3 commit e5f67ff
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 24 deletions.
1 change: 1 addition & 0 deletions core/.changelog.d/3536.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[T3T1] Show account info in ETH send/stake flow.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
16 changes: 16 additions & 0 deletions core/src/apps/ethereum/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
42 changes: 35 additions & 7 deletions core/src/apps/ethereum/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -97,19 +120,24 @@ 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,
chunkify: bool,
) -> 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
Expand Down
9 changes: 8 additions & 1 deletion core/src/apps/ethereum/sign_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ async def confirm_tx_data(
await require_confirm_tx(
recipient,
value,
msg.address_n,
maximum_fee,
fee_items,
defs.network,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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]],
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions core/src/trezor/ui/layouts/mercury/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions core/src/trezor/ui/layouts/tr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions core/src/trezor/ui/layouts/tt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions tests/ui_tests/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e5f67ff

Please sign in to comment.