Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): show account info in ETH send/stake flow #4175

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]:
obrusvit marked this conversation as resolved.
Show resolved Hide resolved
from apps.common import paths

from .keychain import PATTERNS_ADDRESS

if not address_n or len(address_n) < 2:
return (None, None)

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)
account_path = paths.address_n_to_str(address_n)

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 | None,
_account_path: str | None,
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 | None,
_account_path: str | None,
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
8 changes: 4 additions & 4 deletions core/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
"addr_mismatch__wrong_derivation_path": "Ableitungspfad für gewähltes Konto falsch.",
"addr_mismatch__xpub_mismatch": "XPUB passt nicht?",
"address__cancel_contact_support": "Wenn die Empfängeradresse nicht übereinstimmt, dann wende dich bitte unter trezor.io/support an den Trezor Support.",
"address__cancel_receive": "Empfang abbrechen",
"address__cancel_receive": "Empfang abbr.",
"address__confirmed": "Empfängeradresse bestätigt",
"address__public_key": "Public Key",
"address__qr_code": "QR-Code",
"address__title_cosigner": "Mitunterzeich.",
"address__title_receive_address": "Empfäng-adresse",
"address__title_yours": "Deiner",
"address_details__account_info": "Kontoinformationen",
"address_details__account_info": "Konto-Info",
"address_details__derivation_path": "Ableitungspfad",
"address_details__derivation_path_colon": "Ableitungspfad:",
"address_details__title_receive_address": "Empfäng-adresse",
Expand Down Expand Up @@ -340,10 +340,10 @@
"ethereum__show_full_struct": "Ganze zeigen",
"ethereum__sign_eip712": "EIP-712-Daten wirklich signieren?",
"ethereum__staking_claim": "Einlösen",
"ethereum__staking_claim_address": "Adresse zum einlösen",
"ethereum__staking_claim_address": "Einlöse-Adresse",
"ethereum__staking_claim_intro": "ETH von Everstake einlösen?",
"ethereum__staking_stake": "Stake",
"ethereum__staking_stake_address": "Staking adresse",
"ethereum__staking_stake_address": "Staking-Adresse",
"ethereum__staking_stake_intro": "ETH auf Everstake staken?",
"ethereum__staking_unstake": "Entstaken",
"ethereum__staking_unstake_intro": "ETH von Everstake entstaken?",
Expand Down
8 changes: 4 additions & 4 deletions core/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
"addr_mismatch__wrong_derivation_path": "Chemin dériv. incorrect du compte sélectionné.",
"addr_mismatch__xpub_mismatch": "Err. clé publ. (XPUB) ?",
"address__cancel_contact_support": "Si l'adresse de réception ne correspond pas, contactez l'assistance Trezor sur trezor.io/support.",
"address__cancel_receive": "Annuler la réception",
"address__cancel_receive": "Annuler réception",
"address__confirmed": "Adresse de réception confirmée",
"address__public_key": "Clé publique",
"address__qr_code": "Code QR",
"address__title_cosigner": "Cosignataire",
"address__title_receive_address": "Adr. de récep.",
"address__title_yours": "La vôtre",
"address_details__account_info": "Infos sur le compte",
"address_details__account_info": "Info compte",
"address_details__derivation_path": "Chemin de dérivation",
"address_details__derivation_path_colon": "Chemin de dérivation:",
"address_details__title_receive_address": "Adr. de récep.",
Expand Down Expand Up @@ -343,7 +343,7 @@
"ethereum__staking_claim_address": "Adresse de retrait",
"ethereum__staking_claim_intro": "Retirer l'ETH d'Everstake ?",
"ethereum__staking_stake": "Stake",
"ethereum__staking_stake_address": "Adresse de staking",
"ethereum__staking_stake_address": "Adr. de staking",
"ethereum__staking_stake_intro": "Staker de l'ETH sur Everstake ?",
"ethereum__staking_unstake": "Unstake",
"ethereum__staking_unstake_intro": "Terminer le Staking de l'ETH sur Everstake ?",
Expand Down Expand Up @@ -753,7 +753,7 @@
"sd_card__wanna_format": "Voulez-vous vraiment formater la carte SD ?",
"sd_card__wrong_sd_card": "Mauvaise carte SD.",
"send__address_path": "chemin d'adr.",
"send__cancel_sign": "Annuler la signature",
"send__cancel_sign": "Annuler signature",
"send__confirm_sending": "Montant de l'envoi",
"send__from_multiple_accounts": "Envoi depuis plusieurs comptes.",
"send__incl_transaction_fee": "Frais de transaction inclus",
Expand Down
7 changes: 5 additions & 2 deletions core/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"addr_mismatch__support_url": "trezor.io/suporte",
"addr_mismatch__wrong_derivation_path": "Caminho de derivação incorreto para a conta.",
"addr_mismatch__xpub_mismatch": "XPUB não coincide?",
"address__cancel_receive": "Canc. receb.",
"address__public_key": "Chave pública",
"address__title_cosigner": "Cosigner",
"address__title_receive_address": "End. de recebimento",
"address__title_yours": "Seu",
"address_details__account_info": "Info conta",
"address_details__derivation_path": "Caminho de derivação:",
"address_details__title_receive_address": "End. de recebimento",
"address_details__title_receiving_to": "Recebendo para",
Expand Down Expand Up @@ -330,10 +332,10 @@
"ethereum__show_full_struct": "Exibir estrutura",
"ethereum__sign_eip712": "Deseja assinar dados digitados do EIP-712?",
"ethereum__staking_claim": "Resgatar",
"ethereum__staking_claim_address": "Endereço de resgate",
"ethereum__staking_claim_address": "End. de resgate",
"ethereum__staking_claim_intro": "Resgatar ETH do Everstake?",
"ethereum__staking_stake": "Stake",
"ethereum__staking_stake_address": "Endereço de stake",
"ethereum__staking_stake_address": "End. de stake",
"ethereum__staking_stake_intro": "Fazer stake de ETH no Everstake?",
"ethereum__staking_unstake": "Tirar do stake",
"ethereum__staking_unstake_intro": "Tirar ETH do stake no Everstake?",
Expand Down Expand Up @@ -703,6 +705,7 @@
"sd_card__wanna_format": "Deseja mesmo formatar o cartão SD?",
"sd_card__wrong_sd_card": "Cartão SD incorreto.",
"send__address_path": "caminho do endereço",
"send__cancel_sign": "Canc. assinatura",
"send__confirm_sending": "Quantia de envio",
"send__from_multiple_accounts": "Envio de múltiplas contas.",
"send__including_fee": "Incluindo taxa:",
Expand Down
6 changes: 3 additions & 3 deletions core/translations/signatures.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"current": {
"merkle_root": "3f354ff51c2d3855bf128509cd29b88c442eb7421f40e3788c1999cbbbe852eb",
"datetime": "2024-09-16T08:04:38.685162",
"commit": "1fac12992b035ba9ed86399ba00d52ca44cc9bc5"
"merkle_root": "26606d3bdf268494b2be43cf6f7da4d652bd06dc3a60ffa038c3c79169274d98",
"datetime": "2024-09-20T10:56:24.947001",
"commit": "d202d9feada4fd2ef4eab645b0a5d94b9602c372"
},
"history": [
{
Expand Down
Loading
Loading