@metamask/bridge-status-controller 69.0.0 → 70.0.1

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 (130) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/bridge-status-controller.cjs +115 -354
  3. package/dist/bridge-status-controller.cjs.map +1 -1
  4. package/dist/bridge-status-controller.d.cts +3 -5
  5. package/dist/bridge-status-controller.d.cts.map +1 -1
  6. package/dist/bridge-status-controller.d.mts +3 -5
  7. package/dist/bridge-status-controller.d.mts.map +1 -1
  8. package/dist/bridge-status-controller.intent.cjs +12 -25
  9. package/dist/bridge-status-controller.intent.cjs.map +1 -1
  10. package/dist/bridge-status-controller.intent.d.cts +3 -14
  11. package/dist/bridge-status-controller.intent.d.cts.map +1 -1
  12. package/dist/bridge-status-controller.intent.d.mts +3 -14
  13. package/dist/bridge-status-controller.intent.d.mts.map +1 -1
  14. package/dist/bridge-status-controller.intent.mjs +12 -25
  15. package/dist/bridge-status-controller.intent.mjs.map +1 -1
  16. package/dist/bridge-status-controller.mjs +118 -357
  17. package/dist/bridge-status-controller.mjs.map +1 -1
  18. package/dist/index.cjs +1 -3
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +0 -1
  21. package/dist/index.d.cts.map +1 -1
  22. package/dist/index.d.mts +0 -1
  23. package/dist/index.d.mts.map +1 -1
  24. package/dist/index.mjs +0 -1
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/types.cjs.map +1 -1
  27. package/dist/types.d.cts +11 -5
  28. package/dist/types.d.cts.map +1 -1
  29. package/dist/types.d.mts +11 -5
  30. package/dist/types.d.mts.map +1 -1
  31. package/dist/types.mjs.map +1 -1
  32. package/dist/utils/accounts.cjs +8 -0
  33. package/dist/utils/accounts.cjs.map +1 -0
  34. package/dist/utils/accounts.d.cts +36 -0
  35. package/dist/utils/accounts.d.cts.map +1 -0
  36. package/dist/utils/accounts.d.mts +36 -0
  37. package/dist/utils/accounts.d.mts.map +1 -0
  38. package/dist/utils/accounts.mjs +4 -0
  39. package/dist/utils/accounts.mjs.map +1 -0
  40. package/dist/utils/authentication.cjs +15 -0
  41. package/dist/utils/authentication.cjs.map +1 -0
  42. package/dist/utils/authentication.d.cts +3 -0
  43. package/dist/utils/authentication.d.cts.map +1 -0
  44. package/dist/utils/authentication.d.mts +3 -0
  45. package/dist/utils/authentication.d.mts.map +1 -0
  46. package/dist/utils/authentication.mjs +11 -0
  47. package/dist/utils/authentication.mjs.map +1 -0
  48. package/dist/utils/bridge-status.cjs +17 -1
  49. package/dist/utils/bridge-status.cjs.map +1 -1
  50. package/dist/utils/bridge-status.d.cts +8 -2
  51. package/dist/utils/bridge-status.d.cts.map +1 -1
  52. package/dist/utils/bridge-status.d.mts +8 -2
  53. package/dist/utils/bridge-status.d.mts.map +1 -1
  54. package/dist/utils/bridge-status.mjs +15 -0
  55. package/dist/utils/bridge-status.mjs.map +1 -1
  56. package/dist/utils/bridge.cjs +16 -0
  57. package/dist/utils/bridge.cjs.map +1 -0
  58. package/dist/utils/bridge.d.cts +10 -0
  59. package/dist/utils/bridge.d.cts.map +1 -0
  60. package/dist/utils/bridge.d.mts +10 -0
  61. package/dist/utils/bridge.d.mts.map +1 -0
  62. package/dist/utils/bridge.mjs +11 -0
  63. package/dist/utils/bridge.mjs.map +1 -0
  64. package/dist/utils/gas.cjs +1 -61
  65. package/dist/utils/gas.cjs.map +1 -1
  66. package/dist/utils/gas.d.cts +3 -26
  67. package/dist/utils/gas.d.cts.map +1 -1
  68. package/dist/utils/gas.d.mts +3 -26
  69. package/dist/utils/gas.d.mts.map +1 -1
  70. package/dist/utils/gas.mjs +0 -58
  71. package/dist/utils/gas.mjs.map +1 -1
  72. package/dist/utils/history.cjs +98 -0
  73. package/dist/utils/history.cjs.map +1 -0
  74. package/dist/utils/history.d.cts +22 -0
  75. package/dist/utils/history.d.cts.map +1 -0
  76. package/dist/utils/history.d.mts +22 -0
  77. package/dist/utils/history.d.mts.map +1 -0
  78. package/dist/utils/history.mjs +91 -0
  79. package/dist/utils/history.mjs.map +1 -0
  80. package/dist/utils/intent-api.cjs +41 -26
  81. package/dist/utils/intent-api.cjs.map +1 -1
  82. package/dist/utils/intent-api.d.cts +16 -3
  83. package/dist/utils/intent-api.d.cts.map +1 -1
  84. package/dist/utils/intent-api.d.mts +16 -3
  85. package/dist/utils/intent-api.d.mts.map +1 -1
  86. package/dist/utils/intent-api.mjs +38 -25
  87. package/dist/utils/intent-api.mjs.map +1 -1
  88. package/dist/utils/keyring.cjs +12 -0
  89. package/dist/utils/keyring.cjs.map +1 -0
  90. package/dist/utils/keyring.d.cts +8 -0
  91. package/dist/utils/keyring.d.cts.map +1 -0
  92. package/dist/utils/keyring.d.mts +8 -0
  93. package/dist/utils/keyring.d.mts.map +1 -0
  94. package/dist/utils/keyring.mjs +8 -0
  95. package/dist/utils/keyring.mjs.map +1 -0
  96. package/dist/utils/network.cjs +17 -0
  97. package/dist/utils/network.cjs.map +1 -0
  98. package/dist/utils/network.d.cts +5 -0
  99. package/dist/utils/network.d.cts.map +1 -0
  100. package/dist/utils/network.d.mts +5 -0
  101. package/dist/utils/network.d.mts.map +1 -0
  102. package/dist/utils/network.mjs +12 -0
  103. package/dist/utils/network.mjs.map +1 -0
  104. package/dist/utils/snaps.cjs +146 -1
  105. package/dist/utils/snaps.cjs.map +1 -1
  106. package/dist/utils/snaps.d.cts +48 -0
  107. package/dist/utils/snaps.d.cts.map +1 -1
  108. package/dist/utils/snaps.d.mts +48 -0
  109. package/dist/utils/snaps.d.mts.map +1 -1
  110. package/dist/utils/snaps.mjs +141 -0
  111. package/dist/utils/snaps.mjs.map +1 -1
  112. package/dist/utils/trace.cjs +31 -0
  113. package/dist/utils/trace.cjs.map +1 -0
  114. package/dist/utils/trace.d.cts +17 -0
  115. package/dist/utils/trace.d.cts.map +1 -0
  116. package/dist/utils/trace.d.mts +17 -0
  117. package/dist/utils/trace.d.mts.map +1 -0
  118. package/dist/utils/trace.mjs +26 -0
  119. package/dist/utils/trace.mjs.map +1 -0
  120. package/dist/utils/transaction.cjs +239 -184
  121. package/dist/utils/transaction.cjs.map +1 -1
  122. package/dist/utils/transaction.d.cts +85 -236
  123. package/dist/utils/transaction.d.cts.map +1 -1
  124. package/dist/utils/transaction.d.mts +85 -236
  125. package/dist/utils/transaction.d.mts.map +1 -1
  126. package/dist/utils/transaction.mjs +226 -176
  127. package/dist/utils/transaction.mjs.map +1 -1
  128. package/dist/utils/validators.d.cts +2 -2
  129. package/dist/utils/validators.d.mts +2 -2
  130. package/package.json +3 -3
