@@ -57,7 +57,6 @@ import View from "../shared/View";
5757import TokenInput from "../swaps/TokenInput" ;
5858
5959import type { Chain , Token } from "@lifi/sdk" ;
60- import type { TFunction } from "i18next" ;
6160
6261export default function Bridge ( ) {
6362 const router = useRouter ( ) ;
@@ -375,41 +374,41 @@ export default function Bridge() {
375374 await switchChain ( senderConfig , { chainId : source . chain } ) ;
376375 }
377376 setBridgeStatus ( t ( "Submitting bridge transaction..." ) ) ;
378- let id : string | undefined ;
379377 try {
380- const result = await sendCallsTx ( {
381- chainId : source . chain ,
382- calls : [
383- ...( approval ? [ { to : getAddress ( source . address ) , data : approval } ] : [ ] ) ,
384- { to : from . to , data : from . data , value : from . value } ,
385- ] ,
386- } ) ;
387- id = result . id ;
388- } catch ( error ) {
389- if ( isExaSender ) throw error ;
390- if ( classifyError ( error ) . authKnown ) throw error ;
391- reportError ( error , {
392- level : "warning" ,
393- extra : error instanceof Error ? { cause : error . cause } : undefined ,
394- } ) ;
395- await switchChain ( senderConfig , { chainId : source . chain } ) ;
378+ let id : string | undefined ;
396379 try {
380+ const result = await sendCallsTx ( {
381+ chainId : source . chain ,
382+ calls : [
383+ ...( approval ? [ { to : getAddress ( source . address ) , data : approval } ] : [ ] ) ,
384+ { to : from . to , data : from . data , value : from . value } ,
385+ ] ,
386+ } ) ;
387+ id = result . id ;
388+ } catch ( error ) {
389+ if ( isExaSender ) throw error ;
390+ if ( classifyError ( error ) . authKnown ) throw error ;
391+ reportError ( error , {
392+ level : "warning" ,
393+ extra : error instanceof Error ? { cause : error . cause } : undefined ,
394+ } ) ;
395+ await switchChain ( senderConfig , { chainId : source . chain } ) ;
397396 if ( approval ) {
398397 const hash = await sendTx ( { chainId : source . chain , to : getAddress ( source . address ) , data : approval } ) ;
399398 await waitForTransactionReceipt ( senderConfig , { hash, chainId : source . chain } ) ;
400399 }
401400 const hash = await sendTx ( { chainId : source . chain , to : from . to , data : from . data , value : from . value } ) ;
402401 await waitForTransactionReceipt ( senderConfig , { hash, chainId : source . chain } ) ;
403- } finally {
404- await switchChain ( senderConfig , { chainId : chain . id } ) . catch ( reportError ) ;
402+ setBridgeStatus ( t ( "Bridge transaction submitted" ) ) ;
403+ return ;
405404 }
405+ if ( ! id ) throw new Error ( "missing sendCalls id" ) ;
406+ const { status } = await waitForCallsStatus ( senderConfig , { id } ) ;
407+ if ( status === "failure" ) throw new Error ( "failed to submit bridge transaction" ) ;
406408 setBridgeStatus ( t ( "Bridge transaction submitted" ) ) ;
407- return ;
409+ } finally {
410+ if ( ! isExaSender ) await switchChain ( senderConfig , { chainId : chain . id } ) . catch ( reportError ) ;
408411 }
409- if ( ! id ) throw new Error ( "missing sendCalls id" ) ;
410- const { status } = await waitForCallsStatus ( senderConfig , { id } ) ;
411- if ( status === "failure" ) throw new Error ( "failed to submit bridge transaction" ) ;
412- setBridgeStatus ( t ( "Bridge transaction submitted" ) ) ;
413412 } ,
414413 onSuccess : async ( ) => {
415414 toast . show ( t ( "Bridge transaction submitted" ) , {
@@ -419,8 +418,17 @@ export default function Bridge() {
419418 } ) ;
420419 await queryClient . invalidateQueries ( { queryKey : [ "bridge" , "sources" ] } ) ;
421420 } ,
422- onError : ( error : unknown ) => {
423- handleError ( error , toast , t ) ;
421+ onError ( error ) {
422+ if ( classifyError ( error ) . authKnown ) {
423+ setBridgePreview ( undefined ) ;
424+ resetBridgeMutation ( ) ;
425+ return ;
426+ }
427+ toast . show ( t ( "Bridge failed. Please try again." ) , {
428+ native : true ,
429+ duration : 1000 ,
430+ burntOptions : { haptic : "error" , preset : "error" } ,
431+ } ) ;
424432 } ,
425433 onSettled : ( ) => {
426434 setBridgeStatus ( undefined ) ;
@@ -464,8 +472,17 @@ export default function Bridge() {
464472 } ) ;
465473 await queryClient . invalidateQueries ( { queryKey : [ "bridge" , "sources" ] } ) ;
466474 } ,
467- onError : ( error : unknown ) => {
468- handleError ( error , toast , t , true ) ;
475+ onError ( error ) {
476+ if ( classifyError ( error ) . authKnown ) {
477+ setBridgePreview ( undefined ) ;
478+ resetTransferMutation ( ) ;
479+ return ;
480+ }
481+ toast . show ( t ( "Transfer failed. Please try again." ) , {
482+ native : true ,
483+ duration : 1000 ,
484+ burntOptions : { haptic : "error" , preset : "error" } ,
485+ } ) ;
469486 } ,
470487 onSettled : ( ) => {
471488 setBridgeStatus ( undefined ) ;
@@ -1041,12 +1058,3 @@ export default function Bridge() {
10411058 </ SafeView >
10421059 ) ;
10431060}
1044-
1045- function handleError ( error : unknown , toast : ReturnType < typeof useToastController > , t : TFunction , isTransfer ?: boolean ) {
1046- if ( ! reportError ( error ) . authKnown )
1047- toast . show ( isTransfer ? t ( "Transfer failed. Please try again." ) : t ( "Bridge failed. Please try again." ) , {
1048- native : true ,
1049- duration : 1000 ,
1050- burntOptions : { haptic : "error" , preset : "error" } ,
1051- } ) ;
1052- }
0 commit comments