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 2d59444 commit 4e15e34
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 84 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
Loading

0 comments on commit 4e15e34

Please sign in to comment.