Skip to content
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
35 changes: 11 additions & 24 deletions core/src/apps/tron/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,30 @@ 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,
banner_text=banner_text,
)


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",
Expand Down
21 changes: 6 additions & 15 deletions core/src/apps/tron/sign_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
Loading