@@ -10,22 +10,27 @@ 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_instances, _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_intentManager, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionFn, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_updateTransactionFn, _BridgeStatusController_estimateGasFeeFn, _BridgeStatusController_trace, _BridgeStatusController_markTxAsFailed, _BridgeStatusController_restartPollingForIncompleteHistoryItems, _BridgeStatusController_addTxToHistory, _BridgeStatusController_rekeyHistoryItem, _BridgeStatusController_startPollingForTxId, _BridgeStatusController_shouldPollHistoryItem, _BridgeStatusController_getMultichainSelectedAccount, _BridgeStatusController_handleFetchFailure, _BridgeStatusController_fetchBridgeTxStatus, _BridgeStatusController_getJwt, _BridgeStatusController_getSrcTxHash, _BridgeStatusController_updateSrcTxHash, _BridgeStatusController_wipeBridgeStatusByChainId, _BridgeStatusController_handleNonEvmTx, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, _BridgeStatusController_waitForTxConfirmation, _BridgeStatusController_handleApprovalTx, _BridgeStatusController_handleEvmTransaction, _BridgeStatusController_handleUSDTAllowanceReset, _BridgeStatusController_calculateGasFees, _BridgeStatusController_handleEvmTransactionBatch, _BridgeStatusController_trackUnifiedSwapBridgeEvent;
13
+ var _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_intentManager, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_trace, _BridgeStatusController_markTxAsFailed, _BridgeStatusController_restartPollingForIncompleteHistoryItems, _BridgeStatusController_addTxToHistory, _BridgeStatusController_rekeyHistoryItem, _BridgeStatusController_startPollingForTxId, _BridgeStatusController_handleFetchFailure, _BridgeStatusController_fetchBridgeTxStatus, _BridgeStatusController_getSrcTxHash, _BridgeStatusController_updateSrcTxHash, _BridgeStatusController_wipeBridgeStatusByChainId, _BridgeStatusController_handleApprovalTx, _BridgeStatusController_handleEvmTransactionBatch, _BridgeStatusController_trackUnifiedSwapBridgeEvent;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.BridgeStatusController = void 0;
16
16
  const bridge_controller_1 = require("@metamask/bridge-controller");
17
- const controller_utils_1 = require("@metamask/controller-utils");
18
- const keyring_controller_1 = require("@metamask/keyring-controller");
19
17
  const polling_controller_1 = require("@metamask/polling-controller");
20
18
  const transaction_controller_1 = require("@metamask/transaction-controller");
21
19
  const utils_1 = require("@metamask/utils");
22
20
  const bridge_status_controller_intent_1 = require("./bridge-status-controller.intent.cjs");
23
21
  const constants_1 = require("./constants.cjs");
24
22
  const types_1 = require("./types.cjs");
23
+ const accounts_1 = require("./utils/accounts.cjs");
24
+ const authentication_1 = require("./utils/authentication.cjs");
25
+ const bridge_1 = require("./utils/bridge.cjs");
25
26
  const bridge_status_1 = require("./utils/bridge-status.cjs");
26
- const gas_1 = require("./utils/gas.cjs");
27
+ const history_1 = require("./utils/history.cjs");
27
28
  const intent_api_1 = require("./utils/intent-api.cjs");
29
+ const keyring_1 = require("./utils/keyring.cjs");
28
30
  const metrics_1 = require("./utils/metrics.cjs");
31
+ const network_1 = require("./utils/network.cjs");
32
+ const snaps_1 = require("./utils/snaps.cjs");
33
+ const trace_1 = require("./utils/trace.cjs");
29
34
  const transaction_1 = require("./utils/transaction.cjs");
30
35
  const metadata = {
31
36
  // We want to persist the bridge status state so that we can show the proper data for the Activity list
@@ -38,7 +43,7 @@ const metadata = {
38
43
  },
39
44
  };
40
45
  class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPollingController)() {
41
- constructor({ messenger, state, clientId, fetchFn, addTransactionFn, addTransactionBatchFn, updateTransactionFn, estimateGasFeeFn, config, traceFn, }) {
46
+ constructor({ messenger, state, clientId, fetchFn, addTransactionBatchFn, config, traceFn, }) {
42
47
  super({
43
48
  name: constants_1.BRIDGE_STATUS_CONTROLLER_NAME,
44
49
  metadata,
@@ -49,16 +54,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
49
54
  ...state,
50
55
  },
51
56
  });
52
- _BridgeStatusController_instances.add(this);
53
57
  _BridgeStatusController_pollingTokensByTxMetaId.set(this, {});
54
58
  _BridgeStatusController_intentManager.set(this, void 0);
55
59
  _BridgeStatusController_clientId.set(this, void 0);
56
60
  _BridgeStatusController_fetchFn.set(this, void 0);
57
61
  _BridgeStatusController_config.set(this, void 0);
58
- _BridgeStatusController_addTransactionFn.set(this, void 0);
59
62
  _BridgeStatusController_addTransactionBatchFn.set(this, void 0);
60
- _BridgeStatusController_updateTransactionFn.set(this, void 0);
61
- _BridgeStatusController_estimateGasFeeFn.set(this, void 0);
62
63
  _BridgeStatusController_trace.set(this, void 0);
63
64
  // Mark tx as failed in txHistory if either the approval or trade fails
64
65
  _BridgeStatusController_markTxAsFailed.set(this, ({ id: txMetaId, actionId, }) => {
@@ -93,9 +94,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
93
94
  });
94
95
  }
95
96
  else {
96
- const { selectedNetworkClientId } = this.messenger.call('NetworkController:getState');
97
- const selectedNetworkClient = this.messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
98
- const selectedChainId = selectedNetworkClient.configuration.chainId;
97
+ const selectedChainId = (0, network_1.getSelectedChainId)(this.messenger);
99
98
  __classPrivateFieldGet(this, _BridgeStatusController_wipeBridgeStatusByChainId, "f").call(this, address, selectedChainId);
100
99
  }
101
100
  };
@@ -137,7 +136,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
137
136
  }
138
137
  });
139
138
  // Restart polling if it was stopped and this tx still needs status updates
