@metamask-previews/bridge-status-controller 66.0.2-preview-e7b1aa6 → 66.0.2-preview-e8f4442d4
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 +10 -0
- package/dist/bridge-status-controller.cjs +35 -9
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +5 -2
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +5 -2
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +36 -10
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +7 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +7 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _BridgeStatusController_instances, _BridgeStatusController_pollingTokensByTxMetaId, _BridgeStatusController_intentStatusManager, _BridgeStatusController_clientId, _BridgeStatusController_fetchFn, _BridgeStatusController_config, _BridgeStatusController_addTransactionFn, _BridgeStatusController_addTransactionBatchFn, _BridgeStatusController_updateTransactionFn, _BridgeStatusController_estimateGasFeeFn, _BridgeStatusController_trace, _BridgeStatusController_markTxAsFailed, _BridgeStatusController_restartPollingForIncompleteHistoryItems, _BridgeStatusController_addTxToHistory, _BridgeStatusController_rekeyHistoryItem, _BridgeStatusController_startPollingForTxId, _BridgeStatusController_shouldPollHistoryItem, _BridgeStatusController_getMultichainSelectedAccount, _BridgeStatusController_handleFetchFailure, _BridgeStatusController_fetchBridgeTxStatus, _BridgeStatusController_getSrcTxHash, _BridgeStatusController_updateSrcTxHash, _BridgeStatusController_wipeBridgeStatusByChainId, _BridgeStatusController_handleNonEvmTx, _BridgeStatusController_waitForHashAndReturnFinalTxMeta, _BridgeStatusController_waitForTxConfirmation, _BridgeStatusController_handleApprovalTx, _BridgeStatusController_handleEvmTransaction, _BridgeStatusController_handleUSDTAllowanceReset, _BridgeStatusController_calculateGasFees, _BridgeStatusController_handleEvmTransactionBatch, _BridgeStatusController_trackUnifiedSwapBridgeEvent;
|
|
13
|
-
import { formatChainIdToHex, isNonEvmChainId, StatusTypes, UnifiedSwapBridgeEventName, formatChainIdToCaip, isCrossChain, isTronChainId, isEvmTxData, isHardwareWallet, MetricsActionType, isBitcoinTrade, isTronTrade, AbortReason, PollingStatus } from "@metamask/bridge-controller";
|
|
13
|
+
import { formatChainIdToHex, isNonEvmChainId, StatusTypes, UnifiedSwapBridgeEventName, formatChainIdToCaip, isCrossChain, isTronChainId, isEvmTxData, isHardwareWallet, MetricsActionType, MetaMetricsSwapsEventSource, isBitcoinTrade, isTronTrade, AbortReason, PollingStatus } from "@metamask/bridge-controller";
|
|
14
14
|
import { toHex } from "@metamask/controller-utils";
|
|
15
15
|
import { StaticIntervalPollingController } from "@metamask/polling-controller";
|
|
16
16
|
import { TransactionStatus, TransactionType } from "@metamask/transaction-controller";
|
|
@@ -156,6 +156,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
156
156
|
action_type: MetricsActionType.SWAPBRIDGE_V1,
|
|
157
157
|
polling_status: PollingStatus.ManuallyRestarted,
|
|
158
158
|
retry_attempts: previousAttempts,
|
|
159
|
+
location: historyItem.location ?? MetaMetricsSwapsEventSource.MainView,
|
|
159
160
|
});
|
|
160
161
|
}
|
|
161
162
|
}
|
|
@@ -204,7 +205,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
204
205
|
});
|
|
205
206
|
});
|
|
206
207
|
_BridgeStatusController_addTxToHistory.set(this, (startPollingForBridgeTxStatusArgs, actionId) => {
|
|
207
|
-
const { bridgeTxMeta, statusRequest, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, accountAddress: selectedAddress, } = startPollingForBridgeTxStatusArgs;
|
|
208
|
+
const { bridgeTxMeta, statusRequest, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, accountAddress: selectedAddress, } = startPollingForBridgeTxStatusArgs;
|
|
208
209
|
// Determine the key for this history item:
|
|
209
210
|
// - For pre-submission (non-batch EVM): use actionId
|
|
210
211
|
// - For post-submission or other cases: use bridgeTxMeta.id
|
|
@@ -244,6 +245,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
244
245
|
approvalTxId,
|
|
245
246
|
isStxEnabled: isStxEnabled ?? false,
|
|
246
247
|
featureId: quoteResponse.featureId,
|
|
248
|
+
location,
|
|
247
249
|
};
|
|
248
250
|
this.update((state) => {
|
|
249
251
|
// Use actionId as key for pre-submission, or txMeta.id for post-submission
|
|
@@ -352,6 +354,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
352
354
|
action_type: MetricsActionType.SWAPBRIDGE_V1,
|
|
353
355
|
polling_status: PollingStatus.MaxPollingReached,
|
|
354
356
|
retry_attempts: newAttempts.counter,
|
|
357
|
+
location: historyItem.location ?? MetaMetricsSwapsEventSource.MainView,
|
|
355
358
|
});
|
|
356
359
|
}
|
|
357
360
|
}
|
|
@@ -403,6 +406,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
403
406
|
if (validationFailures.length > 0) {
|
|
404
407
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.StatusValidationFailed, bridgeTxMetaId, {
|
|
405
408
|
failures: validationFailures,
|
|
409
|
+
location: historyItem.location ?? MetaMetricsSwapsEventSource.MainView,
|
|
406
410
|
});
|
|
407
411
|
throw new Error(`Bridge status validation failed: ${validationFailures.join(', ')}`);
|
|
408
412
|
}
|
|
@@ -698,9 +702,10 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
698
702
|
* @param quoteResponse - The quote response
|
|
699
703
|
* @param isStxEnabledOnClient - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
|
|
700
704
|
* @param quotesReceivedContext - The context for the QuotesReceived event
|
|
705
|
+
* @param location - The entry point from which the user initiated the swap or bridge (e.g. Main View, Token View, trending_explore)
|
|
701
706
|
* @returns The transaction meta
|
|
702
707
|
*/
|
|
703
|
-
this.submitTx = async (accountAddress, quoteResponse, isStxEnabledOnClient, quotesReceivedContext) => {
|
|
708
|
+
this.submitTx = async (accountAddress, quoteResponse, isStxEnabledOnClient, quotesReceivedContext, location) => {
|
|
704
709
|
this.messenger.call('BridgeController:stopPollingForQuotes', AbortReason.TransactionSubmitted,
|
|
705
710
|
// If trade is submitted before all quotes are loaded, the QuotesReceived event is published
|
|
706
711
|
// If the trade has a featureId, it means it was submitted outside of the Unified Swap and Bridge experience, so no QuotesReceived event is published
|
|
@@ -713,7 +718,10 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
713
718
|
const preConfirmationProperties = getPreConfirmationPropertiesFromQuote(quoteResponse, isStxEnabledOnClient, isHardwareAccount);
|
|
714
719
|
// Emit Submitted event after submit button is clicked
|
|
715
720
|
!quoteResponse.featureId &&
|
|
716
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Submitted, undefined,
|
|
721
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Submitted, undefined, {
|
|
722
|
+
...preConfirmationProperties,
|
|
723
|
+
location: location ?? MetaMetricsSwapsEventSource.MainView,
|
|
724
|
+
});
|
|
717
725
|
let txMeta;
|
|
718
726
|
let approvalTxId;
|
|
719
727
|
const startTime = Date.now();
|
|
@@ -743,6 +751,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
743
751
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, undefined, {
|
|
744
752
|
error_message: error?.message,
|
|
745
753
|
...preConfirmationProperties,
|
|
754
|
+
location: location ?? MetaMetricsSwapsEventSource.MainView,
|
|
746
755
|
});
|
|
747
756
|
throw error;
|
|
748
757
|
}
|
|
@@ -773,6 +782,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
773
782
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, txMeta?.id, {
|
|
774
783
|
error_message: error?.message,
|
|
775
784
|
...preConfirmationProperties,
|
|
785
|
+
location: location ?? MetaMetricsSwapsEventSource.MainView,
|
|
776
786
|
});
|
|
777
787
|
throw error;
|
|
778
788
|
}
|
|
@@ -831,6 +841,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
831
841
|
isStxEnabled: isStxEnabledOnClient,
|
|
832
842
|
startTime,
|
|
833
843
|
approvalTxId,
|
|
844
|
+
location,
|
|
834
845
|
}, actionId);
|
|
835
846
|
// Pass txFee when gasIncluded is true to use the quote's gas fees
|
|
836
847
|
// instead of re-estimating (which would fail for max native token swaps)
|
|
@@ -870,6 +881,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
870
881
|
isStxEnabled: isStxEnabledOnClient,
|
|
871
882
|
startTime,
|
|
872
883
|
approvalTxId,
|
|
884
|
+
location,
|
|
873
885
|
});
|
|
874
886
|
}
|
|
875
887
|
if (isNonEvmChainId(quoteResponse.quote.srcChainId)) {
|
|
@@ -894,10 +906,11 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
894
906
|
* @param params.quoteResponse - Quote carrying intent data
|
|
895
907
|
* @param params.signature - Hex signature produced by eth_signTypedData_v4
|
|
896
908
|
* @param params.accountAddress - The EOA submitting the order
|
|
909
|
+
* @param params.location - The entry point from which the user initiated the swap or bridge
|
|
897
910
|
* @returns A lightweight TransactionMeta-like object for history linking
|
|
898
911
|
*/
|
|
899
912
|
this.submitIntent = async (params) => {
|
|
900
|
-
const { quoteResponse, signature, accountAddress } = params;
|
|
913
|
+
const { quoteResponse, signature, accountAddress, location } = params;
|
|
901
914
|
this.messenger.call('BridgeController:stopPollingForQuotes', AbortReason.TransactionSubmitted);
|
|
902
915
|
// Build pre-confirmation properties for error tracking parity with submitTx
|
|
903
916
|
const account = __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_getMultichainSelectedAccount).call(this, accountAddress);
|
|
@@ -997,6 +1010,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
997
1010
|
isStxEnabled: false,
|
|
998
1011
|
approvalTxId,
|
|
999
1012
|
startTime,
|
|
1013
|
+
location,
|
|
1000
1014
|
});
|
|
1001
1015
|
// Start polling using the orderId key to route to intent manager
|
|
1002
1016
|
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeHistoryKey);
|
|
@@ -1011,6 +1025,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1011
1025
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, undefined, {
|
|
1012
1026
|
error_message: error?.message,
|
|
1013
1027
|
...preConfirmationProperties,
|
|
1028
|
+
location: location ?? MetaMetricsSwapsEventSource.MainView,
|
|
1014
1029
|
});
|
|
1015
1030
|
throw error;
|
|
1016
1031
|
}
|
|
@@ -1027,26 +1042,32 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1027
1042
|
action_type: MetricsActionType.SWAPBRIDGE_V1,
|
|
1028
1043
|
...(eventProperties ?? {}),
|
|
1029
1044
|
};
|
|
1045
|
+
// The messenger.call for trackUnifiedSwapBridgeEvent is generic but TypeScript
|
|
1046
|
+
// can't narrow EventName within this method's body, so we use `any` for the
|
|
1047
|
+
// properties argument. The real type safety comes from the external call sites.
|
|
1048
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1049
|
+
const callTrack = (properties) => this.messenger.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, properties);
|
|
1030
1050
|
// This will publish events for PERPS dropped tx failures as well
|
|
1031
1051
|
if (!txMetaId) {
|
|
1032
|
-
|
|
1052
|
+
callTrack(baseProperties);
|
|
1033
1053
|
return;
|
|
1034
1054
|
}
|
|
1035
1055
|
const historyItem = this.state.txHistory[txMetaId];
|
|
1036
1056
|
if (!historyItem) {
|
|
1037
|
-
|
|
1057
|
+
callTrack(eventProperties ?? {});
|
|
1038
1058
|
return;
|
|
1039
1059
|
}
|
|
1040
1060
|
const requestParamProperties = getRequestParamFromHistory(historyItem);
|
|
1041
1061
|
// Always publish StatusValidationFailed event, regardless of featureId
|
|
1042
1062
|
if (eventName === UnifiedSwapBridgeEventName.StatusValidationFailed) {
|
|
1043
|
-
|
|
1063
|
+
callTrack({
|
|
1044
1064
|
...baseProperties,
|
|
1045
1065
|
chain_id_source: requestParamProperties.chain_id_source,
|
|
1046
1066
|
chain_id_destination: requestParamProperties.chain_id_destination,
|
|
1047
1067
|
token_address_source: requestParamProperties.token_address_source,
|
|
1048
1068
|
token_address_destination: requestParamProperties.token_address_destination,
|
|
1049
1069
|
refresh_count: historyItem.attempts?.counter ?? 0,
|
|
1070
|
+
location: historyItem.location ?? MetaMetricsSwapsEventSource.MainView,
|
|
1050
1071
|
});
|
|
1051
1072
|
return;
|
|
1052
1073
|
}
|
|
@@ -1066,8 +1087,9 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1066
1087
|
...getTxStatusesFromHistory(historyItem),
|
|
1067
1088
|
...getFinalizedTxProperties(historyItem, txMeta, approvalTxMeta),
|
|
1068
1089
|
...getPriceImpactFromQuote(historyItem.quote),
|
|
1090
|
+
location: historyItem.location ?? MetaMetricsSwapsEventSource.MainView,
|
|
1069
1091
|
};
|
|
1070
|
-
|
|
1092
|
+
callTrack(requiredEventProperties);
|
|
1071
1093
|
});
|
|
1072
1094
|
__classPrivateFieldSet(this, _BridgeStatusController_clientId, clientId, "f");
|
|
1073
1095
|
__classPrivateFieldSet(this, _BridgeStatusController_fetchFn, fetchFn, "f");
|
|
@@ -1119,7 +1141,11 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1119
1141
|
else if (actionId && this.state.txHistory[actionId]) {
|
|
1120
1142
|
historyKey = actionId;
|
|
1121
1143
|
}
|
|
1122
|
-
|
|
1144
|
+
const historyLocation = this.state.txHistory[historyKey ?? txMetaId]?.location;
|
|
1145
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, historyKey ?? txMetaId, {
|
|
1146
|
+
...getEVMTxPropertiesFromTransactionMeta(transactionMeta),
|
|
1147
|
+
location: historyLocation ?? MetaMetricsSwapsEventSource.MainView,
|
|
1148
|
+
});
|
|
1123
1149
|
}
|
|
1124
1150
|
}
|
|
1125
1151
|
});
|