app-monorepo icon indicating copy to clipboard operation
app-monorepo copied to clipboard

feat: support resource rental on tron

Open weatherstar opened this issue 5 months ago • 2 comments
trafficstars

weatherstar avatar Jun 05 '25 09:06 weatherstar

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders
Open Preview

codesandbox[bot] avatar Jun 05 '25 09:06 codesandbox[bot]

Walkthrough

This update adds support for Tron resource rental and token-based fee payments. It introduces new UI components, state atoms, and service methods for handling Tron resource rental, including order creation, signing, and uploading. The Wallet UI now features a Reward Center for Tron. Several types and constants are extended for Tron-specific logic.

Changes

File(s) / Group Change Summary
.../Dialog/Header.tsx, .../Dialog/type.ts Added support for 'info' tone in dialog headers and footers.
.../tron/constants.ts Added tronTokenAddress constant mapping token symbols to Tron addresses.
.../ServiceSend.ts, .../Send/pages/SendConfirm/SendConfirmActionsContainer.tsx, .../SendReplaceTx... Renamed method updateUnSignedTxBeforeSend to updateUnSignedTxBeforeSending.
.../ServiceSignatureConfirm.ts, .../vaults/base/VaultBase.ts, .../vaults/impls/tron/Vault.ts Added preActionsBeforeSending method to support Tron resource rental. Implemented Tron-specific order creation, signing, and upload in Tron vault.
.../vaults/impls/tron/settings.ts, .../vaults/types.ts Added hasRewardCenter and payWithTokenEnabled flags to Tron vault settings and types.
.../RewardCenter/TronRewardCenter.tsx, .../RewardCenter/index.ts, .../WalletActions/WalletActionMore.tsx Introduced Reward Center UI for Tron, with dialog and configuration logic. Integrated Reward Center action into wallet menu when enabled.
.../signatureConfirm/actions.ts, .../signatureConfirm/atoms.ts Added state atoms and actions for Tron resource rental and token payment info. Extended send transaction status for token balance checks.
.../SignatureConfirm/components/SignatureConfirmActions/TxConfirmActions.tsx Integrated Tron resource rental info into pre-send validation. Disabled submit if token balance insufficient.
.../SignatureConfirm/components/SignatureConfirmAlert/TxConfirmAlert.tsx Added alert for insufficient token balance when using token to pay fees.
.../SignatureConfirm/components/SignatureConfirmExtraInfo/ExtraInfoTron/ResourceRental.tsx Added new component for managing Tron resource rental options in the signature confirmation UI.
.../SignatureConfirm/components/SignatureConfirmExtraInfo/ExtraInfoTron/index.tsx Replaced description text with the new ResourceRental component.
.../SignatureConfirm/components/SignatureConfirmItem/SignatureConfirmItem.tsx Added SignatureConfirmItem.Block subcomponent for UI layout.
.../SignatureConfirm/components/TxFee/TxFeeInfo.tsx Enhanced fee info logic to handle Tron resource rental and token payment, with updated balance checks and fee displays.
.../SignatureConfirm/hooks/usePreCheckTokenBalance.ts, .../pages/TxConfirm/TxConfirm.tsx Renamed and extended hook to check both native and token balances for fee sufficiency.
.../presetNetworks.ts Added Tron Nile Testnet network configuration.
.../locale/enum/translations.ts Added three new translation keys for hardware and update errors.
.../txActionUtils.ts Added calculateTokenAmountInActions function to sum token amounts in decoded actions.
.../fee.ts Added ETronResourceRentalPayType enum, ITronResourceRentalInfo type, and extended IFeeTron type for Tron resource rental details.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Wallet UI
    participant Reward Center
    participant SignatureConfirm
    participant ServiceSend
    participant ServiceSignatureConfirm
    participant TronVault

    User->>Wallet UI: Open Wallet Actions
    Wallet UI->>Reward Center: Check config for network
    Reward Center-->>Wallet UI: Provide handler if Tron
    User->>Wallet UI: Click Reward Center
    Wallet UI->>Reward Center: Show dialog

    User->>SignatureConfirm: Initiate transaction
    SignatureConfirm->>ServiceSignatureConfirm: preActionsBeforeSending(unsignedTxs, tronResourceRentalInfo)
    ServiceSignatureConfirm->>TronVault: preActionsBeforeSending(...)
    TronVault->>TronVault: If resource rental needed
    TronVault->>TronVault: Create rental order
    TronVault->>TronVault: Sign rental tx
    TronVault->>TronVault: Upload signed rental order
    TronVault-->>ServiceSignatureConfirm: Done
    ServiceSignatureConfirm-->>SignatureConfirm: Done
    SignatureConfirm->>ServiceSend: updateUnSignedTxBeforeSending(...)
    ServiceSend-->>SignatureConfirm: Done
    SignatureConfirm->>User: Display confirmation
sequenceDiagram
    participant User
    participant SignatureConfirm
    participant StateAtoms

    User->>SignatureConfirm: Prepare to send transaction
    SignatureConfirm->>StateAtoms: Check native and token balances
    StateAtoms-->>SignatureConfirm: Return balance status
    SignatureConfirm->>User: Show insufficient balance alert if needed