140
- if (__classPrivateFieldGet(this, _BridgeStatusController_shouldPollHistoryItem, "f").call(this, historyItem)) {
139
+ if ((0, history_1.shouldPollHistoryItem)(historyItem)) {
141
140
  // Check if polling was stopped (no active polling token)
142
141
  const existingPollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[targetTxMetaId];
143
142
  if (!existingPollingToken) {
@@ -145,7 +144,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
145
144
  __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, targetTxMetaId);
146
145
  // Track polling manually restarted event
147
146
  if (!historyItem.featureId) {
148
- const selectedAccount = this.messenger.call('AccountsController:getAccountByAddress', historyItem.account);
147
+ const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, historyItem.account);
149
148
  const requestParams = (0, metrics_1.getRequestParamFromHistory)(historyItem);
150
149
  const requestMetadata = (0, metrics_1.getRequestMetadataFromHistory)(historyItem, selectedAccount);
151
150
  const { security_warnings: _, ...metadataWithoutWarnings } = requestMetadata;
@@ -194,7 +193,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
194
193
  })
195
194
  // Only restart polling for items that still require status updates
196
195
  .filter((historyItem) => {
197
- return __classPrivateFieldGet(this, _BridgeStatusController_shouldPollHistoryItem, "f").call(this, historyItem);
196
+ return (0, history_1.shouldPollHistoryItem)(historyItem);
198
197
  });
199
198
  incompleteHistoryItems.forEach((historyItem) => {
200
199
  const bridgeTxMetaId = historyItem.txMetaId;
@@ -207,51 +206,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
207
206
  __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeTxMetaId);
208
207
  });
209
208
  });
