You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using useReadContract in order to have live updates from a variable called account_debt, in order to fetch that data I read a "view" method on a smart contract called get_pending_market_state_for_account.
The way the view functions works is:
If the user has no debt the view will revert.
If the user has debt the view will return account_debt
If the user closes his debt the view will revert again.
The natural user flow on the application goes as this:
User starts with no debt
User creates debt
User pays debt
User has no debt again UI should return to (1)
The problem is when a user pays the debt on step (3) the UI never returns to (1), because:
While the user has no debt the value of account_debt is null
When debt is created it becomes a bigint
When debt is closed the value never turns back to null because ( I assume ) Wagmi won't update the data if the contract starts reverting with the same params?
Debugging
When I look at the ReactQueryDevTools on the stuck page I can see this and it NEVER changes even though I see the "fetch" happening often, the cached data is always here.
If I press the blue button "Trigger Loading" then the data is updated and becomes "null" again ( which is the original state ).
Questions
Is there a recommended way of dealing with this problem?
Is there a way of overriding this problem, for instance have a hook where I can check if the view reverted for a given reason I can return some "empty state" to my frontend?
Why clicking "Trigger Loading" has a different behaviour than "Refetch" and would it be possible to have "refetch" working as "trigger loading" by itself?
I checked there isn't already an issue for the bug I encountered.
Anything else?
To reproduce the error I would need to send some test tokens on FTM + FTM for gas and I think it's not needed in this case as the problem is well explained.
Thanks a lot for your hard work on the library!
The text was updated successfully, but these errors were encountered:
the view function is called get_pending_market_state_for_account
the revert happens on line 470
assert coll_change > 0 and debt_change > 0, "DFM:C 0 coll or debt"
I believe deploying this contract on a test net / local network would be a little to complicated, so would be better to write a simple contract with a parameter that triggers the failed assert.
Describe the bug
Problem
I'm using useReadContract in order to have live updates from a variable called
account_debt
, in order to fetch that data I read a "view" method on a smart contract calledget_pending_market_state_for_account
.The way the view functions works is:
account_debt
The natural user flow on the application goes as this:
The problem is when a user pays the debt on step (3) the UI never returns to (1), because:
account_debt
is nullnull
because ( I assume ) Wagmi won't update the data if the contract starts reverting with the same params?Debugging
When I look at the ReactQueryDevTools on the stuck page I can see this and it NEVER changes even though I see the "fetch" happening often, the cached data is always here.
If I press the blue button "Trigger Loading" then the data is updated and becomes "null" again ( which is the original state ).
Questions
Link to Minimal Reproducible Example
https://stackblitz.com/edit/new-wagmi?file=src%2FApp.tsx
Steps To Reproduce
Described on the preview comment
Wagmi Version
2.8.1
Viem Version
2.10.2
TypeScript Version
5.4.5
Check existing issues
Anything else?
To reproduce the error I would need to send some test tokens on FTM + FTM for gas and I think it's not needed in this case as the problem is well explained.
Thanks a lot for your hard work on the library!
The text was updated successfully, but these errors were encountered: