-
Notifications
You must be signed in to change notification settings - Fork 43
fix: unable to get wallet balances #1373
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?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
void fetchUserPoolInfo(curve, poolId, true) | ||
if ( | ||
curve && | ||
!curve.isNoRPC && |
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.
This does not make any sense. Why would curve
have a signer address (haveAddress = !!curve.signerAddress
) and no RPC?
!curve.isNoRPC && |
If that is really happening we must fix it, not work around it
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.
Here's the chain of events in chronological order that hopefully makes the problem more clear:
- Open app
- CurveJS inits with no RPC
- CurveJS gets hydrated
- CurveJS gets init again but this time with RPC
- The
useEffect
that callsfetchUserPoolInfo
and relies oncurvejs
gets called. The functionfetchUserPoolInfo
however relies on a hydrated version ofcurvejs
(as it requires pools being fetched etc). This fails, as the newcurvejs
with RPC is not yet hydrated - CurveJS with RPC gets hydrated
So the fix was aimed at hydrating the specific part for fetchUserPoolInfo
when we get a new curvejs
with RPC. The issue basically boils down to having a curvejs
that has an RPC but is not yet hydrated. You can't wait in the useEffect
for curvejs
to be hydrated because there's no such tracking. We only have an isHydrated
check at at the root in the tanstack router, but there's no 'hasRehydratedWithRpcThisTime'.
That sounds like a band-aid too. This ticket was outside of the sprint so I'll leave it be for now.
Fwiw a real solution would be Tanstackifying everything and getting rid of the hydration, but that's a step too big for now.
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.
If it's necessary we can add a hydration flag in the connection context. Or even inject a property in the curve
object.
We should also fix the double-hydration issue, I already tried to fix this:
curve-frontend/packages/curve-ui-kit/src/features/connect-wallet/lib/ConnectionContext.tsx
Line 114 in 0ff0d5c
if (isReconnecting) return // wait for wagmi to auto-reconnect |
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.
See also #1022 and
curve-frontend/packages/curve-ui-kit/src/features/connect-wallet/lib/ConnectionContext.tsx
Lines 41 to 42 in 0ff0d5c
// `useAccount` and `useClient` are not always in sync, so check both. `isReconnecting` is set when switching pages | |
isReconnecting: !address && (isReconnecting || isConnected), |
By the light this shit is nasty.
So the problem is, when you visit the website for the first time the CurveJS library gets hydrated without an RPC. But to fetch user walles balances, you need a CurveJS instance with an RPC. After a short time, a second hydration occurs with an RPC. However, there's a brief moment in time where you have a CurveJS instance with RPC, but it's not yet hydrated. Only the old
NoRPC
version is hydrated. There's no easy way to detect if the new RPC'd version of CurveJS is hydrated, so out of caution if you want to callfetchUserPoolInfo
you have to make absolutely sure the pool we're fetching data from is hydrated, hence the preceding calls offetchUserPoolList
.Ugh, this one ugly fix. Can't wait until we get rid of this whole library and can rely on just TanStack queries, which would be a proper fix.
EDIT: it's still not 100% fixed but it's better. Burn this shit with fire ugh
If you go to a pool page in prod and refresh with F5 you can reproduce it
