@metamask-previews/bridge-status-controller 72.0.2-preview-f5ff6e53c → 72.0.2-preview-2b6e433

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 (48) hide show
  1. package/CHANGELOG.md +3 -6
  2. package/dist/bridge-status-controller.cjs +77 -66
  3. package/dist/bridge-status-controller.cjs.map +1 -1
  4. package/dist/bridge-status-controller.d.cts +3 -3
  5. package/dist/bridge-status-controller.d.cts.map +1 -1
  6. package/dist/bridge-status-controller.d.mts +3 -3
  7. package/dist/bridge-status-controller.d.mts.map +1 -1
  8. package/dist/bridge-status-controller.mjs +52 -41
  9. package/dist/bridge-status-controller.mjs.map +1 -1
  10. package/dist/constants.cjs +1 -8
  11. package/dist/constants.cjs.map +1 -1
  12. package/dist/constants.d.cts +0 -2
  13. package/dist/constants.d.cts.map +1 -1
  14. package/dist/constants.d.mts +0 -2
  15. package/dist/constants.d.mts.map +1 -1
  16. package/dist/constants.mjs +0 -7
  17. package/dist/constants.mjs.map +1 -1
  18. package/dist/strategy/batch-sell-strategy.cjs +7 -8
  19. package/dist/strategy/batch-sell-strategy.cjs.map +1 -1
  20. package/dist/strategy/batch-sell-strategy.d.cts.map +1 -1
  21. package/dist/strategy/batch-sell-strategy.d.mts.map +1 -1
  22. package/dist/strategy/batch-sell-strategy.mjs +7 -8
  23. package/dist/strategy/batch-sell-strategy.mjs.map +1 -1
  24. package/dist/strategy/types.cjs +0 -20
  25. package/dist/strategy/types.cjs.map +1 -1
  26. package/dist/strategy/types.d.cts +0 -39
  27. package/dist/strategy/types.d.cts.map +1 -1
  28. package/dist/strategy/types.d.mts +0 -39
  29. package/dist/strategy/types.d.mts.map +1 -1
  30. package/dist/strategy/types.mjs +0 -20
  31. package/dist/strategy/types.mjs.map +1 -1
  32. package/dist/utils/bridge.cjs +5 -2
  33. package/dist/utils/bridge.cjs.map +1 -1
  34. package/dist/utils/bridge.d.cts +2 -2
  35. package/dist/utils/bridge.d.cts.map +1 -1
  36. package/dist/utils/bridge.d.mts +2 -2
  37. package/dist/utils/bridge.d.mts.map +1 -1
  38. package/dist/utils/bridge.mjs +6 -3
  39. package/dist/utils/bridge.mjs.map +1 -1
  40. package/dist/utils/metrics.cjs +22 -6
  41. package/dist/utils/metrics.cjs.map +1 -1
  42. package/dist/utils/metrics.d.cts +27 -9
  43. package/dist/utils/metrics.d.cts.map +1 -1
  44. package/dist/utils/metrics.d.mts +27 -9
  45. package/dist/utils/metrics.d.mts.map +1 -1
  46. package/dist/utils/metrics.mjs +21 -6
  47. package/dist/utils/metrics.mjs.map +1 -1
  48. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -7,13 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
10
+ ### Changed
11
11
 
