Skip to content

feat(tron): integrate Tron network support#549

Merged
chibie merged 3 commits into
mainfrom
feat/tron-network-support
Jul 7, 2026
Merged

feat(tron): integrate Tron network support#549
chibie merged 3 commits into
mainfrom
feat/tron-network-support

Conversation

@sundayonah

@sundayonah sundayonah commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator
  • Added configuration for Tron network in .env.example.
  • Implemented Tron mainnet details in mocks and integrated it into the network selection.
  • Updated context and providers to include Tron functionality.
  • Enhanced wallet management to support Tron wallet creation and balance fetching.
  • Adjusted transaction forms and UI components to accommodate Tron-specific logic, including off-ramp restrictions.
  • Added validation for Tron addresses and updated utility functions accordingly.

This commit introduces comprehensive support for the Tron network, enhancing the overall functionality of the application.

Description

Describe the purpose of this PR along with any background information and the impacts of the proposed change. For the benefit of the community, please do not assume prior context.

Provide details that support your chosen implementation, including: breaking changes, alternatives considered, changes to the API, contracts etc.

References

Closes: #488

Testing

Describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this project has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

Please include any manual steps for testing end-to-end or functionality not covered by unit/integration tests.

Also include details of the environment this PR was developed in (language/platform/browser version).

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation and tests for new/changed functionality in this PR
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not main

By submitting a PR, I agree to Paycrest's Contributor Code of Conduct and Contribution Guide.

Summary by CodeRabbit

  • New Features
    • Added Tron network support across wallet creation, balances, Tron address validation, and transaction explorer/RPC linking, including default Tron token (USDT).
    • Introduced NEXT_PUBLIC_TRON_ENABLED feature flag (default off) with optional Tron RPC and TronGrid API key placeholders.
  • Bug Fixes
    • Updated network switching and wallet selection to correctly initialize/keep the right Tron wallet.
    • Enforced off-ramp-only behavior on networks without on-ramp support (including Tron) and blocked switching into on-ramp/buy modes when unsupported.
    • Updated transaction UI/analytics to use Tron wallet balances correctly.

- Added configuration for Tron network in .env.example.
- Implemented Tron mainnet details in mocks and integrated it into the network selection.
- Updated context and providers to include Tron functionality.
- Enhanced wallet management to support Tron wallet creation and balance fetching.
- Adjusted transaction forms and UI components to accommodate Tron-specific logic, including off-ramp restrictions.
- Added validation for Tron addresses and updated utility functions accordingly.

This commit introduces comprehensive support for the Tron network, enhancing the overall functionality of the application.
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d6e93043-58b6-4345-99a2-5bdf548c828b

📥 Commits

Reviewing files that changed from the base of the PR and between 0e2da76 and b12c884.

📒 Files selected for processing (12)
  • .env.example
  • app/components/MainPageContent.tsx
  • app/components/MobileDropdown.tsx
  • app/components/SettingsDropdown.tsx
  • app/components/WalletDetails.tsx
  • app/context/index.ts
  • app/lib/config.ts
  • app/pages/TransactionForm.tsx
  • app/pages/TransactionStatus.tsx
  • app/providers.tsx
  • app/types.ts
  • app/utils.ts
💤 Files with no reviewable changes (1)
  • app/context/index.ts
🚧 Files skipped from review as they are similar to previous changes (10)
  • app/lib/config.ts
  • app/types.ts
  • app/pages/TransactionStatus.tsx
  • app/providers.tsx
  • app/components/WalletDetails.tsx
  • app/components/SettingsDropdown.tsx
  • app/utils.ts
  • app/components/MobileDropdown.tsx
  • app/pages/TransactionForm.tsx
  • app/components/MainPageContent.tsx

📝 Walkthrough

Walkthrough

Adds Tron support across feature gating, wallet creation, balance and address routing, network switching, and transaction form handling. Tron is treated as a non-EVM, off-ramp-only network with its own validation, explorer/RPC helpers, and Privy wallet flow.

Changes

Tron network support

