@metamask/bridge-status-controller 71.2.0 → 72.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/dist/bridge-status-controller-method-action-types.cjs.map +1 -1
  3. package/dist/bridge-status-controller-method-action-types.d.cts +5 -1
  4. package/dist/bridge-status-controller-method-action-types.d.cts.map +1 -1
  5. package/dist/bridge-status-controller-method-action-types.d.mts +5 -1
  6. package/dist/bridge-status-controller-method-action-types.d.mts.map +1 -1
  7. package/dist/bridge-status-controller-method-action-types.mjs.map +1 -1
  8. package/dist/bridge-status-controller.cjs +161 -366
  9. package/dist/bridge-status-controller.cjs.map +1 -1
  10. package/dist/bridge-status-controller.d.cts +27 -7
  11. package/dist/bridge-status-controller.d.cts.map +1 -1
  12. package/dist/bridge-status-controller.d.mts +27 -7
  13. package/dist/bridge-status-controller.d.mts.map +1 -1
  14. package/dist/bridge-status-controller.mjs +162 -370
  15. package/dist/bridge-status-controller.mjs.map +1 -1
  16. package/dist/index.cjs +4 -1
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +1 -0
  19. package/dist/index.d.cts.map +1 -1
  20. package/dist/index.d.mts +1 -0
  21. package/dist/index.d.mts.map +1 -1
  22. package/dist/index.mjs +1 -0
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/strategy/batch-sell-strategy.cjs +101 -0
  25. package/dist/strategy/batch-sell-strategy.cjs.map +1 -0
  26. package/dist/strategy/batch-sell-strategy.d.cts +10 -0
  27. package/dist/strategy/batch-sell-strategy.d.cts.map +1 -0
  28. package/dist/strategy/batch-sell-strategy.d.mts +10 -0
  29. package/dist/strategy/batch-sell-strategy.d.mts.map +1 -0
  30. package/dist/strategy/batch-sell-strategy.mjs +97 -0
  31. package/dist/strategy/batch-sell-strategy.mjs.map +1 -0
  32. package/dist/strategy/batch-strategy.cjs +64 -0
  33. package/dist/strategy/batch-strategy.cjs.map +1 -0
  34. package/dist/strategy/batch-strategy.d.cts +10 -0
  35. package/dist/strategy/batch-strategy.d.cts.map +1 -0
  36. package/dist/strategy/batch-strategy.d.mts +10 -0
  37. package/dist/strategy/batch-strategy.d.mts.map +1 -0
  38. package/dist/strategy/batch-strategy.mjs +60 -0
  39. package/dist/strategy/batch-strategy.mjs.map +1 -0
  40. package/dist/strategy/evm-strategy.cjs +149 -0
  41. package/dist/strategy/evm-strategy.cjs.map +1 -0
  42. package/dist/strategy/evm-strategy.d.cts +38 -0
  43. package/dist/strategy/evm-strategy.d.cts.map +1 -0
  44. package/dist/strategy/evm-strategy.d.mts +38 -0
  45. package/dist/strategy/evm-strategy.d.mts.map +1 -0
  46. package/dist/strategy/evm-strategy.mjs +143 -0
  47. package/dist/strategy/evm-strategy.mjs.map +1 -0
  48. package/dist/strategy/index.cjs +70 -0
  49. package/dist/strategy/index.cjs.map +1 -0
  50. package/dist/strategy/index.d.cts +12 -0
  51. package/dist/strategy/index.d.cts.map +1 -0
  52. package/dist/strategy/index.d.mts +12 -0
  53. package/dist/strategy/index.d.mts.map +1 -0
  54. package/dist/strategy/index.mjs +68 -0
  55. package/dist/strategy/index.mjs.map +1 -0
  56. package/dist/strategy/intent-strategy.cjs +160 -0
  57. package/dist/strategy/intent-strategy.cjs.map +1 -0
  58. package/dist/strategy/intent-strategy.d.cts +17 -0
  59. package/dist/strategy/intent-strategy.d.cts.map +1 -0
  60. package/dist/strategy/intent-strategy.d.mts +17 -0
  61. package/dist/strategy/intent-strategy.d.mts.map +1 -0
  62. package/dist/strategy/intent-strategy.mjs +156 -0
  63. package/dist/strategy/intent-strategy.mjs.map +1 -0
  64. package/dist/strategy/non-evm-strategy.cjs +80 -0
  65. package/dist/strategy/non-evm-strategy.cjs.map +1 -0
  66. package/dist/strategy/non-evm-strategy.d.cts +15 -0
  67. package/dist/strategy/non-evm-strategy.d.cts.map +1 -0
  68. package/dist/strategy/non-evm-strategy.d.mts +15 -0
  69. package/dist/strategy/non-evm-strategy.d.mts.map +1 -0
  70. package/dist/strategy/non-evm-strategy.mjs +76 -0
  71. package/dist/strategy/non-evm-strategy.mjs.map +1 -0
  72. package/dist/strategy/types.cjs +13 -0
  73. package/dist/strategy/types.cjs.map +1 -0
  74. package/dist/strategy/types.d.cts +77 -0
  75. package/dist/strategy/types.d.cts.map +1 -0
  76. package/dist/strategy/types.d.mts +77 -0
  77. package/dist/strategy/types.d.mts.map +1 -0
  78. package/dist/strategy/types.mjs +10 -0
  79. package/dist/strategy/types.mjs.map +1 -0
  80. package/dist/types.cjs.map +1 -1
  81. package/dist/types.d.cts +41 -6
  82. package/dist/types.d.cts.map +1 -1
  83. package/dist/types.d.mts +41 -6
  84. package/dist/types.d.mts.map +1 -1
  85. package/dist/types.mjs.map +1 -1
  86. package/dist/utils/bridge.cjs +5 -1
  87. package/dist/utils/bridge.cjs.map +1 -1
  88. package/dist/utils/bridge.d.cts +2 -2
  89. package/dist/utils/bridge.d.cts.map +1 -1
  90. package/dist/utils/bridge.d.mts +2 -2
  91. package/dist/utils/bridge.d.mts.map +1 -1
  92. package/dist/utils/bridge.mjs +3 -0
  93. package/dist/utils/bridge.mjs.map +1 -1
  94. package/dist/utils/history.cjs +72 -20
  95. package/dist/utils/history.cjs.map +1 -1
  96. package/dist/utils/history.d.cts +19 -5
  97. package/dist/utils/history.d.cts.map +1 -1
  98. package/dist/utils/history.d.mts +19 -5
  99. package/dist/utils/history.d.mts.map +1 -1
  100. package/dist/utils/history.mjs +69 -19
  101. package/dist/utils/history.mjs.map +1 -1
  102. package/dist/utils/metrics.cjs +10 -7
  103. package/dist/utils/metrics.cjs.map +1 -1
  104. package/dist/utils/metrics.d.cts +7 -6
  105. package/dist/utils/metrics.d.cts.map +1 -1
  106. package/dist/utils/metrics.d.mts +7 -6
  107. package/dist/utils/metrics.d.mts.map +1 -1
  108. package/dist/utils/metrics.mjs +10 -7
  109. package/dist/utils/metrics.mjs.map +1 -1
  110. package/dist/utils/trace.cjs +4 -4
  111. package/dist/utils/trace.cjs.map +1 -1
  112. package/dist/utils/trace.d.cts +2 -2
  113. package/dist/utils/trace.d.cts.map +1 -1
  114. package/dist/utils/trace.d.mts +2 -2
  115. package/dist/utils/trace.d.mts.map +1 -1
  116. package/dist/utils/trace.mjs +4 -4
  117. package/dist/utils/trace.mjs.map +1 -1
  118. package/dist/utils/transaction.cjs +223 -252
  119. package/dist/utils/transaction.cjs.map +1 -1
  120. package/dist/utils/transaction.d.cts +68 -147
  121. package/dist/utils/transaction.d.cts.map +1 -1
  122. package/dist/utils/transaction.d.mts +68 -147
  123. package/dist/utils/transaction.d.mts.map +1 -1
  124. package/dist/utils/transaction.mjs +214 -247
  125. package/dist/utils/transaction.mjs.map +1 -1
  126. package/package.json +5 -5
