Skip to content

Merge stable into Main#443

Merged
5ran6 merged 7 commits intomainfrom
stable
Apr 6, 2026
Merged

Merge stable into Main#443
5ran6 merged 7 commits intomainfrom
stable

Conversation

@Dprof-in-tech
Copy link
Copy Markdown
Collaborator

@Dprof-in-tech Dprof-in-tech commented Apr 3, 2026

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:

  • Added logic to detect when a user only has an embedded wallet (EOA), and fetches balances directly for that address, including cross-chain balances and correctly applying CNGN balance conversions. This ensures new users see accurate balance information without requiring a smart contract wallet.

Supported chain configuration and RPC handling:

  • Extended the SUPPORTED_CHAINS object to include a networkName property for each chain, improving readability and maintainability when referencing networks throughout the codebase.
  • Updated the parseRpcUrl function to use the new networkName property and a generic getRpcUrl utility, removing the dependency on the NEXT_PUBLIC_THIRDWEB_CLIENT_ID environment variable and providing clearer error messages if an RPC URL is missing.

References

Testing

  • 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

Release Notes

  • Chores
    • Improved balance tracking for embedded wallet users across multiple chains
    • Enhanced blockchain RPC URL resolution for more reliable transaction processing

onahprosper and others added 4 commits March 25, 2026 06:04
* 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
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

📝 Walkthrough

Walkthrough

This 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 getRpcUrl utility instead of Thirdweb client ID.

Changes

Cohort / File(s) Summary
Embedded Wallet Balance Handling
app/context/BalanceContext.tsx
Added new conditional branch for embedded wallet accounts (else if (embeddedWalletAccount)): sets primaryIsEOA = true, fetches cross-chain balance entries, populates crossChainBalances, clears smartWalletBalance, and falls back to single-network balance fetching with CNGN correction when selected-network entry is unavailable.
Chain Configuration & RPC Resolution
app/lib/bundler/chains.ts
Extended SUPPORTED_CHAINS to include networkName field per chain; refactored parseRpcUrl() to resolve RPC URLs via getRpcUrl(entry.networkName) instead of constructing Thirdweb RPC URLs, with updated error handling.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • chibie
  • 5ran6
  • onahprosper

Poem

🐰 A fresh path blooms for embedded wallets so fine,
Cross-chains now balance in perfect design,
Network names guide the RPC quest,
EOA flows with the very best,
No migration? No trouble—fallback's your friend! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Merge stable into Main' is vague and generic, describing a branch merge operation rather than the actual code changes (wallet balance handling and chain configuration improvements). Use a more descriptive title that summarizes the main changes, such as 'Improve wallet balance handling for embedded wallets and refactor chain configuration'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description covers the main changes well but has incomplete sections: References section is empty, and Testing section lacks specific details on how to test the changes and what environments were used.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch stable

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.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
app/lib/bundler/chains.ts (1)

10-18: Remove unused envKey field from SUPPORTED_CHAINS.

The envKey property 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 use getRpcUrl(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

📥 Commits

Reviewing files that changed from the base of the PR and between 140ae0d and 502e949.

📒 Files selected for processing (2)
  • app/context/BalanceContext.tsx
  • app/lib/bundler/chains.ts

@5ran6 5ran6 merged commit cac70dc into main Apr 6, 2026
1 check passed
@5ran6 5ran6 deleted the stable branch April 6, 2026 11:11
@5ran6 5ran6 restored the stable branch April 6, 2026 11:12
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.

3 participants