Layer / File(s) Summary
Shared Tron contracts and helpers
.env.example, app/lib/config.ts, app/types.ts, app/mocks.ts, app/lib/validation.ts, app/utils.ts, app/context/NetworksContext.tsx
Adds the Tron feature flag, chain metadata, address validation, RPC/explorer helpers, fallback tokens, balance fetching, and Tron-aware network/on-ramp helpers.
Tron wallet API and provider
app/api/tron/create-wallet/route.ts, app/context/TronContext.tsx, app/context/index.ts, app/providers.tsx
Adds the Tron wallet creation route, client context, public exports, and provider wiring that persist and expose Tron wallet state.
Wallet identity and balance routing
app/context/BalanceContext.tsx, app/hooks/useWalletAddress.ts, app/components/WalletDetails.tsx, app/components/Navbar.tsx, app/components/SettingsDropdown.tsx, app/components/MobileDropdown.tsx, app/pages/TransactionStatus.tsx
Routes Tron addresses and balances through balance state, wallet selectors, wallet previews, and transaction balance tracking.
Network switching callbacks
app/components/MobileDropdown.tsx, app/components/NetworkSelectionModal.tsx, app/components/NetworksDropdown.tsx, app/components/WalletDetails.tsx, app/utils.ts
Updates network-switch callbacks to request Starknet or Tron wallets before completing a chain change and keeps Tron out of the EVM injected-wallet path.
On-ramp and transaction flow
app/components/MainPageContent.tsx, app/pages/TransactionForm.tsx, app/utils.ts
For networks without on-ramp support, the home form and transaction form force off-ramp mode, disable buy actions, and use Tron-aware swap-mode defaults.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related issues

  • paycrest/dashboard#398 — Adds Tron network support across network selection, wallet, balance, validation, and on/off-ramp code paths.
  • paycrest/dashboard#396 — Covers the same Tron network, wallet, and transaction support areas touched here.
  • paycrest/aggregator#779 — Shares the Tron network metadata, explorer/RPC, token, and balance handling additions.

Possibly related PRs

  • paycrest/noblocks#474 — Extends the shared chain abstractions that this PR reuses for Tron wallet and network handling.
  • paycrest/noblocks#480 — Introduces the on-ramp/off-ramp flow that this PR extends to treat Tron as off-ramp only.
  • paycrest/noblocks#504 — Changes the same transaction-form gating and network-aware validation paths, with Tron-specific branches added here.

Suggested labels: enhancement

Suggested reviewers: onahprosper, 5ran6, chibie

Poem

A rabbit hopped on Tron so bright,
With wallets, balances, and tokens in sight.
Buy mode paused, off-ramp won the race,
Then explorer links lit up the place.
🐇✨

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description still includes template placeholders for Description, Testing, and Checklist, so it lacks required implementation details. Replace the placeholders with a real description of the change, add concrete testing steps and environment details, and complete the checklist.
Linked Issues check ⚠️ Warning Most Tron support is implemented, but the linked issue's transaction history requirement is not evidenced in the changed files. Add or point to the Tron transaction history integration, and verify all linked acceptance criteria are covered.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding Tron network support.
Out of Scope Changes check ✅ Passed The changes stay focused on Tron support and related wallet, balance, validation, and UI updates.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
app/utils.ts (1)

1623-1633: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Comment contradicts the actual precedence for Tron.

The doc comment states "Explicit side wins; else Tron/Starknet default to off-ramp," but the early if (!networkSupportsOnramp(chain)) return "offramp" runs before the side param is read. So for Tron, ?side=buy is silently ignored and forced to off-ramp. This is likely intended (Tron has no on-ramp), but the comment is misleading. Either reword the comment to reflect that unsupported on-ramp networks override the side param, or move the check after the side read if explicit side should still win.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/utils.ts` around lines 1623 - 1633, The precedence in
initialSwapModeForHomeForm is inconsistent with the doc comment: the early
networkSupportsOnramp(chain) guard overrides
swapModeFromSideParam(searchParams.get("side")), so explicit side is not
actually winning on unsupported networks like Tron. Update the comment near
initialSwapModeForHomeForm to match the real behavior, or move the
networkSupportsOnramp check below the side parsing if explicit side should take
priority; keep the note aligned with isStarknetChain and the off-ramp fallback.
app/components/SettingsDropdown.tsx (1)

171-174: 🔒 Security & Privacy | 🟡 Minor

Clear Tron wallet keys during logout

clearUserSessionData() removes several session keys, but it does not remove tron_walletId_${user.id} or tron_address_${user.id}. Add those Tron keys to the shared logout cleanup so stale wallet state doesn’t persist into the next session.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/components/SettingsDropdown.tsx` around lines 171 - 174, The shared
logout cleanup in clearUserSessionData() is missing the Tron session keys, so
stale Tron wallet state can survive across logouts. Update the same localStorage
removal block that already clears starknet_walletId_ and starknet_address_ to
also remove tron_walletId_${user?.id} and tron_address_${user?.id}, keeping the
logout cleanup centralized in SettingsDropdown.tsx.
🧹 Nitpick comments (2)
app/utils.ts (1)

