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

fix: receipt timeouts #1127

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ export function AddLiquidityModal({
}: Props & Omit<ModalProps, 'children'>) {
const { isDesktop } = useBreakpoints()
const initialFocusRef = useRef(null)
const { transactionSteps, addLiquidityTxHash, hasQuoteContext, setInitialHumanAmountsIn } =
useAddLiquidity()
const {
transactionSteps,
addLiquidityTxHash,
hasQuoteContext,
urlTxHash,
setInitialHumanAmountsIn,
} = useAddLiquidity()
const { pool, chain } = usePool()
const { redirectToPoolPage } = usePoolRedirect(pool)
const { userAddress } = useUserAccount()
Expand Down Expand Up @@ -101,6 +106,7 @@ export function AddLiquidityModal({
currentStep={transactionSteps.currentStep}
returnLabel="Return to pool"
returnAction={redirectToPoolPage}
urlTxHash={urlTxHash}
/>
</ModalContent>
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export function _useRemoveLiquidity(urlTxHash?: Hash) {
previewModalDisclosure,
handler,
wethIsEth,
urlTxHash,
removeLiquidityTxHash,
hasQuoteContext,
amountsOut,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export function RemoveLiquidityModal({
}: Props & Omit<ModalProps, 'children'>) {
const { isDesktop } = useBreakpoints()
const initialFocusRef = useRef(null)
const { transactionSteps, removeLiquidityTxHash, hasQuoteContext } = useRemoveLiquidity()
const { transactionSteps, removeLiquidityTxHash, urlTxHash, hasQuoteContext } =
useRemoveLiquidity()
const { pool, chain } = usePool()
const { redirectToPoolPage } = usePoolRedirect(pool)
const { userAddress } = useUserAccount()
Expand Down Expand Up @@ -99,6 +100,7 @@ export function RemoveLiquidityModal({
currentStep={transactionSteps.currentStep}
returnLabel="Return to pool"
returnAction={redirectToPoolPage}
urlTxHash={urlTxHash}
/>
</ModalContent>
</Modal>
Expand Down
12 changes: 10 additions & 2 deletions lib/modules/swap/modal/SwapModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ export function SwapPreviewModal({
const { userAddress } = useUserAccount()
const { stopTokenPricePolling } = useTokens()

const { transactionSteps, swapAction, isWrap, selectedChain, swapTxHash, hasQuoteContext } =
useSwap()
const {
transactionSteps,
swapAction,
isWrap,
selectedChain,
swapTxHash,
urlTxHash,
hasQuoteContext,
} = useSwap()

const swapReceipt = useSwapReceipt({
txHash: swapTxHash,
Expand Down Expand Up @@ -97,6 +104,7 @@ export function SwapPreviewModal({
currentStep={transactionSteps.currentStep}
returnLabel="Swap again"
returnAction={onClose}
urlTxHash={urlTxHash}
/>
</ModalContent>
</Modal>
Expand Down
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
15 changes: 7 additions & 8 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
*/
*/
/* eslint-disable @typescript-eslint/no-unused-vars */
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()
/* 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
}
17 changes: 16 additions & 1 deletion lib/shared/components/modals/ActionModalFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,24 @@ type Props = {
currentStep: TransactionStep
returnLabel: string
returnAction: () => void
urlTxHash?: string
}

export function ActionModalFooter({ isSuccess, currentStep, returnLabel, returnAction }: Props) {
export function ActionModalFooter({
isSuccess,
currentStep,
returnLabel,
returnAction,
urlTxHash,
}: Props) {
// Avoid animations when displaying a historic receipt
if (urlTxHash) {
return (
<ModalFooter>
<SuccessActions returnLabel={returnLabel} returnAction={returnAction} />
</ModalFooter>
)
}
return (
<ModalFooter>
<AnimatePresence mode="wait" initial={false}>
Expand Down
Loading