210
- _BridgeStatusController_addTxToHistory.set(this, (startPollingForBridgeTxStatusArgs, actionId) => {
211
- const { bridgeTxMeta, statusRequest, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, activeAbTests, accountAddress: selectedAddress, } = startPollingForBridgeTxStatusArgs;
212
- // Determine the key for this history item:
213
- // - For pre-submission (non-batch EVM): use actionId
214
- // - For post-submission or other cases: use bridgeTxMeta.id
215
- const historyKey = (0, transaction_1.getHistoryKey)(actionId, bridgeTxMeta?.id);
216
- // Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API
217
- // We know it's in progress but not the exact status yet
218
- const txHistoryItem = {
219
- txMetaId: bridgeTxMeta?.id,
220
- actionId,
221
- originalTransactionId: bridgeTxMeta
222
- ?.originalTransactionId || bridgeTxMeta?.id, // Keep original for intent transactions
223
- batchId: bridgeTxMeta?.batchId,
224
- quote: quoteResponse.quote,
225
- startTime,
226
- estimatedProcessingTimeInSeconds: quoteResponse.estimatedProcessingTimeInSeconds,
227
- slippagePercentage,
228
- pricingData: {
229
- amountSent: quoteResponse.sentAmount?.amount ?? '0',
230
- amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,
231
- quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,
232
- quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,
233
- quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,
234
- },
235
- initialDestAssetBalance,
236
- targetContractAddress,
237
- account: selectedAddress,
238
- status: {
239
- // We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that
240
- // Also we know the bare minimum fields for status at this point in time
241
- status: bridge_controller_1.StatusTypes.PENDING,
242
- srcChain: {
243
- chainId: statusRequest.srcChainId,
244
- txHash: statusRequest.srcTxHash,
245
- },
246
- },
247
- hasApprovalTx: Boolean(quoteResponse.approval),
248
- approvalTxId,
249
- isStxEnabled: Boolean(isStxEnabled),
250
- featureId: quoteResponse.featureId,
251
- location,
252
- ...(abTests && { abTests }),
253
- ...(activeAbTests && { activeAbTests }),
254
- };
209
+ _BridgeStatusController_addTxToHistory.set(this, (...args) => {
210
+ const { historyKey, txHistoryItem } = (0, history_1.getInitialHistoryItem)(...args);
255
211
  this.update((state) => {
256
212
  // Use actionId as key for pre-submission, or txMeta.id for post-submission
257
213
  state.txHistory[historyKey] = txHistoryItem;
@@ -268,7 +224,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
268
224
  */
269
225
  _BridgeStatusController_rekeyHistoryItem.set(this, (actionId, txMeta) => {
270
226
  this.update((state) => {
271
- (0, transaction_1.rekeyHistoryItemInState)(state, actionId, txMeta);
227
+ (0, history_1.rekeyHistoryItemInState)(state, actionId, txMeta);
272
228
  });
273
229
  });
274
230
  _BridgeStatusController_startPollingForTxId.set(this, (txId) => {
@@ -281,18 +237,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
281
237
  if (!txHistoryItem) {
282
238
  return;
283
239
  }
284
- if (__classPrivateFieldGet(this, _BridgeStatusController_shouldPollHistoryItem, "f").call(this, txHistoryItem)) {
240
+ if ((0, history_1.shouldPollHistoryItem)(txHistoryItem)) {
285
241
  __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId] = this.startPolling({
286
242
  bridgeTxMetaId: txId,
287
243
  });
288
244
  }
289
245
  });
290
- _BridgeStatusController_shouldPollHistoryItem.set(this, (historyItem) => {
291
- const isIntent = Boolean(historyItem?.quote?.intent);
292
- const isBridgeTx = (0, bridge_controller_1.isCrossChain)(historyItem.quote.srcChainId, historyItem.quote.destChainId);
293
- const isTronTx = (0, bridge_controller_1.isTronChainId)(historyItem.quote.srcChainId);
294
- return [isBridgeTx, isIntent, isTronTx].some(Boolean);
295
- });
296
246
  /**
297
247
  * @deprecated For EVM/Solana swap/bridge txs we add tx to history in submitTx()
298
248
  * For Solana swap/bridge we start polling in submitTx()
@@ -344,7 +294,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
344
294
  // Track max polling reached event
345
295
  const historyItem = this.state.txHistory[bridgeTxMetaId];
346
296
  if (historyItem && !historyItem.featureId) {
347
- const selectedAccount = this.messenger.call('AccountsController:getAccountByAddress', historyItem.account);
297
+ const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, historyItem.account);
348
298
  const requestParams = (0, metrics_1.getRequestParamFromHistory)(historyItem);
349
299
  const requestMetadata = (0, metrics_1.getRequestMetadataFromHistory)(historyItem, selectedAccount);
350
300
  const { security_warnings: _, ...metadataWithoutWarnings } = requestMetadata;
@@ -400,7 +350,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
400
350
  }
401
351
  __classPrivateFieldGet(this, _BridgeStatusController_updateSrcTxHash, "f").call(this, bridgeTxMetaId, srcTxHash);
402
352
  const statusRequest = (0, bridge_status_1.getStatusRequestWithSrcTxHash)(historyItem.quote, srcTxHash);
403
- const response = await (0, bridge_status_1.fetchBridgeTxStatus)(statusRequest, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), await __classPrivateFieldGet(this, _BridgeStatusController_getJwt, "f").call(this), __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"), __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl);
353
+ const response = await (0, bridge_status_1.fetchBridgeTxStatus)(statusRequest, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), await (0, authentication_1.getJwt)(this.messenger), __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"), __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl);
404
354
  status = response.status;
405
355
  validationFailures = response.validationFailures;
406
356
  }
@@ -456,16 +406,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
456
406
  __classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
457
407
  }
458
408
  });
459
- _BridgeStatusController_getJwt.set(this, async () => {
460
- try {
461
- const token = await this.messenger.call('AuthenticationController:getBearerToken');
462
- return token;
463
- }
464
- catch (error) {
465
- console.error('Error getting JWT token for bridge-api request', error);
466
- return undefined;
467
- }
468
- });
469
409
  _BridgeStatusController_getSrcTxHash.set(this, (bridgeTxMetaId) => {
470
410
  const { txHistory } = this.state;
471
411
  // Prefer the srcTxHash from bridgeStatusState so we don't have to l ook up in TransactionController
@@ -475,8 +415,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
475
415
  return srcTxHash;
476
416
  }
477
417
  // Look up in TransactionController if txMeta has been updated with the srcTxHash
478
- const txControllerState = this.messenger.call('TransactionController:getState');
479
- const txMeta = txControllerState.transactions.find((tx) => tx.id === bridgeTxMetaId);
418
+ const txMeta = (0, transaction_1.getTransactionMetaById)(this.messenger, bridgeTxMetaId);
480
419
  return txMeta?.hash;
481
420
  });
482
421
  _BridgeStatusController_updateSrcTxHash.set(this, (bridgeTxMetaId, srcTxHash) => {
@@ -515,57 +454,18 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
515
454
  * TX SUBMISSION HANDLING
516
455
  *******************************************************
517
456
  */
518
- /**
519
- * Submits the transaction to the snap using the new unified ClientRequest interface
520
- * Works for all non-EVM chains (Solana, BTC, Tron)
521
- * This adds an approval tx to the ApprovalsController in the background
522
- * The client needs to handle the approval tx by redirecting to the confirmation page with the approvalTxId in the URL
523
- *
524
- * @param trade - The trade data (can be approval or main trade)
525
- * @param quoteResponse - The quote response containing metadata
526
- * @param selectedAccount - The account to submit the transaction for
527
- * @returns The transaction meta
528
- */
529
- _BridgeStatusController_handleNonEvmTx.set(this, async (trade, quoteResponse, selectedAccount) => {
530
- if (!selectedAccount.metadata?.snap?.id) {
531
- throw new Error('Failed to submit cross-chain swap transaction: undefined snap id');
532
- }
533
- const request = (0, transaction_1.getClientRequest)(trade, quoteResponse.quote.srcChainId, selectedAccount);
534
- const requestResponse = (await this.messenger.call('SnapController:handleRequest', request));
535
- // Create quote response with the specified trade
536
- // This allows the same method to handle both approvals and main trades
537
- const txQuoteResponse = {
538
- ...quoteResponse,
539
- trade,
540
- };
541
- const txMeta = (0, transaction_1.handleNonEvmTxResponse)(requestResponse, txQuoteResponse, selectedAccount);
542
- // TODO remove this eventually, just returning it now to match extension behavior
543
- // OR if the snap can propagate the snapRequestId or keyringReqId to the ApprovalsController, this can return the approvalTxId instead and clients won't need to subscribe to the ApprovalsController state to redirect
544
- return txMeta;
545
- });
546
- _BridgeStatusController_waitForHashAndReturnFinalTxMeta.set(this, async (hashPromise) => {
547
- const transactionHash = await hashPromise;
548
- const finalTransactionMeta = this.messenger
549
- .call('TransactionController:getState')
550
- .transactions.find((tx) => tx.hash === transactionHash);
551
- if (!finalTransactionMeta) {
552
- throw new Error('Failed to submit cross-chain swap tx: txMeta for txHash was not found');
553
- }
554
- return finalTransactionMeta;
555
- });
556
- // Waits until a given transaction (by id) reaches confirmed/finalized status or fails/times out.
557
- _BridgeStatusController_waitForTxConfirmation.set(this, async (txId, { timeoutMs = 5 * 60000, // 5 minutes default
558
- pollMs = 3000, } = {}) => {
559
- return await (0, transaction_1.waitForTxConfirmation)(this.messenger, txId, {
560
- timeoutMs,
561
- pollMs,
562
- });
563
- });
564
- _BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
457
+ _BridgeStatusController_handleApprovalTx.set(this, async (quoteResponse, isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
565
458
  if (approval && (0, bridge_controller_1.isEvmTxData)(approval)) {
566
459
  const approveTx = async () => {
567
- await __classPrivateFieldGet(this, _BridgeStatusController_handleUSDTAllowanceReset, "f").call(this, resetApproval);
568
- const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
460
+ if (resetApproval) {
461
+ await (0, transaction_1.submitEvmTransaction)({
462
+ messenger: this.messenger,
463
+ transactionType: transaction_controller_1.TransactionType.bridgeApproval,
464
+ trade: resetApproval,
465
+ });
466
+ }
467
+ const approvalTxMeta = await (0, transaction_1.submitEvmTransaction)({
468
+ messenger: this.messenger,
569
469
  transactionType: isBridgeTx
570
470
  ? transaction_controller_1.TransactionType.bridgeApproval
571
471
  : transaction_controller_1.TransactionType.swapApproval,
@@ -575,101 +475,11 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
575
475
  await (0, transaction_1.handleApprovalDelay)(srcChainId);
576
476
  return approvalTxMeta;
577
477
  };
578
- return await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
579
- name: isBridgeTx
580
- ? constants_1.TraceName.BridgeTransactionApprovalCompleted
581
- : constants_1.TraceName.SwapTransactionApprovalCompleted,
582
- data: {
583
- srcChainId: (0, bridge_controller_1.formatChainIdToCaip)(srcChainId),
584
- stxEnabled: false,
585
- },
586
- }, approveTx);
478
+ return await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getApprovalTraceParams)(quoteResponse, false), approveTx);
587
479
  }
588
480
  return undefined;
589
481
  });
590
- /**
591
- * Submits an EVM transaction to the TransactionController
592
- *
593
- * @param params - The parameters for the transaction
594
- * @param params.transactionType - The type of transaction to submit
595
- * @param params.trade - The trade data to confirm
596
- * @param params.requireApproval - Whether to require approval for the transaction
597
- * @param params.txFee - Optional gas fee parameters from the quote (used when gasIncluded is true)
598
- * @param params.txFee.maxFeePerGas - The maximum fee per gas from the quote
599
- * @param params.txFee.maxPriorityFeePerGas - The maximum priority fee per gas from the quote
600
- * @param params.actionId - Optional actionId for pre-submission history (if not provided, one is generated)
601
- * @returns The transaction meta
602
- */
603
- _BridgeStatusController_handleEvmTransaction.set(this, async ({ transactionType, trade, requireApproval = false, txFee, actionId: providedActionId, }) => {
604
- // Use provided actionId (for pre-submission history) or generate one
605
- const actionId = providedActionId ?? (0, transaction_1.generateActionId)().toString();
606
- const selectedAccount = this.messenger.call('AccountsController:getAccountByAddress', trade.from);
607
- if (!selectedAccount) {
608
- throw new Error('Failed to submit cross-chain swap transaction: unknown account in trade data');
609
- }
610
- const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(trade.chainId);
611
- const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', hexChainId);
612
- const requestOptions = {
613
- actionId,
614
- networkClientId,
615
- requireApproval,
616
- type: transactionType,
617
- origin: 'metamask',
618
- };
619
- // Exclude gasLimit from trade to avoid type issues (it can be null)
620
- const { gasLimit: tradeGasLimit, ...tradeWithoutGasLimit } = trade;
621
- const transactionParams = {
622
- ...tradeWithoutGasLimit,
623
- chainId: hexChainId,
624
- // Only add gasLimit and gas if they're valid (not undefined/null/zero)
625
- ...(tradeGasLimit &&
626
- tradeGasLimit !== 0 && {
627
- gasLimit: tradeGasLimit.toString(),
628
- gas: tradeGasLimit.toString(),
629
- }),
630
- };
631
- const transactionParamsWithMaxGas = {
632
- ...transactionParams,
633
- ...(await __classPrivateFieldGet(this, _BridgeStatusController_calculateGasFees, "f").call(this, transactionParams, networkClientId, hexChainId, txFee)),
634
- };
635
- const { result } = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionFn, "f").call(this, transactionParamsWithMaxGas, requestOptions);
636
- return await __classPrivateFieldGet(this, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, "f").call(this, result);
637
- });
638
- _BridgeStatusController_handleUSDTAllowanceReset.set(this, async (resetApproval) => {
639
- if (resetApproval) {
640
- await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
641
- transactionType: transaction_controller_1.TransactionType.bridgeApproval,
642
- trade: resetApproval,
643
- });
644
- }
645
- });
646
- _BridgeStatusController_calculateGasFees.set(this, async (transactionParams, networkClientId, chainId, txFee) => {
647
- const { gas } = transactionParams;
648
- // If txFee is provided (gasIncluded case), use the quote's gas fees
649
- // Convert to hex since txFee values from the quote are decimal strings
650
- if (txFee) {
651
- return {
652
- maxFeePerGas: (0, controller_utils_1.toHex)(txFee.maxFeePerGas),
653
- maxPriorityFeePerGas: (0, controller_utils_1.toHex)(txFee.maxPriorityFeePerGas),
654
- gas: gas ? (0, controller_utils_1.toHex)(gas) : undefined,
655
- };
656
- }
657
- const { gasFeeEstimates } = this.messenger.call('GasFeeController:getState');
658
- const { estimates: txGasFeeEstimates } = await __classPrivateFieldGet(this, _BridgeStatusController_estimateGasFeeFn, "f").call(this, {
659
- transactionParams,
660
- chainId,
661
- networkClientId,
662
- });
663
- const { maxFeePerGas, maxPriorityFeePerGas } = (0, gas_1.getTxGasEstimates)({
664
- networkGasFeeEstimates: gasFeeEstimates,
665
- txGasFeeEstimates,
666
- });
667
- return {
668
- maxFeePerGas,
669
- maxPriorityFeePerGas,
670
- gas: gas ? (0, controller_utils_1.toHex)(gas) : undefined,
671
- };
672
- });
482
+ // TODO simplify and make more readable
673
483
  /**
674
484
  * Submits batched EVM transactions to the TransactionController
675
485
  *
@@ -685,26 +495,9 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
685
495
  _BridgeStatusController_handleEvmTransactionBatch.set(this, async (args) => {
686
496
  const transactionParams = await (0, transaction_1.getAddTransactionBatchParams)({
687
497
  messenger: this.messenger,
688
- estimateGasFeeFn: __classPrivateFieldGet(this, _BridgeStatusController_estimateGasFeeFn, "f"),
689
498
  ...args,
690
499
  });
691
- const txDataByType = {
692
- [transaction_controller_1.TransactionType.bridgeApproval]: transactionParams.transactions.find(({ type }) => type === transaction_controller_1.TransactionType.bridgeApproval)?.params.data,
693
- [transaction_controller_1.TransactionType.swapApproval]: transactionParams.transactions.find(({ type }) => type === transaction_controller_1.TransactionType.swapApproval)?.params.data,
694
- [transaction_controller_1.TransactionType.bridge]: transactionParams.transactions.find(({ type }) => type === transaction_controller_1.TransactionType.bridge)?.params.data,
695
- [transaction_controller_1.TransactionType.swap]: transactionParams.transactions.find(({ type }) => type === transaction_controller_1.TransactionType.swap)?.params.data,
696
- };
697
- const { batchId } = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionBatchFn, "f").call(this, transactionParams);
698
- const { approvalMeta, tradeMeta } = (0, transaction_1.findAndUpdateTransactionsInBatch)({
699
- messenger: this.messenger,
700
- updateTransactionFn: __classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f"),
701
- batchId,
702
- txDataByType,
703
- });
704
- if (!tradeMeta) {
705
- throw new Error('Failed to update cross-chain swap transaction batch: tradeMeta not found');
706
- }
707
- return { approvalMeta, tradeMeta };
500
+ return await (0, transaction_1.addTransactionBatch)(this.messenger, __classPrivateFieldGet(this, _BridgeStatusController_addTransactionBatchFn, "f"), transactionParams);
708
501
  });
709
502
  /**
710
503
  * Submits a cross-chain swap transaction
@@ -719,11 +512,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
719
512
  * @returns The transaction meta
720
513
  */
721
514
  this.submitTx = async (accountAddress, quoteResponse, isStxEnabledOnClient, quotesReceivedContext, location = bridge_controller_1.MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests) => {
722
- this.messenger.call('BridgeController:stopPollingForQuotes', bridge_controller_1.AbortReason.TransactionSubmitted,
723
- // If trade is submitted before all quotes are loaded, the QuotesReceived event is published
724
- // If the trade has a featureId, it means it was submitted outside of the Unified Swap and Bridge experience, so no QuotesReceived event is published
725
- quoteResponse.featureId ? undefined : quotesReceivedContext);
726
- const selectedAccount = __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_getMultichainSelectedAccount).call(this, accountAddress);
515
+ (0, bridge_1.stopPollingForQuotes)(this.messenger, quoteResponse.featureId, quotesReceivedContext);
516
+ const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, accountAddress);
727
517
  if (!selectedAccount) {
728
518
  throw new Error('Failed to submit cross-chain swap transaction: undefined multichain account');
729
519
  }