12
- - Add `batch_id` property to BatchSell events ([#8964](https://github.com/MetaMask/core/pull/8964))
13
- - pre-generate the batchId using transaction controller's `generateBatchId` util
14
- - attach batchId to the `Submitted`, `Completed` and `Failed` events
15
- - provide batchId to the `TransactionController:addTransactionBatch` to propagate it the TransactionMeta
16
- - Publish tx submission metrics for `BatchSell`, `QuickBuy` and `UnifiedSwapBridge` actions ([#8964](https://github.com/MetaMask/core/pull/8964))
12
+ - Bump `@metamask/transaction-controller` from `^66.0.1` to `^67.0.0` ([#9021](https://github.com/MetaMask/core/pull/9021))
13
+ - Bump `@metamask/bridge-controller` from `^73.2.1` to `^74.0.0` ([#9045](https://github.com/MetaMask/core/pull/9045))
17
14
 
18
15
  ## [72.0.2]
19
16
 
@@ -17,7 +17,6 @@ var _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_int
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.BridgeStatusController = void 0;
19
19
  const bridge_controller_1 = require("@metamask/bridge-controller");
20
- const bridge_controller_2 = require("@metamask/bridge-controller");
21
20
  const polling_controller_1 = require("@metamask/polling-controller");
22
21
  const transaction_controller_1 = require("@metamask/transaction-controller");
23
22
  const utils_1 = require("@metamask/utils");
@@ -77,11 +76,11 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
77
76
  _BridgeStatusController_onTransactionFailed.set(this, ({ txMeta, historyKey, isApprovalTxMeta, }) => {
78
77
  // Check if the history item is already marked as a failure
79
78
  const isHistoryItemAlreadyFailed = historyKey
80
- ? this.state.txHistory[historyKey]?.status.status === bridge_controller_2.StatusTypes.FAILED
79
+ ? this.state.txHistory[historyKey]?.status.status === bridge_controller_1.StatusTypes.FAILED
81
80
  : false;
82
81
  __classPrivateFieldGet(this, _BridgeStatusController_updateHistoryItem, "f").call(this, {
83
82
  historyKey,
84
- status: bridge_controller_2.StatusTypes.FAILED,
83
+ status: bridge_controller_1.StatusTypes.FAILED,
85
84
  txHash: isApprovalTxMeta ? undefined : txMeta.hash,
86
85
  completionTime: Date.now(),
87
86
  });
@@ -93,7 +92,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
93
92
  if (isHistoryItemAlreadyFailed) {
94
93
  return;
95
94
  }
96
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_2.UnifiedSwapBridgeEventName.Failed, historyKey, (0, metrics_1.getEVMTxPropertiesFromTransactionMeta)(txMeta));
95
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, historyKey, (0, metrics_1.getEVMTxPropertiesFromTransactionMeta)(txMeta));
97
96
  });
98
97
  // Only EVM txs
99
98
  _BridgeStatusController_onTransactionConfirmed.set(this, ({ txMeta, historyKey, isApprovalTxMeta, }) => {
@@ -111,10 +110,10 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
111
110
  case true:
112
111
  __classPrivateFieldGet(this, _BridgeStatusController_updateHistoryItem, "f").call(this, {
113
112
  historyKey,
114
- status: bridge_controller_2.StatusTypes.COMPLETE,
113
+ status: bridge_controller_1.StatusTypes.COMPLETE,
115
114
  completionTime: Date.now(),
116
115
  });
117
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_2.UnifiedSwapBridgeEventName.Completed, historyKey);
116
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, historyKey);
118
117
  break;
119
118
  default:
120
119
  if (historyKey) {
@@ -185,10 +184,24 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
185
184
  // Restart polling
186
185
  __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, targetTxMetaId);
187
186
  // Track polling manually restarted event
188
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_2.UnifiedSwapBridgeEventName.PollingStatusUpdated, targetTxMetaId, {
189
- polling_status: bridge_controller_2.PollingStatus.ManuallyRestarted,
190
- retry_attempts: previousAttempts,
191
- });
187
+ if (!historyItem.featureId) {
188
+ const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, historyItem.account);
189
+ const requestParams = (0, metrics_1.getRequestParamFromHistory)(historyItem);
190
+ const requestMetadata = (0, metrics_1.getRequestMetadataFromHistory)(historyItem, selectedAccount);
191
+ const { security_warnings: _, ...metadataWithoutWarnings } = requestMetadata;
192
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.PollingStatusUpdated, targetTxMetaId, {
193
+ ...(0, metrics_1.getTradeDataFromHistory)(historyItem),
194
+ ...(0, metrics_1.getPriceImpactFromQuote)(historyItem.quote),
195
+ ...metadataWithoutWarnings,
196
+ chain_id_source: requestParams.chain_id_source,
197
+ chain_id_destination: requestParams.chain_id_destination,
198
+ token_symbol_source: requestParams.token_symbol_source,
199
+ token_symbol_destination: requestParams.token_symbol_destination,
200
+ action_type: bridge_controller_1.MetricsActionType.SWAPBRIDGE_V1,
201
+ polling_status: bridge_controller_1.PollingStatus.ManuallyRestarted,
202
+ retry_attempts: previousAttempts,
203
+ });
204
+ }
192
205
  }
193
206
  }
194
207
  };