@@ -10,7 +10,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_intentManager, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_trace, _BridgeStatusController_onTransactionFailed, _BridgeStatusController_onTransactionConfirmed, _BridgeStatusController_restartPollingForIncompleteHistoryItems, _BridgeStatusController_addTxToHistory, _BridgeStatusController_rekeyHistoryItem, _BridgeStatusController_startPollingForTxId, _BridgeStatusController_handleFetchFailure, _BridgeStatusController_handleOldHistoryItem, _BridgeStatusController_fetchBridgeTxStatus, _BridgeStatusController_setAndGetSrcTxHash, _BridgeStatusController_updateHistoryItem, _BridgeStatusController_deleteHistoryItem, _BridgeStatusController_wipeBridgeStatusByChainId, _BridgeStatusController_handleApprovalTx, _BridgeStatusController_handleEvmTransactionBatch, _BridgeStatusController_trackPollingStatusUpdatedEvent, _BridgeStatusController_trackUnifiedSwapBridgeEvent;
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_intentManager, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_trace, _BridgeStatusController_onTransactionFailed, _BridgeStatusController_onTransactionConfirmed, _BridgeStatusController_restartPollingForIncompleteHistoryItems, _BridgeStatusController_addTxToHistory, _BridgeStatusController_rekeyHistoryItem, _BridgeStatusController_startPollingForTxId, _BridgeStatusController_handleFetchFailure, _BridgeStatusController_handleOldHistoryItem, _BridgeStatusController_fetchBridgeTxStatus, _BridgeStatusController_setAndGetSrcTxHash, _BridgeStatusController_updateHistoryItem, _BridgeStatusController_deleteHistoryItem, _BridgeStatusController_wipeBridgeStatusByChainId, _BridgeStatusController_executeSubmitStrategy, _BridgeStatusController_trackPollingStatusUpdatedEvent, _BridgeStatusController_trackUnifiedSwapBridgeEvent;
14
17
  Object.defineProperty(exports, "__esModule", { value: true });
15
18
  exports.BridgeStatusController = void 0;
16
19
  const bridge_controller_1 = require("@metamask/bridge-controller");
@@ -19,17 +22,16 @@ const transaction_controller_1 = require("@metamask/transaction-controller");
19
22
  const utils_1 = require("@metamask/utils");
20
23
  const bridge_status_controller_intent_1 = require("./bridge-status-controller.intent.cjs");
21
24
  const constants_1 = require("./constants.cjs");
22
- const types_1 = require("./types.cjs");
25
+ const strategy_1 = __importDefault(require("./strategy/index.cjs"));
26
+ const types_1 = require("./strategy/types.cjs");
27
+ const types_2 = require("./types.cjs");
23
28
  const accounts_1 = require("./utils/accounts.cjs");
24
29
  const authentication_1 = require("./utils/authentication.cjs");
25
30
  const bridge_1 = require("./utils/bridge.cjs");
26
31
  const bridge_status_1 = require("./utils/bridge-status.cjs");
27
32
  const history_1 = require("./utils/history.cjs");
28
- const intent_api_1 = require("./utils/intent-api.cjs");
29
- const keyring_1 = require("./utils/keyring.cjs");
30
33
  const metrics_1 = require("./utils/metrics.cjs");
31
34
  const network_1 = require("./utils/network.cjs");
32
- const snaps_1 = require("./utils/snaps.cjs");
33
35
  const trace_1 = require("./utils/trace.cjs");
34
36
  const transaction_1 = require("./utils/transaction.cjs");
35
37
  const metadata = {
@@ -48,6 +50,7 @@ const MESSENGER_EXPOSED_METHODS = [
48
50
  'resetState',
49
51
  'submitTx',
50
52
  'submitIntent',
53
+ 'submitBatchSell',
51
54
  'restartPollingForFailedAttempts',
52
55
  'getBridgeHistoryItemByTxMetaId',
53
56
  ];
@@ -79,14 +82,11 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
79
82
  historyKey,
80
83
  status: bridge_controller_1.StatusTypes.FAILED,
81
84
  txHash: isApprovalTxMeta ? undefined : txMeta.hash,
85
+ completionTime: Date.now(),
82
86
  });