@@ -742,19 +532,11 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
742
532
  if ((0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId)) {
743
533
  // Handle non-EVM approval if present (e.g., Tron token approvals)
744
534
  if (quoteResponse.approval && (0, bridge_controller_1.isTronTrade)(quoteResponse.approval)) {
745
- const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
746
- name: isBridgeTx
747
- ? constants_1.TraceName.BridgeTransactionApprovalCompleted
748
- : constants_1.TraceName.SwapTransactionApprovalCompleted,
749
- data: {
750
- srcChainId: (0, bridge_controller_1.formatChainIdToCaip)(quoteResponse.quote.srcChainId),
751
- stxEnabled: false,
752
- },
753
- }, async () => {
535
+ const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getApprovalTraceParams)(quoteResponse, false), async () => {
754
536
  try {
755
537
  return quoteResponse.approval &&
756
538
  (0, bridge_controller_1.isTronTrade)(quoteResponse.approval)
757
- ? await __classPrivateFieldGet(this, _BridgeStatusController_handleNonEvmTx, "f").call(this, quoteResponse.approval, quoteResponse, selectedAccount)
539
+ ? await (0, snaps_1.handleNonEvmTx)(this.messenger, quoteResponse.approval, quoteResponse, selectedAccount)
758
540
  : /* c8 ignore start */
759
541
  undefined;
760
542
  /* c8 ignore end */
@@ -772,22 +554,14 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
772
554
  // Add delay after approval similar to EVM flow
773
555
  await (0, transaction_1.handleApprovalDelay)(quoteResponse.quote.srcChainId);
774
556
  }
775
- txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
776
- name: isBridgeTx
777
- ? constants_1.TraceName.BridgeTransactionCompleted
778
- : constants_1.TraceName.SwapTransactionCompleted,
779
- data: {
780
- srcChainId: (0, bridge_controller_1.formatChainIdToCaip)(quoteResponse.quote.srcChainId),
781
- stxEnabled: false,
782
- },
783
- }, async () => {
557
+ txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getTraceParams)(quoteResponse, false), async () => {
784
558
  try {
785
559
  if (!((0, bridge_controller_1.isTronTrade)(quoteResponse.trade) ||
786
560
  (0, bridge_controller_1.isBitcoinTrade)(quoteResponse.trade) ||
787
561
  typeof quoteResponse.trade === 'string')) {
788
562
  throw new Error('Failed to submit cross-chain swap transaction: trade is not a non-EVM transaction');
789
563
  }
790
- return await __classPrivateFieldGet(this, _BridgeStatusController_handleNonEvmTx, "f").call(this, quoteResponse.trade, quoteResponse, selectedAccount);
564
+ return await (0, snaps_1.handleNonEvmTx)(this.messenger, quoteResponse.trade, quoteResponse, selectedAccount);
791
565
  }
792
566
  catch (error) {
793
567
  !quoteResponse.featureId &&
@@ -805,15 +579,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
805
579
  // Extension does not have this issue
806
580
  const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE && isHardwareAccount;
807
581
  // Handle smart transactions if enabled
808
- txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, {
809
- name: isBridgeTx
810
- ? constants_1.TraceName.BridgeTransactionCompleted
811
- : constants_1.TraceName.SwapTransactionCompleted,
812
- data: {
813
- srcChainId: (0, bridge_controller_1.formatChainIdToCaip)(quoteResponse.quote.srcChainId),
814
- stxEnabled: isStxEnabledOnClient,
815
- },
816
- }, async () => {
582
+ txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getTraceParams)(quoteResponse, isStxEnabledOnClient), async () => {
817
583
  if (!(0, bridge_controller_1.isEvmTxData)(quoteResponse.trade)) {
818
584
  throw new Error('Failed to submit cross-chain swap transaction: trade is not an EVM transaction');
819
585
  }
@@ -821,18 +587,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
821
587
  // Delegated accounts only allow 1 in-flight tx, so approve + swap
822
588
  // must be batched into a single transaction
823
589
  const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.srcChainId);
824
- isDelegatedAccount = await (async () => {
825
- try {
826
- const atomicBatchSupport = await this.messenger.call('TransactionController:isAtomicBatchSupported', {
827
- address: quoteResponse.trade.from,
828
- chainIds: [hexChainId],
829
- });
830
- return atomicBatchSupport.some((entry) => entry.isSupported && entry.delegationAddress);
831
- }
832
- catch {
833
- return false;
834
- }
835
- })();
590
+ isDelegatedAccount = await (0, transaction_1.checkIsDelegatedAccount)(this.messenger, quoteResponse.trade.from, [hexChainId]);
836
591
  if (isStxEnabledOnClient ||
837
592
  quoteResponse.quote.gasIncluded7702 ||
838
593
  isDelegatedAccount) {
@@ -851,21 +606,25 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
851
606
  return tradeMeta;
852
607
  }
853
608
  // Set approval time and id if an approval tx is needed
854
- const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && (0, bridge_controller_1.isEvmTxData)(quoteResponse.approval)
609
+ const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && (0, bridge_controller_1.isEvmTxData)(quoteResponse.approval)
855
610
  ? quoteResponse.approval
856
611
  : undefined, quoteResponse.resetApproval, requireApproval);
857
612
  approvalTxId = approvalTxMeta?.id;
858
- await (0, transaction_1.handleMobileHardwareWalletDelay)(requireApproval);
613
+ // Hardware-wallet delay first (Ledger second-prompt spacing), then wait for
614
+ // on-chain approval confirmation so swap gas estimation runs after allowance is set.
615
+ if (requireApproval && approvalTxMeta) {
616
+ await (0, transaction_1.handleMobileHardwareWalletDelay)(requireApproval);
617
+ await (0, transaction_1.waitForTxConfirmation)(this.messenger, approvalTxMeta.id);
618
+ }
619
+ else {
620
+ await (0, transaction_1.handleMobileHardwareWalletDelay)(requireApproval);
621
+ }
859
622
  // Generate actionId for pre-submission history (non-batch EVM only)
860
623
  const actionId = (0, transaction_1.generateActionId)().toString();
861
624
  // Add pre-submission history keyed by actionId
862
625
  // This ensures we have quote data available if transaction fails during submission
863
626
  __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
864
627
  accountAddress: selectedAccount.address,
865
- statusRequest: {
866
- ...(0, transaction_1.getStatusRequestParams)(quoteResponse),
867
- srcTxHash: '', // Not available yet
868
- },
869
628
  quoteResponse,
870
629
  slippagePercentage: 0,
871
630
  isStxEnabled: isStxEnabledOnClient,
@@ -874,10 +633,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
874
633
  location,
875
634
  abTests,
876
635
  activeAbTests,
877
- }, actionId);
636
+ actionId,
637
+ });
878
638
  // Pass txFee when gasIncluded is true to use the quote's gas fees