@@ -210,8 +223,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
210
223
  const { txHistory } = this.state;
211
224
  const historyItems = Object.entries(txHistory);
212
225
  const incompleteHistoryItems = historyItems
213
- .filter(([_, historyItem]) => historyItem.status.status === bridge_controller_2.StatusTypes.PENDING ||
214
- historyItem.status.status === bridge_controller_2.StatusTypes.UNKNOWN)
226
+ .filter(([_, historyItem]) => historyItem.status.status === bridge_controller_1.StatusTypes.PENDING ||
227
+ historyItem.status.status === bridge_controller_1.StatusTypes.UNKNOWN)
215
228
  // Only poll items with txMetaId (post-submission items)
216
229
  .filter(([_, historyItem]) => {
217
230
  if (!historyItem.txMetaId) {
@@ -320,9 +333,9 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
320
333
  delete __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
321
334
  // Track max polling reached event
322
335
  const historyItem = this.state.txHistory[bridgeTxMetaId];
323
- if (historyItem) {
336
+ if (historyItem && !historyItem.featureId) {
324
337
  // Track polling status updated event
325
- __classPrivateFieldGet(this, _BridgeStatusController_trackPollingStatusUpdatedEvent, "f").call(this, bridgeTxMetaId, bridge_controller_2.PollingStatus.MaxPollingReached);
338
+ __classPrivateFieldGet(this, _BridgeStatusController_trackPollingStatusUpdatedEvent, "f").call(this, bridgeTxMetaId, bridge_controller_1.PollingStatus.MaxPollingReached);
326
339
  }
327
340
  }
328
341
  // Update the attempts counter
@@ -344,7 +357,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
344
357
  }
345
358
  const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
346
359
  // Track polling status updated event
347
- __classPrivateFieldGet(this, _BridgeStatusController_trackPollingStatusUpdatedEvent, "f").call(this, bridgeTxMetaId, bridge_controller_2.PollingStatus.InvalidTransactionHash);
360
+ __classPrivateFieldGet(this, _BridgeStatusController_trackPollingStatusUpdatedEvent, "f").call(this, bridgeTxMetaId, bridge_controller_1.PollingStatus.InvalidTransactionHash);
348
361
  // If we've failed too many times, stop polling for the tx
349
362
  if (pollingToken) {
350
363
  this.stopPollingByPollingToken(pollingToken);
@@ -390,7 +403,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
390
403
  validationFailures = response.validationFailures;
391
404
  }
392
405
  if (validationFailures.length > 0) {
393
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_2.UnifiedSwapBridgeEventName.StatusValidationFailed, bridgeTxMetaId, {
406
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.StatusValidationFailed, bridgeTxMetaId, {
394
407
  failures: validationFailures,
395
408
  refresh_count: historyItem.attempts?.counter ?? 0,
396
409
  });
@@ -400,8 +413,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
400
413
  const newBridgeHistoryItem = {
401
414
  ...historyItem,
402
415
  status,
403
- completionTime: status.status === bridge_controller_2.StatusTypes.COMPLETE ||
404
- status.status === bridge_controller_2.StatusTypes.FAILED
416
+ completionTime: status.status === bridge_controller_1.StatusTypes.COMPLETE ||
417
+ status.status === bridge_controller_1.StatusTypes.FAILED
405
418
  ? Date.now()
406
419
  : undefined, // TODO make this more accurate by looking up dest txHash block time
407
420
  attempts: undefined,
@@ -418,17 +431,21 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
418
431
  }
419
432
  // 5. After effects
420
433
  const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
421
- const isFinalStatus = status.status === bridge_controller_2.StatusTypes.COMPLETE ||
422
- status.status === bridge_controller_2.StatusTypes.FAILED;
434
+ const isFinalStatus = status.status === bridge_controller_1.StatusTypes.COMPLETE ||
435
+ status.status === bridge_controller_1.StatusTypes.FAILED;
423
436
  if (isFinalStatus && pollingToken) {
424
437
  this.stopPollingByPollingToken(pollingToken);
425
438
  delete __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
426
- if (status.status === bridge_controller_2.StatusTypes.COMPLETE) {
427
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_2.UnifiedSwapBridgeEventName.Completed, bridgeTxMetaId);
439
+ // Skip tracking events when featureId is set (i.e. PERPS)
440
+ if (historyItem.featureId) {
441
+ return;
442
+ }
443
+ if (status.status === bridge_controller_1.StatusTypes.COMPLETE) {
444
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, bridgeTxMetaId);
428
445
  this.messenger.publish('BridgeStatusController:destinationTransactionCompleted', historyItem.quote.destAsset.assetId);
429
446
  }
430
- if (status.status === bridge_controller_2.StatusTypes.FAILED) {
431
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_2.UnifiedSwapBridgeEventName.Failed, bridgeTxMetaId);
447
+ if (status.status === bridge_controller_1.StatusTypes.FAILED) {
448
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, bridgeTxMetaId);
432
449
  }
433
450
  }
434
451
  }
