@metamask-previews/bridge-status-controller 65.0.1-preview-ce3ee897a → 65.0.1-preview-e4aa1532
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.
- package/CHANGELOG.md +1 -10
- package/dist/bridge-status-controller.cjs +226 -67
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +229 -70
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +7 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +7 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/intent-api.cjs +7 -42
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +4 -7
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +4 -7
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +3 -38
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/transaction.cjs +1 -44
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +0 -9
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +0 -9
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +0 -41
- package/dist/utils/transaction.mjs.map +1 -1
- package/package.json +5 -5
- package/dist/bridge-status-controller.intent.cjs +0 -70
- package/dist/bridge-status-controller.intent.cjs.map +0 -1
- package/dist/bridge-status-controller.intent.d.cts +0 -13
- package/dist/bridge-status-controller.intent.d.cts.map +0 -1
- package/dist/bridge-status-controller.intent.d.mts +0 -13
- package/dist/bridge-status-controller.intent.d.mts.map +0 -1
- package/dist/bridge-status-controller.intent.mjs +0 -66
- package/dist/bridge-status-controller.intent.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,12 +9,7 @@ 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
|
-
- Bump `@metamask/bridge-controller` from `^65.1.0` to `^65.2.0` ([#7802](https://github.com/MetaMask/core/pull/7802))
|
|
14
|
-
|
|
15
|
-
### Fixed
|
|
16
|
-
|
|
17
|
-
- Fix Tron same-chain swap polling and Completed event tracking ([#7697](https://github.com/MetaMask/core/pull/7697))
|
|
12
|
+
- Bump `@metamask/transaction-controller` from `^62.11.0` to `^62.12.0` ([#7775](https://github.com/MetaMask/core/pull/7775))
|
|
18
13
|
|
|
19
14
|
## [65.0.1]
|
|
20
15
|
|
|
@@ -45,10 +40,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
45
40
|
|
|
46
41
|
- 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))
|
|
47
42
|
|
|
48
|
-
### Fixed
|
|
49
|
-
|
|
50
|
-
- Fix Tron same-chain swap polling and Completed event tracking ([#7697](https://github.com/MetaMask/core/pull/7697))
|
|
51
|
-
|
|
52
43
|
## [64.4.3]
|
|
53
44
|
|
|
54
45
|
### 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,
|
|
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;
|
|
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,7 +18,6 @@ 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");
|
|
22
21
|
const constants_1 = require("./constants.cjs");
|
|
23
22
|
const types_1 = require("./types.cjs");
|
|
24
23
|
const bridge_status_1 = require("./utils/bridge-status.cjs");
|
|
@@ -26,6 +25,7 @@ const gas_1 = require("./utils/gas.cjs");
|
|
|
26
25
|
const intent_api_1 = require("./utils/intent-api.cjs");
|
|
27
26
|
const metrics_1 = require("./utils/metrics.cjs");
|
|
28
27
|
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,7 +50,6 @@ 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);
|
|
54
53
|
_BridgeStatusController_clientId.set(this, void 0);
|
|
55
54
|
_BridgeStatusController_fetchFn.set(this, void 0);
|
|
56
55
|
_BridgeStatusController_config.set(this, void 0);
|
|
@@ -133,8 +132,9 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
133
132
|
state.txHistory[targetTxMetaId].attempts = undefined;
|
|
134
133
|
}
|
|
135
134
|
});
|
|
136
|
-
// Restart polling if it was stopped and this
|
|
137
|
-
|
|
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) {
|
|
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,9 +170,10 @@ 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
|
-
//
|
|
173
|
+
// Swap txs don't need to have their statuses polled
|
|
174
174
|
.filter((historyItem) => {
|
|
175
|
-
|
|
175
|
+
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(historyItem.quote.srcChainId, historyItem.quote.destChainId);
|
|
176
|
+
return isBridgeTx;
|
|
176
177
|
});
|
|
177
178
|
incompleteHistoryItems.forEach((historyItem) => {
|
|
178
179
|
const bridgeTxMetaId = historyItem.txMetaId;
|
|
@@ -242,8 +243,28 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
242
243
|
* @param txMeta.hash - The transaction hash to set on the history item
|
|
243
244
|
*/
|
|
244
245
|
_BridgeStatusController_rekeyHistoryItem.set(this, (actionId, txMeta) => {
|
|
246
|
+
const historyItem = this.state.txHistory[actionId];
|
|
247
|
+
if (!historyItem) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
245
250
|
this.update((state) => {
|
|
246
|
-
|
|
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];
|
|
247
268
|
});
|
|
248
269
|
});
|
|
249
270
|
_BridgeStatusController_startPollingForTxId.set(this, (txId) => {
|
|
@@ -256,18 +277,15 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
256
277
|
if (!txHistoryItem) {
|
|
257
278
|
return;
|
|
258
279
|
}
|
|
259
|
-
|
|
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) {
|
|
260
284
|
__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId] = this.startPolling({
|
|
261
285
|
bridgeTxMetaId: txId,
|
|
262
286
|
});
|
|
263
287
|
}
|
|
264
288
|
});
|
|
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
|
-
});
|
|
271
289
|
/**
|
|
272
290
|
* @deprecated For EVM/Solana swap/bridge txs we add tx to history in submitTx()
|
|
273
291
|
* For Solana swap/bridge we start polling in submitTx()
|
|
@@ -323,52 +341,33 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
323
341
|
});
|
|
324
342
|
});
|
|
325
343
|
_BridgeStatusController_fetchBridgeTxStatus.set(this, async ({ bridgeTxMetaId, }) => {
|
|
326
|
-
// 1. Check for history item
|
|
327
344
|
const { txHistory } = this.state;
|
|
328
|
-
|
|
329
|
-
if (
|
|
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 });
|
|
330
348
|
return;
|
|
331
349
|
}
|
|
332
|
-
|
|
333
|
-
if ((0, bridge_status_1.shouldSkipFetchDueToFetchFailures)(historyItem.attempts)) {
|
|
350
|
+
if ((0, bridge_status_1.shouldSkipFetchDueToFetchFailures)(txHistory[bridgeTxMetaId]?.attempts)) {
|
|
334
351
|
return;
|
|
335
352
|
}
|
|
336
|
-
// 3. Fetch transcation status
|
|
337
353
|
try {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
if (
|
|
344
|
-
|
|
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;
|
|
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;
|
|
364
361
|
}
|
|
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
|
|
372
371
|
const newBridgeHistoryItem = {
|
|
373
372
|
...historyItem,
|
|
374
373
|
status,
|
|
@@ -385,10 +384,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
385
384
|
this.update((state) => {
|
|
386
385
|
state.txHistory[bridgeTxMetaId] = newBridgeHistoryItem;
|
|
387
386
|
});
|
|
388
|
-
if (isIntent && intentTranslation && intentOrderStatus) {
|
|
389
|
-
__classPrivateFieldGet(this, _BridgeStatusController_intentStatusManager, "f").syncTransactionFromIntentStatus(bridgeTxMetaId, historyItem, intentTranslation, intentOrderStatus);
|
|
390
|
-
}
|
|
391
|
-
// 5. After effects
|
|
392
387
|
const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
|
|
393
388
|
const isFinalStatus = status.status === bridge_controller_1.StatusTypes.COMPLETE ||
|
|
394
389
|
status.status === bridge_controller_1.StatusTypes.FAILED;
|
|
@@ -413,6 +408,33 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
413
408
|
__classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
|
|
414
409
|
}
|
|
415
410
|
});
|
|
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
|
+
});
|
|
416
438
|
_BridgeStatusController_getSrcTxHash.set(this, (bridgeTxMetaId) => {
|
|
417
439
|
const { txHistory } = this.state;
|
|
418
440
|
// Prefer the srcTxHash from bridgeStatusState so we don't have to l ook up in TransactionController
|
|
@@ -503,10 +525,31 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
503
525
|
// Waits until a given transaction (by id) reaches confirmed/finalized status or fails/times out.
|
|
504
526
|
_BridgeStatusController_waitForTxConfirmation.set(this, async (txId, { timeoutMs = 5 * 60000, // 5 minutes default
|
|
505
527
|
pollMs = 3000, } = {}) => {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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 */
|
|
510
553
|
});
|
|
511
554
|
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
|
|
512
555
|
if (approval) {
|
|
@@ -680,7 +723,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
680
723
|
let approvalTxId;
|
|
681
724
|
const startTime = Date.now();
|
|
682
725
|
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
683
|
-
const isTronTx = (0, bridge_controller_1.isTronChainId)(quoteResponse.quote.srcChainId);
|
|
684
726
|
// Submit non-EVM tx (Solana, BTC, Tron)
|
|
685
727
|
if ((0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId)) {
|
|
686
728
|
// Handle non-EVM approval if present (e.g., Tron token approvals)
|
|
@@ -838,7 +880,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
838
880
|
// Start polling for bridge tx status
|
|
839
881
|
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, txMeta.id);
|
|
840
882
|
// Track non-EVM Swap completed event
|
|
841
|
-
if (!
|
|
883
|
+
if (!isBridgeTx) {
|
|
842
884
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, txMeta.id);
|
|
843
885
|
}
|
|
844
886
|
}
|
|
@@ -938,12 +980,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
938
980
|
};
|
|
939
981
|
// Record in bridge history with actual transaction metadata
|
|
940
982
|
try {
|
|
941
|
-
// Use
|
|
942
|
-
const bridgeHistoryKey = orderUid
|
|
983
|
+
// Use 'intent:' prefix for intent transactions
|
|
984
|
+
const bridgeHistoryKey = `intent:${orderUid}`;
|
|
943
985
|
// Create a bridge transaction metadata that includes the original txId
|
|
944
986
|
const bridgeTxMetaForHistory = {
|
|
945
987
|
...syntheticMeta,
|
|
946
|
-
id: bridgeHistoryKey,
|
|
988
|
+
id: bridgeHistoryKey, // Use intent: prefix for bridge history key
|
|
947
989
|
originalTransactionId: syntheticMeta.id, // Keep original txId for TransactionController updates
|
|
948
990
|
};
|
|
949
991
|
const startTime = Date.now();
|
|
@@ -960,7 +1002,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
960
1002
|
approvalTxId,
|
|
961
1003
|
startTime,
|
|
962
1004
|
});
|
|
963
|
-
// Start polling using the
|
|
1005
|
+
// Start polling using the intent: prefixed key to route to intent manager
|
|
964
1006
|
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeHistoryKey);
|
|
965
1007
|
}
|
|
966
1008
|
catch (error) {
|
|
@@ -1041,10 +1083,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
1041
1083
|
customBridgeApiBaseUrl: config?.customBridgeApiBaseUrl ?? constants_1.BRIDGE_PROD_API_BASE_URL,
|
|
1042
1084
|
}, "f");
|
|
1043
1085
|
__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");
|
|
1048
1086
|
// Register action handlers
|
|
1049
1087
|
this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:startPollingForBridgeTxStatus`, this.startPollingForBridgeTxStatus.bind(this));
|
|
1050
1088
|
this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:wipeBridgeStatus`, this.wipeBridgeStatus.bind(this));
|
|
@@ -1101,7 +1139,128 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
1101
1139
|
}
|
|
1102
1140
|
}
|
|
1103
1141
|
exports.BridgeStatusController = BridgeStatusController;
|
|
1104
|
-
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(),
|
|
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) {
|
|
1105
1143
|
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
|
+
}
|
|
1106
1265
|
};
|
|
1107
1266
|
//# sourceMappingURL=bridge-status-controller.cjs.map
|