Assessment against linked issues

Objective Addressed Explanation
Support TRON resource rental fee payment with TRX and USDT, including swap for small TRX amounts (OK-38794)
Implement subsidy claim and redemption code UI within wallet, no third-party redirects (OK-38794)
Integrate resource rental pre-send actions in transaction flow, including order creation, signing, and upload
Manage token and native balance checks and alerts in signature confirmation UI

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro Cache: Disabled due to data retention organization setting Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 52902f80c60226b95e017c9aa880a4557b44bfa8 and a5e5537715adb3112afa3c68acaaa79a95dbdef7.

📒 Files selected for processing (3)
  • packages/kit-bg/src/vaults/base/VaultBase.ts (2 hunks)
  • packages/kit-bg/src/vaults/impls/tron/Vault.ts (3 hunks)
  • packages/kit/src/views/SignatureConfirm/hooks/usePreCheckTokenBalance.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
`packages/kit/**`: This package contains application logic, state management, and API integrations.

packages/kit/**: This package contains application logic, state management, and API integrations.

  • packages/kit/src/views/SignatureConfirm/hooks/usePreCheckTokenBalance.ts
`packages/kit/src/**`: Business logic should be placed here.

packages/kit/src/**: Business logic should be placed here.

  • packages/kit/src/views/SignatureConfirm/hooks/usePreCheckTokenBalance.ts
`**/use*.ts`: Hook files should use camelCase with a 'use' prefix.

**/use*.ts: Hook files should use camelCase with a 'use' prefix.

  • packages/kit/src/views/SignatureConfirm/hooks/usePreCheckTokenBalance.ts
`packages/kit/**/*`: `@onekeyhq/kit` may import from `@onekeyhq/shared`, `@onekeyhq/components`, and `@onekeyhq/kit-bg`.

packages/kit/**/*: @onekeyhq/kit may import from @onekeyhq/shared, @onekeyhq/components, and @onekeyhq/kit-bg.

  • packages/kit/src/views/SignatureConfirm/hooks/usePreCheckTokenBalance.ts
`packages/kit-bg/**`: This package contains background services and workers.

packages/kit-bg/**: This package contains background services and workers.

  • packages/kit-bg/src/vaults/base/VaultBase.ts
  • packages/kit-bg/src/vaults/impls/tron/Vault.ts
`packages/kit-bg/**/*`: `@onekeyhq/kit-bg` may import from `@onekeyhq/shared` and `@onekeyhq/core`, but not from `@onekeyhq/components` or `@onekeyhq/kit`.

packages/kit-bg/**/*: @onekeyhq/kit-bg may import from @onekeyhq/shared and @onekeyhq/core, but not from @onekeyhq/components or @onekeyhq/kit.

  • packages/kit-bg/src/vaults/base/VaultBase.ts
  • packages/kit-bg/src/vaults/impls/tron/Vault.ts
🪛 Biome (1.9.4)
packages/kit-bg/src/vaults/impls/tron/Vault.ts

[error] 909-909: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 947-947: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Cursor BugBot
  • GitHub Check: unittest (20.x)
  • GitHub Check: lint (20.x)
  • GitHub Check: Analyze (java-kotlin)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
packages/kit/src/views/SignatureConfirm/hooks/usePreCheckTokenBalance.ts (4)

1-16: LGTM! Clean imports for token payment support.

The new imports align well with the hook's expanded functionality to handle token payments alongside native tokens.


21-37: Function rename reflects its expanded scope.

The rename from usePreCheckNativeBalance to usePreCheckTokenBalance better describes the hook's dual responsibility for both native and token balance checks.


53-70: Clean implementation of token amount calculation.

The parallel structure for calculating payWithTokenTransferBN mirrors the native token logic nicely. The conditional check for vaultSettings.payWithTokenEnabled ensures the calculation only runs when needed.


139-155: State updates and dependencies are properly managed.

Both transfer amounts are updated correctly, and the effect dependencies include all the necessary values for proper re-execution.

packages/kit-bg/src/vaults/base/VaultBase.ts (1)

440-449: Well-documented extension point for pre-send actions.

The JSDoc clearly explains the method's purpose. The flexible signature supports both general transaction preparation and chain-specific features like Tron resource rental.

packages/kit-bg/src/vaults/impls/tron/Vault.ts (3)

36-45: Import organization looks good.

The new imports for resource rental types and password verification reason are properly placed.

Also applies to: 86-86


957-979: Clean implementation of rental transaction signing.

The method properly handles password verification and hardware wallet support through the existing service layers.


981-1013: Well-structured orchestration of the rental workflow.

The method properly checks conditions before executing the rental process. The sequential flow of create → sign → upload is logical and handles early returns appropriately.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate Unit Tests
  • [ ] Create PR with Unit Tests
  • [ ] Post Copyable Unit Tests in Comment
  • [ ] Commit Unit Tests in branch feat/tron-energy-rental

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or Summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Jun 05 '25 09:06 coderabbitai[bot]