Skip to content

Commit

Permalink
fix: change waitForReceipt timeout to undefined to avoid wagmi bug
Browse files Browse the repository at this point in the history
  • Loading branch information
agualis committed Sep 25, 2024
1 parent fe8dd82 commit f27f996
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions lib/modules/web3/contracts/useManagedSendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export function useManagedSendTransaction({
hash: txHash,
confirmations: minConfirmations,
timeout: getWaitForReceiptTimeout(chainId),
query: {
...onlyExplicitRefetch,
},
})

const bundle = {
Expand Down
17 changes: 8 additions & 9 deletions lib/modules/web3/contracts/wagmi-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Helpers for wagmi transactions
import { Address } from 'viem'
import { TransactionBundle } from './contract.types'
import { polygon } from 'viem/chains'
import { secs } from '@/lib/shared/utils/time'

export function getHashFromTransaction(transactionBundle?: TransactionBundle): Address | undefined {
if (!transactionBundle) return
Expand All @@ -23,11 +21,12 @@ export function isValidUserAddress(userAddress?: Address) {
Returns timeout to be used in useWaitForTransactionReceipt options
By default all react queries retry 3 times
More info: https://tanstack.com/query/v5/docs/framework/react/guides/query-retries
*/
export function getWaitForReceiptTimeout(chainId: number) {
// In polygon there will be 3 retries of 25 seconds until we throw the timeout error
if (chainId === polygon.id) return secs(25).toMs()

// In other chains there will be 3 retries of 15 seconds until we throw the timeout error
return secs(15).toMs()
*/
/* eslint-disable @typescript-eslint/no-unused-vars */
export function getWaitForReceiptTimeout(_chainId: number) {
/* Using an specific timeout was throwing a timeout error after confirmation
Wagmi bug: https://github.com/wevm/viem/discussions/1351
Using undefined seems to be more reliable
*/
return undefined
}

0 comments on commit f27f996

Please sign in to comment.