@@ -28,6 +28,7 @@ import type {
28
28
import { isSwapError } from '../utils/isSwapError' ;
29
29
import { processSwapTransaction } from '../utils/processSwapTransaction' ;
30
30
import { useFundSwapTokens } from '../hooks/useFundSwapTokens' ;
31
+ import { useResetFundSwapInputs } from '../hooks/useResetFundSwapInputs' ;
31
32
32
33
const emptyContext = { } as FundSwapContextType ;
33
34
@@ -84,7 +85,7 @@ export function FundSwapProvider({
84
85
const { sendCallsAsync } = useSendCalls ( ) ; // Atomic Batch transactions (and approval, if applicable)
85
86
86
87
// Refreshes balances and inputs post-swap
87
- // const resetInputs = useResetInputs ({ from , to });
88
+ const resetInputs = useResetFundSwapInputs ( { fromETH , fromUSDC , to } ) ;
88
89
// For batched transactions, listens to and awaits calls from the Wallet server
89
90
const awaitCallsStatus = useAwaitCalls ( {
90
91
accountConfig,
@@ -123,9 +124,9 @@ export function FundSwapProvider({
123
124
// prevents multiple calls to `onStatus`
124
125
if ( lifecycleStatus . statusName === 'init' && hasHandledSuccess ) {
125
126
setHasHandledSuccess ( false ) ;
126
- // resetInputs();
127
+ resetInputs ( ) ;
127
128
}
128
- } , [ hasHandledSuccess , lifecycleStatus . statusName ] ) ;
129
+ } , [ hasHandledSuccess , lifecycleStatus . statusName , resetInputs ] ) ;
129
130
130
131
useEffect ( ( ) => {
131
132
// For batched transactions, `transactionApproved` will contain the calls ID
@@ -145,16 +146,24 @@ export function FundSwapProvider({
145
146
] ) ;
146
147
147
148
useEffect ( ( ) => {
149
+ let timer : NodeJS . Timeout ;
148
150
// Reset status to init after success has been handled
149
151
if ( lifecycleStatus . statusName === 'success' && hasHandledSuccess ) {
150
- updateLifecycleStatus ( {
151
- statusName : 'init' ,
152
- statusData : {
153
- isMissingRequiredField : true ,
154
- maxSlippage : config . maxSlippage ,
155
- } ,
156
- } ) ;
152
+ timer = setTimeout ( ( ) => {
153
+ updateLifecycleStatus ( {
154
+ statusName : 'init' ,
155
+ statusData : {
156
+ isMissingRequiredField : true ,
157
+ maxSlippage : config . maxSlippage ,
158
+ } ,
159
+ } ) ;
160
+ } , 3000 ) ;
157
161
}
162
+ return ( ) => {
163
+ if ( timer ) {
164
+ return clearTimeout ( timer ) ;
165
+ }
166
+ } ;
158
167
} , [
159
168
config . maxSlippage ,
160
169
hasHandledSuccess ,
0 commit comments