Conversation
* Updated the SUPPORTED_CHAINS object to include network names for better clarity. * Refactored the parseRpcUrl function to utilize dynamic RPC URLs based on the network name, improving configurability and error handling.
refactor: enhance SUPPORTED_CHAINS structure and RPC URL handling
…w-users fix-faulty-balance-fetch-for-new-users
📝 WalkthroughWalkthroughThis PR adds support for embedded (Privy) wallet users by implementing a new control flow branch in BalanceContext that handles cross-chain balance fetching and wallet balance population for non-migrated embedded wallet accounts. Simultaneously, chain configuration is refactored to include per-chain network names and RPC URL resolution is updated to use a Changes
Sequence DiagramsequenceDiagram
participant User as User (Embedded Wallet)
participant BalanceCtx as BalanceContext
participant CrossChain as Cross-Chain<br/>Fetch Service
participant SingleNet as Single-Network<br/>Fetch Service
participant State as State Update
User->>BalanceCtx: Fetch balances (embedded wallet, no migration)
BalanceCtx->>BalanceCtx: Check: embeddedWalletAccount?
BalanceCtx->>CrossChain: Fetch cross-chain entries
CrossChain-->>BalanceCtx: Cross-chain balance data
BalanceCtx->>BalanceCtx: Populate crossChainBalances
alt Selected network entry found
BalanceCtx->>BalanceCtx: Set externalWalletBalance from selected network
else Selected network entry missing
BalanceCtx->>SingleNet: fetchWalletBalance (fallback)
SingleNet-->>BalanceCtx: Balance + rawBalances
BalanceCtx->>BalanceCtx: Apply CNGN correction & conversion
end
BalanceCtx->>State: Update primaryIsEOA, balances, totals
State-->>User: Display embedded wallet balances
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
app/lib/bundler/chains.ts (1)
10-18: Remove unusedenvKeyfield fromSUPPORTED_CHAINS.The
envKeyproperty is not used within this file or anywhere else in the codebase. It was retained from the previous implementation but is no longer referenced after refactoring to usegetRpcUrl(entry.networkName). Removing it will improve code clarity.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/lib/bundler/chains.ts` around lines 10 - 18, SUPPORTED_CHAINS currently defines an unused envKey property; remove it and tighten the type so entries are just { chain: Chain; networkName: string } (update the Record type declaration and each entry for bsc, base, arbitrum, polygon, mainnet, lisk, celo to drop envKey), ensuring all usages (e.g., where getRpcUrl(entry.networkName) is used) keep working unchanged; run TS typecheck and remove any now-dead references to envKey if they exist elsewhere.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/lib/bundler/chains.ts`:
- Around line 10-18: SUPPORTED_CHAINS currently defines an unused envKey
property; remove it and tighten the type so entries are just { chain: Chain;
networkName: string } (update the Record type declaration and each entry for
bsc, base, arbitrum, polygon, mainnet, lisk, celo to drop envKey), ensuring all
usages (e.g., where getRpcUrl(entry.networkName) is used) keep working
unchanged; run TS typecheck and remove any now-dead references to envKey if they
exist elsewhere.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 75d7ef0f-9495-47e9-ae13-1afddd290b5b
📒 Files selected for processing (2)
app/context/BalanceContext.tsxapp/lib/bundler/chains.ts
Revert "Merge Main to Stable"
Description
This pull request introduces improvements to wallet balance handling for new users and enhances the way supported blockchain networks are managed and referenced in the codebase. The most significant changes include better detection and balance fetching for embedded wallets, and a more flexible, maintainable approach to handling supported chains and their RPC URLs.
Wallet balance handling:
Supported chain configuration and RPC handling:
SUPPORTED_CHAINSobject to include anetworkNameproperty for each chain, improving readability and maintainability when referencing networks throughout the codebase.parseRpcUrlfunction to use the newnetworkNameproperty and a genericgetRpcUrlutility, removing the dependency on theNEXT_PUBLIC_THIRDWEB_CLIENT_IDenvironment variable and providing clearer error messages if an RPC URL is missing.References
Testing
Checklist
mainBy submitting a PR, I agree to Paycrest's Contributor Code of Conduct and Contribution Guide.
Summary by CodeRabbit
Release Notes