Skip to content

Commit 6d29b2e

Browse files
authored
fix: wait for replaced transaction (#80)
1 parent 83fb7c0 commit 6d29b2e

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/execution/allowance.execute.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import BigNumber from 'bignumber.js'
2-
import { constants, Signer } from 'ethers'
2+
import { constants, ContractTransaction, Signer } from 'ethers'
33
import { getApproved, setApproval } from '../allowance/utils'
4-
import { Chain, Step, Token } from '../types'
4+
import { Chain, Process, Step, Token } from '../types'
55
import { getProvider } from '../utils/getProvider'
66
import { parseError } from '../utils/parseError'
77
import { StatusManager } from './StatusManager'
@@ -68,11 +68,13 @@ export const checkAllowance = async (
6868
} catch (e: any) {
6969
// -> set status
7070
if (e.code === 'TRANSACTION_REPLACED' && e.replacement) {
71-
statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
72-
txHash: e.replacement.hash,
73-
txLink:
74-
chain.metamask.blockExplorerUrls[0] + 'tx/' + e.replacement.hash,
75-
})
71+
await transactionReplaced(
72+
e.replacement,
73+
allowanceProcess,
74+
step,
75+
chain,
76+
statusManager
77+
)
7678
} else {
7779
const error = await parseError(e, step, allowanceProcess)
7880
statusManager.updateProcess(step, allowanceProcess.type, 'FAILED', {
@@ -87,3 +89,31 @@ export const checkAllowance = async (
8789
}
8890
}
8991
}
92+
93+
const transactionReplaced = async (
94+
replacementTx: ContractTransaction,
95+
allowanceProcess: Process,
96+
step: Step,
97+
chain: Chain,
98+
statusManager: StatusManager
99+
) => {
100+
try {
101+
statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
102+
txHash: replacementTx.hash,
103+
txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' + replacementTx.hash,
104+
})
105+
await replacementTx.wait()
106+
statusManager.updateProcess(step, allowanceProcess.type, 'DONE')
107+
} catch (e: any) {
108+
if (e.code === 'TRANSACTION_REPLACED' && e.replacement) {
109+
await transactionReplaced(
110+
e.replacement,
111+
allowanceProcess,
112+
step,
113+
chain,
114+
statusManager
115+
)
116+
}
117+
throw e
118+
}
119+
}

0 commit comments

Comments
 (0)