@metamask-previews/bridge-status-controller 65.0.1-preview-fb7aa07ff → 65.0.1-preview-8f3469e9c

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 (38) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/bridge-status-controller.cjs +67 -226
  3. package/dist/bridge-status-controller.cjs.map +1 -1
  4. package/dist/bridge-status-controller.d.cts.map +1 -1
  5. package/dist/bridge-status-controller.d.mts.map +1 -1
  6. package/dist/bridge-status-controller.intent.cjs +70 -0
  7. package/dist/bridge-status-controller.intent.cjs.map +1 -0
  8. package/dist/bridge-status-controller.intent.d.cts +13 -0
  9. package/dist/bridge-status-controller.intent.d.cts.map +1 -0
  10. package/dist/bridge-status-controller.intent.d.mts +13 -0
  11. package/dist/bridge-status-controller.intent.d.mts.map +1 -0
  12. package/dist/bridge-status-controller.intent.mjs +66 -0
  13. package/dist/bridge-status-controller.intent.mjs.map +1 -0
  14. package/dist/bridge-status-controller.mjs +70 -229
  15. package/dist/bridge-status-controller.mjs.map +1 -1
  16. package/dist/types.cjs.map +1 -1
  17. package/dist/types.d.cts +0 -7
  18. package/dist/types.d.cts.map +1 -1
  19. package/dist/types.d.mts +0 -7
  20. package/dist/types.d.mts.map +1 -1
  21. package/dist/types.mjs.map +1 -1
  22. package/dist/utils/intent-api.cjs +42 -7
  23. package/dist/utils/intent-api.cjs.map +1 -1
  24. package/dist/utils/intent-api.d.cts +7 -4
  25. package/dist/utils/intent-api.d.cts.map +1 -1
  26. package/dist/utils/intent-api.d.mts +7 -4
  27. package/dist/utils/intent-api.d.mts.map +1 -1
  28. package/dist/utils/intent-api.mjs +38 -3
  29. package/dist/utils/intent-api.mjs.map +1 -1
  30. package/dist/utils/transaction.cjs +44 -1
  31. package/dist/utils/transaction.cjs.map +1 -1
  32. package/dist/utils/transaction.d.cts +9 -0
  33. package/dist/utils/transaction.d.cts.map +1 -1
  34. package/dist/utils/transaction.d.mts +9 -0
  35. package/dist/utils/transaction.d.mts.map +1 -1
  36. package/dist/utils/transaction.mjs +41 -0
  37. package/dist/utils/transaction.mjs.map +1 -1
  38. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -9,9 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
