@@ -34,6 +34,8 @@ import {
34
34
selectIsEvmSolanaBridge ,
35
35
selectIsSolanaSwap ,
36
36
setSlippage ,
37
+ selectIsSubmittingTx ,
38
+ setIsSubmittingTx ,
37
39
} from '../../../../../core/redux/slices/bridge' ;
38
40
import {
39
41
useNavigation ,
@@ -46,7 +48,6 @@ import { strings } from '../../../../../../locales/i18n';
46
48
import useSubmitBridgeTx from '../../../../../util/bridge/hooks/useSubmitBridgeTx' ;
47
49
import Engine from '../../../../../core/Engine' ;
48
50
import Routes from '../../../../../constants/navigation/Routes' ;
49
- import { selectBasicFunctionalityEnabled } from '../../../../../selectors/settings' ;
50
51
import ButtonIcon from '../../../../../component-library/components/Buttons/ButtonIcon' ;
51
52
import QuoteDetailsCard from '../../components/QuoteDetailsCard' ;
52
53
import { useBridgeQuoteRequest } from '../../hooks/useBridgeQuoteRequest' ;
@@ -70,11 +71,16 @@ import { useSwitchTokens } from '../../hooks/useSwitchTokens';
70
71
71
72
const BridgeView = ( ) => {
72
73
const [ isInputFocused , setIsInputFocused ] = useState ( false ) ;
73
- const [ isSubmittingTx , setIsSubmittingTx ] = useState ( false ) ;
74
- // The same as getUseExternalServices in Extension
75
- const isBasicFunctionalityEnabled = useSelector (
76
- selectBasicFunctionalityEnabled ,
77
- ) ;
74
+ const isSubmittingTx = useSelector ( selectIsSubmittingTx ) ;
75
+
76
+ // Ref necessary to avoid race condition between Redux state and component state
77
+ // Without it, the component would reset the bridge state when it shouldn't
78
+ const isSubmittingTxRef = useRef ( isSubmittingTx ) ;
79
+
80
+ // Update ref when Redux state changes
81
+ useEffect ( ( ) => {
82
+ isSubmittingTxRef . current = isSubmittingTx ;
83
+ } , [ isSubmittingTx ] ) ;
78
84
79
85
const { styles } = useStyles ( createStyles , { } ) ;
80
86
const dispatch = useDispatch ( ) ;
@@ -175,10 +181,13 @@ const BridgeView = () => {
175
181
// Reset bridge state when component unmounts
176
182
useEffect (
177
183
( ) => ( ) => {
178
- dispatch ( resetBridgeState ( ) ) ;
179
- // Clear bridge controller state if available
180
- if ( Engine . context . BridgeController ?. resetState ) {
181
- Engine . context . BridgeController . resetState ( ) ;
184
+ // Only reset state if we're not in the middle of a transaction
185
+ if ( ! isSubmittingTxRef . current ) {
186
+ dispatch ( resetBridgeState ( ) ) ;
187
+ // Clear bridge controller state if available
188
+ if ( Engine . context . BridgeController ?. resetState ) {
189
+ Engine . context . BridgeController . resetState ( ) ;
190
+ }
182
191
}
183
192
} ,
184
193
[ dispatch ] ,
@@ -188,23 +197,6 @@ const BridgeView = () => {
188
197
navigation . setOptions ( getBridgeNavbar ( navigation , route , colors ) ) ;
189
198
} , [ navigation , route , colors ] ) ;
190
199
191
- useEffect ( ( ) => {
192
- const setBridgeFeatureFlags = async ( ) => {
193
- try {
194
- if (
195
- isBasicFunctionalityEnabled &&
196
- Engine . context . BridgeController ?. setBridgeFeatureFlags
197
- ) {
198
- await Engine . context . BridgeController . setBridgeFeatureFlags ( ) ;
199
- }
200
- } catch ( error ) {
201
- console . error ( 'Error setting bridge feature flags' , error ) ;
202
- }
203
- } ;
204
-
205
- setBridgeFeatureFlags ( ) ;
206
- } , [ isBasicFunctionalityEnabled ] ) ;
207
-
208
200
const hasTrackedPageView = useRef ( false ) ;
209
201
useEffect ( ( ) => {
210
202
const shouldTrackPageView = sourceToken && ! hasTrackedPageView . current ;
@@ -248,11 +240,12 @@ const BridgeView = () => {
248
240
249
241
const handleContinue = async ( ) => {
250
242
if ( activeQuote ) {
251
- setIsSubmittingTx ( true ) ;
243
+ dispatch ( setIsSubmittingTx ( true ) ) ;
252
244
await submitBridgeTx ( {
253
245
quoteResponse : activeQuote ,
254
246
} ) ;
255
247
navigation . navigate ( Routes . TRANSACTIONS_VIEW ) ;
248
+ dispatch ( setIsSubmittingTx ( false ) ) ;
256
249
}
257
250
} ;
258
251
0 commit comments