879
639
  // instead of re-estimating (which would fail for max native token swaps)
880
- const tradeTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
640
+ const tradeTxMeta = await (0, transaction_1.submitEvmTransaction)({
641
+ messenger: this.messenger,
881
642
  transactionType: isBridgeTx
882
643
  ? transaction_controller_1.TransactionType.bridge
883
644
  : transaction_controller_1.TransactionType.swap,
@@ -905,10 +666,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
905
666
  __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
906
667
  accountAddress: selectedAccount.address,
907
668
  bridgeTxMeta: txMeta, // Only the id field is used by the BridgeStatusController
908
- statusRequest: {
909
- ...(0, transaction_1.getStatusRequestParams)(quoteResponse),
910
- srcTxHash: txMeta.hash,
911
- },
912
669
  quoteResponse,
913
670
  slippagePercentage: 0, // TODO include slippage provided by quote if using dynamic slippage, or slippage from quote request
914
671
  isStxEnabled: isStxEnabledOnClient,
@@ -947,28 +704,31 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
947
704
  */
948
705
  this.submitIntent = async (params) => {
949
706
  const { quoteResponse, accountAddress, location, abTests, activeAbTests } = params;
950
- this.messenger.call('BridgeController:stopPollingForQuotes', bridge_controller_1.AbortReason.TransactionSubmitted);
707
+ // TODO add metrics context
708
+ (0, bridge_1.stopPollingForQuotes)(this.messenger);
709
+ const startTime = Date.now();
951
710
  // Build pre-confirmation properties for error tracking parity with submitTx
952
- const account = __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_getMultichainSelectedAccount).call(this, accountAddress);
711
+ const account = (0, accounts_1.getAccountByAddress)(this.messenger, accountAddress);
953
712
  const isHardwareAccount = Boolean(account) && (0, bridge_controller_1.isHardwareWallet)(account);
954
713
  const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, false, isHardwareAccount, location, abTests, activeAbTests);
955
714
  try {
956
- const intent = (0, transaction_1.getIntentFromQuote)(quoteResponse);
715
+ const intent = (0, intent_api_1.getIntentFromQuote)(quoteResponse);
957
716
  // If backend provided an approval tx for this intent quote, submit it first (on-chain),
958
717
  // then proceed with off-chain intent submission.
959
718
  const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
960
719
  const requireApproval = isHardwareAccount && __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE;
961
720
  // Handle approval silently for better UX in intent flows
962
- const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval, quoteResponse.resetApproval, requireApproval);
721
+ const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval, quoteResponse.resetApproval, requireApproval);
963
722
  const approvalTxId = approvalTxMeta?.id;
