@@ -34,7 +34,7 @@ import {
3434 MAX_ATTEMPTS ,
3535 REFRESH_INTERVAL_MS ,
3636} from './constants' ;
37- import selectSubmitStrategy from './submit-flows' ;
37+ import { executeApproval , executeBatch , executeTrade } from './submit-flows' ;
3838import type {
3939 BridgeStatusControllerState ,
4040 StartPollingForBridgeTxStatusArgsSerialized ,
@@ -890,9 +890,12 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
890890
891891 const startTime = Date . now ( ) ;
892892
893- const tradeMeta = await this . #trace(
893+ return await this . #trace(
894894 getTraceParams ( quoteResponse , isStxEnabledOnClient ) ,
895- async ( ) : Promise < TransactionMeta | undefined > => {
895+ async ( ) => {
896+ let tradeTxMeta : TransactionMeta | undefined ;
897+ let approvalTxId : string | undefined ;
898+
896899 try {
897900 const isBridgeTx = isCrossChain (
898901 quoteResponse . quote . srcChainId ,
@@ -917,12 +920,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
917920 [ formatChainIdToHex ( quoteResponse . quote . srcChainId ) ] ,
918921 ) ;
919922
920- const submitStrategy = selectSubmitStrategy ( {
921- quoteResponse,
922- isStxEnabledOnClient,
923- isDelegatedAccount,
924- } ) ;
925-
926923 const params = {
927924 quoteResponse,
928925 isStxEnabledOnClient,
@@ -937,39 +934,71 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
937934 fetchFn : this . #fetchFn,
938935 bridgeApiBaseUrl : this . #config. customBridgeApiBaseUrl ,
939936 } ;
940- const execute = submitStrategy . execute ( params ) ;
941-
942- let tradeTxMeta : TransactionMeta | undefined ;
943-
944- // Each submission strategy determines when to return values, which means these values can be returned in any order
945- for await ( const value of execute ) {
946- if ( value . historyItem ) {
947- this . #addTxToHistory( {
948- ...value . historyItem ,
949- quoteResponse,
950- accountAddress : selectedAccount . address ,
951- isStxEnabled : isStxEnabledOnClient ,
952- startTime,
953- location,
954- abTests,
955- activeAbTests,
956- slippagePercentage : 0 , // TODO include slippage provided by quote if using dynamic slippage, or slippage from quote request
957- } ) ;
958- }
959- if ( value . tradeMeta ) {
960- this . #rekeyHistoryItem( actionId , value . tradeMeta ) ;
961- tradeTxMeta = value . tradeMeta ;
962- }
963- if ( value . pollingToken ) {
964- this . #startPollingForTxId( value . pollingToken ) ;
965- }
966- if ( value . completedEventPayload ) {
967- this . #trackUnifiedSwapBridgeEvent(
968- UnifiedSwapBridgeEventName . Completed ,
969- value . completedEventPayload ,
970- ) ;
971- }
937+
938+ const partialHistoryItem = {
939+ quoteResponse,
940+ accountAddress : selectedAccount . address ,
941+ isStxEnabled : isStxEnabledOnClient ,
942+ startTime,
943+ location,
944+ abTests,
945+ activeAbTests,
946+ slippagePercentage : 0 , // TODO include slippage provided by quote if using dynamic slippage, or slippage from quote request
947+ } ;
948+
949+ const {
950+ tradeMeta : batchTradeTxMeta ,
951+ approvalTxId : batchApprovalTxId ,
952+ } = await executeBatch ( params ) ;
953+ if ( batchApprovalTxId ) {
954+ approvalTxId = batchApprovalTxId ;
955+ }
956+ if ( batchTradeTxMeta ) {
957+ tradeTxMeta = batchTradeTxMeta ;
958+ this . #addTxToHistory( {
959+ bridgeTxMeta : tradeTxMeta ,
960+ approvalTxId,
961+ ...partialHistoryItem ,
962+ } ) ;
963+ }
964+
965+ const { approvalTxId : approvalTxIdResult } =
966+ await executeApproval ( params ) ;
967+ if ( approvalTxIdResult ) {
968+ approvalTxId = approvalTxIdResult ;
969+ this . #addTxToHistory( {
970+ approvalTxId,
971+ ...partialHistoryItem ,
972+ } ) ;
973+ }
974+
975+ const {
976+ tradeMeta : tradeTxMetaResult ,
977+ pollingToken,
978+ completedEventPayload,
979+ } = await executeTrade ( params ) ;
980+ if ( tradeTxMetaResult ) {
981+ tradeTxMeta = tradeTxMetaResult ;
982+ this . #rekeyHistoryItem( actionId , tradeTxMetaResult ) ;
983+ // TODO this should onkly happen if there was no prior approval, check for actionId
984+ this . #addTxToHistory( {
985+ approvalTxId,
986+ bridgeTxMeta : tradeTxMeta ,
987+ ...partialHistoryItem ,
988+ } ) ;
989+ }
990+
991+ if ( pollingToken ) {
992+ this . #startPollingForTxId( pollingToken ) ;
993+ }
994+ if ( completedEventPayload ) {
995+ this . #trackUnifiedSwapBridgeEvent(
996+ UnifiedSwapBridgeEventName . Completed ,
997+ tradeTxMeta ?. id ,
998+ completedEventPayload ,
999+ ) ;
9721000 }
1001+
9731002 return tradeTxMeta ;
9741003 } catch ( error ) {
9751004 ! quoteResponse . featureId &&
@@ -982,16 +1011,13 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
9821011 } ,
9831012 ) ;
9841013 }
1014+ if ( ! tradeTxMeta ) {
1015+ throw new Error (
1016+ 'Failed to submit cross-chain swap transaction: no trade meta found' ,
1017+ ) ;
1018+ }
9851019 } ,
9861020 ) ;
987-
988- if ( ! tradeMeta ) {
989- throw new Error (
990- 'Failed to submit cross-chain swap transaction: no trade meta found' ,
991- ) ;
992- }
993-
994- return tradeMeta ;
9951021 } ;
9961022
9971023 /**
0 commit comments