83
87
  if (txMeta.status === transaction_controller_1.TransactionStatus.rejected) {
84
88
  return;
85
89
  }
86
- // Skip account lookup and tracking when featureId is set (e.g. PERPS)
87
- if (historyKey && this.state.txHistory[historyKey]?.featureId) {
88
- return;
89
- }
90
90
  // Skip tracking if this is a duplicate failed event for the same history item
91
91
  // This can happen if the transaction includes an approval tx that fails
92
92
  if (isHistoryItemAlreadyFailed) {
@@ -105,11 +105,13 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
105
105
  historyKey,
106
106
  txHash: txMeta.hash,
107
107
  });
108
- switch (txMeta.type) {
109
- case transaction_controller_1.TransactionType.swap:
108
+ const isSwap = txMeta.type === transaction_controller_1.TransactionType.swap || (0, transaction_1.hasNestedSwapTransactions)(txMeta);
109
+ switch (isSwap) {
110
+ case true:
110
111
  __classPrivateFieldGet(this, _BridgeStatusController_updateHistoryItem, "f").call(this, {
111
112
  historyKey,
112
113
  status: bridge_controller_1.StatusTypes.COMPLETE,
114
+ completionTime: Date.now(),
113
115
  });
114
116
  __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, historyKey);
115
117
  break;
@@ -246,10 +248,9 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
246
248
  __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
247
249
  });
248
250
  });