1180-1183: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add a timeout/abort to the TronGrid fetch.

fetch has no timeout, so a slow/hung TronGrid response can stall the balance-fetch path indefinitely (this is reached from BalanceContext). Wrap with AbortSignal.timeout(...) (or an AbortController) so a stuck request fails fast and falls back to the empty-balance result.

♻️ Suggested change
     const response = await fetch(
       `https://api.trongrid.io/v1/accounts/${encodeURIComponent(address)}`,
-      { headers },
+      { headers, signal: AbortSignal.timeout(10_000) },
     );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/utils.ts` around lines 1180 - 1183, The TronGrid request in the balance
fetch path can hang indefinitely because the `fetch` call has no timeout. Update
the `fetch` in the account lookup flow (the `getTron...`/balance-related helper
in `app/utils.ts`, reached from `BalanceContext`) to use an abortable request
via `AbortSignal.timeout(...)` or an `AbortController`, and make sure timeout
errors are handled by falling back to the existing empty-balance result rather
than blocking the caller.
app/api/tron/create-wallet/route.ts (1)

59-96: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Inner try/catch is redundant.

The block only logs and re-throws, duplicating the outer catch's logging at Line 125. If the intent was just to annotate the failure source, the extra layer adds little; otherwise it can be removed so the outer handler manages it uniformly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/api/tron/create-wallet/route.ts` around lines 59 - 96, The inner
try/catch around privy.getUser and the existingTronWallet lookup is redundant
because it only logs and re-throws before the outer handler logs the same
failure. Remove this extra catch in create-wallet route handling, or fold any
source-specific context into the outer error path so the route’s main catch
manages the error uniformly without duplicate logging.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.env.example:
- Line 92: Add the missing Tron environment variables to the example env file by
documenting NEXT_PUBLIC_TRON_RPC_URL and NEXT_PUBLIC_TRONGRID_API_KEY alongside
NEXT_PUBLIC_TRON_ENABLED. Update the .env.example entries so developers can
configure Tron explicitly instead of relying on the default
https://api.trongrid.io fallback without an API key.

In `@app/api/tron/create-wallet/route.ts`:
- Around line 35-37: The JWT validation in create-wallet’s route handler is
letting invalid or expired tokens fall into the outer error path, so update the
auth block around verifyJWT in route.ts to catch token verification failures
explicitly and return a 401 response instead of surfacing them as 500s. Use the
existing auth flow variables like authHeader, token, verifyJWT, and authUserId
to keep the change localized, and reserve the outer catch for unexpected server
errors only.

In `@app/context/TronContext.tsx`:
- Around line 159-179: ensureWalletExists is swallowing wallet-creation
failures, so handleNetworkSwitch cannot abort the network change on Tron
failure. Update TronContext’s ensureWalletExists to let the error propagate
instead of only logging it in the outer catch, while keeping the existing
toast/error handling around createWallet. Make sure the awaited callback path
used by handleNetworkSwitch in app/utils.ts receives a rejection when wallet
creation fails, matching the Starknet flow.

In `@app/mocks.ts`:
- Around line 37-62: The injected-wallet network switch path in NetworksContext
still treats every selected chain as EVM, so Tron’s string id from tronMainnet
gets converted into an invalid hex chain id and breaks
wallet_switchEthereumChain. Update the injected-wallet selection logic in the
network switch flow to skip Tron or route tronMainnet through the non-EVM wallet
handling instead of calling the EVM chain-switch conversion on its id.

