Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit b72ffb6

Browse files
authored
fix: receipt timeouts (#1127)
* fix: change waitForReceipt timeout to undefined to avoid wagmi bug * mend * fix: avoid animations when rendering a historic receipt (#1128)
1 parent fe8dd82 commit b72ffb6

File tree

7 files changed

+48
-14
lines changed

7 files changed

+48
-14
lines changed

lib/modules/pool/actions/add-liquidity/modal/AddLiquidityModal.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ export function AddLiquidityModal({
3535
}: Props & Omit<ModalProps, 'children'>) {
3636
const { isDesktop } = useBreakpoints()
3737
const initialFocusRef = useRef(null)
38-
const { transactionSteps, addLiquidityTxHash, hasQuoteContext, setInitialHumanAmountsIn } =
39-
useAddLiquidity()
38+
const {
39+
transactionSteps,
40+
addLiquidityTxHash,
41+
hasQuoteContext,
42+
urlTxHash,
43+
setInitialHumanAmountsIn,
44+
} = useAddLiquidity()
4045
const { pool, chain } = usePool()
4146
const { redirectToPoolPage } = usePoolRedirect(pool)
4247
const { userAddress } = useUserAccount()
@@ -101,6 +106,7 @@ export function AddLiquidityModal({
101106
currentStep={transactionSteps.currentStep}
102107
returnLabel="Return to pool"
103108
returnAction={redirectToPoolPage}
109+
urlTxHash={urlTxHash}
104110
/>
105111
</ModalContent>
106112
</Modal>

lib/modules/pool/actions/remove-liquidity/RemoveLiquidityProvider.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export function _useRemoveLiquidity(urlTxHash?: Hash) {
254254
previewModalDisclosure,
255255
handler,
256256
wethIsEth,
257+
urlTxHash,
257258
removeLiquidityTxHash,
258259
hasQuoteContext,
259260
amountsOut,

lib/modules/pool/actions/remove-liquidity/modal/RemoveLiquidityModal.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export function RemoveLiquidityModal({
3535
}: Props & Omit<ModalProps, 'children'>) {
3636
const { isDesktop } = useBreakpoints()
3737
const initialFocusRef = useRef(null)
38-
const { transactionSteps, removeLiquidityTxHash, hasQuoteContext } = useRemoveLiquidity()
38+
const { transactionSteps, removeLiquidityTxHash, urlTxHash, hasQuoteContext } =
39+
useRemoveLiquidity()
3940
const { pool, chain } = usePool()
4041
const { redirectToPoolPage } = usePoolRedirect(pool)
4142
const { userAddress } = useUserAccount()
@@ -99,6 +100,7 @@ export function RemoveLiquidityModal({
99100
currentStep={transactionSteps.currentStep}
100101
returnLabel="Return to pool"
101102
returnAction={redirectToPoolPage}
103+
urlTxHash={urlTxHash}
102104
/>
103105
</ModalContent>
104106
</Modal>

lib/modules/swap/modal/SwapModal.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ export function SwapPreviewModal({
3939
const { userAddress } = useUserAccount()
4040
const { stopTokenPricePolling } = useTokens()
4141

42-
const { transactionSteps, swapAction, isWrap, selectedChain, swapTxHash, hasQuoteContext } =
43-
useSwap()
42+
const {
43+
transactionSteps,
44+
swapAction,
45+
isWrap,
46+
selectedChain,
47+
swapTxHash,
48+
urlTxHash,
49+
hasQuoteContext,
50+
} = useSwap()
4451

4552
const swapReceipt = useSwapReceipt({
4653
txHash: swapTxHash,
@@ -97,6 +104,7 @@ export function SwapPreviewModal({
97104
currentStep={transactionSteps.currentStep}
98105
returnLabel="Swap again"
99106
returnAction={onClose}
107+
urlTxHash={urlTxHash}
100108
/>
101109
</ModalContent>
102110
</Modal>

lib/modules/web3/contracts/useManagedSendTransaction.ts

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export function useManagedSendTransaction({
6464
hash: txHash,
6565
confirmations: minConfirmations,
6666
timeout: getWaitForReceiptTimeout(chainId),
67+
query: {
68+
...onlyExplicitRefetch,
69+
},
6770
})
6871

6972
const bundle = {

lib/modules/web3/contracts/wagmi-helpers.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Helpers for wagmi transactions
22
import { Address } from 'viem'
33
import { TransactionBundle } from './contract.types'
4-
import { polygon } from 'viem/chains'
5-
import { secs } from '@/lib/shared/utils/time'
64

75
export function getHashFromTransaction(transactionBundle?: TransactionBundle): Address | undefined {
86
if (!transactionBundle) return
@@ -23,11 +21,12 @@ export function isValidUserAddress(userAddress?: Address) {
2321
Returns timeout to be used in useWaitForTransactionReceipt options
2422
By default all react queries retry 3 times
2523
More info: https://tanstack.com/query/v5/docs/framework/react/guides/query-retries
26-
*/
24+
*/
25+
/* eslint-disable @typescript-eslint/no-unused-vars */
2726
export function getWaitForReceiptTimeout(chainId: number) {
28-
// In polygon there will be 3 retries of 25 seconds until we throw the timeout error
29-
if (chainId === polygon.id) return secs(25).toMs()
30-
31-
// In other chains there will be 3 retries of 15 seconds until we throw the timeout error
32-
return secs(15).toMs()
27+
/* Using an specific timeout was throwing a timeout error after confirmation
28+
Wagmi bug: https://github.com/wevm/viem/discussions/1351
29+
Using undefined seems to be more reliable
30+
*/
31+
return undefined
3332
}

lib/shared/components/modals/ActionModalFooter.tsx

+16-1
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,24 @@ type Props = {
4949
currentStep: TransactionStep
5050
returnLabel: string
5151
returnAction: () => void
52+
urlTxHash?: string
5253
}
5354

54-
export function ActionModalFooter({ isSuccess, currentStep, returnLabel, returnAction }: Props) {
55+
export function ActionModalFooter({
56+
isSuccess,
57+
currentStep,
58+
returnLabel,
59+
returnAction,
60+
urlTxHash,
61+
}: Props) {
62+
// Avoid animations when displaying a historic receipt
63+
if (urlTxHash) {
64+
return (
65+
<ModalFooter>
66+
<SuccessActions returnLabel={returnLabel} returnAction={returnAction} />
67+
</ModalFooter>
68+
)
69+
}
5570
return (
5671
<ModalFooter>
5772
<AnimatePresence mode="wait" initial={false}>

0 commit comments

Comments
 (0)