@@ -453,7 +470,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
453
470
  // But it is possible to have bridgeHistoryItem in state without the srcTxHash yet when it is an STX
454
471
  const srcTxHash = txHistory[bridgeTxMetaId].status.srcChain.txHash;
455
472
  if (srcTxHash ||
456
- (0, bridge_controller_2.isNonEvmChainId)(txHistory[bridgeTxMetaId].quote.srcChainId)) {
473
+ (0, bridge_controller_1.isNonEvmChainId)(txHistory[bridgeTxMetaId].quote.srcChainId)) {
457
474
  return srcTxHash;
458
475
  }
459
476
  // Update history with TransactionController's hash if it has been updated
@@ -561,7 +578,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
561
578
  __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, payload.historyKey);
562
579
  break;
563
580
  case types_1.SubmitStep.PublishCompletedEvent:
564
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_2.UnifiedSwapBridgeEventName.Completed, payload.historyKey);
581
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, payload.historyKey);
565
582
  break;
566
583
  /* c8 ignore start */
567
584
  default:
@@ -590,7 +607,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
590
607
  * @returns The transaction meta
591
608
  * @throws An error if transaction submission fails before it gets published
592
609
  */
593
- this.submitTx = async (accountAddress, maybeQuoteResponses, isStxEnabled, quotesReceivedContext, location = bridge_controller_2.MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades) => {
610
+ this.submitTx = async (accountAddress, maybeQuoteResponses, isStxEnabled, quotesReceivedContext, location = bridge_controller_1.MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades) => {
594
611
  /**
595
612
  * If there are multiple quote responses, we assume that they all originate from the same src chain
596
613
  * and the same account. In this case its safe to use the first quote response's properties for
@@ -600,35 +617,32 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
600
617
  ? maybeQuoteResponses
601
618
  : [maybeQuoteResponses];
602
619
  const quoteResponse = quoteResponses[0];
603
- const { quote } = quoteResponse;
620
+ const { featureId, quote } = quoteResponse;
604
621
  const startTime = Date.now();
605
- (0, bridge_1.stopPollingForQuotes)(this.messenger, quotesReceivedContext);
622
+ (0, bridge_1.stopPollingForQuotes)(this.messenger, featureId, quotesReceivedContext);
606
623
  const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, accountAddress);
607
624
  if (!selectedAccount) {
608
625
  throw new Error('Failed to submit cross-chain swap transaction: undefined multichain account');
609
626
  }
610
- const accountHardwareType = (0, bridge_controller_2.getAccountHardwareType)(selectedAccount);
627
+ const accountHardwareType = (0, bridge_controller_1.getAccountHardwareType)(selectedAccount);
611
628
  /**
612
629
  * For hardware wallets on Mobile, this is fixes an issue where the Ledger does not get prompted for the 2nd approval.
613
630
  * Extension does not have this issue
614
631
  */
615
632
  const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_2.BridgeClientId.MOBILE && accountHardwareType !== null;
616
- const isBridgeTx = (0, bridge_controller_2.isCrossChain)(quote.srcChainId, quote.destChainId);
617
- const batchId = quoteResponses.some(({ featureId: quoteFeatureId }) => quoteFeatureId === bridge_controller_1.FeatureId.BATCH_SELL)
618
- ? (0, transaction_controller_1.generateBatchId)()
619
- : undefined;
620
- const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, isStxEnabled, accountHardwareType, location, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades, batchId);
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);
621
635
  try {
622
636
  // Emit Submitted event after submit button is clicked
623
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_2.UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties);
637
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties, featureId);
624
638
  /**
625
639
  * Check if the account is an EIP-7702 delegated account.
626
640
  * Delegated accounts only allow 1 in-flight tx, so approve + swap
627
641
  * must be batched into a single transaction
628
642
  */
