Skip to content

fixes faulty balance fetch for new users#440

Merged
5ran6 merged 2 commits intomainfrom
fix-faulty-balance-fetch
Apr 3, 2026
Merged

fixes faulty balance fetch for new users#440
5ran6 merged 2 commits intomainfrom
fix-faulty-balance-fetch

Conversation

@Dprof-in-tech
Copy link
Copy Markdown
Collaborator

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

Description

This pull request updates the balance handling logic in the BalanceProvider context to better support new users with embedded wallets. Now, if a user has an embedded wallet account but no smart wallet, the app fetches and displays their EOA (Externally Owned Account) balances directly, ensuring accurate cross-chain and network-specific balances.

Balance handling improvements for embedded wallet users:

  • Added logic to detect when a user has only an embedded wallet (EOA) and fetch their cross-chain balances accordingly, setting smart wallet balances to null and updating the remaining total to 0.
  • If the selected network's entry is not found among the cross-chain balances, the app now fetches the wallet balance directly, applies CNGN rate conversions, and updates the external wallet balance with both corrected and raw balances.

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

  • Bug Fixes
    • Improved balance handling for users with embedded wallets: external/EOA balances and cross‑chain balances are now calculated and displayed correctly.
    • Smart-wallet totals show zero when appropriate and raw balance data is preserved for accuracy.
    • Added reliable fallbacks for cases without an embedded wallet to ensure balances clear correctly.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8098e7a1-63d5-46ee-b782-9748abb97588

📥 Commits

Reviewing files that changed from the base of the PR and between cdf721e and 9cc9f52.

📒 Files selected for processing (1)
  • app/context/BalanceContext.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/context/BalanceContext.tsx

📝 Walkthrough

Walkthrough

Adds a new control-flow branch in BalanceContext for users with no smart-wallet but an embedded wallet. It fetches EOA cross-chain entries, sets EOA flags and balances (including CNGN corrections), clears smart-wallet balances, and preserves raw balance data; falls back to clearing balances if no embedded wallet.

Changes

Cohort / File(s) Summary
Embedded/EOA Balance Flow
app/context/BalanceContext.tsx
Introduce an else if (embeddedWalletAccount) branch: mark primary as EOA, clear smartWalletBalance, fetch fetchCrossChainEntriesForAddress, populate crossChainBalances, set smartWalletRemainingTotal = 0, derive externalWalletBalance from selected-network cross-chain entry or fallback to fetchWalletBalance, apply CNGN total correction and per-balance CNGN conversion, preserve rawBalances. Final fallback to clearAllWalletBalances() unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • chibie
  • 5ran6
  • onahprosper

Poem

🐰
I sniffed the chains both near and far,
Found embedded coins like a shining star.
Cleared the smart-wallet, kept raw in store,
Hopped the balances across each door.
Puff of CNGN, and balances roar!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description provides a clear explanation of the changes and rationale, though the References and Testing sections are incomplete and no test coverage was added despite the checklist indicating it should be. Complete the References section with relevant issue/PR numbers, provide detailed testing instructions, and confirm whether test coverage was actually added to support the new embedded wallet balance-fetch logic.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change—fixing balance fetch logic for new users with embedded wallets, which is the core purpose of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 fix-faulty-balance-fetch

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.

@Dprof-in-tech Dprof-in-tech changed the title fixes fixes faulty balance fetch for new users Apr 3, 2026
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/context/BalanceContext.tsx`:
- Around line 340-349: In the embedded-only branch where you call
setSmartWalletBalance(null), fetchCrossChainEntriesForAddress and
setCrossChainBalances (and setSmartWalletRemainingTotal(0)), also set the
primaryIsEOA flag to true (e.g., via setPrimaryIsEOA(true)) so downstream logic
that checks primaryIsEOA won't overwrite the EOA balances; update the branch
that handles embeddedWalletAccount to mark primaryIsEOA = true alongside the
other state updates (setSmartWalletBalance, setCrossChainBalances,
setSmartWalletRemainingTotal).
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 63b9bf80-5f8a-42c5-aa59-bdce137cf360

📥 Commits

Reviewing files that changed from the base of the PR and between 447a769 and cdf721e.

📒 Files selected for processing (1)
  • app/context/BalanceContext.tsx

Comment thread app/context/BalanceContext.tsx
Copy link
Copy Markdown
Contributor

@5ran6 5ran6 left a comment

Choose a reason for hiding this comment

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

LGTM

@5ran6 5ran6 merged commit 140ae0d into main Apr 3, 2026
1 check passed
@5ran6 5ran6 deleted the fix-faulty-balance-fetch branch April 3, 2026 16:36
This was referenced Apr 6, 2026
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.

2 participants