-
Notifications
You must be signed in to change notification settings - Fork 45
refactor: use tanstack query for fetching user balances #1757
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
Open
0xAlunara
wants to merge
14
commits into
main
Choose a base branch
from
refactor/user-balances-tanstack-query
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−168
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
0xAlunara
commented
Dec 11, 2025
0xAlunara
commented
Dec 11, 2025
6be990f to
f249222
Compare
0xAlunara
commented
Dec 11, 2025
0xPearce
reviewed
Dec 11, 2025
Collaborator
0xPearce
left a 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.
0xPearce
previously approved these changes
Dec 12, 2025
DanielSchiavini
previously approved these changes
Dec 12, 2025
OnlyJousting
previously approved these changes
Dec 15, 2025
f97ca3b
OnlyJousting
approved these changes
Dec 16, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


To keep the PR small, the goal here is not to replace the Zustand stores & mapper just yet. The goal here is to only replace the actual balance fetching with wagmi core functionality. This allows using the
useTokenBalancequery everywhere, as it'll be fetching from the same (Tanstack) cache as wheneverfetchTokenBalanceis called by the stores, without actually relying on data from the store. In other words, it makes removing the stores for balances and tokens later easier.This means that
useTokenBalancehas been refactored such that it usesgetNativeBalanceQueryOptionsandgetERC20QueryContractsfactory functions that can be re-used for the imperativefetchTokenBalancefunction (with a staleTime of 0 to ensure freshness as the stores expect).After some checking I'm fairly confident that all native gas tokens use
ethAddressas their token address in the Curve eco. This means we no longer need the token symbol to check if a token is a native gas token or not. This is good news, because we don't always have token symbols at hand, we often have merely the address at our disposal.In the end I would've loved to use
queryFactory, but it's not really suitable when using wagmi actions. You want to make proper use of its internal Tanstack logic when using both native wagmi hooks and aqueryClient. For example, we don't really have any say in whateverqueryKeyit's using internally. Perhaps we could make awagmiQueryFactorylater, but that's some serious refactoring that I'm not willing to do now. And I'm not sure if that's even worthwhile.Additional reading material if you question the method on how I've implemented fetchQuery.