@metamask/bridge-status-controller 70.0.5 → 71.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -8
- package/dist/bridge-status-controller-method-action-types.cjs +7 -0
- package/dist/bridge-status-controller-method-action-types.cjs.map +1 -0
- package/dist/bridge-status-controller-method-action-types.d.cts +38 -0
- package/dist/bridge-status-controller-method-action-types.d.cts.map +1 -0
- package/dist/bridge-status-controller-method-action-types.d.mts +38 -0
- package/dist/bridge-status-controller-method-action-types.d.mts.map +1 -0
- package/dist/bridge-status-controller-method-action-types.mjs +6 -0
- package/dist/bridge-status-controller-method-action-types.mjs.map +1 -0
- package/dist/bridge-status-controller.cjs +217 -123
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +4 -1
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +4 -1
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +222 -128
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/constants.cjs +2 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +1 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +1 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +1 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +21 -18
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +21 -18
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +4 -0
- package/dist/types.mjs.map +1 -1
- package/dist/utils/accounts.d.cts +1 -1
- package/dist/utils/accounts.d.mts +1 -1
- package/dist/utils/bridge-status.cjs +49 -2
- package/dist/utils/bridge-status.cjs.map +1 -1
- package/dist/utils/bridge-status.d.cts +2 -1
- package/dist/utils/bridge-status.d.cts.map +1 -1
- package/dist/utils/bridge-status.d.mts +2 -1
- package/dist/utils/bridge-status.d.mts.map +1 -1
- package/dist/utils/bridge-status.mjs +48 -2
- package/dist/utils/bridge-status.mjs.map +1 -1
- package/dist/utils/feature-flags.cjs +12 -0
- package/dist/utils/feature-flags.cjs.map +1 -0
- package/dist/utils/feature-flags.d.cts +3 -0
- package/dist/utils/feature-flags.d.cts.map +1 -0
- package/dist/utils/feature-flags.d.mts +3 -0
- package/dist/utils/feature-flags.d.mts.map +1 -0
- package/dist/utils/feature-flags.mjs +8 -0
- package/dist/utils/feature-flags.mjs.map +1 -0
- package/dist/utils/history.cjs +48 -3
- package/dist/utils/history.cjs.map +1 -1
- package/dist/utils/history.d.cts +19 -1
- package/dist/utils/history.d.cts.map +1 -1
- package/dist/utils/history.d.mts +19 -1
- package/dist/utils/history.d.mts.map +1 -1
- package/dist/utils/history.mjs +45 -3
- package/dist/utils/history.mjs.map +1 -1
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +1 -1
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +1 -1
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/metrics.cjs +45 -8
- package/dist/utils/metrics.cjs.map +1 -1
- package/dist/utils/metrics.d.cts +37 -6
- package/dist/utils/metrics.d.cts.map +1 -1
- package/dist/utils/metrics.d.mts +37 -6
- package/dist/utils/metrics.d.mts.map +1 -1
- package/dist/utils/metrics.mjs +44 -8
- package/dist/utils/metrics.mjs.map +1 -1
- package/dist/utils/network.cjs +7 -1
- package/dist/utils/network.cjs.map +1 -1
- package/dist/utils/network.d.cts +4 -2
- package/dist/utils/network.d.cts.map +1 -1
- package/dist/utils/network.d.mts +4 -2
- package/dist/utils/network.d.mts.map +1 -1
- package/dist/utils/network.mjs +5 -0
- package/dist/utils/network.mjs.map +1 -1
- package/dist/utils/transaction.cjs +10 -9
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +3 -0
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +3 -0
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +8 -8
- package/dist/utils/transaction.mjs.map +1 -1
- package/dist/utils/validators.d.cts +2 -2
- package/dist/utils/validators.d.mts +2 -2
- package/package.json +22 -20
|
@@ -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_pollingTokensByTxMetaId, _BridgeStatusController_intentManager, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_trace,
|
|
13
|
+
var _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_intentManager, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_trace, _BridgeStatusController_onTransactionFailed, _BridgeStatusController_onTransactionConfirmed, _BridgeStatusController_restartPollingForIncompleteHistoryItems, _BridgeStatusController_addTxToHistory, _BridgeStatusController_rekeyHistoryItem, _BridgeStatusController_startPollingForTxId, _BridgeStatusController_handleFetchFailure, _BridgeStatusController_handleOldHistoryItem, _BridgeStatusController_fetchBridgeTxStatus, _BridgeStatusController_setAndGetSrcTxHash, _BridgeStatusController_updateHistoryItem, _BridgeStatusController_deleteHistoryItem, _BridgeStatusController_wipeBridgeStatusByChainId, _BridgeStatusController_handleApprovalTx, _BridgeStatusController_handleEvmTransactionBatch, _BridgeStatusController_trackPollingStatusUpdatedEvent, _BridgeStatusController_trackUnifiedSwapBridgeEvent;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.BridgeStatusController = void 0;
|
|
16
16
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
@@ -42,6 +42,15 @@ const metadata = {
|
|
|
42
42
|
usedInUi: true,
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
46
|
+
'startPollingForBridgeTxStatus',
|
|
47
|
+
'wipeBridgeStatus',
|
|
48
|
+
'resetState',
|
|
49
|
+
'submitTx',
|
|
50
|
+
'submitIntent',
|
|
51
|
+
'restartPollingForFailedAttempts',
|
|
52
|
+
'getBridgeHistoryItemByTxMetaId',
|
|
53
|
+
];
|
|
45
54
|
class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPollingController)() {
|
|
46
55
|
constructor({ messenger, state, clientId, fetchFn, addTransactionBatchFn, config, traceFn, }) {
|
|
47
56
|
super({
|
|
@@ -61,25 +70,55 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
61
70
|
_BridgeStatusController_config.set(this, void 0);
|
|
62
71
|
_BridgeStatusController_addTransactionBatchFn.set(this, void 0);
|
|
63
72
|
_BridgeStatusController_trace.set(this, void 0);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
_BridgeStatusController_onTransactionFailed.set(this, ({ txMeta, historyKey, isApprovalTxMeta, }) => {
|
|
74
|
+
// Check if the history item is already marked as a failure
|
|
75
|
+
const isHistoryItemAlreadyFailed = historyKey
|
|
76
|
+
? this.state.txHistory[historyKey]?.status.status === bridge_controller_1.StatusTypes.FAILED
|
|
77
|
+
: false;
|
|
78
|
+
__classPrivateFieldGet(this, _BridgeStatusController_updateHistoryItem, "f").call(this, {
|
|
79
|
+
historyKey,
|
|
80
|
+
status: bridge_controller_1.StatusTypes.FAILED,
|
|
81
|
+
txHash: isApprovalTxMeta ? undefined : txMeta.hash,
|
|
82
|
+
});
|
|
83
|
+
if (txMeta.status === transaction_controller_1.TransactionStatus.rejected) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// Skip account lookup and tracking when featureId is set (e.g. PERPS)
|
|
87
|
+
if (historyKey && this.state.txHistory[historyKey]?.featureId) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// Skip tracking if this is a duplicate failed event for the same history item
|
|
91
|
+
// This can happen if the transaction includes an approval tx that fails
|
|
92
|
+
if (isHistoryItemAlreadyFailed) {
|
|
93
|
+
return;
|
|
73
94
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
95
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, historyKey, (0, metrics_1.getEVMTxPropertiesFromTransactionMeta)(txMeta));
|
|
96
|
+
});
|
|
97
|
+
// Only EVM txs
|
|
98
|
+
_BridgeStatusController_onTransactionConfirmed.set(this, ({ txMeta, historyKey, isApprovalTxMeta, }) => {
|
|
99
|
+
// Return early if the confirmed txMeta is for an approval since we
|
|
100
|
+
// still need to wait for the trade to be confirmed
|
|
101
|
+
if (isApprovalTxMeta) {
|
|
77
102
|
return;
|
|
78
103
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
104
|
+
__classPrivateFieldGet(this, _BridgeStatusController_updateHistoryItem, "f").call(this, {
|
|
105
|
+
historyKey,
|
|
106
|
+
txHash: txMeta.hash,
|
|
82
107
|
});
|
|
108
|
+
switch (txMeta.type) {
|
|
109
|
+
case transaction_controller_1.TransactionType.swap:
|
|
110
|
+
__classPrivateFieldGet(this, _BridgeStatusController_updateHistoryItem, "f").call(this, {
|
|
111
|
+
historyKey,
|
|
112
|
+
status: bridge_controller_1.StatusTypes.COMPLETE,
|
|
113
|
+
});
|
|
114
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, historyKey);
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
if (historyKey) {
|
|
118
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
83
122
|
});
|
|
84
123
|
this.resetState = () => {
|
|
85
124
|
this.update((state) => {
|
|
@@ -180,30 +219,31 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
180
219
|
_BridgeStatusController_restartPollingForIncompleteHistoryItems.set(this, () => {
|
|
181
220
|
// Check for historyItems that do not have a status of complete and restart polling
|
|
182
221
|
const { txHistory } = this.state;
|
|
183
|
-
const historyItems = Object.
|
|
222
|
+
const historyItems = Object.entries(txHistory);
|
|
184
223
|
const incompleteHistoryItems = historyItems
|
|
185
|
-
.filter((historyItem) => historyItem.status.status === bridge_controller_1.StatusTypes.PENDING ||
|
|
224
|
+
.filter(([_, historyItem]) => historyItem.status.status === bridge_controller_1.StatusTypes.PENDING ||
|
|
186
225
|
historyItem.status.status === bridge_controller_1.StatusTypes.UNKNOWN)
|
|
187
226
|
// Only poll items with txMetaId (post-submission items)
|
|
188
|
-
.filter((historyItem) =>
|
|
189
|
-
|
|
227
|
+
.filter(([_, historyItem]) => {
|
|
228
|
+
if (!historyItem.txMetaId) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
190
231
|
// Check if we are already polling this tx, if so, skip restarting polling for that
|
|
191
232
|
const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[historyItem.txMetaId];
|
|
192
233
|
return !pollingToken;
|
|
193
234
|
})
|
|
194
235
|
// Only restart polling for items that still require status updates
|
|
195
|
-
.filter((historyItem) => {
|
|
236
|
+
.filter(([_, historyItem]) => {
|
|
196
237
|
return (0, history_1.shouldPollHistoryItem)(historyItem);
|
|
197
238
|
});
|
|
198
|
-
incompleteHistoryItems.forEach((historyItem) => {
|
|
199
|
-
const bridgeTxMetaId = historyItem.txMetaId;
|
|
239
|
+
incompleteHistoryItems.forEach(([historyKey, historyItem]) => {
|
|
200
240
|
const shouldSkipFetch = (0, bridge_status_1.shouldSkipFetchDueToFetchFailures)(historyItem.attempts);
|
|
201
241
|
if (shouldSkipFetch) {
|
|
202
242
|
return;
|
|
203
243
|
}
|
|
204
244
|
// We manually call startPolling() here rather than go through startPollingForBridgeTxStatus()
|
|
205
245
|
// because we don't want to overwrite the existing historyItem in state
|
|
206
|
-
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this,
|
|
246
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
|
|
207
247
|
});
|
|
208
248
|
});
|
|
209
249
|
_BridgeStatusController_addTxToHistory.set(this, (...args) => {
|
|
@@ -212,6 +252,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
212
252
|
// Use actionId as key for pre-submission, or txMeta.id for post-submission
|
|
213
253
|
state.txHistory[historyKey] = txHistoryItem;
|
|
214
254
|
});
|
|
255
|
+
return historyKey;
|
|
215
256
|
});
|
|
216
257
|
/**
|
|
217
258
|
* Rekeys a history item from actionId to txMeta.id after successful submission.
|
|
@@ -234,10 +275,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
234
275
|
this.stopPollingByPollingToken(existingPollingToken);
|
|
235
276
|
}
|
|
236
277
|
const txHistoryItem = this.state.txHistory[txId];
|
|
237
|
-
if (
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
if ((0, history_1.shouldPollHistoryItem)(txHistoryItem)) {
|
|
278
|
+
if (txHistoryItem && (0, history_1.shouldPollHistoryItem)(txHistoryItem)) {
|
|
241
279
|
__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[txId] = this.startPolling({
|
|
242
280
|
bridgeTxMetaId: txId,
|
|
243
281
|
});
|
|
@@ -258,8 +296,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
258
296
|
if (!bridgeTxMeta?.id) {
|
|
259
297
|
throw new Error('Cannot start polling: bridgeTxMeta.id is required for polling');
|
|
260
298
|
}
|
|
261
|
-
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, txHistoryMeta);
|
|
262
|
-
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this,
|
|
299
|
+
const historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, txHistoryMeta);
|
|
300
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
|
|
263
301
|
};
|
|
264
302
|
// This will be called after you call this.startPolling()
|
|
265
303
|
// The args passed in are the args you passed in to startPolling()
|
|
@@ -294,29 +332,38 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
294
332
|
// Track max polling reached event
|
|
295
333
|
const historyItem = this.state.txHistory[bridgeTxMetaId];
|
|
296
334
|
if (historyItem && !historyItem.featureId) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const requestMetadata = (0, metrics_1.getRequestMetadataFromHistory)(historyItem, selectedAccount);
|
|
300
|
-
const { security_warnings: _, ...metadataWithoutWarnings } = requestMetadata;
|
|
301
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.PollingStatusUpdated, bridgeTxMetaId, {
|
|
302
|
-
...(0, metrics_1.getTradeDataFromHistory)(historyItem),
|
|
303
|
-
...(0, metrics_1.getPriceImpactFromQuote)(historyItem.quote),
|
|
304
|
-
...metadataWithoutWarnings,
|
|
305
|
-
chain_id_source: requestParams.chain_id_source,
|
|
306
|
-
chain_id_destination: requestParams.chain_id_destination,
|
|
307
|
-
token_symbol_source: requestParams.token_symbol_source,
|
|
308
|
-
token_symbol_destination: requestParams.token_symbol_destination,
|
|
309
|
-
action_type: bridge_controller_1.MetricsActionType.SWAPBRIDGE_V1,
|
|
310
|
-
polling_status: bridge_controller_1.PollingStatus.MaxPollingReached,
|
|
311
|
-
retry_attempts: newAttempts.counter,
|
|
312
|
-
});
|
|
335
|
+
// Track polling status updated event
|
|
336
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackPollingStatusUpdatedEvent, "f").call(this, bridgeTxMetaId, bridge_controller_1.PollingStatus.MaxPollingReached);
|
|
313
337
|
}
|
|
314
338
|
}
|
|
315
339
|
// Update the attempts counter
|
|
316
|
-
this.
|
|
317
|
-
|
|
340
|
+
__classPrivateFieldGet(this, _BridgeStatusController_updateHistoryItem, "f").call(this, {
|
|
341
|
+
historyKey: bridgeTxMetaId,
|
|
342
|
+
attempts: newAttempts,
|
|
318
343
|
});
|
|
319
344
|
});
|
|
345
|
+
/**
|
|
346
|
+
* Checks if the history item should be preserved so its status can be fetched.
|
|
347
|
+
*
|
|
348
|
+
* @param bridgeTxMetaId - The txMetaId of the bridge tx
|
|
349
|
+
*/
|
|
350
|
+
_BridgeStatusController_handleOldHistoryItem.set(this, async (bridgeTxMetaId) => {
|
|
351
|
+
// Continue polling on next restart if the history item is valid
|
|
352
|
+
if (this.state.txHistory[bridgeTxMetaId] &&
|
|
353
|
+
(await (0, bridge_status_1.shouldWaitForFinalBridgeStatus)(this.messenger, this.state.txHistory[bridgeTxMetaId]))) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
|
|
357
|
+
// Track polling status updated event
|
|
358
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackPollingStatusUpdatedEvent, "f").call(this, bridgeTxMetaId, bridge_controller_1.PollingStatus.InvalidTransactionHash);
|
|
359
|
+
// If we've failed too many times, stop polling for the tx
|
|
360
|
+
if (pollingToken) {
|
|
361
|
+
this.stopPollingByPollingToken(pollingToken);
|
|
362
|
+
delete __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[bridgeTxMetaId];
|
|
363
|
+
}
|
|
364
|
+
// Delete the history item so polling doesn't start over on the next restart
|
|
365
|
+
__classPrivateFieldGet(this, _BridgeStatusController_deleteHistoryItem, "f").call(this, bridgeTxMetaId);
|
|
366
|
+
});
|
|
320
367
|
_BridgeStatusController_fetchBridgeTxStatus.set(this, async ({ bridgeTxMetaId, }) => {
|
|
321
368
|
// 1. Check for history item
|
|
322
369
|
const { txHistory } = this.state;
|
|
@@ -328,7 +375,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
328
375
|
if ((0, bridge_status_1.shouldSkipFetchDueToFetchFailures)(historyItem.attempts)) {
|
|
329
376
|
return;
|
|
330
377
|
}
|
|
331
|
-
// 3. Fetch
|
|
378
|
+
// 3. Fetch transaction status
|
|
332
379
|
try {
|
|
333
380
|
let status;
|
|
334
381
|
let validationFailures = [];
|
|
@@ -344,11 +391,10 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
344
391
|
// We try here because we receive 500 errors from Bridge API if we try to fetch immediately after submitting the source tx
|
|
345
392
|
// Oddly mostly happens on Optimism, never on Arbitrum. By the 2nd fetch, the Bridge API responds properly.
|
|
346
393
|
// Also srcTxHash may not be available immediately for STX, so we don't want to fetch in those cases
|
|
347
|
-
const srcTxHash = __classPrivateFieldGet(this,
|
|
394
|
+
const srcTxHash = __classPrivateFieldGet(this, _BridgeStatusController_setAndGetSrcTxHash, "f").call(this, bridgeTxMetaId);
|
|
348
395
|
if (!srcTxHash) {
|
|
349
396
|
return;
|
|
350
397
|
}
|
|
351
|
-
__classPrivateFieldGet(this, _BridgeStatusController_updateSrcTxHash, "f").call(this, bridgeTxMetaId, srcTxHash);
|
|
352
398
|
const statusRequest = (0, bridge_status_1.getStatusRequestWithSrcTxHash)(historyItem.quote, srcTxHash);
|
|
353
399
|
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);
|
|
354
400
|
status = response.status;
|
|
@@ -405,26 +451,65 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
405
451
|
console.warn('Failed to fetch bridge tx status', error);
|
|
406
452
|
__classPrivateFieldGet(this, _BridgeStatusController_handleFetchFailure, "f").call(this, bridgeTxMetaId);
|
|
407
453
|
}
|
|
454
|
+
finally {
|
|
455
|
+
await __classPrivateFieldGet(this, _BridgeStatusController_handleOldHistoryItem, "f").call(this, bridgeTxMetaId);
|
|
456
|
+
}
|
|
408
457
|
});
|
|
409
|
-
|
|
458
|
+
/**
|
|
459
|
+
* Returns the srcTxHash for a non-STX EVM tx, the hash from the bridge status api,
|
|
460
|
+
* or the local hash from the TransactionController if the tx is in a finalized state
|
|
461
|
+
*
|
|
462
|
+
* @param bridgeTxMetaId - The bridge tx meta id
|
|
463
|
+
* @returns The srcTxHash
|
|
464
|
+
*/
|
|
465
|
+
_BridgeStatusController_setAndGetSrcTxHash.set(this, (bridgeTxMetaId) => {
|
|
410
466
|
const { txHistory } = this.state;
|
|
411
|
-
// Prefer the srcTxHash from bridgeStatusState so we don't have to
|
|
467
|
+
// Prefer the srcTxHash from bridgeStatusState so we don't have to look up in TransactionController
|
|
412
468
|
// But it is possible to have bridgeHistoryItem in state without the srcTxHash yet when it is an STX
|
|
413
469
|
const srcTxHash = txHistory[bridgeTxMetaId].status.srcChain.txHash;
|
|
414
|
-
if (srcTxHash
|
|
470
|
+
if (srcTxHash ||
|
|
471
|
+
(0, bridge_controller_1.isNonEvmChainId)(txHistory[bridgeTxMetaId].quote.srcChainId)) {
|
|
415
472
|
return srcTxHash;
|
|
416
473
|
}
|
|
417
|
-
//
|
|
474
|
+
// Update history with TransactionController's hash if it has been updated
|
|
418
475
|
const txMeta = (0, transaction_1.getTransactionMetaById)(this.messenger, bridgeTxMetaId);
|
|
419
|
-
|
|
476
|
+
if (!txMeta) {
|
|
477
|
+
return undefined;
|
|
478
|
+
}
|
|
479
|
+
// Wait for finalized status before updating the history item
|
|
480
|
+
const localTxHash = [
|
|
481
|
+
transaction_controller_1.TransactionStatus.confirmed,
|
|
482
|
+
transaction_controller_1.TransactionStatus.dropped,
|
|
483
|
+
transaction_controller_1.TransactionStatus.rejected,
|
|
484
|
+
transaction_controller_1.TransactionStatus.failed,
|
|
485
|
+
].includes(txMeta.status)
|
|
486
|
+
? txMeta.hash
|
|
487
|
+
: undefined;
|
|
488
|
+
__classPrivateFieldGet(this, _BridgeStatusController_updateHistoryItem, "f").call(this, {
|
|
489
|
+
historyKey: bridgeTxMetaId,
|
|
490
|
+
txHash: localTxHash,
|
|
491
|
+
});
|
|
492
|
+
return localTxHash;
|
|
420
493
|
});
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (txHistory[bridgeTxMetaId].status.srcChain.txHash) {
|
|
494
|
+
_BridgeStatusController_updateHistoryItem.set(this, ({ historyKey, status, txHash, attempts, }) => {
|
|
495
|
+
if (!historyKey) {
|
|
424
496
|
return;
|
|
425
497
|
}
|
|
426
|
-
this.update((
|
|
427
|
-
|
|
498
|
+
this.update((currentState) => {
|
|
499
|
+
if (status) {
|
|
500
|
+
currentState.txHistory[historyKey].status.status = status;
|
|
501
|
+
}
|
|
502
|
+
if (txHash) {
|
|
503
|
+
currentState.txHistory[historyKey].status.srcChain.txHash = txHash;
|
|
504
|
+
}
|
|
505
|
+
if (attempts) {
|
|
506
|
+
currentState.txHistory[historyKey].attempts = attempts;
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
_BridgeStatusController_deleteHistoryItem.set(this, (historyKey) => {
|
|
511
|
+
this.update((currentState) => {
|
|
512
|
+
delete currentState.txHistory[historyKey];
|
|
428
513
|
});
|
|
429
514
|
});
|
|
430
515
|
// Wipes the bridge status for the given address and chainId
|
|
@@ -440,6 +525,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
440
525
|
const pollingToken = __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[sourceTxMetaId];
|
|
441
526
|
if (pollingToken) {
|
|
442
527
|
this.stopPollingByPollingToken(__classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[sourceTxMetaId]);
|
|
528
|
+
delete __classPrivateFieldGet(this, _BridgeStatusController_pollingTokensByTxMetaId, "f")[sourceTxMetaId];
|
|
443
529
|
}
|
|
444
530
|
});
|
|
445
531
|
this.update((state) => {
|
|
@@ -509,16 +595,17 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
509
595
|
* @param location - The entry point from which the user initiated the swap or bridge (e.g. Main View, Token View, Trending Explore)
|
|
510
596
|
* @param abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
|
|
511
597
|
* @param activeAbTests - New A/B test context for `active_ab_tests` (migration target). Attributes events to specific experiments.
|
|
598
|
+
* @param tokenSecurityTypeDestination - The security classification of the destination token, supplied by the client (e.g. from token security/scanning data). Pass `null` when no security data is available.
|
|
512
599
|
* @returns The transaction meta
|
|
513
600
|
*/
|
|
514
|
-
this.submitTx = async (accountAddress, quoteResponse, isStxEnabledOnClient, quotesReceivedContext, location = bridge_controller_1.MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests) => {
|
|
601
|
+
this.submitTx = async (accountAddress, quoteResponse, isStxEnabledOnClient, quotesReceivedContext, location = bridge_controller_1.MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests, tokenSecurityTypeDestination) => {
|
|
515
602
|
(0, bridge_1.stopPollingForQuotes)(this.messenger, quoteResponse.featureId, quotesReceivedContext);
|
|
516
603
|
const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, accountAddress);
|
|
517
604
|
if (!selectedAccount) {
|
|
518
605
|
throw new Error('Failed to submit cross-chain swap transaction: undefined multichain account');
|
|
519
606
|
}
|
|
520
|
-
const
|
|
521
|
-
const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, isStxEnabledOnClient,
|
|
607
|
+
const accountHardwareType = (0, bridge_controller_1.getAccountHardwareType)(selectedAccount);
|
|
608
|
+
const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, isStxEnabledOnClient, accountHardwareType, location, abTests, activeAbTests, tokenSecurityTypeDestination);
|
|
522
609
|
let txMeta;
|
|
523
610
|
let approvalTxId;
|
|
524
611
|
let isDelegatedAccount = false;
|
|
@@ -558,7 +645,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
558
645
|
// Submit EVM tx
|
|
559
646
|
// For hardware wallets on Mobile, this is fixes an issue where the Ledger does not get prompted for the 2nd approval
|
|
560
647
|
// Extension does not have this issue
|
|
561
|
-
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE &&
|
|
648
|
+
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE &&
|
|
649
|
+
accountHardwareType !== null;
|
|
562
650
|
// Handle smart transactions if enabled
|
|
563
651
|
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getTraceParams)(quoteResponse, isStxEnabledOnClient), async () => {
|
|
564
652
|
if (!(0, bridge_controller_1.isEvmTxData)(quoteResponse.trade)) {
|
|
@@ -605,7 +693,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
605
693
|
const actionId = (0, transaction_1.generateActionId)().toString();
|
|
606
694
|
// Add pre-submission history keyed by actionId
|
|
607
695
|
// This ensures we have quote data available if transaction fails during submission
|
|
608
|
-
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
696
|
+
const historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
609
697
|
accountAddress: selectedAccount.address,
|
|
610
698
|
quoteResponse,
|
|
611
699
|
slippagePercentage: 0,
|
|
@@ -616,6 +704,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
616
704
|
abTests,
|
|
617
705
|
activeAbTests,
|
|
618
706
|
actionId,
|
|
707
|
+
tokenSecurityTypeDestination,
|
|
619
708
|
});
|
|
620
709
|
// Pass txFee when gasIncluded is true to use the quote's gas fees
|
|
621
710
|
// instead of re-estimating (which would fail for max native token swaps)
|
|
@@ -632,7 +721,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
632
721
|
actionId,
|
|
633
722
|
});
|
|
634
723
|
// On success, rekey from actionId to txMeta.id and update srcTxHash
|
|
635
|
-
__classPrivateFieldGet(this, _BridgeStatusController_rekeyHistoryItem, "f").call(this,
|
|
724
|
+
__classPrivateFieldGet(this, _BridgeStatusController_rekeyHistoryItem, "f").call(this, historyKey, tradeTxMeta);
|
|
636
725
|
return tradeTxMeta;
|
|
637
726
|
});
|
|
638
727
|
}
|
|
@@ -652,11 +741,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
652
741
|
!isStxEnabledOnClient &&
|
|
653
742
|
!quoteResponse.quote.gasIncluded7702 &&
|
|
654
743
|
!isDelegatedAccount;
|
|
744
|
+
let historyKey = txMeta.id;
|
|
655
745
|
if (!isNonBatchEvm) {
|
|
656
746
|
// Add swap or bridge tx to history
|
|
657
|
-
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
747
|
+
historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
658
748
|
accountAddress: selectedAccount.address,
|
|
659
|
-
bridgeTxMeta: txMeta, // Only the id
|
|
749
|
+
bridgeTxMeta: txMeta, // Only the id and hash fields are used by the BridgeStatusController
|
|
660
750
|
quoteResponse,
|
|
661
751
|
slippagePercentage: 0, // TODO include slippage provided by quote if using dynamic slippage, or slippage from quote request
|
|
662
752
|
isStxEnabled: isStxEnabledOnClient,
|
|
@@ -665,14 +755,15 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
665
755
|
location,
|
|
666
756
|
abTests,
|
|
667
757
|
activeAbTests,
|
|
758
|
+
tokenSecurityTypeDestination,
|
|
668
759
|
});
|
|
669
760
|
}
|
|
670
761
|
if ((0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId)) {
|
|
671
762
|
// Start polling for bridge tx status
|
|
672
|
-
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this,
|
|
763
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
|
|
673
764
|
// Track non-EVM Swap completed event
|
|
674
765
|
if (!(isBridgeTx || isTronTx)) {
|
|
675
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed,
|
|
766
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, historyKey);
|
|
676
767
|
}
|
|
677
768
|
}
|
|
678
769
|
}
|
|
@@ -691,23 +782,25 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
691
782
|
* @param params.location - The entry point from which the user initiated the swap or bridge
|
|
692
783
|
* @param params.abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
|
|
693
784
|
* @param params.activeAbTests - New A/B test context for `active_ab_tests` (migration target). Attributes events to specific experiments.
|
|
785
|
+
* @param params.tokenSecurityTypeDestination - The security classification of the destination token, supplied by the client (e.g. from token security/scanning data). Pass `null` when no security data is available.
|
|
694
786
|
* @returns A lightweight TransactionMeta-like object for history linking
|
|
695
787
|
*/
|
|
696
788
|
this.submitIntent = async (params) => {
|
|
697
|
-
const { quoteResponse, accountAddress, location, abTests, activeAbTests } = params;
|
|
789
|
+
const { quoteResponse, accountAddress, location, abTests, activeAbTests, tokenSecurityTypeDestination, } = params;
|
|
698
790
|
// TODO add metrics context
|
|
699
791
|
(0, bridge_1.stopPollingForQuotes)(this.messenger);
|
|
700
792
|
const startTime = Date.now();
|
|
701
793
|
// Build pre-confirmation properties for error tracking parity with submitTx
|
|
702
794
|
const account = (0, accounts_1.getAccountByAddress)(this.messenger, accountAddress);
|
|
703
|
-
const
|
|
704
|
-
const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, false,
|
|
795
|
+
const accountHardwareType = (0, bridge_controller_1.getAccountHardwareType)(account);
|
|
796
|
+
const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, false, accountHardwareType, location, abTests, activeAbTests, tokenSecurityTypeDestination);
|
|
705
797
|
try {
|
|
706
798
|
const intent = (0, intent_api_1.getIntentFromQuote)(quoteResponse);
|
|
707
799
|
// If backend provided an approval tx for this intent quote, submit it first (on-chain),
|
|
708
800
|
// then proceed with off-chain intent submission.
|
|
709
801
|
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
710
|
-
const requireApproval =
|
|
802
|
+
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE &&
|
|
803
|
+
accountHardwareType !== null;
|
|
711
804
|
// Handle approval silently for better UX in intent flows
|
|
712
805
|
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval, quoteResponse.resetApproval, requireApproval);
|
|
713
806
|
const approvalTxId = approvalTxMeta?.id;
|
|
@@ -770,15 +863,14 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
770
863
|
};
|
|
771
864
|
// Record in bridge history with actual transaction metadata
|
|
772
865
|
try {
|
|
773
|
-
// Use orderId as the history key for intent transactions
|
|
774
|
-
const bridgeHistoryKey = orderUid;
|
|
775
866
|
// Create a bridge transaction metadata that includes the original txId
|
|
776
867
|
const bridgeTxMetaForHistory = {
|
|
777
868
|
...syntheticMeta,
|
|
778
|
-
id:
|
|
869
|
+
id: orderUid,
|
|
779
870
|
originalTransactionId: syntheticMeta.id, // Keep original txId for TransactionController updates
|
|
780
871
|
};
|
|
781
|
-
|
|
872
|
+
// Use orderId as the history key for intent transactions
|
|
873
|
+
const historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
782
874
|
accountAddress,
|
|
783
875
|
bridgeTxMeta: bridgeTxMetaForHistory,
|
|
784
876
|
quoteResponse,
|
|
@@ -789,9 +881,10 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
789
881
|
location,
|
|
790
882
|
abTests,
|
|
791
883
|
activeAbTests,
|
|
884
|
+
tokenSecurityTypeDestination,
|
|
792
885
|
});
|
|
793
886
|
// Start polling using the orderId key to route to intent manager
|
|
794
|
-
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this,
|
|
887
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
|
|
795
888
|
}
|
|
796
889
|
catch (error) {
|
|
797
890
|
console.error('📝 [submitIntent] Failed to add to bridge history', error);
|
|
@@ -807,6 +900,13 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
807
900
|
throw error;
|
|
808
901
|
}
|
|
809
902
|
};
|
|
903
|
+
_BridgeStatusController_trackPollingStatusUpdatedEvent.set(this, (historyKey, pollingStatus) => {
|
|
904
|
+
// Track polling status updated event
|
|
905
|
+
const historyItem = this.state.txHistory[historyKey];
|
|
906
|
+
if (historyItem && !historyItem.featureId) {
|
|
907
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.PollingStatusUpdated, historyKey, (0, metrics_1.getPollingStatusUpdatedProperties)(this.messenger, pollingStatus, historyItem));
|
|
908
|
+
}
|
|
909
|
+
});
|
|
810
910
|
/**
|
|
811
911
|
* Tracks post-submission events for a cross-chain swap based on the history item
|
|
812
912
|
*
|
|
@@ -870,6 +970,7 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
870
970
|
chain_id_destination: requestParamProperties.chain_id_destination,
|
|
871
971
|
token_address_source: requestParamProperties.token_address_source,
|
|
872
972
|
token_address_destination: requestParamProperties.token_address_destination,
|
|
973
|
+
token_security_type_destination: requestParamProperties.token_security_type_destination,
|
|
873
974
|
refresh_count: historyItem.attempts?.counter ?? 0,
|
|
874
975
|
},
|
|
875
976
|
});
|
|
@@ -911,53 +1012,46 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
911
1012
|
fetchFn: __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"),
|
|
912
1013
|
}), "f");
|
|
913
1014
|
// Register action handlers
|
|
914
|
-
this.messenger.
|
|
915
|
-
this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:wipeBridgeStatus`, this.wipeBridgeStatus.bind(this));
|
|
916
|
-
this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:resetState`, this.resetState.bind(this));
|
|
917
|
-
this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:submitTx`, this.submitTx.bind(this));
|
|
918
|
-
this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:submitIntent`, this.submitIntent.bind(this));
|
|
919
|
-
this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:restartPollingForFailedAttempts`, this.restartPollingForFailedAttempts.bind(this));
|
|
920
|
-
this.messenger.registerActionHandler(`${constants_1.BRIDGE_STATUS_CONTROLLER_NAME}:getBridgeHistoryItemByTxMetaId`, this.getBridgeHistoryItemByTxMetaId.bind(this));
|
|
1015
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
921
1016
|
// Set interval
|
|
922
1017
|
this.setIntervalLength(constants_1.REFRESH_INTERVAL_MS);
|
|
923
|
-
this.messenger.subscribe('TransactionController:
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
[
|
|
927
|
-
transaction_controller_1.TransactionType.bridge,
|
|
928
|
-
transaction_controller_1.TransactionType.swap,
|
|
929
|
-
transaction_controller_1.TransactionType.bridgeApproval,
|
|
930
|
-
transaction_controller_1.TransactionType.swapApproval,
|
|
931
|
-
].includes(type) &&
|
|
932
|
-
[
|
|
933
|
-
transaction_controller_1.TransactionStatus.failed,
|
|
934
|
-
transaction_controller_1.TransactionStatus.dropped,
|
|
935
|
-
transaction_controller_1.TransactionStatus.rejected,
|
|
936
|
-
].includes(status)) {
|
|
937
|
-
// Mark tx as failed in txHistory
|
|
938
|
-
__classPrivateFieldGet(this, _BridgeStatusController_markTxAsFailed, "f").call(this, transactionMeta);
|
|
939
|
-
// Track failed event
|
|
940
|
-
if (status !== transaction_controller_1.TransactionStatus.rejected) {
|
|
941
|
-
// Look up history by txMetaId first, then by actionId (for pre-submission failures)
|
|
942
|
-
let historyKey;
|
|
943
|
-
if (this.state.txHistory[txMetaId]) {
|
|
944
|
-
historyKey = txMetaId;
|
|
945
|
-
}
|
|
946
|
-
else if (actionId && this.state.txHistory[actionId]) {
|
|
947
|
-
historyKey = actionId;
|
|
948
|
-
}
|
|
949
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, historyKey ?? txMetaId, (0, metrics_1.getEVMTxPropertiesFromTransactionMeta)(transactionMeta));
|
|
950
|
-
}
|
|
1018
|
+
this.messenger.subscribe('TransactionController:transactionStatusUpdated', ({ txMeta, historyKey, historyItem, isApprovalTxMeta }) => {
|
|
1019
|
+
if (!txMeta) {
|
|
1020
|
+
return;
|
|
951
1021
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
1022
|
+
const { type, status } = txMeta;
|
|
1023
|
+
// Allow event publishing if the txMeta is a swap/bridge OR if the
|
|
1024
|
+
// corresponding history item exists
|
|
1025
|
+
const isSwapOrBridgeTransaction = type && (0, transaction_1.isCrossChainTx)(type);
|
|
1026
|
+
if (!isSwapOrBridgeTransaction && !historyKey && !historyItem) {
|
|
1027
|
+
return;
|
|
957
1028
|
}
|
|
958
|
-
|
|
959
|
-
|
|
1029
|
+
switch (status) {
|
|
1030
|
+
case transaction_controller_1.TransactionStatus.confirmed:
|
|
1031
|
+
__classPrivateFieldGet(this, _BridgeStatusController_onTransactionConfirmed, "f").call(this, {
|
|
1032
|
+
txMeta,
|
|
1033
|
+
historyKey,
|
|
1034
|
+
isApprovalTxMeta,
|
|
1035
|
+
});
|
|
1036
|
+
break;
|
|
1037
|
+
case transaction_controller_1.TransactionStatus.failed:
|
|
1038
|
+
case transaction_controller_1.TransactionStatus.dropped:
|
|
1039
|
+
case transaction_controller_1.TransactionStatus.rejected:
|
|
1040
|
+
__classPrivateFieldGet(this, _BridgeStatusController_onTransactionFailed, "f").call(this, { txMeta, historyKey, isApprovalTxMeta });
|
|
1041
|
+
break;
|
|
1042
|
+
default:
|
|
1043
|
+
break;
|
|
960
1044
|
}
|
|
1045
|
+
}, ({ transactionMeta }) => {
|
|
1046
|
+
const entry = (0, history_1.getMatchingHistoryEntryForTxMeta)(this.state.txHistory, transactionMeta);
|
|
1047
|
+
const approvalEntry = (0, history_1.getMatchingHistoryEntryForApprovalTxMeta)(this.state.txHistory, transactionMeta);
|
|
1048
|
+
const entryToUse = entry ?? approvalEntry;
|
|
1049
|
+
return {
|
|
1050
|
+
historyKey: entryToUse?.[0],
|
|
1051
|
+
historyItem: entryToUse?.[1],
|
|
1052
|
+
txMeta: transactionMeta,
|
|
1053
|
+
isApprovalTxMeta: entryToUse?.[1]?.approvalTxId === transactionMeta.id,
|
|
1054
|
+
};
|
|
961
1055
|
});
|
|
962
1056
|
// If you close the extension, but keep the browser open, the polling continues
|
|
963
1057
|
// If you close the browser, the polling stops
|
|
@@ -966,5 +1060,5 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
966
1060
|
}
|
|
967
1061
|
}
|
|
968
1062
|
exports.BridgeStatusController = BridgeStatusController;
|
|
969
|
-
_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(),
|
|
1063
|
+
_BridgeStatusController_pollingTokensByTxMetaId = new WeakMap(), _BridgeStatusController_intentManager = new WeakMap(), _BridgeStatusController_clientId = new WeakMap(), _BridgeStatusController_fetchFn = new WeakMap(), _BridgeStatusController_config = new WeakMap(), _BridgeStatusController_addTransactionBatchFn = new WeakMap(), _BridgeStatusController_trace = new WeakMap(), _BridgeStatusController_onTransactionFailed = new WeakMap(), _BridgeStatusController_onTransactionConfirmed = new WeakMap(), _BridgeStatusController_restartPollingForIncompleteHistoryItems = new WeakMap(), _BridgeStatusController_addTxToHistory = new WeakMap(), _BridgeStatusController_rekeyHistoryItem = new WeakMap(), _BridgeStatusController_startPollingForTxId = new WeakMap(), _BridgeStatusController_handleFetchFailure = new WeakMap(), _BridgeStatusController_handleOldHistoryItem = new WeakMap(), _BridgeStatusController_fetchBridgeTxStatus = new WeakMap(), _BridgeStatusController_setAndGetSrcTxHash = new WeakMap(), _BridgeStatusController_updateHistoryItem = new WeakMap(), _BridgeStatusController_deleteHistoryItem = new WeakMap(), _BridgeStatusController_wipeBridgeStatusByChainId = new WeakMap(), _BridgeStatusController_handleApprovalTx = new WeakMap(), _BridgeStatusController_handleEvmTransactionBatch = new WeakMap(), _BridgeStatusController_trackPollingStatusUpdatedEvent = new WeakMap(), _BridgeStatusController_trackUnifiedSwapBridgeEvent = new WeakMap();
|
|
970
1064
|
//# sourceMappingURL=bridge-status-controller.cjs.map
|