1
1
import BigNumber from 'bignumber.js'
2
- import { constants , Signer } from 'ethers'
2
+ import { constants , ContractTransaction , Signer } from 'ethers'
3
3
import { getApproved , setApproval } from '../allowance/utils'
4
- import { Chain , Step , Token } from '../types'
4
+ import { Chain , Process , Step , Token } from '../types'
5
5
import { getProvider } from '../utils/getProvider'
6
6
import { parseError } from '../utils/parseError'
7
7
import { StatusManager } from './StatusManager'
@@ -68,11 +68,13 @@ export const checkAllowance = async (
68
68
} catch ( e : any ) {
69
69
// -> set status
70
70
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
+ )
76
78
} else {
77
79
const error = await parseError ( e , step , allowanceProcess )
78
80
statusManager . updateProcess ( step , allowanceProcess . type , 'FAILED' , {
@@ -87,3 +89,31 @@ export const checkAllowance = async (
87
89
}
88
90
}
89
91
}
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