-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(ramps): use asset chainId to fetch correct token balance in useBalance cp-7.61.0 #23719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
|
bugbot run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Bugbot reviewed your changes and found no bugs!
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsThe change modifies the This is a targeted improvement that makes the balance lookup chain-aware in the Ramp/Aggregator feature. The hook is used in:
The change is specific to the on/off ramp (buy/sell) functionality and should be tested with
The risk is medium because while the change is well-contained, it affects an important financial feature (displaying user balances during buy/sell operations). |
|



Description
The
useBalancehook in the Ramp Aggregator was usingselectContractBalances, which returns token balances only for the currently selected network. This caused incorrect behavior.Solution: Changed the hook to use
selectContractBalancesPerChainIdand access the correct chain's balances using theasset.chainIdparameter that is already passed to the hook.Changelog
CHANGELOG entry: Fixed incorrect token balance check in Ramp when selecting tokens from non-active networks
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/TRAM-2875?atlOrigin=eyJpIjoiNDE5YjQ4YjQ3NGRkNGUzMGFkODUxNjI0M2QxMzlkNjUiLCJwIjoiaiJ9
Fixes #23722
Manual testing steps
Screenshots/Recordings
Before
balanceBNwasnullfor tokens on non-active networks, causing false insufficient balance errors.(quick amount selector isn't shown because amount is not being detected)
After
balanceBNcorrectly reflects the token balance on the asset's chain regardless of the currently active network.Pre-merge author checklist
Pre-merge reviewer checklist
Note
Compute token balances from the asset’s chain using per-chain balances, fixing incorrect balances when the active network differs.
useBalance(app/components/UI/Ramp/Aggregator/hooks/useBalance.ts):selectContractBalancesPerChainIdand index by the asset’schainId(viatoHex) to retrieve correct per-chain ERC-20 balances.balance,balanceBN,balanceFiat) to use chain-scoped balances and existing exchange rates.accountsByChainId[hexChainId]guard for the asset’s chain.Written by Cursor Bugbot for commit 2fa36f1. This will update automatically on new commits. Configure here.