Skip to content

Commit 89972f3

Browse files
committed
feat: support tron energy parse
Signed-off-by: Lu1zz <[email protected]>
1 parent 5797f1a commit 89972f3

File tree

15 files changed

+162
-279
lines changed

15 files changed

+162
-279
lines changed

core/src/apps/ethereum/layout.py

Lines changed: 31 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
confirm_sign_typed_hash,
2020
confirm_text,
2121
should_show_approve_details,
22-
should_show_details,
2322
should_show_more,
2423
)
2524
from trezor.ui.layouts.lvgl.altcoin import (
@@ -82,9 +81,9 @@ def require_show_overview(
8281
else:
8382
to_str = _(i18n_keys.LIST_VALUE__NEW_CONTRACT)
8483
fee_max = gas_price * gas_limit
85-
84+
8685
from trezor.ui.layouts.lvgl import should_show_details_new
87-
print("\n# token", token)
86+
8887
return should_show_details_new(
8988
ctx,
9089
title=_(i18n_keys.TITLE__SEND_MULTILINE).format(
@@ -94,7 +93,9 @@ def require_show_overview(
9493
to_address=to_str,
9594
max_fee=format_ethereum_amount(fee_max, None, chain_id),
9695
token_address=token_address,
97-
banner_key=_(i18n_keys.WARNING_UNRECOGNIZED_TOKEN) if token is tokens.UNKNOWN_TOKEN else None
96+
banner_key=_(i18n_keys.WARNING_UNRECOGNIZED_TOKEN)
97+
if token is tokens.UNKNOWN_TOKEN
98+
else None,
9899
)
99100

100101
# return should_show_details(
@@ -106,6 +107,7 @@ def require_show_overview(
106107
# br_code=ButtonRequestType.SignTx,
107108
# )
108109

110+
109111
def require_confirm_fee(
110112
ctx: Context,
111113
spending: int,
@@ -228,6 +230,7 @@ async def require_confirm_eip1559_erc20_approve(
228230
token: tokens.EthereumTokenInfo,
229231
from_address: str | None = None,
230232
to_address: str | None = None,
233+
token_address: str | None = None,
231234
token_id: int | None = None,
232235
evm_chain_id: int | None = None,
233236
raw_data: bytes | None = None,
@@ -239,13 +242,6 @@ async def require_confirm_eip1559_erc20_approve(
239242
title = format_approve_title(token, approve_value, chain_id, provider_name)
240243
is_unlimited = approve_value == 2**256 - 1
241244

242-
if token and token.address:
243-
approve_token_address_str = address_from_bytes(
244-
token.address, networks.by_chain_id(chain_id)
245-
)
246-
else:
247-
approve_token_address_str = None
248-
249245
await confirm_approve_eip1559(
250246
ctx,
251247
title,
@@ -258,9 +254,9 @@ async def require_confirm_eip1559_erc20_approve(
258254
from_address,
259255
to_address,
260256
format_ethereum_amount(approve_value + fee_max, None, chain_id)
261-
if (token is None and approve_token_address_str is None)
257+
if (token is None and token_address is None)
262258
else None,
263-
approve_token_address_str,
259+
token_address,
264260
token_id,
265261
evm_chain_id=evm_chain_id,
266262
raw_data=raw_data,
@@ -279,6 +275,7 @@ async def require_confirm_legacy_erc20_approve(
279275
token: tokens.EthereumTokenInfo,
280276
from_address: str | None = None,
281277
to_address: str | None = None,
278+
token_address: str | None = None,
282279
token_id: int | None = None,
283280
evm_chain_id: int | None = None,
284281
raw_data: bytes | None = None,
@@ -290,13 +287,6 @@ async def require_confirm_legacy_erc20_approve(
290287
title = format_approve_title(token, approve_value, chain_id, provider_name)
291288
is_unlimited = approve_value == 2**256 - 1
292289

293-
if token and token.address:
294-
approve_token_address_str = address_from_bytes(
295-
token.address, networks.by_chain_id(chain_id)
296-
)
297-
else:
298-
approve_token_address_str = None
299-
300290
await confirm_approve(
301291
ctx,
302292
title,
@@ -308,9 +298,9 @@ async def require_confirm_legacy_erc20_approve(
308298
from_address,
309299
to_address,
310300
format_ethereum_amount(approve_value + fee_max, None, chain_id)
311-
if (token is None and approve_token_address_str is None)
301+
if (token is None and token_address is None)
312302
else None,
313-
approve_token_address_str,
303+
token_address,
314304
token_id,
315305
evm_chain_id=evm_chain_id,
316306
raw_data=raw_data,
@@ -636,109 +626,76 @@ def format_approve_title(
636626
chain_id: int,
637627
provider_name: str | None = None,
638628
) -> str:
639-
640-
# Determine action type
629+
641630
if value == 0:
642631
action_type = "REVOKE"
643632
elif value == 2**256 - 1:
644633
action_type = "APPROVE_UNLIMITED"
645634
else:
646635
action_type = "APPROVE_LIMITED"
647-
648-
# Determine token status
636+
649637
token_status = "UNKNOWN" if approve_token == tokens.UNKNOWN_TOKEN else "KNOWN"
650-
651-
# Determine provider status
638+
652639
provider_status = "KNOWN" if provider_name is not None else "UNKNOWN"
653-
654-
# Create combination key for lookup
640+
655641
combination_key = f"{action_type}_{token_status}_{provider_status}"
656-
657-
# Token display name
642+
658643
if token_status == "UNKNOWN":
659644
token_name = "UNKN"
660645
else:
661646
token_name = approve_token.symbol
662-
663-
# Amount display for limited approval
647+
648+
amount_display = ""
664649
if action_type == "APPROVE_LIMITED":
665650
amount_display = strip_amount(
666651
format_ethereum_amount(value, approve_token, chain_id)
667652
)[0]
668-
669-
# Title mapping for all 12 combinations
653+
670654
title_map = {
671-
# REVOKE + UNKNOWN_TOKEN + KNOWN_PROVIDER
672655
# Example: "Revoke UNKN for 1inch"
673656
"REVOKE_UNKNOWN_KNOWN": _(i18n_keys.REVOKE_TOKEN).format(
674657
token=token_name, name=provider_name
675658
),
676-
677-
# REVOKE + UNKNOWN_TOKEN + UNKNOWN_PROVIDER
678659
# Example: "Revoke UNKN"
679-
"REVOKE_UNKNOWN_UNKNOWN": _(i18n_keys.TITLE_REVOKE).format(
680-
name=token_name
681-
),
682-
683-
# REVOKE + KNOWN_TOKEN + KNOWN_PROVIDER
660+
"REVOKE_UNKNOWN_UNKNOWN": _(i18n_keys.TITLE_REVOKE).format(name=token_name),
684661
# Example: "Revoke USDT for 1inch"
685662
"REVOKE_KNOWN_KNOWN": _(i18n_keys.REVOKE_TOKEN).format(
686663
token=token_name, name=provider_name
687664
),
688-
689-
# REVOKE + KNOWN_TOKEN + UNKNOWN_PROVIDER
690665
# Example: "Revoke USDT"
691-
"REVOKE_KNOWN_UNKNOWN": _(i18n_keys.TITLE_REVOKE).format(
692-
name=token_name
693-
),
694-
695-
# APPROVE_UNLIMITED + UNKNOWN_TOKEN + KNOWN_PROVIDER
696-
# Example: "Approve UNKN for 1inch"
697-
"APPROVE_UNLIMITED_UNKNOWN_KNOWN": _(i18n_keys.APPROVE_TOKEN_AMOUNT).format(
666+
"REVOKE_KNOWN_UNKNOWN": _(i18n_keys.TITLE_REVOKE).format(name=token_name),
667+
# Example: "Approve Unlimited UNKN for 1inch"
668+
"APPROVE_UNLIMITED_UNKNOWN_KNOWN": _(i18n_keys.APPROVE_UNLIMITED_TOKEN).format(
698669
token=token_name, name=provider_name
699670
),
700-
701-
# APPROVE_UNLIMITED + UNKNOWN_TOKEN + UNKNOWN_PROVIDER
702-
# Example: "Approve UNKN"
703-
"APPROVE_UNLIMITED_UNKNOWN_UNKNOWN": _(i18n_keys.TITLE_APPROVE).format(
671+
# Example: "Approve Unlimited UNKN"
672+
"APPROVE_UNLIMITED_UNKNOWN_UNKNOWN": _(i18n_keys.TITLE_UNLIMITED).format(
704673
name=token_name
705674
),
706-
707-
# APPROVE_UNLIMITED + KNOWN_TOKEN + KNOWN_PROVIDER
708675
# Example: "Approve unlimited USDT for 1inch"
709676
"APPROVE_UNLIMITED_KNOWN_KNOWN": _(i18n_keys.APPROVE_UNLIMITED_TOKEN).format(
710677
token=token_name, name=provider_name
711678
),
712-
713-
# APPROVE_UNLIMITED + KNOWN_TOKEN + UNKNOWN_PROVIDER
714679
# Example: "Approve unlimited USDT"
715680
"APPROVE_UNLIMITED_KNOWN_UNKNOWN": _(i18n_keys.TITLE_UNLIMITED).format(
716681
name=token_name
717682
),
718-
719-
# APPROVE_LIMITED + UNKNOWN_TOKEN + KNOWN_PROVIDER
720-
# Example: "Approve UNKN for 1inch"
683+
# Example: "Approve 10.678 UNKN for 1inch"
721684
"APPROVE_LIMITED_UNKNOWN_KNOWN": _(i18n_keys.APPROVE_TOKEN_AMOUNT).format(
722-
token=token_name, name=provider_name
685+
token=amount_display, name=provider_name
723686
),
724-
725-
# APPROVE_LIMITED + UNKNOWN_TOKEN + UNKNOWN_PROVIDER
726-
# Example: "Approve UNKN"
687+
# Example: "Approve 10.678 UNKN"
727688
"APPROVE_LIMITED_UNKNOWN_UNKNOWN": _(i18n_keys.TITLE_APPROVE).format(
728-
name=token_name
689+
name=amount_display
729690
),
730-
731-
# APPROVE_LIMITED + KNOWN_TOKEN + KNOWN_PROVIDER
732691
# Example: "Approve 10.678 USDT for 1inch"
733692
"APPROVE_LIMITED_KNOWN_KNOWN": _(i18n_keys.APPROVE_TOKEN_AMOUNT).format(
734693
token=amount_display, name=provider_name
735694
),
736-
737-
# APPROVE_LIMITED + KNOWN_TOKEN + UNKNOWN_PROVIDER
738695
# Example: "Approve 10.678 USDT"
739696
"APPROVE_LIMITED_KNOWN_UNKNOWN": _(i18n_keys.TITLE_APPROVE).format(
740697
name=amount_display
741698
),
742699
}
743-
700+
744701
return title_map[combination_key]

core/src/apps/ethereum/onekey/providers.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33

44
class ProviderInfo:
5-
"""Swap provider information"""
6-
75
def __init__(
86
self,
97
name: str | None,
@@ -35,10 +33,8 @@ def __init__(
3533

3634

3735
def provider_by_chain_address(chain_id: int, address: str) -> ProviderInfo:
38-
"""Find provider by chain ID and address"""
3936
for approve_addr, name, swap_addr in _provider_iterator(chain_id):
4037
if address.lower() == approve_addr.lower():
41-
# Get icon path from mapping table
4238
icon_path = PROVIDER_META.get(name)
4339
return ProviderInfo(
4440
name=name,
@@ -50,13 +46,10 @@ def provider_by_chain_address(chain_id: int, address: str) -> ProviderInfo:
5046

5147

5248
def get_provider_icon(provider_name: str) -> str | None:
53-
"""Get provider icon path"""
5449
return PROVIDER_META.get(provider_name)
5550

5651

5752
def _provider_iterator(chain_id: int) -> Iterator[tuple[str, str, str | None]]:
58-
"""Return provider information iterator for specified chain: (approve_address, name, swap_address)"""
59-
6053
if chain_id == 1: # Ethereum Mainnet
6154
yield (
6255
"0x111111125421cA6dc452d289314280a0f8842A65",
@@ -372,10 +365,3 @@ def _provider_iterator(chain_id: int) -> Iterator[tuple[str, str, str | None]]:
372365
"Socket",
373366
None,
374367
)
375-
376-
# Note: The following chain IDs correspond to networks not found in evm_tokens, but supported by providers
377-
# if chain_id == 1030: # Conflux eSpace - OKX: 0x68D6B739D2020067D1e2F713b999dA97E4d54812
378-
# if chain_id == 169: # Manta - OKX: 0x57df6092665eb6058DE53939612413ff4B09114E
379-
# if chain_id == 4200: # Merlin - OKX: 0x8b773D83bc66Be128c60e07E17C8901f7a64F000
380-
# if chain_id == 196: # X Layer - OKX: 0x8b773D83bc66Be128c60e07E17C8901f7a64F000
381-
# if chain_id == 11155111: # Sepolia - CoW: 0xC92E8bdf79f0507f65a392b0ab4667716BFE0110

core/src/apps/ethereum/onekey/sign_tx.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
require_confirm_data,
2727
require_confirm_fee,
2828
require_confirm_legacy_erc20_approve,
29-
require_confirm_unknown_token,
3029
require_show_approve_overview,
3130
require_show_overview,
3231
)
@@ -144,8 +143,6 @@ async def sign_tx(
144143
)
145144

146145
else:
147-
print("# gas_price", msg.gas_price, int.from_bytes(msg.gas_price, "big"))
148-
print("# gas_limit", msg.gas_limit, int.from_bytes(msg.gas_limit, "big"))
149146
show_details = await require_show_overview(
150147
ctx,
151148
recipient,
@@ -185,7 +182,9 @@ async def sign_tx(
185182
if network is not networks.UNKNOWN_NETWORK
186183
else msg.chain_id,
187184
raw_data=msg.data_initial_chunk if has_raw_data else None,
188-
token_address=address_from_bytes(address_bytes, network) if token else None,
185+
token_address=address_from_bytes(address_bytes, network)
186+
if token
187+
else None,
189188
)
190189

191190
data = bytearray()
@@ -244,9 +243,6 @@ async def handle_erc20(
244243
recipient = msg.data_initial_chunk[16:36]
245244
value = int.from_bytes(msg.data_initial_chunk[36:68], "big")
246245

247-
# if token is tokens.UNKNOWN_TOKEN and not device.is_turbomode_enabled():
248-
# await require_confirm_unknown_token(ctx, address_bytes)
249-
250246
return token, address_bytes, recipient, value
251247

252248

@@ -298,8 +294,6 @@ async def handle_erc_721_or_1155(
298294

299295

300296
class ApproveInfo:
301-
"""ERC20 approve transaction information"""
302-
303297
def __init__(
304298
self,
305299
spender: bytes,

core/src/apps/ethereum/onekey/sign_tx_eip1559.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ async def sign_tx_eip1559(
162162
approve_info.token,
163163
from_address=from_str,
164164
to_address=address_from_bytes(approve_info.spender, network),
165+
token_address=address_from_bytes(approve_info.token_address, network),
165166
token_id=None,
166167
evm_chain_id=None
167168
if network is not networks.UNKNOWN_NETWORK
@@ -211,7 +212,9 @@ async def sign_tx_eip1559(
211212
if network is not networks.UNKNOWN_NETWORK
212213
else msg.chain_id,
213214
raw_data=msg.data_initial_chunk if has_raw_data else None,
214-
token_address=address_from_bytes(address_bytes, network) if token else None,
215+
token_address=address_from_bytes(address_bytes, network)
216+
if token
217+
else None,
215218
)
216219

217220
data = bytearray()

core/src/apps/ethereum/sign_tx.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ async def sign_tx(
6666
ctx,
6767
recipient,
6868
value,
69+
int.from_bytes(msg.gas_price, "big"),
70+
int.from_bytes(msg.gas_limit, "big"),
6971
msg.chain_id,
7072
token,
73+
address_from_bytes(address_bytes, network) if token else None,
7174
is_nft_transfer,
7275
)
7376

core/src/apps/ethereum/sign_tx_eip1559.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ async def sign_tx_eip1559(
8888
ctx,
8989
recipient,
9090
value,
91+
int.from_bytes(msg.max_gas_fee, "big"),
92+
int.from_bytes(msg.gas_limit, "big"),
9193
msg.chain_id,
9294
token,
95+
address_from_bytes(address_bytes, network) if token else None,
9396
is_nft_transfer,
9497
)
9598
if show_details:

0 commit comments

Comments
 (0)