In `@app/pages/TransactionForm.tsx`:
- Around line 967-985: The Buy button is being fully disabled in
TransactionForm, which prevents its onClick guard from firing and stops the Tron
toast from appearing. Update the button logic around the onClick/disabled
handling so the click still reaches the existing onrampSupported check in
TransactionForm, using aria-disabled or another non-blocking state instead of
disabled, or move the Tron explanation to visible helper text/tooltip while
keeping the guard in place.
- Around line 202-210: The balance routing in TransactionForm’s activeBalance
selection only checks selectedNetwork.chain.name for Tron, so Tron networks
identified by network (for example tron-mainnet) can fall through to EVM
balances. Update the ternary branch to use the same shared Tron classifier as
networkSupportsOnramp, or otherwise centralize the Tron check in a reusable
helper, so tronWalletBalance is selected for all Tron variants.

---

Outside diff comments:
In `@app/components/SettingsDropdown.tsx`:
- Around line 171-174: The shared logout cleanup in clearUserSessionData() is
missing the Tron session keys, so stale Tron wallet state can survive across
logouts. Update the same localStorage removal block that already clears
starknet_walletId_ and starknet_address_ to also remove
tron_walletId_${user?.id} and tron_address_${user?.id}, keeping the logout
cleanup centralized in SettingsDropdown.tsx.

In `@app/utils.ts`:
- Around line 1623-1633: The precedence in initialSwapModeForHomeForm is
inconsistent with the doc comment: the early networkSupportsOnramp(chain) guard
overrides swapModeFromSideParam(searchParams.get("side")), so explicit side is
not actually winning on unsupported networks like Tron. Update the comment near
initialSwapModeForHomeForm to match the real behavior, or move the
networkSupportsOnramp check below the side parsing if explicit side should take
priority; keep the note aligned with isStarknetChain and the off-ramp fallback.

---

Nitpick comments:
In `@app/api/tron/create-wallet/route.ts`:
- Around line 59-96: The inner try/catch around privy.getUser and the
existingTronWallet lookup is redundant because it only logs and re-throws before
the outer handler logs the same failure. Remove this extra catch in
create-wallet route handling, or fold any source-specific context into the outer
error path so the route’s main catch manages the error uniformly without
duplicate logging.

In `@app/utils.ts`:
- Around line 1180-1183: The TronGrid request in the balance fetch path can hang
indefinitely because the `fetch` call has no timeout. Update the `fetch` in the
account lookup flow (the `getTron...`/balance-related helper in `app/utils.ts`,
reached from `BalanceContext`) to use an abortable request via
`AbortSignal.timeout(...)` or an `AbortController`, and make sure timeout errors
are handled by falling back to the existing empty-balance result rather than
blocking the caller.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9be95396-d3b0-467c-a31c-7632ff018daa

📥 Commits

Reviewing files that changed from the base of the PR and between 290c84d and 0016169.

📒 Files selected for processing (21)
  • .env.example
  • app/api/tron/create-wallet/route.ts
  • app/components/MainPageContent.tsx
  • app/components/MobileDropdown.tsx
  • app/components/Navbar.tsx
  • app/components/NetworkSelectionModal.tsx
  • app/components/NetworksDropdown.tsx
  • app/components/SettingsDropdown.tsx
  • app/components/WalletDetails.tsx
  • app/context/BalanceContext.tsx
  • app/context/TronContext.tsx
  • app/context/index.ts
  • app/hooks/useWalletAddress.ts
  • app/lib/config.ts
  • app/lib/validation.ts
  • app/mocks.ts
  • app/pages/TransactionForm.tsx
  • app/pages/TransactionStatus.tsx
  • app/providers.tsx
  • app/types.ts
  • app/utils.ts

Comment thread .env.example
Comment thread app/api/tron/create-wallet/route.ts
Comment thread app/context/TronContext.tsx
Comment thread app/mocks.ts
Comment thread app/pages/TransactionForm.tsx
Comment thread app/pages/TransactionForm.tsx Outdated
- Updated .env.example to include optional Tron RPC URL and API key configurations.
- Improved error handling in the Tron wallet creation process, ensuring better user feedback on failures.
- Refactored network change logic to accommodate non-EVM chains like Tron, preventing invalid network switches.
- Enhanced transaction form to correctly handle balances for Tron and Starknet chains.

This commit further solidifies Tron network support within the application, improving user experience and wallet management.
@sundayonah sundayonah marked this pull request as draft June 25, 2026 07:16
@sundayonah sundayonah marked this pull request as ready for review July 3, 2026 08:01
@chibie chibie merged commit d3e440a into main Jul 7, 2026
2 checks passed
@chibie chibie deleted the feat/tron-network-support branch July 7, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Tron Network Support to Noblocks

2 participants