@metamask-previews/bridge-status-controller 71.2.0-preview-c7c3c44 → 71.2.0-preview-8751708e2
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 +2 -0
- package/dist/bridge-status-controller-method-action-types.cjs.map +1 -1
- package/dist/bridge-status-controller-method-action-types.d.cts +5 -1
- package/dist/bridge-status-controller-method-action-types.d.cts.map +1 -1
- package/dist/bridge-status-controller-method-action-types.d.mts +5 -1
- package/dist/bridge-status-controller-method-action-types.d.mts.map +1 -1
- package/dist/bridge-status-controller-method-action-types.mjs.map +1 -1
- package/dist/bridge-status-controller.cjs +152 -364
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +27 -7
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +27 -7
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +153 -368
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/strategy/batch-sell-strategy.cjs +163 -0
- package/dist/strategy/batch-sell-strategy.cjs.map +1 -0
- package/dist/strategy/batch-sell-strategy.d.cts +10 -0
- package/dist/strategy/batch-sell-strategy.d.cts.map +1 -0
- package/dist/strategy/batch-sell-strategy.d.mts +10 -0
- package/dist/strategy/batch-sell-strategy.d.mts.map +1 -0
- package/dist/strategy/batch-sell-strategy.mjs +159 -0
- package/dist/strategy/batch-sell-strategy.mjs.map +1 -0
- package/dist/strategy/batch-strategy.cjs +73 -0
- package/dist/strategy/batch-strategy.cjs.map +1 -0
- package/dist/strategy/batch-strategy.d.cts +10 -0
- package/dist/strategy/batch-strategy.d.cts.map +1 -0
- package/dist/strategy/batch-strategy.d.mts +10 -0
- package/dist/strategy/batch-strategy.d.mts.map +1 -0
- package/dist/strategy/batch-strategy.mjs +69 -0
- package/dist/strategy/batch-strategy.mjs.map +1 -0
- package/dist/strategy/evm-strategy.cjs +147 -0
- package/dist/strategy/evm-strategy.cjs.map +1 -0
- package/dist/strategy/evm-strategy.d.cts +38 -0
- package/dist/strategy/evm-strategy.d.cts.map +1 -0
- package/dist/strategy/evm-strategy.d.mts +38 -0
- package/dist/strategy/evm-strategy.d.mts.map +1 -0
- package/dist/strategy/evm-strategy.mjs +141 -0
- package/dist/strategy/evm-strategy.mjs.map +1 -0
- package/dist/strategy/index.cjs +68 -0
- package/dist/strategy/index.cjs.map +1 -0
- package/dist/strategy/index.d.cts +12 -0
- package/dist/strategy/index.d.cts.map +1 -0
- package/dist/strategy/index.d.mts +12 -0
- package/dist/strategy/index.d.mts.map +1 -0
- package/dist/strategy/index.mjs +66 -0
- package/dist/strategy/index.mjs.map +1 -0
- package/dist/strategy/intent-strategy.cjs +160 -0
- package/dist/strategy/intent-strategy.cjs.map +1 -0
- package/dist/strategy/intent-strategy.d.cts +17 -0
- package/dist/strategy/intent-strategy.d.cts.map +1 -0
- package/dist/strategy/intent-strategy.d.mts +17 -0
- package/dist/strategy/intent-strategy.d.mts.map +1 -0
- package/dist/strategy/intent-strategy.mjs +156 -0
- package/dist/strategy/intent-strategy.mjs.map +1 -0
- package/dist/strategy/non-evm-strategy.cjs +80 -0
- package/dist/strategy/non-evm-strategy.cjs.map +1 -0
- package/dist/strategy/non-evm-strategy.d.cts +15 -0
- package/dist/strategy/non-evm-strategy.d.cts.map +1 -0
- package/dist/strategy/non-evm-strategy.d.mts +15 -0
- package/dist/strategy/non-evm-strategy.d.mts.map +1 -0
- package/dist/strategy/non-evm-strategy.mjs +76 -0
- package/dist/strategy/non-evm-strategy.mjs.map +1 -0
- package/dist/strategy/types.cjs +13 -0
- package/dist/strategy/types.cjs.map +1 -0
- package/dist/strategy/types.d.cts +88 -0
- package/dist/strategy/types.d.cts.map +1 -0
- package/dist/strategy/types.d.mts +88 -0
- package/dist/strategy/types.d.mts.map +1 -0
- package/dist/strategy/types.mjs +10 -0
- package/dist/strategy/types.mjs.map +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +10 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +10 -3
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/bridge.cjs +5 -1
- package/dist/utils/bridge.cjs.map +1 -1
- package/dist/utils/bridge.d.cts +2 -2
- package/dist/utils/bridge.d.cts.map +1 -1
- package/dist/utils/bridge.d.mts +2 -2
- package/dist/utils/bridge.d.mts.map +1 -1
- package/dist/utils/bridge.mjs +3 -0
- package/dist/utils/bridge.mjs.map +1 -1
- package/dist/utils/history.cjs +37 -20
- package/dist/utils/history.cjs.map +1 -1
- package/dist/utils/history.d.cts +3 -5
- package/dist/utils/history.d.cts.map +1 -1
- package/dist/utils/history.d.mts +3 -5
- package/dist/utils/history.d.mts.map +1 -1
- package/dist/utils/history.mjs +37 -20
- package/dist/utils/history.mjs.map +1 -1
- package/dist/utils/metrics.cjs +3 -3
- package/dist/utils/metrics.cjs.map +1 -1
- package/dist/utils/metrics.d.cts +3 -3
- package/dist/utils/metrics.d.cts.map +1 -1
- package/dist/utils/metrics.d.mts +3 -3
- package/dist/utils/metrics.d.mts.map +1 -1
- package/dist/utils/metrics.mjs +3 -3
- package/dist/utils/metrics.mjs.map +1 -1
- package/dist/utils/trace.cjs +4 -4
- package/dist/utils/trace.cjs.map +1 -1
- package/dist/utils/trace.d.cts +2 -2
- package/dist/utils/trace.d.cts.map +1 -1
- package/dist/utils/trace.d.mts +2 -2
- package/dist/utils/trace.d.mts.map +1 -1
- package/dist/utils/trace.mjs +4 -4
- package/dist/utils/trace.mjs.map +1 -1
- package/dist/utils/transaction.cjs +211 -229
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +64 -99
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +64 -99
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +204 -223
- package/dist/utils/transaction.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,10 @@ 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
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
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_executeSubmitStrategy, _BridgeStatusController_trackPollingStatusUpdatedEvent, _BridgeStatusController_trackUnifiedSwapBridgeEvent;
|
|
14
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
18
|
exports.BridgeStatusController = void 0;
|
|
16
19
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
@@ -19,17 +22,16 @@ const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
|
19
22
|
const utils_1 = require("@metamask/utils");
|
|
20
23
|
const bridge_status_controller_intent_1 = require("./bridge-status-controller.intent.cjs");
|
|
21
24
|
const constants_1 = require("./constants.cjs");
|
|
22
|
-
const
|
|
25
|
+
const strategy_1 = __importDefault(require("./strategy/index.cjs"));
|
|
26
|
+
const types_1 = require("./strategy/types.cjs");
|
|
27
|
+
const types_2 = require("./types.cjs");
|
|
23
28
|
const accounts_1 = require("./utils/accounts.cjs");
|
|
24
29
|
const authentication_1 = require("./utils/authentication.cjs");
|
|
25
30
|
const bridge_1 = require("./utils/bridge.cjs");
|
|
26
31
|
const bridge_status_1 = require("./utils/bridge-status.cjs");
|
|
27
32
|
const history_1 = require("./utils/history.cjs");
|
|
28
|
-
const intent_api_1 = require("./utils/intent-api.cjs");
|
|
29
|
-
const keyring_1 = require("./utils/keyring.cjs");
|
|
30
33
|
const metrics_1 = require("./utils/metrics.cjs");
|
|
31
34
|
const network_1 = require("./utils/network.cjs");
|
|
32
|
-
const snaps_1 = require("./utils/snaps.cjs");
|
|
33
35
|
const trace_1 = require("./utils/trace.cjs");
|
|
34
36
|
const transaction_1 = require("./utils/transaction.cjs");
|
|
35
37
|
const metadata = {
|
|
@@ -48,6 +50,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
48
50
|
'resetState',
|
|
49
51
|
'submitTx',
|
|
50
52
|
'submitIntent',
|
|
53
|
+
'submitBatchSell',
|
|
51
54
|
'restartPollingForFailedAttempts',
|
|
52
55
|
'getBridgeHistoryItemByTxMetaId',
|
|
53
56
|
];
|
|
@@ -83,10 +86,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
83
86
|
if (txMeta.status === transaction_controller_1.TransactionStatus.rejected) {
|
|
84
87
|
return;
|
|
85
88
|
}
|
|
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
89
|
// Skip tracking if this is a duplicate failed event for the same history item
|
|
91
90
|
// This can happen if the transaction includes an approval tx that fails
|
|
92
91
|
if (isHistoryItemAlreadyFailed) {
|
|
@@ -246,26 +245,25 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
246
245
|
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
|
|
247
246
|
});
|
|
248
247
|
});
|
|
249
|
-
_BridgeStatusController_addTxToHistory.set(this, (...args) => {
|
|
250
|
-
const
|
|
248
|
+
_BridgeStatusController_addTxToHistory.set(this, (historyKey, ...args) => {
|
|
249
|
+
const txHistoryItem = (0, history_1.getInitialHistoryItem)(...args);
|
|
251
250
|
this.update((state) => {
|
|
252
|
-
// Use actionId as key for pre-submission, or txMeta.id for post-submission
|
|
253
251
|
state.txHistory[historyKey] = txHistoryItem;
|
|
254
252
|
});
|
|
255
|
-
return historyKey;
|
|
256
253
|
});
|
|
257
254
|
/**
|
|
258
255
|
* Rekeys a history item from actionId to txMeta.id after successful submission.
|
|
259
256
|
* Also updates txMetaId and srcTxHash which weren't available pre-submission.
|
|
260
257
|
*
|
|
261
|
-
* @param
|
|
258
|
+
* @param oldKey - The temporary key to use for the history item, usually the actionId
|
|
259
|
+
* @param newKey - The new key to use, typcally the txmeta.id
|
|
262
260
|
* @param txMeta - The transaction meta from the successful submission
|
|
263
261
|
* @param txMeta.id - The transaction meta id to use as the new key
|
|
264
262
|
* @param txMeta.hash - The transaction hash to set on the history item
|
|
265
263
|
*/
|
|
266
|
-
_BridgeStatusController_rekeyHistoryItem.set(this, (
|
|
264
|
+
_BridgeStatusController_rekeyHistoryItem.set(this, (oldKey, newKey, txMeta) => {
|
|
267
265
|
this.update((state) => {
|
|
268
|
-
(0, history_1.rekeyHistoryItemInState)(state,
|
|
266
|
+
(0, history_1.rekeyHistoryItemInState)(state, oldKey, newKey, txMeta);
|
|
269
267
|
});
|
|
270
268
|
});
|
|
271
269
|
_BridgeStatusController_startPollingForTxId.set(this, (txId) => {
|
|
@@ -296,7 +294,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
296
294
|
if (!bridgeTxMeta?.id) {
|
|
297
295
|
throw new Error('Cannot start polling: bridgeTxMeta.id is required for polling');
|
|
298
296
|
}
|
|
299
|
-
const historyKey =
|
|
297
|
+
const historyKey = bridgeTxMeta.id;
|
|
298
|
+
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, historyKey, txHistoryMeta);
|
|
300
299
|
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
|
|
301
300
|
};
|
|
302
301
|
// This will be called after you call this.startPolling()
|
|
@@ -540,237 +539,133 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
540
539
|
* TX SUBMISSION HANDLING
|
|
541
540
|
*******************************************************
|
|
542
541
|
*/
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
542
|
+
_BridgeStatusController_executeSubmitStrategy.set(this, async (params, sharedHistoryItemProperties) => {
|
|
543
|
+
let tradeTxMeta;
|
|
544
|
+
const steps = (0, strategy_1.default)(params);
|
|
545
|
+
// Each submission strategy determines when to execute step, which means these actions can happen in any order
|
|
546
|
+
for await (const { type, payload } of steps) {
|
|
547
|
+
try {
|
|
548
|
+
switch (type) {
|
|
549
|
+
case types_1.SubmitStep.RekeyHistoryItem:
|
|
550
|
+
__classPrivateFieldGet(this, _BridgeStatusController_rekeyHistoryItem, "f").call(this, payload.oldHistoryKey, payload.newHistoryKey, payload.tradeMeta);
|
|
551
|
+
break;
|
|
552
|
+
case types_1.SubmitStep.UpdateBatchTransactions:
|
|
553
|
+
(0, transaction_1.updateTransactionsInBatch)({
|
|
554
|
+
messenger: this.messenger,
|
|
555
|
+
allTradesWithMetadata: payload.quoteAndTxMetas,
|
|
556
|
+
});
|
|
557
|
+
break;
|
|
558
|
+
case types_1.SubmitStep.SetTradeMeta:
|
|
559
|
+
tradeTxMeta = payload.tradeMeta;
|
|
560
|
+
break;
|
|
561
|
+
case types_1.SubmitStep.AddHistoryItem:
|
|
562
|
+
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, payload.historyKey, {
|
|
563
|
+
...payload,
|
|
564
|
+
...sharedHistoryItemProperties,
|
|
565
|
+
accountAddress: params.selectedAccount.address,
|
|
566
|
+
isStxEnabled: params.isStxEnabled,
|
|
567
|
+
slippagePercentage: 0, // TODO include slippage provided by quote if using dynamic slippage, or slippage from quote request
|
|
568
|
+
});
|
|
569
|
+
break;
|
|
570
|
+
case types_1.SubmitStep.StartPolling:
|
|
571
|
+
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, payload.historyKey);
|
|
572
|
+
break;
|
|
573
|
+
case types_1.SubmitStep.PublishCompletedEvent:
|
|
574
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, payload.historyKey);
|
|
575
|
+
break;
|
|
576
|
+
/* c8 ignore start */
|
|
577
|
+
default:
|
|
578
|
+
throw new Error(`Unknown submit step type: ${String(type)}`);
|
|
579
|
+
/* c8 ignore end */
|
|
552
580
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
: transaction_controller_1.TransactionType.swapApproval,
|
|
558
|
-
trade: approval,
|
|
559
|
-
requireApproval,
|
|
560
|
-
});
|
|
561
|
-
await (0, transaction_1.handleApprovalDelay)(srcChainId);
|
|
562
|
-
return approvalTxMeta;
|
|
563
|
-
};
|
|
564
|
-
return await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getApprovalTraceParams)(quoteResponse, false), approveTx);
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
console.error('Failed to add to bridge history and start polling.', error);
|
|
584
|
+
}
|
|
565
585
|
}
|
|
566
|
-
return
|
|
567
|
-
});
|
|
568
|
-
// TODO simplify and make more readable
|
|
569
|
-
/**
|
|
570
|
-
* Submits batched EVM transactions to the TransactionController
|
|
571
|
-
*
|
|
572
|
-
* @param args - The parameters for the transaction
|
|
573
|
-
* @param args.isBridgeTx - Whether the transaction is a bridge transaction
|
|
574
|
-
* @param args.trade - The trade data to confirm
|
|
575
|
-
* @param args.approval - The approval data to confirm
|
|
576
|
-
* @param args.resetApproval - The ethereum:USDT reset approval data to confirm
|
|
577
|
-
* @param args.quoteResponse - The quote response
|
|
578
|
-
* @param args.requireApproval - Whether to require approval for the transaction
|
|
579
|
-
* @returns The approvalMeta and tradeMeta for the batched transaction
|
|
580
|
-
*/
|
|
581
|
-
_BridgeStatusController_handleEvmTransactionBatch.set(this, async (args) => {
|
|
582
|
-
const transactionParams = await (0, transaction_1.getAddTransactionBatchParams)({
|
|
583
|
-
messenger: this.messenger,
|
|
584
|
-
...args,
|
|
585
|
-
});
|
|
586
|
-
return await (0, transaction_1.addTransactionBatch)(this.messenger, __classPrivateFieldGet(this, _BridgeStatusController_addTransactionBatchFn, "f"), transactionParams);
|
|
586
|
+
return tradeTxMeta;
|
|
587
587
|
});
|
|
588
588
|
/**
|
|
589
589
|
* Submits a cross-chain swap transaction
|
|
590
590
|
*
|
|
591
591
|
* @param accountAddress - The address of the account to submit the transaction for
|
|
592
|
-
* @param
|
|
593
|
-
* @param
|
|
592
|
+
* @param maybeQuoteResponses - A single quote response or an array of quote responses
|
|
593
|
+
* @param isStxEnabled - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
|
|
594
594
|
* @param quotesReceivedContext - The context for the QuotesReceived event
|
|
595
595
|
* @param location - The entry point from which the user initiated the swap or bridge (e.g. Main View, Token View, Trending Explore)
|
|
596
596
|
* @param abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
|
|
597
597
|
* @param activeAbTests - New A/B test context for `active_ab_tests` (migration target). Attributes events to specific experiments.
|
|
598
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.
|
|
599
|
+
* @param batchSellTrades - Contains transaction data for the quotes, provided by the obtainGaslessBatch API
|
|
599
600
|
* @returns The transaction meta
|
|
601
|
+
* @throws An error if transaction submission fails before it gets published
|
|
600
602
|
*/
|
|
601
|
-
this.submitTx = async (accountAddress,
|
|
602
|
-
|
|
603
|
+
this.submitTx = async (accountAddress, maybeQuoteResponses, isStxEnabled, quotesReceivedContext, location = bridge_controller_1.MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests, tokenSecurityTypeDestination, batchSellTrades) => {
|
|
604
|
+
/**
|
|
605
|
+
* If there are multiple quote responses, we assume that they all originate from the same src chain
|
|
606
|
+
* and the same account. In this case its safe to use the first quote response's properties for
|
|
607
|
+
* metrics and other pre-submission logic
|
|
608
|
+
*/
|
|
609
|
+
const quoteResponses = Array.isArray(maybeQuoteResponses)
|
|
610
|
+
? maybeQuoteResponses
|
|
611
|
+
: [maybeQuoteResponses];
|
|
612
|
+
const quoteResponse = quoteResponses[0];
|
|
613
|
+
const { featureId, quote } = quoteResponse;
|
|
614
|
+
const startTime = Date.now();
|
|
615
|
+
(0, bridge_1.stopPollingForQuotes)(this.messenger, featureId, quotesReceivedContext);
|
|
603
616
|
const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, accountAddress);
|
|
604
617
|
if (!selectedAccount) {
|
|
605
618
|
throw new Error('Failed to submit cross-chain swap transaction: undefined multichain account');
|
|
606
619
|
}
|
|
607
620
|
const accountHardwareType = (0, bridge_controller_1.getAccountHardwareType)(selectedAccount);
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
-
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(
|
|
614
|
-
const
|
|
621
|
+
/**
|
|
622
|
+
* For hardware wallets on Mobile, this is fixes an issue where the Ledger does not get prompted for the 2nd approval.
|
|
623
|
+
* Extension does not have this issue
|
|
624
|
+
*/
|
|
625
|
+
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_2.BridgeClientId.MOBILE && accountHardwareType !== null;
|
|
626
|
+
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quote.srcChainId, quote.destChainId);
|
|
627
|
+
const preConfirmationProperties = (0, metrics_1.getPreConfirmationPropertiesFromQuote)(quoteResponse, isStxEnabled, accountHardwareType, location, abTests, activeAbTests, tokenSecurityTypeDestination);
|
|
615
628
|
try {
|
|
616
629
|
// Emit Submitted event after submit button is clicked
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE &&
|
|
649
|
-
accountHardwareType !== null;
|
|
650
|
-
// Handle smart transactions if enabled
|
|
651
|
-
txMeta = await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getTraceParams)(quoteResponse, isStxEnabledOnClient), async () => {
|
|
652
|
-
if (!(0, bridge_controller_1.isEvmTxData)(quoteResponse.trade)) {
|
|
653
|
-
throw new Error('Failed to submit cross-chain swap transaction: trade is not an EVM transaction');
|
|
654
|
-
}
|
|
655
|
-
// Check if the account is an EIP-7702 delegated account
|
|
656
|
-
// Delegated accounts only allow 1 in-flight tx, so approve + swap
|
|
657
|
-
// must be batched into a single transaction
|
|
658
|
-
const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.srcChainId);
|
|
659
|
-
isDelegatedAccount = await (0, transaction_1.checkIsDelegatedAccount)(this.messenger, quoteResponse.trade.from, [hexChainId]);
|
|
660
|
-
if (isStxEnabledOnClient ||
|
|
661
|
-
quoteResponse.quote.gasIncluded7702 ||
|
|
662
|
-
isDelegatedAccount) {
|
|
663
|
-
const { tradeMeta, approvalMeta } = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransactionBatch, "f").call(this, {
|
|
664
|
-
isBridgeTx,
|
|
665
|
-
resetApproval: quoteResponse.resetApproval,
|
|
666
|
-
approval: quoteResponse.approval &&
|
|
667
|
-
(0, bridge_controller_1.isEvmTxData)(quoteResponse.approval)
|
|
668
|
-
? quoteResponse.approval
|
|
669
|
-
: undefined,
|
|
670
|
-
trade: quoteResponse.trade,
|
|
671
|
-
quoteResponse,
|
|
672
|
-
requireApproval,
|
|
673
|
-
isDelegatedAccount,
|
|
674
|
-
});
|
|
675
|
-
approvalTxId = approvalMeta?.id;
|
|
676
|
-
return tradeMeta;
|
|
677
|
-
}
|
|
678
|
-
// Set approval time and id if an approval tx is needed
|
|
679
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval && (0, bridge_controller_1.isEvmTxData)(quoteResponse.approval)
|
|
680
|
-
? quoteResponse.approval
|
|
681
|
-
: undefined, quoteResponse.resetApproval, requireApproval);
|
|
682
|
-
approvalTxId = approvalTxMeta?.id;
|
|
683
|
-
// Hardware-wallet delay first (Ledger second-prompt spacing), then wait for
|
|
684
|
-
// on-chain approval confirmation so swap gas estimation runs after allowance is set.
|
|
685
|
-
if (requireApproval && approvalTxMeta) {
|
|
686
|
-
await (0, transaction_1.handleMobileHardwareWalletDelay)(requireApproval);
|
|
687
|
-
await (0, transaction_1.waitForTxConfirmation)(this.messenger, approvalTxMeta.id);
|
|
688
|
-
}
|
|
689
|
-
else {
|
|
690
|
-
await (0, transaction_1.handleMobileHardwareWalletDelay)(requireApproval);
|
|
691
|
-
}
|
|
692
|
-
// Generate actionId for pre-submission history (non-batch EVM only)
|
|
693
|
-
const actionId = (0, transaction_1.generateActionId)().toString();
|
|
694
|
-
// Add pre-submission history keyed by actionId
|
|
695
|
-
// This ensures we have quote data available if transaction fails during submission
|
|
696
|
-
const historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
697
|
-
accountAddress: selectedAccount.address,
|
|
698
|
-
quoteResponse,
|
|
699
|
-
slippagePercentage: 0,
|
|
700
|
-
isStxEnabled: isStxEnabledOnClient,
|
|
701
|
-
startTime,
|
|
702
|
-
approvalTxId,
|
|
703
|
-
location,
|
|
704
|
-
abTests,
|
|
705
|
-
activeAbTests,
|
|
706
|
-
actionId,
|
|
707
|
-
tokenSecurityTypeDestination,
|
|
708
|
-
});
|
|
709
|
-
// Pass txFee when gasIncluded is true to use the quote's gas fees
|
|
710
|
-
// instead of re-estimating (which would fail for max native token swaps)
|
|
711
|
-
const tradeTxMeta = await (0, transaction_1.submitEvmTransaction)({
|
|
712
|
-
messenger: this.messenger,
|
|
713
|
-
transactionType: isBridgeTx
|
|
714
|
-
? transaction_controller_1.TransactionType.bridge
|
|
715
|
-
: transaction_controller_1.TransactionType.swap,
|
|
716
|
-
trade: quoteResponse.trade,
|
|
717
|
-
requireApproval,
|
|
718
|
-
txFee: quoteResponse.quote.gasIncluded
|
|
719
|
-
? quoteResponse.quote.feeData.txFee
|
|
720
|
-
: undefined,
|
|
721
|
-
actionId,
|
|
722
|
-
});
|
|
723
|
-
// On success, rekey from actionId to txMeta.id and update srcTxHash
|
|
724
|
-
__classPrivateFieldGet(this, _BridgeStatusController_rekeyHistoryItem, "f").call(this, historyKey, tradeTxMeta);
|
|
725
|
-
return tradeTxMeta;
|
|
726
|
-
});
|
|
727
|
-
}
|
|
630
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties, featureId);
|
|
631
|
+
/**
|
|
632
|
+
* Check if the account is an EIP-7702 delegated account.
|
|
633
|
+
* Delegated accounts only allow 1 in-flight tx, so approve + swap
|
|
634
|
+
* must be batched into a single transaction
|
|
635
|
+
*/
|
|
636
|
+
const isDelegatedAccount = (0, bridge_controller_1.isNonEvmChainId)(quote.srcChainId)
|
|
637
|
+
? false
|
|
638
|
+
: await (0, transaction_1.checkIsDelegatedAccount)(this.messenger, selectedAccount.address, [(0, bridge_controller_1.formatChainIdToHex)(quote.srcChainId)]);
|
|
639
|
+
const strategyParams = {
|
|
640
|
+
messenger: this.messenger,
|
|
641
|
+
quoteResponses,
|
|
642
|
+
batchSellTrades,
|
|
643
|
+
isStxEnabled,
|
|
644
|
+
isBridgeTx,
|
|
645
|
+
isDelegatedAccount,
|
|
646
|
+
selectedAccount,
|
|
647
|
+
requireApproval,
|
|
648
|
+
clientId: __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"),
|
|
649
|
+
bridgeApiBaseUrl: __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl,
|
|
650
|
+
addTransactionBatchFn: __classPrivateFieldGet(this, _BridgeStatusController_addTransactionBatchFn, "f"),
|
|
651
|
+
fetchFn: __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"),
|
|
652
|
+
traceFn: __classPrivateFieldGet(this, _BridgeStatusController_trace, "f"),
|
|
653
|
+
};
|
|
654
|
+
return await __classPrivateFieldGet(this, _BridgeStatusController_trace, "f").call(this, (0, trace_1.getTraceParams)(quoteResponse, isStxEnabled), async () => await __classPrivateFieldGet(this, _BridgeStatusController_executeSubmitStrategy, "f").call(this, strategyParams, {
|
|
655
|
+
startTime,
|
|
656
|
+
location,
|
|
657
|
+
abTests,
|
|
658
|
+
activeAbTests,
|
|
659
|
+
tokenSecurityTypeDestination,
|
|
660
|
+
}));
|
|
728
661
|
}
|
|
729
662
|
catch (error) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
});
|
|
663
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, undefined, {
|
|
664
|
+
error_message: error?.message,
|
|
665
|
+
...preConfirmationProperties,
|
|
666
|
+
}, featureId);
|
|
735
667
|
throw error;
|
|
736
668
|
}
|
|
737
|
-
try {
|
|
738
|
-
// For non-batch EVM transactions, history was already added/rekeyed above
|
|
739
|
-
// Only add history here for non-EVM and batch EVM transactions
|
|
740
|
-
const isNonBatchEvm = !(0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId) &&
|
|
741
|
-
!isStxEnabledOnClient &&
|
|
742
|
-
!quoteResponse.quote.gasIncluded7702 &&
|
|
743
|
-
!isDelegatedAccount;
|
|
744
|
-
let historyKey = txMeta.id;
|
|
745
|
-
if (!isNonBatchEvm) {
|
|
746
|
-
// Add swap or bridge tx to history
|
|
747
|
-
historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
748
|
-
accountAddress: selectedAccount.address,
|
|
749
|
-
bridgeTxMeta: txMeta, // Only the id and hash fields are used by the BridgeStatusController
|
|
750
|
-
quoteResponse,
|
|
751
|
-
slippagePercentage: 0, // TODO include slippage provided by quote if using dynamic slippage, or slippage from quote request
|
|
752
|
-
isStxEnabled: isStxEnabledOnClient,
|
|
753
|
-
startTime,
|
|
754
|
-
approvalTxId,
|
|
755
|
-
location,
|
|
756
|
-
abTests,
|
|
757
|
-
activeAbTests,
|
|
758
|
-
tokenSecurityTypeDestination,
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
if ((0, bridge_controller_1.isNonEvmChainId)(quoteResponse.quote.srcChainId)) {
|
|
762
|
-
// Start polling for bridge tx status
|
|
763
|
-
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
|
|
764
|
-
// Track non-EVM Swap completed event
|
|
765
|
-
if (!(isBridgeTx || isTronTx)) {
|
|
766
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Completed, historyKey);
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
catch {
|
|
771
|
-
// Ignore errors here, we don't want to crash the app if this fails and tx submission succeeds
|
|
772
|
-
}
|
|
773
|
-
return txMeta;
|
|
774
669
|
};
|
|
775
670
|
/**
|
|
776
671
|
* Submits an intent order and creates a synthetic history entry for UX.
|
|
@@ -782,136 +677,29 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
782
677
|
* @param params.location - The entry point from which the user initiated the swap or bridge
|
|
783
678
|
* @param params.abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
|
|
784
679
|
* @param params.activeAbTests - New A/B test context for `active_ab_tests` (migration target). Attributes events to specific experiments.
|
|
680
|
+
* @param params.isStxEnabled - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
|
|
681
|
+
* @param params.quotesReceivedContext - The context for the QuotesReceived event
|
|
785
682
|
* @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.
|
|
786
683
|
* @returns A lightweight TransactionMeta-like object for history linking
|
|
684
|
+
* @throws An error if intent or transaction submission fails before they get published
|
|
787
685
|
*/
|
|
788
686
|
this.submitIntent = async (params) => {
|
|
789
|
-
const { quoteResponse, accountAddress, location, abTests, activeAbTests, tokenSecurityTypeDestination, } = params;
|
|
687
|
+
const { quoteResponse, accountAddress, location, abTests, activeAbTests, isStxEnabled = false, quotesReceivedContext, tokenSecurityTypeDestination, } = params;
|
|
790
688
|
// TODO add metrics context
|
|
791
|
-
(
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
// then proceed with off-chain intent submission.
|
|
801
|
-
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
802
|
-
const requireApproval = __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === types_1.BridgeClientId.MOBILE &&
|
|
803
|
-
accountHardwareType !== null;
|
|
804
|
-
// Handle approval silently for better UX in intent flows
|
|
805
|
-
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, quoteResponse, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval, quoteResponse.resetApproval, requireApproval);
|
|
806
|
-
const approvalTxId = approvalTxMeta?.id;
|
|
807
|
-
if (approvalTxId) {
|
|
808
|
-
await (0, transaction_1.waitForTxConfirmation)(this.messenger, approvalTxId);
|
|
809
|
-
}
|
|
810
|
-
const { srcChainId, requestId } = quoteResponse.quote;
|
|
811
|
-
const signature = await (0, keyring_1.signTypedMessage)({
|
|
812
|
-
messenger: this.messenger,
|
|
813
|
-
accountAddress,
|
|
814
|
-
typedData: intent.typedData,
|
|
815
|
-
});
|
|
816
|
-
const submissionParams = {
|
|
817
|
-
srcChainId,
|
|
818
|
-
quoteId: requestId,
|
|
819
|
-
signature,
|
|
820
|
-
order: intent.order,
|
|
821
|
-
userAddress: accountAddress,
|
|
822
|
-
aggregatorId: intent.protocol,
|
|
823
|
-
};
|
|
824
|
-
const { id: orderUid, status } = await (0, intent_api_1.postSubmitOrder)({
|
|
825
|
-
params: submissionParams,
|
|
826
|
-
clientId: __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"),
|
|
827
|
-
jwt: await (0, authentication_1.getJwt)(this.messenger),
|
|
828
|
-
fetchFn: __classPrivateFieldGet(this, _BridgeStatusController_fetchFn, "f"),
|
|
829
|
-
bridgeApiBaseUrl: __classPrivateFieldGet(this, _BridgeStatusController_config, "f").customBridgeApiBaseUrl,
|
|
830
|
-
});
|
|
831
|
-
// Determine transaction type: swap for same-chain, bridge for cross-chain
|
|
832
|
-
const transactionType = isBridgeTx
|
|
833
|
-
? /* c8 ignore start */
|
|
834
|
-
transaction_controller_1.TransactionType.bridge
|
|
835
|
-
: /* c8 ignore end */
|
|
836
|
-
transaction_controller_1.TransactionType.swap;
|
|
837
|
-
// Create actual transaction in Transaction Controller first
|
|
838
|
-
const networkClientId = (0, network_1.getNetworkClientIdByChainId)(this.messenger, srcChainId);
|
|
839
|
-
// This is a synthetic transaction whose purpose is to be able
|
|
840
|
-
// to track the order status via the history
|
|
841
|
-
const intentTransactionParams = {
|
|
842
|
-
chainId: (0, bridge_controller_1.formatChainIdToHex)(srcChainId),
|
|
843
|
-
from: accountAddress,
|
|
844
|
-
to: intent.settlementContract ??
|
|
845
|
-
'0x9008D19f58AAbd9eD0D60971565AA8510560ab41', // Default settlement contract
|
|
846
|
-
data: `0x${orderUid.slice(-8)}`, // Use last 8 chars of orderUid to make each transaction unique
|
|
847
|
-
value: '0x0',
|
|
848
|
-
gas: '0x5208', // Minimal gas for display purposes
|
|
849
|
-
gasPrice: '0x3b9aca00', // 1 Gwei - will be converted to EIP-1559 fees if network supports it
|
|
850
|
-
};
|
|
851
|
-
const initialTxMeta = await (0, transaction_1.addSyntheticTransaction)(this.messenger, intentTransactionParams, {
|
|
852
|
-
requireApproval: false,
|
|
853
|
-
networkClientId,
|
|
854
|
-
type: transactionType,
|
|
855
|
-
});
|
|
856
|
-
// Update txHistory with actual transaction metadata
|
|
857
|
-
const syntheticMeta = {
|
|
858
|
-
...initialTxMeta,
|
|
859
|
-
// Map intent order status to TransactionController status
|
|
860
|
-
status: (0, intent_api_1.mapIntentOrderStatusToTransactionStatus)(status),
|
|
861
|
-
isIntentTx: true,
|
|
862
|
-
orderUid,
|
|
863
|
-
};
|
|
864
|
-
// Record in bridge history with actual transaction metadata
|
|
865
|
-
try {
|
|
866
|
-
// Create a bridge transaction metadata keyed by orderUid for intent polling
|
|
867
|
-
const bridgeTxMetaForHistory = {
|
|
868
|
-
...syntheticMeta,
|
|
869
|
-
id: orderUid,
|
|
870
|
-
};
|
|
871
|
-
// Use orderId as the history key for intent transactions
|
|
872
|
-
// IMPORTANT: pass originalTransactionId as a top-level argument so
|
|
873
|
-
// `getInitialHistoryItem` reads it. Setting it on `bridgeTxMeta` is a no-op
|
|
874
|
-
// because `getInitialHistoryItem` destructures `originalTransactionId` from
|
|
875
|
-
// the top-level args, not from `bridgeTxMeta`. Without this, the field
|
|
876
|
-
// falls back to `bridgeTxMeta.id` (the orderUid), severing the link between
|
|
877
|
-
// the bridge history record and the synthetic TransactionController entry.
|
|
878
|
-
const historyKey = __classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
879
|
-
accountAddress,
|
|
880
|
-
bridgeTxMeta: bridgeTxMetaForHistory,
|
|
881
|
-
originalTransactionId: syntheticMeta.id,
|
|
882
|
-
quoteResponse,
|
|
883
|
-
slippagePercentage: 0,
|
|
884
|
-
isStxEnabled: false,
|
|
885
|
-
approvalTxId,
|
|
886
|
-
startTime,
|
|
887
|
-
location,
|
|
888
|
-
abTests,
|
|
889
|
-
activeAbTests,
|
|
890
|
-
tokenSecurityTypeDestination,
|
|
891
|
-
});
|
|
892
|
-
// Start polling using the orderId key to route to intent manager
|
|
893
|
-
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, historyKey);
|
|
894
|
-
}
|
|
895
|
-
catch (error) {
|
|
896
|
-
console.error('📝 [submitIntent] Failed to add to bridge history', error);
|
|
897
|
-
// non-fatal but log the error
|
|
898
|
-
}
|
|
899
|
-
return syntheticMeta;
|
|
900
|
-
}
|
|
901
|
-
catch (error) {
|
|
902
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.Failed, undefined, {
|
|
903
|
-
error_message: error?.message,
|
|
904
|
-
...preConfirmationProperties,
|
|
905
|
-
});
|
|
906
|
-
throw error;
|
|
907
|
-
}
|
|
689
|
+
return await this.submitTx(accountAddress, quoteResponse, isStxEnabled, quotesReceivedContext, location, abTests, activeAbTests, tokenSecurityTypeDestination);
|
|
690
|
+
};
|
|
691
|
+
this.submitBatchSell = async (params) => {
|
|
692
|
+
/**
|
|
693
|
+
* Retrieve the batch sell trades from the BridgeController's state to ensure we submit
|
|
694
|
+
* the original response data from the bridge-api
|
|
695
|
+
*/
|
|
696
|
+
const batchSellTrades = (0, bridge_1.getBatchSellTrades)(this.messenger);
|
|
697
|
+
return await this.submitTx(params.accountAddress, params.quoteResponses.filter((quoteResponse) => quoteResponse !== null), params.isStxEnabled ?? false, params.quotesReceivedContext, params.location, params.abTests, params.activeAbTests, params.tokenSecurityTypeDestination, batchSellTrades);
|
|
908
698
|
};
|
|
909
699
|
_BridgeStatusController_trackPollingStatusUpdatedEvent.set(this, (historyKey, pollingStatus) => {
|
|
910
700
|
// Track polling status updated event
|
|
911
701
|
const historyItem = this.state.txHistory[historyKey];
|
|
912
|
-
|
|
913
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.PollingStatusUpdated, historyKey, (0, metrics_1.getPollingStatusUpdatedProperties)(this.messenger, pollingStatus, historyItem));
|
|
914
|
-
}
|
|
702
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, bridge_controller_1.UnifiedSwapBridgeEventName.PollingStatusUpdated, historyKey, (0, metrics_1.getPollingStatusUpdatedProperties)(this.messenger, pollingStatus, historyItem));
|
|
915
703
|
});
|
|
916
704
|
/**
|
|
917
705
|
* Tracks post-submission events for a cross-chain swap based on the history item
|
|
@@ -919,8 +707,22 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
919
707
|
* @param eventName - The name of the event to track
|
|
920
708
|
* @param txMetaId - The txMetaId of the history item to track the event for
|
|
921
709
|
* @param eventProperties - The properties for the event
|
|
710
|
+
* @param featureIdOverride - The featureId to use when the history item is not available. Should
|
|
711
|
+
* only be provided for events that are not associated with a history item yet, such as Submitted or Failed
|
|
922
712
|
*/
|
|
923
|
-
_BridgeStatusController_trackUnifiedSwapBridgeEvent.set(this, (eventName, txMetaId, eventProperties) => {
|
|
713
|
+
_BridgeStatusController_trackUnifiedSwapBridgeEvent.set(this, (eventName, txMetaId, eventProperties, featureIdOverride) => {
|
|
714
|
+
const historyItem = txMetaId
|
|
715
|
+
? this.state.txHistory[txMetaId]
|
|
716
|
+
: undefined;
|
|
717
|
+
const featureId = featureIdOverride ?? historyItem?.featureId;
|
|
718
|
+
const shouldSkipMetrics =
|
|
719
|
+
// Skip tracking all other events when featureId is set (i.e. PERPS)
|
|
720
|
+
featureId &&
|
|
721
|
+
// Always publish StatusValidationFailed event, regardless of featureId
|
|
722
|
+
eventName !== bridge_controller_1.UnifiedSwapBridgeEventName.StatusValidationFailed;
|
|
723
|
+
if (shouldSkipMetrics) {
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
924
726
|
// Legacy/new metrics fields are intentionally kept independent during migration.
|
|
925
727
|
const historyAbTests = txMetaId
|
|
926
728
|
? this.state.txHistory?.[txMetaId]?.abTests
|
|
@@ -930,12 +732,12 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
930
732
|
: undefined;
|
|
931
733
|
const resolvedAbTests = eventProperties?.ab_tests ?? historyAbTests;
|
|
932
734
|
const resolvedActiveAbTests = eventProperties?.active_ab_tests ?? historyActiveAbTests;
|
|
735
|
+
const location = (txMetaId ? this.state.txHistory?.[txMetaId]?.location : undefined) ??
|
|
736
|
+
bridge_controller_1.MetaMetricsSwapsEventSource.MainView;
|
|
933
737
|
const baseProperties = {
|
|
934
738
|
action_type: bridge_controller_1.MetricsActionType.SWAPBRIDGE_V1,
|
|
935
|
-
location: eventProperties?.location ??
|
|
936
|
-
(txMetaId ? this.state.txHistory?.[txMetaId]?.location : undefined) ??
|
|
937
|
-
bridge_controller_1.MetaMetricsSwapsEventSource.MainView,
|
|
938
739
|
...(eventProperties ?? {}),
|
|
740
|
+
location,
|
|
939
741
|
...(resolvedAbTests &&
|
|
940
742
|
Object.keys(resolvedAbTests).length > 0 && {
|
|
941
743
|
ab_tests: resolvedAbTests,
|
|
@@ -946,15 +748,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
946
748
|
}),
|
|
947
749
|
};
|
|
948
750
|
// This will publish events for PERPS dropped tx failures as well
|
|
949
|
-
if (!txMetaId) {
|
|
950
|
-
(0, bridge_1.trackMetricsEvent)({
|
|
951
|
-
messenger: this.messenger,
|
|
952
|
-
eventName,
|
|
953
|
-
properties: baseProperties,
|
|
954
|
-
});
|
|
955
|
-
return;
|
|
956
|
-
}
|
|
957
|
-
const historyItem = this.state.txHistory[txMetaId];
|
|
958
751
|
if (!historyItem) {
|
|
959
752
|
(0, bridge_1.trackMetricsEvent)({
|
|
960
753
|
messenger: this.messenger,
|
|
@@ -963,9 +756,8 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
963
756
|
});
|
|
964
757
|
return;
|
|
965
758
|
}
|
|
966
|
-
const {
|
|
759
|
+
const { approvalTxId, quote } = historyItem;
|
|
967
760
|
const requestParamProperties = (0, metrics_1.getRequestParamFromHistory)(historyItem);
|
|
968
|
-
// Always publish StatusValidationFailed event, regardless of featureId
|
|
969
761
|
if (eventName === bridge_controller_1.UnifiedSwapBridgeEventName.StatusValidationFailed) {
|
|
970
762
|
(0, bridge_1.trackMetricsEvent)({
|
|
971
763
|
messenger: this.messenger,
|
|
@@ -982,10 +774,6 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
982
774
|
});
|
|
983
775
|
return;
|
|
984
776
|
}
|
|
985
|
-
// Skip tracking all other events when featureId is set (i.e. PERPS)
|
|
986
|
-
if (featureId) {
|
|
987
|
-
return;
|
|
988
|
-
}
|
|
989
777
|
const selectedAccount = (0, accounts_1.getAccountByAddress)(this.messenger, historyItem.account);
|
|
990
778
|
const transactions = (0, transaction_1.getTransactions)(this.messenger);
|
|
991
779
|
const txMeta = transactions.find((tx) => tx.id === txMetaId);
|
|
@@ -1066,5 +854,5 @@ class BridgeStatusController extends (0, polling_controller_1.StaticIntervalPoll
|
|
|
1066
854
|
}
|
|
1067
855
|
}
|
|
1068
856
|
exports.BridgeStatusController = BridgeStatusController;
|
|
1069
|
-
_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(),
|
|
857
|
+
_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_executeSubmitStrategy = new WeakMap(), _BridgeStatusController_trackPollingStatusUpdatedEvent = new WeakMap(), _BridgeStatusController_trackUnifiedSwapBridgeEvent = new WeakMap();
|
|
1070
858
|
//# sourceMappingURL=bridge-status-controller.cjs.map
|