249
- _BridgeStatusController_addTxToHistory.set(this, (...args) => {
250
- const { historyKey, txHistoryItem } = (0, history_1.getInitialHistoryItem)(...args);
251
+ _BridgeStatusController_addTxToHistory.set(this, (historyKey, ...args) => {
252
+ const txHistoryItem = (0, history_1.getInitialHistoryItem)(...args);
251
253
  this.update((state) => {
252
- // Use actionId as key for pre-submission, or txMeta.id for post-submission
253
254
  state.txHistory[historyKey] = txHistoryItem;
254
255
  });
255
256
  return historyKey;
@@ -258,14 +259,15 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
258
259
  * Rekeys a history item from actionId to txMeta.id after successful submission.
259
260
  * Also updates txMetaId and srcTxHash which weren't available pre-submission.
260
261
  *
261
- * @param actionId - The actionId used as the temporary key for the history item
262
+ * @param oldKey - The temporary key to use for the history item, usually the actionId
263
+ * @param newKey - The new key to use, typcally the txmeta.id
262
264
  * @param txMeta - The transaction meta from the successful submission
263
265
  * @param txMeta.id - The transaction meta id to use as the new key
264
266
  * @param txMeta.hash - The transaction hash to set on the history item
265
267
  */
266
- _BridgeStatusController_rekeyHistoryItem.set(this, (actionId, txMeta) => {
268
+ _BridgeStatusController_rekeyHistoryItem.set(this, (oldKey, newKey, txMeta) => {
267
269
  this.update((state) => {
268
- (0, history_1.rekeyHistoryItemInState)(state, actionId, txMeta);
270
+ (0, history_1.rekeyHistoryItemInState)(state, oldKey, newKey, txMeta);
269
271
  });
270
272
  });
271
273
  _BridgeStatusController_startPollingForTxId.set(this, (txId) => {
@@ -296,7 +298,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
296
298
  if (!bridgeTxMeta?.id) {
297
299
  throw new Error('Cannot start polling: bridgeTxMeta.id is required for polling');
298
300
  }
299
- const historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, txHistoryMeta);
301
+ const historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, bridgeTxMeta.id, txHistoryMeta);
300
302
  __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
301
303
  };
302
304
  // This will be called after you call this.startPolling()
@@ -491,7 +493,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
491
493
  });
492
494
  return localTxHash;
493
495
  });
494
- _BridgeStatusController_updateHistoryItem.set(this, ({ historyKey, status, txHash, attempts, }) => {
496
+ _BridgeStatusController_updateHistoryItem.set(this, ({ historyKey, status, txHash, attempts, completionTime, }) => {
495
497
  if (!historyKey) {
496
498
  return;
497
499
  }
@@ -505,6 +507,9 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
505
507
  if (attempts) {
506
508
  currentState.txHistory[historyKey].attempts = attempts;
507
509
  }
510
+ if (completionTime) {
511
+ currentState.txHistory[historyKey].completionTime = completionTime;
512
+ }
508
513
  });
509
514
  });
510
515
  _BridgeStatusController_deleteHistoryItem.set(this, (historyKey) => {
@@ -540,237 +545,134 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
540
545
  * TX SUBMISSION HANDLING
541
546
  *******************************************************
542
547
  */
543
- _BridgeStatusController_handleApprovalTx.set(this, async (quoteResponse, isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
544
- if (approval && (0, bridge_controller_1.isEvmTxData)(approval)) {
545
- const approveTx = async () => {
546
- if (resetApproval) {
547
- await (0, transaction_1.submitEvmTransaction)({
548
- messenger: this.messenger,
549
- transactionType: transaction_controller_1.TransactionType.bridgeApproval,
550
- trade: resetApproval,
551
- });
548
+ _BridgeStatusController_executeSubmitStrategy.set(this, async (params, sharedHistoryItemProperties) => {
549
+ let tradeTxMeta;
550
+ const steps = (0, strategy_1.default)(params);
551
+ // Each submission strategy determines when to execute step, which means these actions can happen in any order
552
+ for await (const { type, payload } of steps) {
553
+ try {
554
+ switch (type) {
555
+ case types_1.SubmitStep.RekeyHistoryItem:
556
+ __classPrivateFieldGet(this, _BridgeStatusController_rekeyHistoryItem, "f").call(this, payload.oldHistoryKey, payload.newHistoryKey, payload.tradeMeta);
557
+ break;
558
+ case types_1.SubmitStep.UpdateBatchTransactions:
559
+ (0, transaction_1.updateTransactionsInBatch)({
560
+ messenger: this.messenger,
561
+ allTradesWithMetadata: payload.quoteAndTxMetas,
562
+ });
563
+ break;
564
+ case types_1.SubmitStep.SetTradeMeta:
565
+ tradeTxMeta = payload.tradeMeta;
566
+ break;
567
+ case types_1.SubmitStep.AddHistoryItem:
568
+ __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, payload.historyKey, {
569
+ ...payload,
570
+ ...sharedHistoryItemProperties,
571
+ quoteResponse: payload.quoteResponse,
572
+ accountAddress: params.selectedAccount.address,
573
+ isStxEnabled: params.isStxEnabled,
574
+ slippagePercentage: 0, // TODO include slippage provided by quote if using dynamic slippage, or slippage from quote request
575
+ });
576
+ break;
577
+ case types_1.SubmitStep.StartPolling:
578
+ __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, payload.historyKey);
579
+ break;
580
+ case types_1.SubmitStep.PublishCompletedEvent:
581
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, payload.historyKey);
582
+ break;
583
+ /* c8 ignore start */
584
+ default:
585
+ throw new Error(`Unknown submit step type: ${String(type)}`);
586
+ /* c8 ignore end */
552
587
  }
553
- const approvalTxMeta = await (0, transaction_1.submitEvmTransaction)({
554
- messenger: this.messenger,
555
- transactionType: isBridgeTx
556
- ? transaction_controller_1.TransactionType.bridgeApproval
557
- : transaction_controller_1.TransactionType.swapApproval,
558
- trade: approval,
559
- requireApproval,
560
- });
561
- await (0, transaction_1.handleApprovalDelay)(srcChainId);
562
- return approvalTxMeta;
563
- };
564
- return await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getApprovalTraceParams)(quoteResponse, false), approveTx);
588
+ }
589
+ catch (error) {
590
+ console.error('Failed to add to bridge history and start polling.', error);
591
+ }
565
592
  }
566
- return undefined;
567
- });
568
- // TODO simplify and make more readable
569
- /**
570
- * Submits batched EVM transactions to the TransactionController
571
- *
572
- * @param args - The parameters for the transaction
573
- * @param args.isBridgeTx - Whether the transaction is a bridge transaction
574
- * @param args.trade - The trade data to confirm
575
- * @param args.approval - The approval data to confirm
576
- * @param args.resetApproval - The ethereum:USDT reset approval data to confirm
577
- * @param args.quoteResponse - The quote response
578
- * @param args.requireApproval - Whether to require approval for the transaction
579
- * @returns The approvalMeta and tradeMeta for the batched transaction
580
- */
581
- _BridgeStatusController_handleEvmTransactionBatch.set(this, async (args) => {
582
- const transactionParams = await (0, transaction_1.getAddTransactionBatchParams)({
583
- messenger: this.messenger,
584
- ...args,
585
- });
586
- return await (0, transaction_1.addTransactionBatch)(this.messenger, __classPrivateFieldGet(this, _BridgeStatusController_addTransactionBatchFn, "f"), transactionParams);
593
+ return tradeTxMeta;
587
594
  });
588
595
  /**
589
596
  * Submits a cross-chain swap transaction
590
597
  *
591
598
  * @param accountAddress - The address of the account to submit the transaction for
592
- * @param quoteResponse - The quote response
593
- * @param isStxEnabledOnClient - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
599
+ * @param maybeQuoteResponses - A single quote response or an array of quote responses
600
+ * @param isStxEnabled - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
594
601
  * @param quotesReceivedContext - The context for the QuotesReceived event
595
602
  * @param location - The entry point from which the user initiated the swap or bridge (e.g. Main View, Token View, Trending Explore)
596
603
  * @param abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
597
604
  * @param activeAbTests - New A/B test context for `active_ab_tests` (migration target). Attributes events to specific experiments.
598
605
  * @param tokenSecurityTypeDestination - The security classification of the destination token, supplied by the client (e.g. from token security/scanning data). Pass `null` when no security data is available.
606
+ * @param batchSellTrades - Contains transaction data for the quotes, provided by the obtainGaslessBatch API
599
607
  * @returns The transaction meta
608
+ * @throws An error if transaction submission fails before it gets published
600
609
  */
601
- this.submitTx = async (accountAddress, quoteResponse, isStxEnabledOnClient, quotesReceivedContext, location = bridge_controller_1.MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests, tokenSecurityTypeDestination) => {
602
- (0, bridge_1.stopPollingForQuotes)(this.messenger, quoteResponse.featureId, quotesReceivedContext);
610
+ this.submitTx = async (accountAddress, maybeQuoteResponses, isStxEnabled, quotesReceivedContext, location = bridge_controller_1.MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades) => {
611
+ /**
612
+ * If there are multiple quote responses, we assume that they all originate from the same src chain
613
+ * and the same account. In this case its safe to use the first quote response's properties for
614
+ * metrics and other pre-submission logic
615
+ */
616
+ const quoteResponses = Array.isArray(maybeQuoteResponses)
617
+ ? maybeQuoteResponses
618
+ : [maybeQuoteResponses];
619
+ const quoteResponse = quoteResponses[0];
620
+ const { featureId, quote } = quoteResponse;
621
+ const startTime = Date.now();
622
+ (0, bridge_1.stopPollingForQuotes)(this.messenger, featureId, quotesReceivedContext);
603
623
  const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, accountAddress);
604
624
  if (!selectedAccount) {
605
625
  throw new Error('Failed to submit cross-chain swap transaction: undefined multichain account');
606
626
  }
607
627
  const accountHardwareType = (0, bridge_controller_1.getAccountHardwareType)(selectedAccount);
608
- const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, isStxEnabledOnClient, accountHardwareType, location, abTests, activeAbTests, tokenSecurityTypeDestination);
609
- let txMeta;
610
- let approvalTxId;
611
- let isDelegatedAccount = false;
612
- const startTime = Date.now();
613
- const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
614
- const isTronTx = (0, bridge_controller_1.isTronChainId)(quoteResponse.quote.srcChainId);
628
+ /**
629
+ * For hardware wallets on Mobile, this is fixes an issue where the Ledger does not get prompted for the 2nd approval.
630
+ * Extension does not have this issue
631
+ */
632
+ const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_2.BridgeClientId.MOBILE && accountHardwareType !== null;
633
+ const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quote.srcChainId, quote.destChainId);
634
+ const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, isStxEnabled, accountHardwareType, location, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades);
615
635
  try {
616
636
  // Emit Submitted event after submit button is clicked
617
- !quoteResponse.featureId &&
618
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties);
619
- // Submit non-EVM tx (Solana, BTC, Tron)
620
- if ((0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId)) {
621
- // Handle non-EVM approval if present (e.g., Tron token approvals)
622
- if (quoteResponse.approval && (0, bridge_controller_1.isTronTrade)(quoteResponse.approval)) {
623
- const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getApprovalTraceParams)(quoteResponse, false), async () => {
624
- return quoteResponse.approval &&
625
- (0, bridge_controller_1.isTronTrade)(quoteResponse.approval)
626
- ? await (0, snaps_1.handleNonEvmTx)(this.messenger, quoteResponse.approval, quoteResponse, selectedAccount)
627
- : /* c8 ignore start */
628
- undefined;
629
- /* c8 ignore end */
630
- });
631
- approvalTxId = approvalTxMeta?.id;
632
- // Add delay after approval similar to EVM flow
633
- await (0, transaction_1.handleApprovalDelay)(quoteResponse.quote.srcChainId);
634
- }
635
- txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getTraceParams)(quoteResponse, false), async () => {
636
- if (!((0, bridge_controller_1.isTronTrade)(quoteResponse.trade) ||
637
- (0, bridge_controller_1.isBitcoinTrade)(quoteResponse.trade) ||
638
- typeof quoteResponse.trade === 'string')) {
639
- throw new Error('Failed to submit cross-chain swap transaction: trade is not a non-EVM transaction');
640
- }
641
- return await (0, snaps_1.handleNonEvmTx)(this.messenger, quoteResponse.trade, quoteResponse, selectedAccount);
642
- });
643
- }
644
- else {
645
- // Submit EVM tx
646
- // For hardware wallets on Mobile, this is fixes an issue where the Ledger does not get prompted for the 2nd approval
647
- // Extension does not have this issue
648
- const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE &&
649
- accountHardwareType !== null;
650
- // Handle smart transactions if enabled
651
- txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getTraceParams)(quoteResponse, isStxEnabledOnClient), async () => {
652
- if (!(0, bridge_controller_1.isEvmTxData)(quoteResponse.trade)) {
653
- throw new Error('Failed to submit cross-chain swap transaction: trade is not an EVM transaction');
654
- }
655
- // Check if the account is an EIP-7702 delegated account
656
- // Delegated accounts only allow 1 in-flight tx, so approve + swap
657
- // must be batched into a single transaction
658
- const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.srcChainId);
659
- isDelegatedAccount = await (0, transaction_1.checkIsDelegatedAccount)(this.messenger, quoteResponse.trade.from, [hexChainId]);
660
- if (isStxEnabledOnClient ||
661
- quoteResponse.quote.gasIncluded7702 ||
662
- isDelegatedAccount) {
663
- const { tradeMeta, approvalMeta } = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransactionBatch, "f").call(this, {
664
- isBridgeTx,
665
- resetApproval: quoteResponse.resetApproval,
666
- approval: quoteResponse.approval &&
667
- (0, bridge_controller_1.isEvmTxData)(quoteResponse.approval)
668
- ? quoteResponse.approval
669
- : undefined,
670
- trade: quoteResponse.trade,
671
- quoteResponse,
672
- requireApproval,
673
- isDelegatedAccount,
674
- });
675
- approvalTxId = approvalMeta?.id;
676
- return tradeMeta;
677
- }
678
- // Set approval time and id if an approval tx is needed
679
- const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && (0, bridge_controller_1.isEvmTxData)(quoteResponse.approval)
680
- ? quoteResponse.approval
681
- : undefined, quoteResponse.resetApproval, requireApproval);
682
- approvalTxId = approvalTxMeta?.id;
683
- // Hardware-wallet delay first (Ledger second-prompt spacing), then wait for
684
- // on-chain approval confirmation so swap gas estimation runs after allowance is set.
685
- if (requireApproval && approvalTxMeta) {
686
- await (0, transaction_1.handleMobileHardwareWalletDelay)(requireApproval);
687
- await (0, transaction_1.waitForTxConfirmation)(this.messenger, approvalTxMeta.id);
688
- }
689
- else {
690
- await (0, transaction_1.handleMobileHardwareWalletDelay)(requireApproval);
691
- }
692
- // Generate actionId for pre-submission history (non-batch EVM only)
693
- const actionId = (0, transaction_1.generateActionId)().toString();
694
- // Add pre-submission history keyed by actionId
695
- // This ensures we have quote data available if transaction fails during submission
696
- const historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
697
- accountAddress: selectedAccount.address,
698
- quoteResponse,
699
- slippagePercentage: 0,
700
- isStxEnabled: isStxEnabledOnClient,
701
- startTime,
702
- approvalTxId,
703
- location,
704
- abTests,
705
- activeAbTests,
706
- actionId,
707
- tokenSecurityTypeDestination,
708
- });
709
- // Pass txFee when gasIncluded is true to use the quote's gas fees
710
- // instead of re-estimating (which would fail for max native token swaps)
711
- const tradeTxMeta = await (0, transaction_1.submitEvmTransaction)({
712
- messenger: this.messenger,
713
- transactionType: isBridgeTx
714
- ? transaction_controller_1.TransactionType.bridge
715
- : transaction_controller_1.TransactionType.swap,
716
- trade: quoteResponse.trade,
717
- requireApproval,
718
- txFee: quoteResponse.quote.gasIncluded
719
- ? quoteResponse.quote.feeData.txFee
720
- : undefined,
721
- actionId,
722
- });
723
- // On success, rekey from actionId to txMeta.id and update srcTxHash
724
- __classPrivateFieldGet(this, _BridgeStatusController_rekeyHistoryItem, "f").call(this, historyKey, tradeTxMeta);
725
- return tradeTxMeta;
726
- });
727
- }
637
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties, featureId);
638
+ /**
639
+ * Check if the account is an EIP-7702 delegated account.
640
+ * Delegated accounts only allow 1 in-flight tx, so approve + swap
641
+ * must be batched into a single transaction
642
+ */
643
+ const isDelegatedAccount = (0, bridge_controller_1.isNonEvmChainId)(quote.srcChainId)
644
+ ? false
645
+ : await (0, transaction_1.checkIsDelegatedAccount)(this.messenger, selectedAccount.address, [(0, bridge_controller_1.formatChainIdToHex)(quote.srcChainId)]);
646
+ const strategyParams = {
647
+ messenger: this.messenger,
648
+ quoteResponses,
649
+ batchSellTrades,
650
+ isStxEnabled,
651
+ isBridgeTx,
652
+ isDelegatedAccount,
653
+ selectedAccount,
654
+ requireApproval,
655
+ clientId: __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"),
656
+ bridgeApiBaseUrl: __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl,
657
+ addTransactionBatchFn: __classPrivateFieldGet(this, _BridgeStatusController_addTransactionBatchFn, "f"),
658
+ fetchFn: __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"),
659
+ traceFn: __classPrivateFieldGet(this, _BridgeStatusController_trace, "f"),
660
+ };
661
+ return await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getTraceParams)(quoteResponse, isStxEnabled), async () => await __classPrivateFieldGet(this, _BridgeStatusController_executeSubmitStrategy, "f").call(this, strategyParams, {
662
+ startTime,
663
+ location,
664
+ abTests,
665
+ activeAbTests,
666
+ tokenSecurityTypeDestination,
667
+ }));
728
668
  }