- - Bump `@metamask/transaction-controller` from `^62.11.0` to `^62.13.0` ([#7775](https://github.com/MetaMask/core/pull/7775), [#7802](https://github.com/MetaMask/core/pull/7802))
12
+ - Bump `@metamask/transaction-controller` from `^62.11.0` to `^62.14.0` ([#7775](https://github.com/MetaMask/core/pull/7775), [#7802](https://github.com/MetaMask/core/pull/7802), [#7832](https://github.com/MetaMask/core/pull/7832))
13
13
  - Bump `@metamask/bridge-controller` from `^65.1.0` to `^65.2.0` ([#7802](https://github.com/MetaMask/core/pull/7802))
14
14
 
15
+ ### Fixed
16
+
17
+ - Fix Tron same-chain swap polling and Completed event tracking ([#7697](https://github.com/MetaMask/core/pull/7697))
18
+
15
19
  ## [65.0.1]
16
20
 
17
21
  ### Changed
@@ -41,6 +45,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
41
45
 
42
46
  - Bump `@metamask/bridge-controller` from `^64.5.1` to `^64.8.1` ([#7667](https://github.com/MetaMask/core/pull/7667), [#7672](https://github.com/MetaMask/core/pull/7672), [#7694](https://github.com/MetaMask/core/pull/7694), [#7700](https://github.com/MetaMask/core/pull/7700), [#7704](https://github.com/MetaMask/core/pull/7704))
43
47
 
48
+ ### Fixed
49
+
50
+ - Fix Tron same-chain swap polling and Completed event tracking ([#7697](https://github.com/MetaMask/core/pull/7697))
51
+
44
52
  ## [64.4.3]
45
53
 
46
54
  ### Changed
@@ -10,7 +10,7 @@ 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_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_getMultichainSelectedAccount, _BridgeStatusController_handleFetchFailure, _BridgeStatusController_fetchBridgeTxStatus, _BridgeStatusController_fetchIntentOrderStatus, _BridgeStatusController_updateBridgeHistoryFromIntentOrder, _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_instances, _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_intentStatusManager, _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_getSrcTxHash, _BridgeStatusController_updateSrcTxHash, _BridgeStatusController_wipeBridgeStatusByChainId, _BridgeStatusController_handleNonEvmTx, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, _BridgeStatusController_waitForTxConfirmation, _BridgeStatusController_handleApprovalTx, _BridgeStatusController_handleEvmTransaction, _BridgeStatusController_handleUSDTAllowanceReset, _BridgeStatusController_calculateGasFees, _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");
@@ -18,6 +18,7 @@ const controller_utils_1 = require("@metamask/controller-utils");
18
18
  const polling_controller_1 = require("@metamask/polling-controller");
19
19
  const transaction_controller_1 = require("@metamask/transaction-controller");
20
20
  const utils_1 = require("@metamask/utils");
21
+ const bridge_status_controller_intent_1 = require("./bridge-status-controller.intent.cjs");
21
22
  const constants_1 = require("./constants.cjs");
22
23
  const types_1 = require("./types.cjs");
23
24
  const bridge_status_1 = require("./utils/bridge-status.cjs");
@@ -25,7 +26,6 @@ const gas_1 = require("./utils/gas.cjs");
25
26
  const intent_api_1 = require("./utils/intent-api.cjs");
26
27
  const metrics_1 = require("./utils/metrics.cjs");
27
28
  const transaction_1 = require("./utils/transaction.cjs");
28
- const validators_1 = require("./utils/validators.cjs");
29
29
  const metadata = {
30
30
  // We want to persist the bridge status state so that we can show the proper data for the Activity list
31
31
  // basically match the behavior of TransactionController
@@ -50,6 +50,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
50
50
  });
51
51
  _BridgeStatusController_instances.add(this);
52
52
  _BridgeStatusController_pollingTokensByTxMetaId.set(this, {});
53
+ _BridgeStatusController_intentStatusManager.set(this, void 0);
53
54
  _BridgeStatusController_clientId.set(this, void 0);
54
55
  _BridgeStatusController_fetchFn.set(this, void 0);
55
56
  _BridgeStatusController_config.set(this, void 0);
@@ -132,9 +133,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
132
133
  state.txHistory[targetTxMetaId].attempts = undefined;
133
134
  }
134
135
  });
135
- // Restart polling if it was stopped and this is a bridge transaction
136
- const isBridgeTx = (0, bridge_controller_1.isCrossChain)(historyItem.quote.srcChainId, historyItem.quote.destChainId);
137
- if (isBridgeTx) {
136
+ // Restart polling if it was stopped and this tx still needs status updates
137
+ if (__classPrivateFieldGet(this, _BridgeStatusController_shouldPollHistoryItem, "f").call(this, historyItem)) {
138
138
  // Check if polling was stopped (no active polling token)
139
139
  const existingPollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[targetTxMetaId];
140
140
  if (!existingPollingToken) {
@@ -170,10 +170,9 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
170
170
  const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[historyItem.txMetaId];
171
171
  return !pollingToken;
172
172
  })
173
- // Swap txs don't need to have their statuses polled
173
+ // Only restart polling for items that still require status updates
174
174
  .filter((historyItem) => {
175
- const isBridgeTx = (0, bridge_controller_1.isCrossChain)(historyItem.quote.srcChainId, historyItem.quote.destChainId);
176
- return isBridgeTx;
175
+ return __classPrivateFieldGet(this, _BridgeStatusController_shouldPollHistoryItem, "f").call(this, historyItem);
177
176
  });
178
177
  incompleteHistoryItems.forEach((historyItem) => {
179
178
  const bridgeTxMetaId = historyItem.txMetaId;
@@ -243,28 +242,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
243
242
  * @param txMeta.hash - The transaction hash to set on the history item
244
243
  */
245
244
  _BridgeStatusController_rekeyHistoryItem.set(this, (actionId, txMeta) => {
246
- const historyItem = this.state.txHistory[actionId];
247
- if (!historyItem) {
248
- return;
249
- }
250
245
  this.update((state) => {
251
- // Update fields that weren't available pre-submission
252
- const updatedItem = {
253
- ...historyItem,
254
- txMetaId: txMeta.id,
255
- originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,
256
- status: {
257
- ...historyItem.status,
258
- srcChain: {
259
- ...historyItem.status.srcChain,
260
- txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,
261
- },
262
- },
263
- };
264
- // Add under new key (txMeta.id)
265
- state.txHistory[txMeta.id] = updatedItem;
266
- // Remove old key (actionId)
267
- delete state.txHistory[actionId];
246
+ (0, transaction_1.rekeyHistoryItemInState)(state, actionId, txMeta);
268
247
  });
269
248
  });
270
249
  _BridgeStatusController_startPollingForTxId.set(this, (txId) => {
@@ -277,15 +256,18 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
277
256
  if (!txHistoryItem) {
278
257
  return;
279
258
  }
280
- const { quote } = txHistoryItem;
281
- const isIntent = txId.startsWith('intent:');
282
- const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quote.srcChainId, quote.destChainId);
283
- if (isBridgeTx || isIntent) {
259
+ if (__classPrivateFieldGet(this, _BridgeStatusController_shouldPollHistoryItem, "f").call(this, txHistoryItem)) {
284
260
  __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId] = this.startPolling({
285
261
  bridgeTxMetaId: txId,
286
262
  });
287
263
  }
288
264
  });
265
+ _BridgeStatusController_shouldPollHistoryItem.set(this, (historyItem) => {
266
+ const isIntent = Boolean(historyItem?.quote?.intent);
267
+ const isBridgeTx = (0, bridge_controller_1.isCrossChain)(historyItem.quote.srcChainId, historyItem.quote.destChainId);
268
+ const isTronTx = (0, bridge_controller_1.isTronChainId)(historyItem.quote.srcChainId);
269
+ return [isBridgeTx, isIntent, isTronTx].some(Boolean);
270
+ });
289
271
  /**
290
272
  * @deprecated For EVM/Solana swap/bridge txs we add tx to history in submitTx()
291
273
  * For Solana swap/bridge we start polling in submitTx()
@@ -341,33 +323,52 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
341
323
  });
342
324
  });
343
325
  _BridgeStatusController_fetchBridgeTxStatus.set(this, async ({ bridgeTxMetaId, }) => {
326
+ // 1. Check for history item
344
327
  const { txHistory } = this.state;
345
- // Intent-based items: poll intent provider instead of Bridge API
346
- if (bridgeTxMetaId.startsWith('intent:')) {
347
- await __classPrivateFieldGet(this, _BridgeStatusController_fetchIntentOrderStatus, "f").call(this, { bridgeTxMetaId });
328
+ const historyItem = txHistory[bridgeTxMetaId];
329
+ if (!historyItem) {
348
330
  return;
349
331
  }
350
- if ((0, bridge_status_1.shouldSkipFetchDueToFetchFailures)(txHistory[bridgeTxMetaId]?.attempts)) {
332
+ // 2. Check for previous failures
333
+ if ((0, bridge_status_1.shouldSkipFetchDueToFetchFailures)(historyItem.attempts)) {
351
334
  return;
352
335
  }
336
+ // 3. Fetch transcation status
353
337
  try {
354
- // We try here because we receive 500 errors from Bridge API if we try to fetch immediately after submitting the source tx
355
- // Oddly mostly happens on Optimism, never on Arbitrum. By the 2nd fetch, the Bridge API responds properly.
356
- // Also srcTxHash may not be available immediately for STX, so we don't want to fetch in those cases
357
- const historyItem = txHistory[bridgeTxMetaId];
358
- const srcTxHash = __classPrivateFieldGet(this, _BridgeStatusController_getSrcTxHash, "f").call(this, bridgeTxMetaId);
359
- if (!srcTxHash) {
360
- return;
338
+ let status;
339
+ let validationFailures = [];
340
+ let intentTranslation = null;
341
+ let intentOrderStatus;
342
+ const isIntent = Boolean(historyItem.quote.intent);
343
+ if (isIntent) {
344
+ const { srcChainId } = historyItem.quote;
345
+ const intentApi = new intent_api_1.IntentApiImpl(__classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl, __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"));
346
+ const intentOrder = await intentApi.getOrderStatus(bridgeTxMetaId, historyItem.quote.intent?.protocol ?? '', srcChainId.toString(), __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"));
347
+ intentOrderStatus = intentOrder.status;
348
+ intentTranslation = (0, intent_api_1.translateIntentOrderToBridgeStatus)(intentOrder, srcChainId, historyItem.status.srcChain.txHash);
349
+ status = intentTranslation.status;
350
+ }
351
+ else {
352
+ // We try here because we receive 500 errors from Bridge API if we try to fetch immediately after submitting the source tx
353
+ // Oddly mostly happens on Optimism, never on Arbitrum. By the 2nd fetch, the Bridge API responds properly.
354
+ // Also srcTxHash may not be available immediately for STX, so we don't want to fetch in those cases
355
+ const srcTxHash = __classPrivateFieldGet(this, _BridgeStatusController_getSrcTxHash, "f").call(this, bridgeTxMetaId);
356
+ if (!srcTxHash) {
357
+ return;
358
+ }
359
+ __classPrivateFieldGet(this, _BridgeStatusController_updateSrcTxHash, "f").call(this, bridgeTxMetaId, srcTxHash);
360
+ const statusRequest = (0, bridge_status_1.getStatusRequestWithSrcTxHash)(historyItem.quote, srcTxHash);
361
+ const response = await (0, bridge_status_1.fetchBridgeTxStatus)(statusRequest, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"), __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl);
362
+ status = response.status;
363
+ validationFailures = response.validationFailures;
361
364
  }
362
- __classPrivateFieldGet(this, _BridgeStatusController_updateSrcTxHash, "f").call(this, bridgeTxMetaId, srcTxHash);
363
- const statusRequest = (0, bridge_status_1.getStatusRequestWithSrcTxHash)(historyItem.quote, srcTxHash);
364
- const { status, validationFailures } = await (0, bridge_status_1.fetchBridgeTxStatus)(statusRequest, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"), __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl);
365
365
  if (validationFailures.length > 0) {
366
366
  __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.StatusValidationFailed, bridgeTxMetaId, {
367
367
  failures: validationFailures,
368
368
  });
369
369
  throw new Error(`Bridge status validation failed: ${validationFailures.join(', ')}`);
370
370
  }
371
+ // 4. Create bridge history item
371
372
  const newBridgeHistoryItem = {
372
373
  ...historyItem,
373
374
  status,
@@ -384,6 +385,10 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
384
385
  this.update((state) => {
385
386
  state.txHistory[bridgeTxMetaId] = newBridgeHistoryItem;
386
387
  });
388
+ if (isIntent && intentTranslation && intentOrderStatus) {
389
+ __classPrivateFieldGet(this, _BridgeStatusController_intentStatusManager, "f").syncTransactionFromIntentStatus(bridgeTxMetaId, historyItem, intentTranslation, intentOrderStatus);
390
+ }
391
+ // 5. After effects
387
392
  const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
388
393
  const isFinalStatus = status.status === bridge_controller_1.StatusTypes.COMPLETE ||
389
394
  status.status === bridge_controller_1.StatusTypes.FAILED;
@@ -408,33 +413,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
408
413
  __classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
409
414
  }
410
415
  });
411
- _BridgeStatusController_fetchIntentOrderStatus.set(this, async ({ bridgeTxMetaId, }) => {
412
- /* c8 ignore start */
413
- const { txHistory } = this.state;
414
- const historyItem = txHistory[bridgeTxMetaId];
415
- if (!historyItem) {
416
- return;
417
- }
418
- // Backoff handling
419
- if ((0, bridge_status_1.shouldSkipFetchDueToFetchFailures)(historyItem.attempts)) {
420
- return;
421
- }
422
- try {
423
- const orderId = bridgeTxMetaId.replace(/^intent:/u, '');
424
- const { srcChainId } = historyItem.quote;
425
- // Extract provider name from order metadata or default to empty
426
- const providerName = historyItem.quote.intent?.protocol ?? '';
427
- const intentApi = new intent_api_1.IntentApiImpl(__classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl, __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"));
428
- const intentOrder = await intentApi.getOrderStatus(orderId, providerName, srcChainId.toString(), __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"));
429
- // Update bridge history with intent order status
430
- __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_updateBridgeHistoryFromIntentOrder).call(this, bridgeTxMetaId, intentOrder, historyItem);
431
- }
432
- catch (error) {
433
- console.error('Failed to fetch intent order status:', error);
434
- __classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
435
- }
436
- /* c8 ignore stop */
437
- });
438
416
  _BridgeStatusController_getSrcTxHash.set(this, (bridgeTxMetaId) => {
439
417
  const { txHistory } = this.state;
440
418
  // Prefer the srcTxHash from bridgeStatusState so we don't have to l ook up in TransactionController
@@ -525,31 +503,10 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
525
503
  // Waits until a given transaction (by id) reaches confirmed/finalized status or fails/times out.
526
504
  _BridgeStatusController_waitForTxConfirmation.set(this, async (txId, { timeoutMs = 5 * 60000, // 5 minutes default
527
505
  pollMs = 3000, } = {}) => {
528
- /* c8 ignore start */
529
- const start = Date.now();
530
- // Poll the TransactionController state for status changes
531
- // We intentionally keep this simple to avoid extra wiring/subscriptions in this controller
532
- // and because we only need it for the rare intent+approval path.
533
- while (true) {
534
- const { transactions } = this.messenger.call('TransactionController:getState');
535
- const meta = transactions.find((tx) => tx.id === txId);
536
- if (meta) {
537
- // Treat both 'confirmed' and 'finalized' as success to match TC lifecycle
538
- if (meta.status === transaction_controller_1.TransactionStatus.confirmed) {
539
- return meta;
540
- }
541
- if (meta.status === transaction_controller_1.TransactionStatus.failed ||
542
- meta.status === transaction_controller_1.TransactionStatus.dropped ||
543
- meta.status === transaction_controller_1.TransactionStatus.rejected) {
544
- throw new Error('Approval transaction did not confirm');
545
- }
546
- }
547
- if (Date.now() - start > timeoutMs) {
548
- throw new Error('Timed out waiting for approval confirmation');
549
- }
550
- await new Promise((resolve) => setTimeout(resolve, pollMs));
551
- }
552
- /* c8 ignore stop */
506
+ return await (0, transaction_1.waitForTxConfirmation)(this.messenger, txId, {
507
+ timeoutMs,
508
+ pollMs,
509
+ });
553
510
  });
554
511
  _BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
555
512
  if (approval) {
@@ -723,6 +680,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
723
680
  let approvalTxId;
724
681
  const startTime = Date.now();
725
682
  const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
683
+ const isTronTx = (0, bridge_controller_1.isTronChainId)(quoteResponse.quote.srcChainId);
726
684
  // Submit non-EVM tx (Solana, BTC, Tron)
727
685
  if ((0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId)) {
728
686
  // Handle non-EVM approval if present (e.g., Tron token approvals)
@@ -880,7 +838,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
880
838
  // Start polling for bridge tx status
881
839
  __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, txMeta.id);
882
840
  // Track non-EVM Swap completed event
883
- if (!isBridgeTx) {
841
+ if (!(isBridgeTx || isTronTx)) {
884
842
  __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, txMeta.id);
885
843
  }
886
844
  }
@@ -980,12 +938,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
980
938
  };
981
939
  // Record in bridge history with actual transaction metadata
982
940
  try {
983
- // Use 'intent:' prefix for intent transactions
984
- const bridgeHistoryKey = `intent:${orderUid}`;
941
+ // Use orderId as the history key for intent transactions
942
+ const bridgeHistoryKey = orderUid;
985
943
  // Create a bridge transaction metadata that includes the original txId
986
944
  const bridgeTxMetaForHistory = {
987
945
  ...syntheticMeta,
988
- id: bridgeHistoryKey, // Use intent: prefix for bridge history key
946
+ id: bridgeHistoryKey,
989
947
  originalTransactionId: syntheticMeta.id, // Keep original txId for TransactionController updates
990
948
  };
991
949
  const startTime = Date.now();
@@ -1002,7 +960,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
1002
960
  approvalTxId,
1003
961
  startTime,
1004
962
  });
1005
- // Start polling using the intent: prefixed key to route to intent manager
963
+ // Start polling using the orderId key to route to intent manager
1006
964
  __classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeHistoryKey);
1007
965
  }
1008
966
  catch (error) {
@@ -1083,6 +1041,10 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
1083
1041
  customBridgeApiBaseUrl: config?.customBridgeApiBaseUrl ?? constants_1.BRIDGE_PROD_API_BASE_URL,
1084
1042
  }, "f");
1085
1043
  __classPrivateFieldSet(this, _BridgeStatusController_trace, traceFn ?? ((_request, fn) => fn?.()), "f");
1044
+ __classPrivateFieldSet(this, _BridgeStatusController_intentStatusManager, new bridge_status_controller_intent_1.IntentStatusManager({
1045
+ messenger: this.messenger,
1046
+ updateTransactionFn: __classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f"),
1047
+ }), "f");
1086
1048
  // Register action handlers
1087
1049
  this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:startPollingForBridgeTxStatus`, this.startPollingForBridgeTxStatus.bind(this));
1088
1050
  this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:wipeBridgeStatus`, this.wipeBridgeStatus.bind(this));
@@ -1139,128 +1101,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
1139
1101
  }
1140
1102
  }
1141
1103
  exports.BridgeStatusController = BridgeStatusController;
1142
- _BridgeStatusController_pollingTokensByTxMetaId = 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_handleFetchFailure = new WeakMap(), _BridgeStatusController_fetchBridgeTxStatus = new WeakMap(), _BridgeStatusController_fetchIntentOrderStatus = 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) {
1104
+ _BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_intentStatusManager = 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_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) {
1143
1105
  return this.messenger.call('AccountsController:getAccountByAddress', accountAddress);
1144
- }, _BridgeStatusController_updateBridgeHistoryFromIntentOrder = function _BridgeStatusController_updateBridgeHistoryFromIntentOrder(bridgeTxMetaId, intentOrder, historyItem) {
1145
- const { srcChainId } = historyItem.quote;
1146
- // Map intent order status to bridge status using enum values
1147
- let statusType;
1148
- const isComplete = [
1149
- validators_1.IntentOrderStatus.CONFIRMED,
1150
- validators_1.IntentOrderStatus.COMPLETED,
1151
- ].includes(intentOrder.status);
1152
- const isFailed = [
1153
- validators_1.IntentOrderStatus.FAILED,
1154
- validators_1.IntentOrderStatus.EXPIRED,
1155
- validators_1.IntentOrderStatus.CANCELLED,
1156
- ].includes(intentOrder.status);
1157
- const isPending = [validators_1.IntentOrderStatus.PENDING].includes(intentOrder.status);
1158
- const isSubmitted = [validators_1.IntentOrderStatus.SUBMITTED].includes(intentOrder.status);
1159
- if (isComplete) {
1160
- statusType = bridge_controller_1.StatusTypes.COMPLETE;
1161
- }
1162
- else if (isFailed) {
1163
- statusType = bridge_controller_1.StatusTypes.FAILED;
1164
- }
1165
- else if (isPending) {
1166
- statusType = bridge_controller_1.StatusTypes.PENDING;
1167
- }
1168
- else if (isSubmitted) {
1169
- statusType = bridge_controller_1.StatusTypes.SUBMITTED;
1170
- }
1171
- else {
1172
- statusType = bridge_controller_1.StatusTypes.UNKNOWN;
1173
- }
1174
- // Extract transaction hashes from intent order
1175
- const txHash = intentOrder.txHash ?? '';
1176
- // Check metadata for additional transaction hashes
1177
- const metadataTxHashes = Array.isArray(intentOrder.metadata.txHashes)
1178
- ? intentOrder.metadata.txHashes
1179
- : [];
1180
- let allHashes;
1181
- if (metadataTxHashes.length > 0) {
1182
- allHashes = metadataTxHashes;
1183
- }
1184
- else if (txHash) {
1185
- allHashes = [txHash];
1186
- }
1187
- else {
1188
- allHashes = [];
1189
- }
1190
- const newStatus = {
1191
- status: statusType,
1192
- srcChain: {
1193
- chainId: srcChainId,
1194
- txHash: txHash ?? historyItem.status.srcChain.txHash ?? '',
1195
- },
1196
- };
1197
- const newBridgeHistoryItem = {
1198
- ...historyItem,
1199
- status: newStatus,
1200
- completionTime: newStatus.status === bridge_controller_1.StatusTypes.COMPLETE ||
1201
- newStatus.status === bridge_controller_1.StatusTypes.FAILED
1202
- ? Date.now()
1203
- : undefined,
1204
- attempts: undefined,
1205
- srcTxHashes: allHashes.length > 0
1206
- ? Array.from(new Set([...(historyItem.srcTxHashes ?? []), ...allHashes]))
1207
- : historyItem.srcTxHashes,
1208
- };
1209
- this.update((state) => {
1210
- state.txHistory[bridgeTxMetaId] = newBridgeHistoryItem;
1211
- });
1212
- // Update the actual transaction in TransactionController to sync with intent status
1213
- // Use the original transaction ID (not the intent: prefixed bridge history key)
1214
- const originalTxId = historyItem.originalTransactionId ?? historyItem.txMetaId;
1215
- if (originalTxId && !originalTxId.startsWith('intent:')) {
1216
- try {
1217
- const transactionStatus = (0, intent_api_1.mapIntentOrderStatusToTransactionStatus)(intentOrder.status);
1218
- // Merge with existing TransactionMeta to avoid wiping required fields
1219
- const { transactions } = this.messenger.call('TransactionController:getState');
1220
- const existingTxMeta = transactions.find((tx) => tx.id === originalTxId);
1221
- if (existingTxMeta) {
1222
- const updatedTxMeta = {
1223
- ...existingTxMeta,
1224
- status: transactionStatus,
1225
- ...(txHash ? { hash: txHash } : {}),
1226
- ...(txHash
1227
- ? {
1228
- txReceipt: {
1229
- ...existingTxMeta.txReceipt,
1230
- transactionHash: txHash,
1231
- status: (isComplete ? '0x1' : '0x0'),
1232
- },
1233
- }
1234
- : {}),
1235
- };
1236
- __classPrivateFieldGet(this, _BridgeStatusController_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${intentOrder.status}`);
1237
- }
1238
- else {
1239
- console.warn('📝 [fetchIntentOrderStatus] Skipping update; transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
1240
- }
1241
- }
1242
- catch (error) {
1243
- /* c8 ignore start */
1244
- console.error('📝 [fetchIntentOrderStatus] Failed to update transaction status', {
1245
- originalTxId,
1246
- bridgeHistoryKey: bridgeTxMetaId,
1247
- error,
1248
- });
1249
- }
1250
- /* c8 ignore stop */
1251
- }
1252
- const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
1253
- const isFinal = newStatus.status === bridge_controller_1.StatusTypes.COMPLETE ||
1254
- newStatus.status === bridge_controller_1.StatusTypes.FAILED;
1255
- if (isFinal && pollingToken) {
1256
- this.stopPollingByPollingToken(pollingToken);
1257
- delete __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
1258
- if (newStatus.status === bridge_controller_1.StatusTypes.COMPLETE) {
1259
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, bridgeTxMetaId);
1260
- }
1261
- else if (newStatus.status === bridge_controller_1.StatusTypes.FAILED) {
1262
- __classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, bridgeTxMetaId);
1263
- }
1264
- }
1265
1106
  };
1266
1107
  //# sourceMappingURL=bridge-status-controller.cjs.map