Skip to content

Commit c2b7a1a

Browse files
committed
fix(core): tron energy rental tips for token
1 parent eb7f10f commit c2b7a1a

File tree

2 files changed

+17
-39
lines changed

2 files changed

+17
-39
lines changed

core/src/apps/tron/layout.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,30 @@ def require_confirm_tx(
3232
ctx: Context,
3333
to: str,
3434
value: int,
35-
banner_text: str | None = None,
35+
token: tokens.TokenInfo | None = None,
3636
) -> Awaitable[None]:
37-
to_str = to
37+
banner_text = None
38+
from .providers import provider_by_address
39+
40+
if provider_by_address(to) is not None:
41+
banner_text = _(i18n_keys.BANNER_ENERGY_RENTAL)
3842
return confirm_output(
3943
ctx,
40-
address=to_str,
41-
amount=format_amount_trx(value, None),
44+
address=to,
45+
amount=format_amount_trx(value, token),
4246
font_amount=ui.BOLD,
4347
color_to=ui.GREY,
4448
br_code=ButtonRequestType.SignTx,
4549
banner_text=banner_text,
4650
)
4751

4852

49-
def require_confirm_trigger_trc20(
50-
ctx: Context,
51-
verified: bool,
52-
contract_address: str,
53-
amount: int,
54-
token: tokens.TokenInfo,
55-
toAddress: str,
56-
) -> Awaitable[None]:
57-
if verified:
58-
return confirm_output(
59-
ctx,
60-
address=toAddress,
61-
amount=format_amount_trx(amount, token),
62-
font_amount=ui.BOLD,
63-
color_to=ui.GREY,
64-
br_code=ButtonRequestType.SignTx,
65-
)
66-
67-
# Unknown token
53+
def require_confirm_unknown_token(ctx: Context, token_addr: str) -> Awaitable[None]:
54+
6855
return confirm_address(
6956
ctx,
7057
_(i18n_keys.TITLE__UNKNOWN_TOKEN),
71-
contract_address,
58+
token_addr,
7259
description=_(i18n_keys.LIST_KEY__CONTRACT__COLON),
7360
br_type="unknown_token",
7461
icon="A:/res/warning.png",

core/src/apps/tron/sign_tx.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from apps.tron.serialize import serialize
1212

1313
from . import ICON, PRIMARY_COLOR, layout, tokens
14-
from .providers import provider_by_address
1514

1615

1716
@auto_keychain(__name__)
@@ -51,17 +50,10 @@ async def _require_confirm_by_type(ctx, transaction, owner_address):
5150
if contract.transfer_contract.amount is None:
5251
raise wire.DataError("Invalid Tron transfer amount")
5352
recipient = contract.transfer_contract.to_address
54-
banner_text = None
55-
if provider_by_address(recipient) is not None:
56-
from trezor.lvglui.i18n import gettext as _
57-
from trezor.lvglui.i18n import keys as i18n_keys
58-
59-
banner_text = _(i18n_keys.BANNER_ENERGY_RENTAL)
6053
await layout.require_confirm_tx(
6154
ctx,
6255
recipient,
6356
contract.transfer_contract.amount,
64-
banner_text=banner_text,
6557
)
6658
elif contract.trigger_smart_contract:
6759
# check if TRC20 transfer/approval
@@ -83,18 +75,17 @@ async def _require_confirm_by_type(ctx, transaction, owner_address):
8375
action = "Approve"
8476

8577
if action == "Transfer":
86-
token = tokens.token_by_address(
87-
contract.trigger_smart_contract.contract_address
88-
)
78+
token_addr = contract.trigger_smart_contract.contract_address
79+
token = tokens.token_by_address(token_addr)
8980
recipient = _address_base58(b"\x41" + data[16:36])
9081
value = int.from_bytes(data[36:68], "big")
91-
await layout.require_confirm_trigger_trc20(
82+
if token is tokens.UNKNOWN_TOKEN:
83+
await layout.require_confirm_unknown_token(ctx, token_addr)
84+
await layout.require_confirm_tx(
9285
ctx,
93-
False if token is tokens.UNKNOWN_TOKEN else True,
94-
contract.trigger_smart_contract.contract_address,
86+
recipient,
9587
value,
9688
token,
97-
recipient,
9889
)
9990
if transaction.fee_limit:
10091
await layout.require_confirm_fee(

0 commit comments

Comments
 (0)