629
- const isDelegatedAccount = (0, bridge_controller_2.isNonEvmChainId)(quote.srcChainId)
643
+ const isDelegatedAccount = (0, bridge_controller_1.isNonEvmChainId)(quote.srcChainId)
630
644
  ? false
631
- : await (0, transaction_1.checkIsDelegatedAccount)(this.messenger, selectedAccount.address, [(0, bridge_controller_2.formatChainIdToHex)(quote.srcChainId)]);
645
+ : await (0, transaction_1.checkIsDelegatedAccount)(this.messenger, selectedAccount.address, [(0, bridge_controller_1.formatChainIdToHex)(quote.srcChainId)]);
632
646
  const strategyParams = {
633
647
  messenger: this.messenger,
634
648
  quoteResponses,
@@ -643,7 +657,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
643
657
  addTransactionBatchFn: __classPrivateFieldGet(this, _BridgeStatusController_addTransactionBatchFn, "f"),
644
658
  fetchFn: __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"),
645
659
  traceFn: __classPrivateFieldGet(this, _BridgeStatusController_trace, "f"),
646
- batchId,
647
660
  };
648
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, {
649
662
  startTime,
@@ -654,10 +667,10 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
654
667
  }));
655
668
  }
656
669
  catch (error) {
657
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_2.UnifiedSwapBridgeEventName.Failed, undefined, {
670
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, undefined, {
658
671
  error_message: error?.message,
659
672
  ...preConfirmationProperties,
660
- });
673
+ }, featureId);
661
674
  throw error;
662
675
  }
663
676
  };
@@ -693,45 +706,43 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
693
706
  _BridgeStatusController_trackPollingStatusUpdatedEvent.set(this, (historyKey, pollingStatus) => {
694
707
  // Track polling status updated event
695
708
  const historyItem = this.state.txHistory[historyKey];
696
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_2.UnifiedSwapBridgeEventName.PollingStatusUpdated, historyKey, {
697
- polling_status: pollingStatus,
698
- retry_attempts: historyItem.attempts?.counter ?? 0,
699
- });
709
+ __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.PollingStatusUpdated, historyKey, (0, metrics_1.getPollingStatusUpdatedProperties)(this.messenger, pollingStatus, historyItem));
700
710
  });
701
711
  /**
702
712
  * Tracks post-submission events for a cross-chain swap based on the history item
703
713
  *
704
714
  * @param eventName - The name of the event to track
705
- * @param txHistoryKey - The txMetaId of the history item to track the event for
715
+ * @param txMetaId - The txMetaId of the history item to track the event for
706
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
707
719
  */
