-
Notifications
You must be signed in to change notification settings - Fork 184
fix: Auto-refresh wallet balance after transactions #1788
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
base: main
Are you sure you want to change the base?
fix: Auto-refresh wallet balance after transactions #1788
Conversation
…uery invalidation
|
@xerion12 is attempting to deploy a commit to the Warden Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe changes add automatic wallet balance refresh functionality across the application. A new refresh button is introduced in the ConnectWallet component that invalidates and refetches balance queries. Balance query invalidation is simultaneously integrated into transaction success paths in StatusSidebar and the contract write handler to ensure wallet balance reflects post-transaction state. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (2)
spaceward/src/features/actions/StatusSidebar.tsx (1)
457-476: Duplicate invalidation logic.This is identical to the invalidation at lines 349-368. As noted above, extract to a shared helper.
spaceward/src/utils/contract.tsx (1)
111-130: Same predicate duplication applies here.This is the same invalidation predicate used in
StatusSidebar.tsx. Consider using the shared helper suggested in that file's review.
🧹 Nitpick comments (2)
spaceward/src/components/ConnectWallet.tsx (1)
41-53: Consider simplifying the refresh logic.Calling
invalidateQueriesalready marks the query as stale and triggers a background refetch. The subsequent explicitrefetch()call is redundant and may cause a double network request.const handleRefresh = async () => { if (!address || isRefreshing) return; setIsRefreshing(true); try { // Invalidate and refetch balance query - await queryClient.invalidateQueries({ queryKey: balance.queryKey }); - await balance.refetch(); + await balance.refetch(); } catch (error) { console.error("Error refreshing balance:", error); } finally { setIsRefreshing(false); } };Alternatively, if you want to ensure cache invalidation across any shared queries, keep only
invalidateQueriesand removerefetch().spaceward/src/features/actions/StatusSidebar.tsx (1)
349-368: Extract duplicated balance invalidation predicate into a shared helper.This predicate logic is duplicated here, at lines 459-475, and in
contract.tsx. Extracting it to a shared utility would improve maintainability and reduce the risk of inconsistencies.Consider creating a helper function:
// e.g., in src/utils/queryKeys.ts export const createBalanceQueryPredicate = (address: string, chainId: number) => (query: Query) => { const key = query.queryKey; if (!Array.isArray(key) || key[0] !== "balance") return false; const params = key[1]; return ( typeof params === "object" && params !== null && "address" in params && (params as any).address === address && "chainId" in params && (params as any).chainId === chainId ); };Then use it in all three locations:
-queryClient.invalidateQueries({ - predicate: (query) => { - const key = query.queryKey; - if (!Array.isArray(key) || key[0] !== "balance") { - return false; - } - const params = key[1]; - return ( - typeof params === "object" && - params !== null && - "address" in params && - (params as any).address === address && - "chainId" in params && - (params as any).chainId === env.evmChainId - ); - }, -}); +queryClient.invalidateQueries({ + predicate: createBalanceQueryPredicate(address, env.evmChainId), +});
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
spaceward/src/components/ConnectWallet.tsx(3 hunks)spaceward/src/features/actions/StatusSidebar.tsx(2 hunks)spaceward/src/utils/contract.tsx(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
spaceward/src/features/actions/StatusSidebar.tsx (1)
spaceward/src/env.ts (1)
env(37-57)
🔇 Additional comments (2)
spaceward/src/components/ConnectWallet.tsx (1)
196-217: LGTM!The refresh button implementation is well-structured with proper accessibility (tooltip), loading state (spinning icon), and disabled state handling.
spaceward/src/utils/contract.tsx (1)
70-78: LGTM on API extension.The optional parameters are well-designed, maintaining backward compatibility with existing callers while enabling balance invalidation when the new options are provided. Verify that callers of
handleContractWriteare updated to pass the new options (queryClient, address, chainId) where balance refresh is needed.
Implements automatic wallet balance refresh after successful transactions and adds manual refresh button to wallet icon.