From c2b7a1ab832899ca6514635f75b5424424313b2e Mon Sep 17 00:00:00 2001 From: Ritchie Date: Fri, 5 Dec 2025 16:31:47 +0800 Subject: [PATCH] fix(core): tron energy rental tips for token --- core/src/apps/tron/layout.py | 35 +++++++++++------------------------ core/src/apps/tron/sign_tx.py | 21 ++++++--------------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/core/src/apps/tron/layout.py b/core/src/apps/tron/layout.py index ecf0aa26b..fb90de0a3 100644 --- a/core/src/apps/tron/layout.py +++ b/core/src/apps/tron/layout.py @@ -32,13 +32,17 @@ def require_confirm_tx( ctx: Context, to: str, value: int, - banner_text: str | None = None, + token: tokens.TokenInfo | None = None, ) -> Awaitable[None]: - to_str = to + banner_text = None + from .providers import provider_by_address + + if provider_by_address(to) is not None: + banner_text = _(i18n_keys.BANNER_ENERGY_RENTAL) return confirm_output( ctx, - address=to_str, - amount=format_amount_trx(value, None), + address=to, + amount=format_amount_trx(value, token), font_amount=ui.BOLD, color_to=ui.GREY, br_code=ButtonRequestType.SignTx, @@ -46,29 +50,12 @@ def require_confirm_tx( ) -def require_confirm_trigger_trc20( - ctx: Context, - verified: bool, - contract_address: str, - amount: int, - token: tokens.TokenInfo, - toAddress: str, -) -> Awaitable[None]: - if verified: - return confirm_output( - ctx, - address=toAddress, - amount=format_amount_trx(amount, token), - font_amount=ui.BOLD, - color_to=ui.GREY, - br_code=ButtonRequestType.SignTx, - ) - - # Unknown token +def require_confirm_unknown_token(ctx: Context, token_addr: str) -> Awaitable[None]: + return confirm_address( ctx, _(i18n_keys.TITLE__UNKNOWN_TOKEN), - contract_address, + token_addr, description=_(i18n_keys.LIST_KEY__CONTRACT__COLON), br_type="unknown_token", icon="A:/res/warning.png", diff --git a/core/src/apps/tron/sign_tx.py b/core/src/apps/tron/sign_tx.py index 90d4136e3..576fd4868 100644 --- a/core/src/apps/tron/sign_tx.py +++ b/core/src/apps/tron/sign_tx.py @@ -11,7 +11,6 @@ from apps.tron.serialize import serialize from . import ICON, PRIMARY_COLOR, layout, tokens -from .providers import provider_by_address @auto_keychain(__name__) @@ -51,17 +50,10 @@ async def _require_confirm_by_type(ctx, transaction, owner_address): if contract.transfer_contract.amount is None: raise wire.DataError("Invalid Tron transfer amount") recipient = contract.transfer_contract.to_address - banner_text = None - if provider_by_address(recipient) is not None: - from trezor.lvglui.i18n import gettext as _ - from trezor.lvglui.i18n import keys as i18n_keys - - banner_text = _(i18n_keys.BANNER_ENERGY_RENTAL) await layout.require_confirm_tx( ctx, recipient, contract.transfer_contract.amount, - banner_text=banner_text, ) elif contract.trigger_smart_contract: # check if TRC20 transfer/approval @@ -83,18 +75,17 @@ async def _require_confirm_by_type(ctx, transaction, owner_address): action = "Approve" if action == "Transfer": - token = tokens.token_by_address( - contract.trigger_smart_contract.contract_address - ) + token_addr = contract.trigger_smart_contract.contract_address + token = tokens.token_by_address(token_addr) recipient = _address_base58(b"\x41" + data[16:36]) value = int.from_bytes(data[36:68], "big") - await layout.require_confirm_trigger_trc20( + if token is tokens.UNKNOWN_TOKEN: + await layout.require_confirm_unknown_token(ctx, token_addr) + await layout.require_confirm_tx( ctx, - False if token is tokens.UNKNOWN_TOKEN else True, - contract.trigger_smart_contract.contract_address, + recipient, value, token, - recipient, ) if transaction.fee_limit: await layout.require_confirm_fee(