729
669
  catch (error) {
730
- !quoteResponse.featureId &&
731
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, undefined, {
732
- error_message: error?.message,
733
- ...preConfirmationProperties,
734
- });
670
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, undefined, {
671
+ error_message: error?.message,
672
+ ...preConfirmationProperties,
673
+ }, featureId);
735
674
  throw error;
736
675
  }
737
- try {
738
- // For non-batch EVM transactions, history was already added/rekeyed above
739
- // Only add history here for non-EVM and batch EVM transactions
740
- const isNonBatchEvm = !(0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId) &&
741
- !isStxEnabledOnClient &&
742
- !quoteResponse.quote.gasIncluded7702 &&
743
- !isDelegatedAccount;
744
- let historyKey = txMeta.id;
745
- if (!isNonBatchEvm) {
746
- // Add swap or bridge tx to history
747
- historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
748
- accountAddress: selectedAccount.address,
749
- bridgeTxMeta: txMeta, // Only the id and hash fields are used by the BridgeStatusController
750
- quoteResponse,
751
- slippagePercentage: 0, // TODO include slippage provided by quote if using dynamic slippage, or slippage from quote request
752
- isStxEnabled: isStxEnabledOnClient,
753
- startTime,
754
- approvalTxId,
755
- location,
756
- abTests,
757
- activeAbTests,
758
- tokenSecurityTypeDestination,
759
- });
760
- }
761
- if ((0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId)) {
762
- // Start polling for bridge tx status
763
- __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
764
- // Track non-EVM Swap completed event
765
- if (!(isBridgeTx || isTronTx)) {
766
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, historyKey);
767
- }
768
- }
769
- }
770
- catch {
771
- // Ignore errors here, we don't want to crash the app if this fails and tx submission succeeds
772
- }
773
- return txMeta;
774
676
  };
