fix: refetch token balances after dust success#2845
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
✅ All snapshot tests passed |
WalkthroughThe PR decouples token refresh from portfolio refresh by introducing a new ChangesToken-Specific Balance Refresh Flow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/providers/PortfolioProvider/hooks/useBalancesData.ts (1)
148-175: 💤 Low valueConsider persisting refreshed balances to cache.
The
refetchForTokensfunction updates the React Query cache but does not persist tosetBalancesInCache, unlike the mainqueryFnwhich persists on completion. This means refreshed token balances will be lost on next app load until a full refetch occurs.If this is intentional (e.g., relying on next full refresh to persist), the current approach is fine. Otherwise, consider adding persistence:
♻️ Optional: Persist refreshed balances
const refetchForTokens = useCallback( async (address: string, tokens: LifiToken[]) => { const freshBalances = await fetchTokenBalancesForAddress(address, tokens); queryClient.setQueryData<TokenQueryData>( ['portfolio-tokens', address], (prev) => { if (!prev) { return prev; } const kept = differenceWith( prev.balances, tokens, (b, t) => b.token.chainId === t.chainId && b.token.address.toLowerCase() === t.address.toLowerCase(), ); - return { + const newBalances = [...kept, ...freshBalances]; + + // Persist to cache for next app load + if (newBalances.length) { + setBalancesInCache(address, newBalances); + } + + return { ...prev, - balances: [...kept, ...freshBalances], + balances: newBalances, }; }, ); }, - [queryClient], + [queryClient, setBalancesInCache], );🤖 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 `@src/providers/PortfolioProvider/hooks/useBalancesData.ts` around lines 148 - 175, refetchForTokens updates the React Query cache but doesn't persist the refreshed balances to storage; modify refetchForTokens (the function defined as refetchForTokens) to call setBalancesInCache after computing the new TokenQueryData/balances (the same shape produced in the queryFn) so the updated balances are saved persistently; ensure you pass the address and the updated balances/TokenQueryData into setBalancesInCache and keep the existing queryClient.setQueryData update logic intact.
🤖 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.
Nitpick comments:
In `@src/providers/PortfolioProvider/hooks/useBalancesData.ts`:
- Around line 148-175: refetchForTokens updates the React Query cache but
doesn't persist the refreshed balances to storage; modify refetchForTokens (the
function defined as refetchForTokens) to call setBalancesInCache after computing
the new TokenQueryData/balances (the same shape produced in the queryFn) so the
updated balances are saved persistently; ensure you pass the address and the
updated balances/TokenQueryData into setBalancesInCache and keep the existing
queryClient.setQueryData update logic intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 62448d6a-4635-4d0a-82c9-1208ccefb271
📒 Files selected for processing (6)
src/components/composite/DustFlow/hooks/useDustModalFlow.tsxsrc/providers/PortfolioProvider/PortfolioContext.tssrc/providers/PortfolioProvider/hooks/useBalancesData.tssrc/providers/PortfolioProvider/hooks/useOrchestrationState.tssrc/providers/PortfolioProvider/lib/fetchBalancesForAddresses.tssrc/providers/PortfolioProvider/types.ts
Playwright test results
Details
Failed testschromium › earnPage.spec.ts › Analytics filters on Earn page › Should be able to verify analytics buttons are visible (Qase ID: 47) Flaky testschromium › mainMenu.spec.ts › Main Menu flows › Should be able to navigate to X (Qase ID: 16) Skipped testschromium › themeManipulation.spec.ts › Switch between dark and light theme and check the background color › Partner theme should appear in theme menu and apply background color (Qase ID: 49) |
Which Jira task belongs to this PR?
Closes https://linear.app/lifi-linear/issue/JUM-911/check-frequency-of-token-balance-refresh
Testing steps
Why did I implement it this way?
Checklist before requesting a review
Summary by CodeRabbit