-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix(react): out-of-sync persisted contract results #552
Conversation
…ual contract result
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Nice job hunting this down.
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.
Looks great! Nice job on getting RQ update in.
@jxom Since updating to wagmi@0.4.10 I'm getting errors with all my instances of useContractRead:
For now I'm reverting to 0.4.7, our previous version. Any idea what this could be caused by? npm view wagmi dependencies
{
'@coinbase/wallet-sdk': '^3.2.0',
'@wagmi/core': '^0.3.7',
'@walletconnect/ethereum-provider': '^1.7.8',
'react-query': '^4.0.0-beta.23',
'use-sync-external-store': '^1.1.0'
} |
@0xfffxfff would you be able to provide me with a minimal reproducible example via a CodeSandbox or something? |
@jxom We're in the middle of a release right now. I can try spinning one up on Monday. 👍 |
@jxom Just to give you an idea where this happens: const balanceOf = useKubboPartsRead('balanceOf', { args: account?.data?.address, enabled: Boolean(account?.data?.address), watch: true }) where export const useKubboPartsRead = (
functionName: string, config?: Parameters<typeof useContractRead>[2]
) => {
const network = useNetwork()
const contract = Contracts.KubboParts[network?.activeChain?.id || chain.mainnet.id];
return useContractRead(contract, functionName, config)
} Entirely possible that my use of the hook is causing this. Edit: This is how we include our contracts KubboParts[chain.mainnet.id] = {
addressOrName: KubboPartsABI.address,
contractInterface: KubboPartsABI.abi as ContractInterface,
} as UseContractConfig |
Thanks! I'll do some digging. |
@0xfffxfff – I'm assuming the return type of this method was a tuple? There is a fix here: #566 |
Thanks @jxom! This fixed it.
It was an array of uint256. Funnily enough, I had to change a useEffect dependency from this: }, [
tokensOf.data,
...
]); to this: }, [
tokensOf.data?.reduce((c,i) => c+i?.toString(),''),
...
]); I'm guessing the reason is that it's no longer receiving the same array but rather a newly constructed one on each call? In any case, with this in place everything's now properly chugging along 👍 |
Fixes #460
Description
There is an interesting bug where persisted
useContractRead
struct results would be out of sync with the ethers contractResult
. This is because the ethersResult
currently doesn't serialize properly with ourserialize
function. I first attempted to try fix this in ourserialize
/deserialize
functions to try get it to persist into our storage, however, after doing that, I then realised that React Query also doesn't cater for this data structure in their data comparison functions.In this proposed fix, I ended up just checking to see if the result returned from RQ is in an out-of-sync state, and if it is, it will use the contract interface to parse it back into an ethers contract
Result
.