964
723
  if (approvalTxId) {
965
- await __classPrivateFieldGet(this, _BridgeStatusController_waitForTxConfirmation, "f").call(this, approvalTxId);
724
+ await (0, transaction_1.waitForTxConfirmation)(this.messenger, approvalTxId);
966
725
  }
967
726
  const { srcChainId, requestId } = quoteResponse.quote;
968
- const signature = await this.messenger.call('KeyringController:signTypedMessage', {
969
- from: accountAddress,
970
- data: intent.typedData,
971
- }, keyring_controller_1.SignTypedDataVersion.V4);
727
+ const signature = await (0, keyring_1.signTypedMessage)({
728
+ messenger: this.messenger,
729
+ accountAddress,
730
+ typedData: intent.typedData,
731
+ });
972
732
  const submissionParams = {
973
733
  srcChainId,
974
734
  quoteId: requestId,
@@ -977,8 +737,13 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
977
737
  userAddress: accountAddress,
978
738
  aggregatorId: intent.protocol,
979
739
  };
980
- const intentOrder = await __classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").submitIntent(submissionParams, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"));
981
- const orderUid = intentOrder.id;
740
+ const { id: orderUid, status } = await (0, intent_api_1.postSubmitOrder)({
741
+ params: submissionParams,
742
+ clientId: __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"),
743
+ jwt: await (0, authentication_1.getJwt)(this.messenger),
744
+ fetchFn: __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"),
745
+ bridgeApiBaseUrl: __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl,
746
+ });
982
747
  // Determine transaction type: swap for same-chain, bridge for cross-chain
983
748
  const transactionType = isBridgeTx
984
749
  ? /* c8 ignore start */
@@ -986,7 +751,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
986
751
  : /* c8 ignore end */
987
752
  transaction_controller_1.TransactionType.swap;
988
753
  // Create actual transaction in Transaction Controller first
989
- const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', (0, bridge_controller_1.formatChainIdToHex)(srcChainId));
754
+ const networkClientId = (0, network_1.getNetworkClientIdByChainId)(this.messenger, srcChainId);
990
755
  // This is a synthetic transaction whose purpose is to be able
991
756
  // to track the order status via the history
992
757
  const intentTransactionParams = {
@@ -999,25 +764,16 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
999
764
  gas: '0x5208', // Minimal gas for display purposes
1000
765
  gasPrice: '0x3b9aca00', // 1 Gwei - will be converted to EIP-1559 fees if network supports it
1001
766
  };
1002
- const { transactionMeta: txMetaPromise } = await __classPrivateFieldGet(this, _BridgeStatusController_addTransactionFn, "f").call(this, intentTransactionParams, {
1003
- origin: 'metamask',
1004
- actionId: (0, transaction_1.generateActionId)(),
767
+ const initialTxMeta = await (0, transaction_1.addSyntheticTransaction)(this.messenger, intentTransactionParams, {
1005
768
  requireApproval: false,
1006
- isStateOnly: true,
1007
769
  networkClientId,
1008
770
  type: transactionType,
1009
771
  });
1010
- const intentTxMeta = txMetaPromise;
1011
- // Map intent order status to TransactionController status
1012
- const initialTransactionStatus = (0, intent_api_1.mapIntentOrderStatusToTransactionStatus)(intentOrder.status);
1013
- // Update transaction with proper initial status based on intent order
1014
- const statusUpdatedTxMeta = {
1015
- ...intentTxMeta,
1016
- status: initialTransactionStatus,
1017
- };
1018
- // Update with actual transaction metadata
772
+ // Update txHistory with actual transaction metadata
1019
773
  const syntheticMeta = {
1020
- ...statusUpdatedTxMeta,
774
+ ...initialTxMeta,
775
+ // Map intent order status to TransactionController status
776
+ status: (0, intent_api_1.mapIntentOrderStatusToTransactionStatus)(status),
1021
777
  isIntentTx: true,
1022
778
  orderUid,
1023
779
  };
@@ -1031,14 +787,9 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
1031
787
  id: bridgeHistoryKey,
1032
788
  originalTransactionId: syntheticMeta.id, // Keep original txId for TransactionController updates
1033
789
  };
1034
- const startTime = Date.now();
1035
790
  __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
1036
791
  accountAddress,
1037
792
  bridgeTxMeta: bridgeTxMetaForHistory,
1038
- statusRequest: {
1039
- ...(0, transaction_1.getStatusRequestParams)(quoteResponse),
1040
- srcTxHash: syntheticMeta.hash ?? '',
1041
- },
1042
793
  quoteResponse,
1043
794
  slippagePercentage: 0,
1044
795
  isStxEnabled: false,
@@ -1099,35 +850,48 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
1099
850
  };
1100
851
  // This will publish events for PERPS dropped tx failures as well
1101
852
  if (!txMetaId) {
1102
- this.messenger.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, baseProperties);
853
+ (0, bridge_1.trackMetricsEvent)({
854
+ messenger: this.messenger,
855
+ eventName,
856
+ properties: baseProperties,
857
+ });
1103
858
  return;
1104
859
  }
1105
860
  const historyItem = this.state.txHistory[txMetaId];
1106
861
  if (!historyItem) {
1107
- this.messenger.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, baseProperties);
862
+ (0, bridge_1.trackMetricsEvent)({
863
+ messenger: this.messenger,
864
+ eventName,
865
+ properties: baseProperties,
866
+ });
1108
867
  return;
1109
868
  }
869
+ const { featureId, approvalTxId, quote } = historyItem;
1110
870
  const requestParamProperties = (0, metrics_1.getRequestParamFromHistory)(historyItem);
1111
871
  // Always publish StatusValidationFailed event, regardless of featureId