708
- _BridgeStatusController_trackUnifiedSwapBridgeEvent.set(this, (eventName, txHistoryKey, eventProperties) => {
709
- const historyItem = txHistoryKey
710
- ? this.state.txHistory[txHistoryKey]
720
+ _BridgeStatusController_trackUnifiedSwapBridgeEvent.set(this, (eventName, txMetaId, eventProperties, featureIdOverride) => {
721
+ const historyItem = txMetaId
722
+ ? this.state.txHistory[txMetaId]
711
723
  : undefined;
712
- const featureId = eventProperties?.feature_id ??
713
- historyItem?.featureId ??
714
- bridge_controller_1.FeatureId.UNIFIED_SWAP_BRIDGE;
715
- if (!(constants_1.ALLOWED_FEATURE_IDS_FOR_STATUS_EVENTS.includes(featureId) ||
716
- eventName === bridge_controller_2.UnifiedSwapBridgeEventName.StatusValidationFailed)) {
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) {
717
731
  return;
718
732
  }
719
733
  // Legacy/new metrics fields are intentionally kept independent during migration.
720
- const historyAbTests = txHistoryKey
721
- ? this.state.txHistory?.[txHistoryKey]?.abTests
734
+ const historyAbTests = txMetaId
735
+ ? this.state.txHistory?.[txMetaId]?.abTests
722
736
  : undefined;
723
- const historyActiveAbTests = txHistoryKey
724
- ? this.state.txHistory?.[txHistoryKey]?.activeAbTests
737
+ const historyActiveAbTests = txMetaId
738
+ ? this.state.txHistory?.[txMetaId]?.activeAbTests
725
739
  : undefined;
726
740
  const resolvedAbTests = eventProperties?.ab_tests ?? historyAbTests;
727
741
  const resolvedActiveAbTests = eventProperties?.active_ab_tests ?? historyActiveAbTests;
728
- const location = (txHistoryKey
729
- ? this.state.txHistory?.[txHistoryKey]?.location
730
- : undefined) ?? bridge_controller_2.MetaMetricsSwapsEventSource.MainView;
742
+ const location = (txMetaId ? this.state.txHistory?.[txMetaId]?.location : undefined) ??
743
+ bridge_controller_1.MetaMetricsSwapsEventSource.MainView;
731
744
  const baseProperties = {
732
- action_type: bridge_controller_2.MetricsActionType.SWAPBRIDGE_V1,
733
- feature_id: featureId ?? bridge_controller_1.FeatureId.UNIFIED_SWAP_BRIDGE,
734
- ...(historyItem?.batchId ? { batch_id: historyItem.batchId } : {}),
745
+ action_type: bridge_controller_1.MetricsActionType.SWAPBRIDGE_V1,
735
746
  ...(eventProperties ?? {}),
736
747
  location,
737
748
  ...(resolvedAbTests &&
@@ -754,7 +765,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
754
765
  }
755
766
  const { approvalTxId, quote } = historyItem;
756
767
  const requestParamProperties = (0, metrics_1.getRequestParamFromHistory)(historyItem);
757
- if (eventName === bridge_controller_2.UnifiedSwapBridgeEventName.StatusValidationFailed) {
768
+ if (eventName === bridge_controller_1.UnifiedSwapBridgeEventName.StatusValidationFailed) {
758
769
  (0, bridge_1.trackMetricsEvent)({
759
770
  messenger: this.messenger,
760
771
  eventName,
@@ -772,7 +783,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
772
783
  }
773
784
  const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, historyItem.account);
774
785
  const transactions = (0, transaction_1.getTransactions)(this.messenger);
775
- const txMeta = transactions.find((tx) => tx.id === txHistoryKey);
786
+ const txMeta = transactions.find((tx) => tx.id === txMetaId);
776
787
  const approvalTxMeta = transactions.find((tx) => tx.id === approvalTxId);
777
788
  const requiredEventProperties = {
778
789
  ...baseProperties,