775
677
  /**
776
678
  * Submits an intent order and creates a synthetic history entry for UX.
@@ -783,135 +685,28 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
783
685
  * @param params.abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
784
686
  * @param params.activeAbTests - New A/B test context for `active_ab_tests` (migration target). Attributes events to specific experiments.
785
687
  * @param params.tokenSecurityTypeDestination - The security classification of the destination token, supplied by the client (e.g. from token security/scanning data). Pass `null` when no security data is available.
688
+ * @param params.isStxEnabled - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
689
+ * @param params.quotesReceivedContext - The context for the QuotesReceived event
786
690
  * @returns A lightweight TransactionMeta-like object for history linking
691
+ * @throws An error if intent or transaction submission fails before they get published
787
692
  */
788
693
  this.submitIntent = async (params) => {
789
- const { quoteResponse, accountAddress, location, abTests, activeAbTests, tokenSecurityTypeDestination, } = params;
694
+ const { quoteResponse, accountAddress, location, abTests, activeAbTests, tokenSecurityTypeDestination, isStxEnabled = false, quotesReceivedContext, } = params;
790
695
  // TODO add metrics context
791
- (0, bridge_1.stopPollingForQuotes)(this.messenger);
792
- const startTime = Date.now();
793
- // Build pre-confirmation properties for error tracking parity with submitTx
794
- const account = (0, accounts_1.getAccountByAddress)(this.messenger, accountAddress);
795
- const accountHardwareType = (0, bridge_controller_1.getAccountHardwareType)(account);
796
- const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, false, accountHardwareType, location, abTests, activeAbTests, tokenSecurityTypeDestination);
797
- try {
798
- const intent = (0, intent_api_1.getIntentFromQuote)(quoteResponse);
799
- // If backend provided an approval tx for this intent quote, submit it first (on-chain),
800
- // then proceed with off-chain intent submission.
801
- const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
802
- const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE &&
803
- accountHardwareType !== null;
804
- // Handle approval silently for better UX in intent flows
805
- const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval, quoteResponse.resetApproval, requireApproval);
806
- const approvalTxId = approvalTxMeta?.id;
807
- if (approvalTxId) {
808
- await (0, transaction_1.waitForTxConfirmation)(this.messenger, approvalTxId);
809
- }
810
- const { srcChainId, requestId } = quoteResponse.quote;
811
- const signature = await (0, keyring_1.signTypedMessage)({
812
- messenger: this.messenger,
813
- accountAddress,
814
- typedData: intent.typedData,
815
- });
816
- const submissionParams = {
817
- srcChainId,
818
- quoteId: requestId,
819
- signature,
820
- order: intent.order,
821
- userAddress: accountAddress,
822
- aggregatorId: intent.protocol,
823
- };
824
- const { id: orderUid, status } = await (0, intent_api_1.postSubmitOrder)({
825
- params: submissionParams,
826
- clientId: __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"),
827
- jwt: await (0, authentication_1.getJwt)(this.messenger),
828
- fetchFn: __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"),
829
- bridgeApiBaseUrl: __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl,
830
- });
831
- // Determine transaction type: swap for same-chain, bridge for cross-chain
832
- const transactionType = isBridgeTx
833
- ? /* c8 ignore start */
834
- transaction_controller_1.TransactionType.bridge
835
- : /* c8 ignore end */
836
- transaction_controller_1.TransactionType.swap;
837
- // Create actual transaction in Transaction Controller first
838
- const networkClientId = (0, network_1.getNetworkClientIdByChainId)(this.messenger, srcChainId);
839
- // This is a synthetic transaction whose purpose is to be able
840
- // to track the order status via the history
841
- const intentTransactionParams = {
842
- chainId: (0, bridge_controller_1.formatChainIdToHex)(srcChainId),
843
- from: accountAddress,
844
- to: intent.settlementContract ??
845
- '0x9008D19f58AAbd9eD0D60971565AA8510560ab41', // Default settlement contract
846
- data: `0x${orderUid.slice(-8)}`, // Use last 8 chars of orderUid to make each transaction unique
847
- value: '0x0',
848
- gas: '0x5208', // Minimal gas for display purposes
849
- gasPrice: '0x3b9aca00', // 1 Gwei - will be converted to EIP-1559 fees if network supports it
850
- };
851
- const initialTxMeta = await (0, transaction_1.addSyntheticTransaction)(this.messenger, intentTransactionParams, {
852
- requireApproval: false,
853
- networkClientId,
854
- type: transactionType,
855
- });
856
- // Update txHistory with actual transaction metadata
857
- const syntheticMeta = {
858
- ...initialTxMeta,
859
- // Map intent order status to TransactionController status
860
- status: (0, intent_api_1.mapIntentOrderStatusToTransactionStatus)(status),
861
- isIntentTx: true,
862
- orderUid,
863
- };
864
- // Record in bridge history with actual transaction metadata
865
- try {
866
- // Create a bridge transaction metadata keyed by orderUid for intent polling
867
- const bridgeTxMetaForHistory = {
868
- ...syntheticMeta,
869
- id: orderUid,
870
- };
871
- // Use orderId as the history key for intent transactions
872
- // IMPORTANT: pass originalTransactionId as a top-level argument so
873
- // `getInitialHistoryItem` reads it. Setting it on `bridgeTxMeta` is a no-op
874
- // because `getInitialHistoryItem` destructures `originalTransactionId` from
875
- // the top-level args, not from `bridgeTxMeta`. Without this, the field
876
- // falls back to `bridgeTxMeta.id` (the orderUid), severing the link between
877
- // the bridge history record and the synthetic TransactionController entry.
878
- const historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
879
- accountAddress,
880
- bridgeTxMeta: bridgeTxMetaForHistory,
881
- originalTransactionId: syntheticMeta.id,
882
- quoteResponse,
883
- slippagePercentage: 0,
884
- isStxEnabled: false,
885
- approvalTxId,
886
- startTime,
887
- location,
888
- abTests,
889
- activeAbTests,
890
- tokenSecurityTypeDestination,
891
- });
892
- // Start polling using the orderId key to route to intent manager
893
- __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
894
- }
895
- catch (error) {
896
- console.error('📝 [submitIntent] Failed to add to bridge history', error);
897
- // non-fatal but log the error
898
- }
899
- return syntheticMeta;
900
- }
901
- catch (error) {
902
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, undefined, {
903
- error_message: error?.message,
904
- ...preConfirmationProperties,
905
- });
906
- throw error;
907
- }
696
+ return await this.submitTx(accountAddress, quoteResponse, isStxEnabled, quotesReceivedContext, location, abTests, activeAbTests, tokenSecurityTypeDestination);
697
+ };
698
+ this.submitBatchSell = async (params) => {
699
+ /**
700
+ * Retrieve the batch sell trades from the BridgeController's state to ensure we submit
701
+ * the original response data from the bridge-api
702
+ */
703
+ const batchSellTrades = (0, bridge_1.getBatchSellTrades)(this.messenger);
704
+ return await this.submitTx(params.accountAddress, params.quoteResponses.filter((quoteResponse) => quoteResponse !== null), params.isStxEnabled ?? false, params.quotesReceivedContext, params.location, params.abTests, params.activeAbTests, params.tokenSecurityTypeDestination, batchSellTrades);
908
705
  };