1112
872
  if (eventName === bridge_controller_1.UnifiedSwapBridgeEventName.StatusValidationFailed) {
1113
- this.messenger.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, {
1114
- ...baseProperties,
1115
- chain_id_source: requestParamProperties.chain_id_source,
1116
- chain_id_destination: requestParamProperties.chain_id_destination,
1117
- token_address_source: requestParamProperties.token_address_source,
1118
- token_address_destination: requestParamProperties.token_address_destination,
1119
- refresh_count: historyItem.attempts?.counter ?? 0,
873
+ (0, bridge_1.trackMetricsEvent)({
874
+ messenger: this.messenger,
875
+ eventName,
876
+ properties: {
877
+ ...baseProperties,
878
+ chain_id_source: requestParamProperties.chain_id_source,
879
+ chain_id_destination: requestParamProperties.chain_id_destination,
880
+ token_address_source: requestParamProperties.token_address_source,
881
+ token_address_destination: requestParamProperties.token_address_destination,
882
+ refresh_count: historyItem.attempts?.counter ?? 0,
883
+ },
1120
884
  });
1121
885
  return;
1122
886
  }
1123
887
  // Skip tracking all other events when featureId is set (i.e. PERPS)
1124
- if (historyItem.featureId) {
888
+ if (featureId) {
1125
889
  return;
1126
890
  }
1127
- const selectedAccount = this.messenger.call('AccountsController:getAccountByAddress', historyItem.account);
1128
- const { transactions } = this.messenger.call('TransactionController:getState');
1129
- const txMeta = transactions?.find((tx) => tx.id === txMetaId);
1130
- const approvalTxMeta = transactions?.find((tx) => tx.id === historyItem.approvalTxId);
891
+ const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, historyItem.account);
892
+ const transactions = (0, transaction_1.getTransactions)(this.messenger);
893
+ const txMeta = transactions.find((tx) => tx.id === txMetaId);
894
+ const approvalTxMeta = transactions.find((tx) => tx.id === approvalTxId);
1131
895
  const requiredEventProperties = {
1132
896
  ...baseProperties,
1133
897
  ...requestParamProperties,
@@ -1135,26 +899,25 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
1135
899
  ...(0, metrics_1.getTradeDataFromHistory)(historyItem),
1136
900
  ...(0, metrics_1.getTxStatusesFromHistory)(historyItem),
1137
901
  ...(0, metrics_1.getFinalizedTxProperties)(historyItem, txMeta, approvalTxMeta),
1138
- ...(0, metrics_1.getPriceImpactFromQuote)(historyItem.quote),
902
+ ...(0, metrics_1.getPriceImpactFromQuote)(quote),
1139
903
  };
1140
- this.messenger.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, requiredEventProperties);
904
+ (0, bridge_1.trackMetricsEvent)({
905
+ messenger: this.messenger,
906
+ eventName,
907
+ properties: requiredEventProperties,
908
+ });
1141
909
  });
1142
910
  __classPrivateFieldSet(this, _BridgeStatusController_clientId, clientId, "f");
1143
911
  __classPrivateFieldSet(this, _BridgeStatusController_fetchFn, fetchFn, "f");
1144
- __classPrivateFieldSet(this, _BridgeStatusController_addTransactionFn, addTransactionFn, "f");
1145
912
  __classPrivateFieldSet(this, _BridgeStatusController_addTransactionBatchFn, addTransactionBatchFn, "f");
1146
- __classPrivateFieldSet(this, _BridgeStatusController_updateTransactionFn, updateTransactionFn, "f");
1147
- __classPrivateFieldSet(this, _BridgeStatusController_estimateGasFeeFn, estimateGasFeeFn, "f");
1148
913
  __classPrivateFieldSet(this, _BridgeStatusController_config, {
1149
914
  customBridgeApiBaseUrl: config?.customBridgeApiBaseUrl ?? constants_1.BRIDGE_PROD_API_BASE_URL,
1150
915
  }, "f");
1151
916
  __classPrivateFieldSet(this, _BridgeStatusController_trace, traceFn ?? ((_request, fn) => fn?.()), "f");
1152
917
  __classPrivateFieldSet(this, _BridgeStatusController_intentManager, new bridge_status_controller_intent_1.IntentManager({
1153
918
  messenger: this.messenger,
1154
- updateTransactionFn: __classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f"),
1155
919
  customBridgeApiBaseUrl: __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl,
1156
920
  fetchFn: __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"),
1157
- getJwt: __classPrivateFieldGet(this, _BridgeStatusController_getJwt, "f"),
1158
921
  }), "f");
1159
922
  // Register action handlers
1160
923
  this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:startPollingForBridgeTxStatus`, this.startPollingForBridgeTxStatus.bind(this));
@@ -1212,7 +975,5 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
1212
975
  }
1213
976
  }
1214
977
  exports.BridgeStatusController = BridgeStatusController;
1215
- _BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_intentManager = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(), _BridgeStatusController_addTransactionFn = new WeakMap(), _BridgeStatusController_addTransactionBatchFn = new WeakMap(), _BridgeStatusController_updateTransactionFn = new WeakMap(), _BridgeStatusController_estimateGasFeeFn = new WeakMap(), _BridgeStatusController_trace = new WeakMap(), _BridgeStatusController_markTxAsFailed = new WeakMap(), _BridgeStatusController_restartPollingForIncompleteHistoryItems = new WeakMap(), _BridgeStatusController_addTxToHistory = new WeakMap(), _BridgeStatusController_rekeyHistoryItem = new WeakMap(), _BridgeStatusController_startPollingForTxId = new WeakMap(), _BridgeStatusController_shouldPollHistoryItem = new WeakMap(), _BridgeStatusController_handleFetchFailure = new WeakMap(), _BridgeStatusController_fetchBridgeTxStatus = new WeakMap(), _BridgeStatusController_getJwt = new WeakMap(), _BridgeStatusController_getSrcTxHash = new WeakMap(), _BridgeStatusController_updateSrcTxHash = new WeakMap(), _BridgeStatusController_wipeBridgeStatusByChainId = new WeakMap(), _BridgeStatusController_handleNonEvmTx = new WeakMap(), _BridgeStatusController_waitForHashAndReturnFinalTxMeta = new WeakMap(), _BridgeStatusController_waitForTxConfirmation = new WeakMap(), _BridgeStatusController_handleApprovalTx = new WeakMap(), _BridgeStatusController_handleEvmTransaction = new WeakMap(), _BridgeStatusController_handleUSDTAllowanceReset = new WeakMap(), _BridgeStatusController_calculateGasFees = new WeakMap(), _BridgeStatusController_handleEvmTransactionBatch = new WeakMap(), _BridgeStatusController_trackUnifiedSwapBridgeEvent = new WeakMap(), _BridgeStatusController_instances = new WeakSet(), _BridgeStatusController_getMultichainSelectedAccount = function _BridgeStatusController_getMultichainSelectedAccount(accountAddress) {
1216
- return this.messenger.call('AccountsController:getAccountByAddress', accountAddress);
1217
- };
978
+ _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_markTxAsFailed = new WeakMap(), _BridgeStatusController_restartPollingForIncompleteHistoryItems = new WeakMap(), _BridgeStatusController_addTxToHistory = new WeakMap(), _BridgeStatusController_rekeyHistoryItem = new WeakMap(), _BridgeStatusController_startPollingForTxId = new WeakMap(), _BridgeStatusController_handleFetchFailure = new WeakMap(), _BridgeStatusController_fetchBridgeTxStatus = new WeakMap(), _BridgeStatusController_getSrcTxHash = new WeakMap(), _BridgeStatusController_updateSrcTxHash = new WeakMap(), _BridgeStatusController_wipeBridgeStatusByChainId = new WeakMap(), _BridgeStatusController_handleApprovalTx = new WeakMap(), _BridgeStatusController_handleEvmTransactionBatch = new WeakMap(), _BridgeStatusController_trackUnifiedSwapBridgeEvent = new WeakMap();
1218
979
  //# sourceMappingURL=bridge-status-controller.cjs.map