909
706
  _BridgeStatusController_trackPollingStatusUpdatedEvent.set(this, (historyKey, pollingStatus) => {
910
707
  // Track polling status updated event
911
708
  const historyItem = this.state.txHistory[historyKey];
912
- if (historyItem && !historyItem.featureId) {
913
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.PollingStatusUpdated, historyKey, (0, metrics_1.getPollingStatusUpdatedProperties)(this.messenger, pollingStatus, historyItem));
914
- }
709
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.PollingStatusUpdated, historyKey, (0, metrics_1.getPollingStatusUpdatedProperties)(this.messenger, pollingStatus, historyItem));
915
710
  });
916
711
  /**
917
712
  * Tracks post-submission events for a cross-chain swap based on the history item
@@ -919,8 +714,22 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
919
714
  * @param eventName - The name of the event to track
920
715
  * @param txMetaId - The txMetaId of the history item to track the event for
921
716
  * @param eventProperties - The properties for the event
717
+ * @param featureIdOverride - The featureId to use when the history item is not available. Should
718
+ * only be provided for events that are not associated with a history item yet, such as Submitted or Failed
922
719
  */
923
- _BridgeStatusController_trackUnifiedSwapBridgeEvent.set(this, (eventName, txMetaId, eventProperties) => {
720
+ _BridgeStatusController_trackUnifiedSwapBridgeEvent.set(this, (eventName, txMetaId, eventProperties, featureIdOverride) => {
721
+ const historyItem = txMetaId
722
+ ? this.state.txHistory[txMetaId]
723
+ : undefined;
724
+ const featureId = featureIdOverride ?? historyItem?.featureId;
725
+ const shouldSkipMetrics =
726
+ // Skip tracking all other events when featureId is set (i.e. PERPS)
727
+ featureId &&
728
+ // Always publish StatusValidationFailed event, regardless of featureId
729
+ eventName !== bridge_controller_1.UnifiedSwapBridgeEventName.StatusValidationFailed;
730
+ if (shouldSkipMetrics) {
731
+ return;
732
+ }
924
733
  // Legacy/new metrics fields are intentionally kept independent during migration.
925
734
  const historyAbTests = txMetaId
926
735
  ? this.state.txHistory?.[txMetaId]?.abTests
@@ -930,12 +739,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
930
739
  : undefined;
931
740
  const resolvedAbTests = eventProperties?.ab_tests ?? historyAbTests;
932
741
  const resolvedActiveAbTests = eventProperties?.active_ab_tests ?? historyActiveAbTests;
742
+ const location = (txMetaId ? this.state.txHistory?.[txMetaId]?.location : undefined) ??
743
+ bridge_controller_1.MetaMetricsSwapsEventSource.MainView;
933
744
  const baseProperties = {
934
745
  action_type: bridge_controller_1.MetricsActionType.SWAPBRIDGE_V1,
935
- location: eventProperties?.location ??
936
- (txMetaId ? this.state.txHistory?.[txMetaId]?.location : undefined) ??
937
- bridge_controller_1.MetaMetricsSwapsEventSource.MainView,
938
746
  ...(eventProperties ?? {}),
747
+ location,
939
748
  ...(resolvedAbTests &&
940
749
  Object.keys(resolvedAbTests).length > 0 && {
941
750
  ab_tests: resolvedAbTests,
@@ -946,15 +755,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
946
755
  }),
947
756
  };
948
757
  // This will publish events for PERPS dropped tx failures as well
949
- if (!txMetaId) {
950
- (0, bridge_1.trackMetricsEvent)({
951
- messenger: this.messenger,
952
- eventName,
953
- properties: baseProperties,
954
- });
955
- return;
956
- }
957
- const historyItem = this.state.txHistory[txMetaId];
958
758
  if (!historyItem) {
959
759
  (0, bridge_1.trackMetricsEvent)({
960
760
  messenger: this.messenger,
@@ -963,9 +763,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
963
763
  });
964
764
  return;
965
765
  }
966
- const { featureId, approvalTxId, quote } = historyItem;
766
+ const { approvalTxId, quote } = historyItem;
967
767
  const requestParamProperties = (0, metrics_1.getRequestParamFromHistory)(historyItem);
968
- // Always publish StatusValidationFailed event, regardless of featureId
969
768
  if (eventName === bridge_controller_1.UnifiedSwapBridgeEventName.StatusValidationFailed) {
970
769
  (0, bridge_1.trackMetricsEvent)({
971
770
  messenger: this.messenger,
@@ -982,10 +781,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
982
781
  });
983
782
  return;
984
783
  }
985
- // Skip tracking all other events when featureId is set (i.e. PERPS)
986
- if (featureId) {
987
- return;
988
- }
989
784
  const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, historyItem.account);
990
785
  const transactions = (0, transaction_1.getTransactions)(this.messenger);
991
786
  const txMeta = transactions.find((tx) => tx.id === txMetaId);
@@ -1066,5 +861,5 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
1066
861
  }
1067
862
  }
1068
863
  exports.BridgeStatusController = BridgeStatusController;
1069
- _BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_intentManager = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(), _BridgeStatusController_addTransactionBatchFn = new WeakMap(), _BridgeStatusController_trace = new WeakMap(), _BridgeStatusController_onTransactionFailed = new WeakMap(), _BridgeStatusController_onTransactionConfirmed = new WeakMap(), _BridgeStatusController_restartPollingForIncompleteHistoryItems = new WeakMap(), _BridgeStatusController_addTxToHistory = new WeakMap(), _BridgeStatusController_rekeyHistoryItem = new WeakMap(), _BridgeStatusController_startPollingForTxId = new WeakMap(), _BridgeStatusController_handleFetchFailure = new WeakMap(), _BridgeStatusController_handleOldHistoryItem = new WeakMap(), _BridgeStatusController_fetchBridgeTxStatus = new WeakMap(), _BridgeStatusController_setAndGetSrcTxHash = new WeakMap(), _BridgeStatusController_updateHistoryItem = new WeakMap(), _BridgeStatusController_deleteHistoryItem = new WeakMap(), _BridgeStatusController_wipeBridgeStatusByChainId = new WeakMap(), _BridgeStatusController_handleApprovalTx = new WeakMap(), _BridgeStatusController_handleEvmTransactionBatch = new WeakMap(), _BridgeStatusController_trackPollingStatusUpdatedEvent = new WeakMap(), _BridgeStatusController_trackUnifiedSwapBridgeEvent = new WeakMap();
864
+ _BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_intentManager = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(), _BridgeStatusController_addTransactionBatchFn = new WeakMap(), _BridgeStatusController_trace = new WeakMap(), _BridgeStatusController_onTransactionFailed = new WeakMap(), _BridgeStatusController_onTransactionConfirmed = new WeakMap(), _BridgeStatusController_restartPollingForIncompleteHistoryItems = new WeakMap(), _BridgeStatusController_addTxToHistory = new WeakMap(), _BridgeStatusController_rekeyHistoryItem = new WeakMap(), _BridgeStatusController_startPollingForTxId = new WeakMap(), _BridgeStatusController_handleFetchFailure = new WeakMap(), _BridgeStatusController_handleOldHistoryItem = new WeakMap(), _BridgeStatusController_fetchBridgeTxStatus = new WeakMap(), _BridgeStatusController_setAndGetSrcTxHash = new WeakMap(), _BridgeStatusController_updateHistoryItem = new WeakMap(), _BridgeStatusController_deleteHistoryItem = new WeakMap(), _BridgeStatusController_wipeBridgeStatusByChainId = new WeakMap(), _BridgeStatusController_executeSubmitStrategy = new WeakMap(), _BridgeStatusController_trackPollingStatusUpdatedEvent = new WeakMap(), _BridgeStatusController_trackUnifiedSwapBridgeEvent = new WeakMap();
1070
865
  //# sourceMappingURL=bridge-status-controller.cjs.map