@metamask-previews/bridge-controller 71.1.1-preview-28da12dab → 71.1.1-preview-f90b07931
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 +7 -0
- package/dist/bridge-controller.cjs +115 -78
- package/dist/bridge-controller.cjs.map +1 -1
- package/dist/bridge-controller.d.cts +14 -4
- package/dist/bridge-controller.d.cts.map +1 -1
- package/dist/bridge-controller.d.mts +14 -4
- package/dist/bridge-controller.d.mts.map +1 -1
- package/dist/bridge-controller.mjs +116 -79
- package/dist/bridge-controller.mjs.map +1 -1
- package/dist/constants/bridge.cjs +5 -3
- package/dist/constants/bridge.cjs.map +1 -1
- package/dist/constants/bridge.d.cts.map +1 -1
- package/dist/constants/bridge.d.mts.map +1 -1
- package/dist/constants/bridge.mjs +5 -3
- package/dist/constants/bridge.mjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs +63 -8
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +7357 -37
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +7357 -37
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs +62 -7
- package/dist/selectors.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +6 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +6 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/fetch.cjs +61 -11
- package/dist/utils/fetch.cjs.map +1 -1
- package/dist/utils/fetch.d.cts +3 -4
- package/dist/utils/fetch.d.cts.map +1 -1
- package/dist/utils/fetch.d.mts +3 -4
- package/dist/utils/fetch.d.mts.map +1 -1
- package/dist/utils/fetch.mjs +62 -12
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/metrics/properties.cjs +1 -1
- package/dist/utils/metrics/properties.cjs.map +1 -1
- package/dist/utils/metrics/properties.mjs +1 -1
- package/dist/utils/metrics/properties.mjs.map +1 -1
- package/dist/utils/quote.cjs +3 -1
- package/dist/utils/quote.cjs.map +1 -1
- package/dist/utils/quote.d.cts +1 -0
- package/dist/utils/quote.d.cts.map +1 -1
- package/dist/utils/quote.d.mts +1 -0
- package/dist/utils/quote.d.mts.map +1 -1
- package/dist/utils/quote.mjs +1 -0
- package/dist/utils/quote.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **BREAKING:** Add support for fetching batched swap transactions ([#8711](https://github.com/MetaMask/core/pull/8711))
|
|
13
|
+
- change `quoteRequest`'s type from `QuoteRequest` to `QuoteRequest[]`
|
|
14
|
+
- allow callers to update specific quote requests within a batch by adding 2 optional parameters to `updateBridgeQuoteRequest`: quoteRequestIndex and quoteRequestCount
|
|
15
|
+
- implement `selectBridgeQuotesBatch` selector which returns the recommended quote for each batched quote, and their aggregated fees and received amounts
|
|
16
|
+
|
|
10
17
|
### Changed
|
|
11
18
|
|
|
12
19
|
- Bump `@metamask/gas-fee-controller` from `^26.1.1` to `^26.2.0` ([#8722](https://github.com/MetaMask/core/pull/8722))
|
|
@@ -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 _BridgeController_instances, _BridgeController_abortController, _BridgeController_quotesFirstFetched, _BridgeController_location, _BridgeController_clientId, _BridgeController_clientVersion, _BridgeController_getLayer1GasFee, _BridgeController_fetchFn, _BridgeController_trackMetaMetricsFn, _BridgeController_trace, _BridgeController_config, _BridgeController_getUseAssetsControllerForRates, _BridgeController_trackQuoteValidationFailures, _BridgeController_getExchangeRateSources, _BridgeController_fetchAssetExchangeRates, _BridgeController_hasInsufficientBalance, _BridgeController_shouldResetApproval, _BridgeController_fetchBridgeQuotes, _BridgeController_handleQuoteStreaming, _BridgeController_setMinimumBalanceForRentExemptionInLamports, _BridgeController_getMultichainSelectedAccount, _BridgeController_getNetworkClientByChainId, _BridgeController_getJwt, _BridgeController_getRequestMetadata, _BridgeController_getQuoteFetchData, _BridgeController_getEventProperties, _BridgeController_trackInputChangedEvents, _BridgeController_getUSDTMainnetAllowance;
|
|
13
|
+
var _BridgeController_instances, _BridgeController_abortController, _BridgeController_quotesFirstFetched, _BridgeController_location, _BridgeController_clientId, _BridgeController_clientVersion, _BridgeController_getLayer1GasFee, _BridgeController_fetchFn, _BridgeController_trackMetaMetricsFn, _BridgeController_trace, _BridgeController_config, _BridgeController_getUseAssetsControllerForRates, _BridgeController_trackQuoteValidationFailures, _BridgeController_getExchangeRateSources, _BridgeController_fetchAssetExchangeRates, _BridgeController_hasInsufficientBalance, _BridgeController_appendInsufficientBalAndResetApproval, _BridgeController_shouldResetApproval, _BridgeController_fetchBridgeQuotes, _BridgeController_handleQuoteStreaming, _BridgeController_setMinimumBalanceForRentExemptionInLamports, _BridgeController_getMultichainSelectedAccount, _BridgeController_getNetworkClientByChainId, _BridgeController_getJwt, _BridgeController_getRequestMetadata, _BridgeController_getQuoteFetchData, _BridgeController_getEventProperties, _BridgeController_trackInputChangedEvents, _BridgeController_getUSDTMainnetAllowance;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.BridgeController = void 0;
|
|
16
16
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
@@ -156,54 +156,42 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
156
156
|
this._executePoll = async (pollingInput) => {
|
|
157
157
|
await __classPrivateFieldGet(this, _BridgeController_fetchBridgeQuotes, "f").call(this, pollingInput);
|
|
158
158
|
};
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Updates the quote request at the specified index with the given parameters, then starts
|
|
161
|
+
* polling for quotes.
|
|
162
|
+
*
|
|
163
|
+
* @param paramsToUpdate - The parameters to update in the quote request at the specified index
|
|
164
|
+
* @param context - metrics context
|
|
165
|
+
* @param quoteRequestIndex - The index of the quote request to update
|
|
166
|
+
* @param quoteRequestCount - The number of quote requests in the UI
|
|
167
|
+
*/
|
|
168
|
+
this.updateBridgeQuoteRequestParams = async (paramsToUpdate, context, quoteRequestIndex = 0, quoteRequestCount = 1) => {
|
|
169
|
+
if (quoteRequestIndex >= quoteRequestCount) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
__classPrivateFieldGet(this, _BridgeController_trackInputChangedEvents, "f").call(this, paramsToUpdate, quoteRequestIndex);
|
|
173
|
+
this.resetState(constants_1.AbortReason.QuoteRequestUpdated, quoteRequestIndex);
|
|
166
174
|
this.update((state) => {
|
|
167
|
-
state.quoteRequest =
|
|
175
|
+
state.quoteRequest = state.quoteRequest
|
|
176
|
+
.slice(0, quoteRequestIndex)
|
|
177
|
+
.concat(paramsToUpdate)
|
|
178
|
+
.concat(state.quoteRequest.slice(quoteRequestIndex + 1, quoteRequestCount));
|
|
168
179
|
state.tokenSecurityTypeDestination =
|
|
169
180
|
context.token_security_type_destination ?? null;
|
|
170
181
|
});
|
|
171
|
-
if ((0, quote_1.isValidQuoteRequest)(
|
|
182
|
+
if ((0, quote_1.isValidQuoteRequest)(paramsToUpdate) &&
|
|
183
|
+
(0, quote_1.isValidQuoteRequestBatch)(this.state.quoteRequest)) {
|
|
172
184
|
__classPrivateFieldSet(this, _BridgeController_quotesFirstFetched, Date.now(), "f");
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (isSrcChainNonEVM) {
|
|
180
|
-
// If the source chain is not an EVM network, use value from params
|
|
181
|
-
insufficientBal = paramsToUpdate.insufficientBal;
|
|
182
|
-
}
|
|
183
|
-
else if (providerConfig?.rpcUrl?.includes('tenderly')) {
|
|
184
|
-
// If the rpcUrl is a tenderly fork (e2e tests), set insufficientBal=true
|
|
185
|
-
// The bridge-api filters out quotes if the balance on mainnet is insufficient so this override allows quotes to always be returned
|
|
186
|
-
insufficientBal = true;
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
// Set loading status if RPC calls are made before the quotes are fetched
|
|
190
|
-
this.update((state) => {
|
|
191
|
-
state.quotesLoadingStatus = types_1.RequestStatus.LOADING;
|
|
192
|
-
});
|
|
193
|
-
resetApproval = await __classPrivateFieldGet(this, _BridgeController_shouldResetApproval, "f").call(this, updatedQuoteRequest);
|
|
194
|
-
// Otherwise query the src token balance from the RPC provider
|
|
195
|
-
insufficientBal =
|
|
196
|
-
paramsToUpdate.insufficientBal ??
|
|
197
|
-
(await __classPrivateFieldGet(this, _BridgeController_hasInsufficientBalance, "f").call(this, updatedQuoteRequest));
|
|
198
|
-
}
|
|
185
|
+
// Update the insufficientBal and resetApproval params for the quote request
|
|
186
|
+
const quoteWithInsufficientBalAndResetApproval = await __classPrivateFieldGet(this, _BridgeController_appendInsufficientBalAndResetApproval, "f").call(this, paramsToUpdate);
|
|
187
|
+
this.update((state) => {
|
|
188
|
+
state.quoteRequest[quoteRequestIndex] =
|
|
189
|
+
quoteWithInsufficientBalAndResetApproval;
|
|
190
|
+
});
|
|
199
191
|
// Set refresh rate based on the source chain before starting polling
|
|
200
192
|
this.setChainIntervalLength();
|
|
201
193
|
this.startPolling({
|
|
202
|
-
|
|
203
|
-
...updatedQuoteRequest,
|
|
204
|
-
insufficientBal,
|
|
205
|
-
resetApproval,
|
|
206
|
-
},
|
|
194
|
+
quoteRequests: this.state.quoteRequest,
|
|
207
195
|
context,
|
|
208
196
|
});
|
|
209
197
|
}
|
|
@@ -261,15 +249,14 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
261
249
|
* Fetches the exchange rates for the assets in the quote request if they are not already in the state
|
|
262
250
|
* In addition to the selected tokens, this also fetches the native asset for the source and destination chains
|
|
263
251
|
*
|
|
264
|
-
* @param
|
|
265
|
-
* @param quoteRequest.srcChainId - The source chain ID
|
|
266
|
-
* @param quoteRequest.srcTokenAddress - The source token address
|
|
267
|
-
* @param quoteRequest.destChainId - The destination chain ID
|
|
268
|
-
* @param quoteRequest.destTokenAddress - The destination token address
|
|
252
|
+
* @param quoteRequests - The quote requests to fetch the exchange rates for
|
|
269
253
|
*/
|
|
270
|
-
_BridgeController_fetchAssetExchangeRates.set(this, async (
|
|
254
|
+
_BridgeController_fetchAssetExchangeRates.set(this, async (quoteRequests) => {
|
|
271
255
|
const assetIds = new Set([]);
|
|
272
256
|
const exchangeRateSources = __classPrivateFieldGet(this, _BridgeController_getExchangeRateSources, "f").call(this);
|
|
257
|
+
const { srcChainId, srcTokenAddress, destChainId, destTokenAddress } =
|
|
258
|
+
// TODO fetch rates for all quote requests
|
|
259
|
+
quoteRequests[0];
|
|
273
260
|
if (srcTokenAddress &&
|
|
274
261
|
srcChainId &&
|
|
275
262
|
!(0, selectors_1.selectIsAssetExchangeRateInState)(exchangeRateSources, srcChainId, srcTokenAddress)) {
|
|
@@ -320,6 +307,39 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
320
307
|
return true;
|
|
321
308
|
}
|
|
322
309
|
});
|
|
310
|
+
_BridgeController_appendInsufficientBalAndResetApproval.set(this, async (quoteRequest) => {
|
|
311
|
+
const isSrcChainNonEVM = (0, bridge_2.isNonEvmChainId)(quoteRequest.srcChainId);
|
|
312
|
+
const providerConfig = isSrcChainNonEVM
|
|
313
|
+
? undefined
|
|
314
|
+
: __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getNetworkClientByChainId).call(this, (0, caip_formatters_1.formatChainIdToHex)(quoteRequest.srcChainId))?.configuration;
|
|
315
|
+
let insufficientBal;
|
|
316
|
+
let resetApproval = Boolean(quoteRequest.resetApproval);
|
|
317
|
+
if (isSrcChainNonEVM) {
|
|
318
|
+
// If the source chain is not an EVM network, use value from params
|
|
319
|
+
insufficientBal = quoteRequest.insufficientBal;
|
|
320
|
+
}
|
|
321
|
+
else if (providerConfig?.rpcUrl?.includes('tenderly')) {
|
|
322
|
+
// If the rpcUrl is a tenderly fork (e2e tests), set insufficientBal=true
|
|
323
|
+
// The bridge-api filters out quotes if the balance on mainnet is insufficient so this override allows quotes to always be returned
|
|
324
|
+
insufficientBal = true;
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
// Set loading status if RPC calls are made before the quotes are fetched
|
|
328
|
+
this.update((state) => {
|
|
329
|
+
state.quotesLoadingStatus = types_1.RequestStatus.LOADING;
|
|
330
|
+
});
|
|
331
|
+
resetApproval = await __classPrivateFieldGet(this, _BridgeController_shouldResetApproval, "f").call(this, quoteRequest);
|
|
332
|
+
// Otherwise query the src token balance from the RPC provider
|
|
333
|
+
insufficientBal =
|
|
334
|
+
quoteRequest.insufficientBal ??
|
|
335
|
+
(await __classPrivateFieldGet(this, _BridgeController_hasInsufficientBalance, "f").call(this, quoteRequest));
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
...quoteRequest,
|
|
339
|
+
insufficientBal,
|
|
340
|
+
resetApproval,
|
|
341
|
+
};
|
|
342
|
+
});
|
|
323
343
|
_BridgeController_shouldResetApproval.set(this, async (quoteRequest) => {
|
|
324
344
|
if ((0, bridge_2.isNonEvmChainId)(quoteRequest.srcChainId)) {
|
|
325
345
|
return false;
|
|
@@ -357,11 +377,21 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
357
377
|
this.setLocation = (location) => {
|
|
358
378
|
__classPrivateFieldSet(this, _BridgeController_location, location, "f");
|
|
359
379
|
};
|
|
360
|
-
this.resetState = (reason = constants_1.AbortReason.ResetState) => {
|
|
380
|
+
this.resetState = (reason = constants_1.AbortReason.ResetState, quoteRequestIndex = null) => {
|
|
361
381
|
this.stopPollingForQuotes(reason);
|
|
362
382
|
this.update((state) => {
|
|
363
383
|
// Cannot do direct assignment to state, i.e. state = {... }, need to manually assign each field
|
|
364
|
-
|
|
384
|
+
if (quoteRequestIndex === null) {
|
|
385
|
+
// Clear all requests if index is null
|
|
386
|
+
state.quoteRequest = bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest;
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
// Otherwise only clear the specified request
|
|
390
|
+
state.quoteRequest = state.quoteRequest
|
|
391
|
+
.slice(0, quoteRequestIndex)
|
|
392
|
+
.concat(bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest[0])
|
|
393
|
+
.concat(state.quoteRequest.slice(quoteRequestIndex + 1));
|
|
394
|
+
}
|
|
365
395
|
state.quotesInitialLoadTime =
|
|
366
396
|
bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotesInitialLoadTime;
|
|
367
397
|
state.quotes = bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;
|
|
@@ -388,7 +418,8 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
388
418
|
*/
|
|
389
419
|
this.setChainIntervalLength = () => {
|
|
390
420
|
const { state } = this;
|
|
391
|
-
|
|
421
|
+
// Batch requests are all in the same chain. Use the first one to determine refresh rate
|
|
422
|
+
const { srcChainId } = state.quoteRequest[0];
|
|
392
423
|
const bridgeFeatureFlags = (0, feature_flags_1.getBridgeFeatureFlags)(this.messenger);
|
|
393
424
|
const refreshRateOverride = srcChainId
|
|
394
425
|
? bridgeFeatureFlags.chains[(0, caip_formatters_1.formatChainIdToCaip)(srcChainId)]?.refreshRate
|
|
@@ -396,16 +427,15 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
396
427
|
const defaultRefreshRate = bridgeFeatureFlags.refreshRate;
|
|
397
428
|
this.setIntervalLength(refreshRateOverride ?? defaultRefreshRate);
|
|
398
429
|
};
|
|
399
|
-
_BridgeController_fetchBridgeQuotes.set(this, async ({
|
|
430
|
+
_BridgeController_fetchBridgeQuotes.set(this, async ({ quoteRequests, context, }) => {
|
|
400
431
|
__classPrivateFieldGet(this, _BridgeController_abortController, "f")?.abort(constants_1.AbortReason.NewQuoteRequest);
|
|
401
432
|
__classPrivateFieldSet(this, _BridgeController_abortController, new AbortController(), "f");
|
|
402
|
-
__classPrivateFieldGet(this, _BridgeController_fetchAssetExchangeRates, "f").call(this,
|
|
433
|
+
__classPrivateFieldGet(this, _BridgeController_fetchAssetExchangeRates, "f").call(this, quoteRequests).catch((error) => console.warn('Failed to fetch asset exchange rates', error));
|
|
403
434
|
this.trackUnifiedSwapBridgeEvent(constants_1.UnifiedSwapBridgeEventName.QuotesRequested, context);
|
|
404
435
|
const { sse, maxRefreshCount } = (0, feature_flags_1.getBridgeFeatureFlags)(this.messenger);
|
|
405
436
|
const shouldStream = sse?.enabled &&
|
|
406
437
|
(0, feature_flags_1.hasMinimumRequiredVersion)(__classPrivateFieldGet(this, _BridgeController_clientVersion, "f"), sse.minimumVersion);
|
|
407
438
|
this.update((state) => {
|
|
408
|
-
state.quoteRequest = updatedQuoteRequest;
|
|
409
439
|
state.quoteFetchError = bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;
|
|
410
440
|
state.tokenWarnings = bridge_1.DEFAULT_BRIDGE_CONTROLLER_STATE.tokenWarnings;
|
|
411
441
|
state.quoteStreamComplete =
|
|
@@ -413,6 +443,7 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
413
443
|
state.quotesLastFetched = Date.now();
|
|
414
444
|
state.quotesLoadingStatus = types_1.RequestStatus.LOADING;
|
|
415
445
|
});
|
|
446
|
+
const [updatedQuoteRequest] = quoteRequests;
|
|
416
447
|
const jwt = await __classPrivateFieldGet(this, _BridgeController_getJwt, "f").call(this);
|
|
417
448
|
try {
|
|
418
449
|
await __classPrivateFieldGet(this, _BridgeController_trace, "f").call(this, {
|
|
@@ -430,7 +461,7 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
430
461
|
__classPrivateFieldGet(this, _BridgeController_setMinimumBalanceForRentExemptionInLamports, "f").call(this, updatedQuoteRequest.srcChainId, selectedAccount?.metadata?.snap?.id);
|
|
431
462
|
// Use SSE if enabled and return early
|
|
432
463
|
if (shouldStream) {
|
|
433
|
-
await __classPrivateFieldGet(this, _BridgeController_handleQuoteStreaming, "f").call(this,
|
|
464
|
+
await __classPrivateFieldGet(this, _BridgeController_handleQuoteStreaming, "f").call(this, quoteRequests, jwt, selectedAccount);
|
|
434
465
|
return;
|
|
435
466
|
}
|
|
436
467
|
// Otherwise use regular fetch
|
|
@@ -497,7 +528,7 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
497
528
|
this.stopAllPolling();
|
|
498
529
|
}
|
|
499
530
|
});
|
|
500
|
-
_BridgeController_handleQuoteStreaming.set(this, async (
|
|
531
|
+
_BridgeController_handleQuoteStreaming.set(this, async (quoteRequests, jwt, selectedAccount) => {
|
|
501
532
|
/**
|
|
502
533
|
* Tracks the number of valid quotes received from the current stream, which is used
|
|
503
534
|
* to determine when to clear the quotes list and set the initial load time
|
|
@@ -508,7 +539,7 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
508
539
|
* before setting quotesLoadingStatus to FETCHED
|
|
509
540
|
*/
|
|
510
541
|
const pendingFeeAppendPromises = new Set();
|
|
511
|
-
await (0, fetch_1.fetchBridgeQuoteStream)(__classPrivateFieldGet(this, _BridgeController_fetchFn, "f"),
|
|
542
|
+
await (0, fetch_1.fetchBridgeQuoteStream)(__classPrivateFieldGet(this, _BridgeController_fetchFn, "f"), quoteRequests, __classPrivateFieldGet(this, _BridgeController_abortController, "f")?.signal, __classPrivateFieldGet(this, _BridgeController_clientId, "f"), jwt, __classPrivateFieldGet(this, _BridgeController_config, "f").customBridgeApiBaseUrl ?? bridge_1.BRIDGE_PROD_API_BASE_URL, {
|
|
512
543
|
onQuoteValidationFailure: __classPrivateFieldGet(this, _BridgeController_trackQuoteValidationFailures, "f"),
|
|
513
544
|
onValidQuoteReceived: async (quote) => {
|
|
514
545
|
const feeAppendPromise = (async () => {
|
|
@@ -595,15 +626,16 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
595
626
|
return undefined;
|
|
596
627
|
}
|
|
597
628
|
});
|
|
598
|
-
_BridgeController_getRequestMetadata.set(this, () => {
|
|
599
|
-
const
|
|
629
|
+
_BridgeController_getRequestMetadata.set(this, (quoteRequestIndex = 0) => {
|
|
630
|
+
const quoteRequest = this.state.quoteRequest[quoteRequestIndex];
|
|
631
|
+
const { walletAddress } = quoteRequest;
|
|
600
632
|
const accountHardwareType = (0, properties_1.getAccountHardwareType)(walletAddress
|
|
601
633
|
? __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getMultichainSelectedAccount).call(this, walletAddress)
|
|
602
634
|
: undefined);
|
|
603
635
|
return {
|
|
604
|
-
slippage_limit:
|
|
605
|
-
swap_type: (0, properties_1.getSwapTypeFromQuote)(
|
|
606
|
-
custom_slippage: (0, properties_1.isCustomSlippage)(
|
|
636
|
+
slippage_limit: quoteRequest.slippage,
|
|
637
|
+
swap_type: (0, properties_1.getSwapTypeFromQuote)(quoteRequest),
|
|
638
|
+
custom_slippage: (0, properties_1.isCustomSlippage)(quoteRequest.slippage),
|
|
607
639
|
account_hardware_type: accountHardwareType,
|
|
608
640
|
is_hardware_wallet: accountHardwareType !== null,
|
|
609
641
|
};
|
|
@@ -616,34 +648,35 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
616
648
|
has_gas_included_quote: this.state.quotes.some(({ quote }) => quote.gasIncluded),
|
|
617
649
|
};
|
|
618
650
|
});
|
|
619
|
-
_BridgeController_getEventProperties.set(this, (eventName, propertiesFromClient) => {
|
|
651
|
+
_BridgeController_getEventProperties.set(this, (eventName, propertiesFromClient, quoteRequestIndex = 0) => {
|
|
620
652
|
const clientProps = propertiesFromClient;
|
|
621
653
|
const baseProperties = {
|
|
622
654
|
...propertiesFromClient,
|
|
623
655
|
location: clientProps?.location ?? __classPrivateFieldGet(this, _BridgeController_location, "f"),
|
|
624
656
|
action_type: constants_1.MetricsActionType.SWAPBRIDGE_V1,
|
|
625
657
|
};
|
|
658
|
+
const quoteRequest = this.state.quoteRequest[quoteRequestIndex];
|
|
626
659
|
switch (eventName) {
|
|
627
660
|
case constants_1.UnifiedSwapBridgeEventName.ButtonClicked:
|
|
628
661
|
return {
|
|
629
|
-
...(0, properties_1.getRequestParams)(
|
|
662
|
+
...(0, properties_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
630
663
|
...baseProperties,
|
|
631
664
|
};
|
|
632
665
|
case constants_1.UnifiedSwapBridgeEventName.PageViewed:
|
|
633
666
|
return {
|
|
634
|
-
...(0, properties_1.getRequestParams)(
|
|
667
|
+
...(0, properties_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
635
668
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
636
669
|
...baseProperties,
|
|
637
670
|
};
|
|
638
671
|
case constants_1.UnifiedSwapBridgeEventName.QuotesValidationFailed:
|
|
639
672
|
return {
|
|
640
|
-
...(0, properties_1.getRequestParams)(
|
|
673
|
+
...(0, properties_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
641
674
|
refresh_count: this.state.quotesRefreshCount,
|
|
642
675
|
...baseProperties,
|
|
643
676
|
};
|
|
644
677
|
case constants_1.UnifiedSwapBridgeEventName.QuotesReceived:
|
|
645
678
|
return {
|
|
646
|
-
...(0, properties_1.getRequestParams)(
|
|
679
|
+
...(0, properties_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
647
680
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
648
681
|
...__classPrivateFieldGet(this, _BridgeController_getQuoteFetchData, "f").call(this),
|
|
649
682
|
refresh_count: this.state.quotesRefreshCount,
|
|
@@ -651,24 +684,24 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
651
684
|
};
|
|
652
685
|
case constants_1.UnifiedSwapBridgeEventName.QuotesRequested:
|
|
653
686
|
return {
|
|
654
|
-
...(0, properties_1.getRequestParams)(
|
|
687
|
+
...(0, properties_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
655
688
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
656
|
-
has_sufficient_funds: !
|
|
689
|
+
has_sufficient_funds: !quoteRequest.insufficientBal,
|
|
657
690
|
...baseProperties,
|
|
658
691
|
};
|
|
659
692
|
case constants_1.UnifiedSwapBridgeEventName.QuotesError:
|
|
660
693
|
return {
|
|
661
|
-
...(0, properties_1.getRequestParams)(
|
|
694
|
+
...(0, properties_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
662
695
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
663
696
|
error_message: this.state.quoteFetchError,
|
|
664
|
-
has_sufficient_funds: !
|
|
697
|
+
has_sufficient_funds: !quoteRequest.insufficientBal,
|
|
665
698
|
...baseProperties,
|
|
666
699
|
};
|
|
667
700
|
case constants_1.UnifiedSwapBridgeEventName.AllQuotesOpened:
|
|
668
701
|
case constants_1.UnifiedSwapBridgeEventName.AllQuotesSorted:
|
|
669
702
|
case constants_1.UnifiedSwapBridgeEventName.QuoteSelected:
|
|
670
703
|
return {
|
|
671
|
-
...(0, properties_1.getRequestParams)(
|
|
704
|
+
...(0, properties_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
672
705
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
673
706
|
...__classPrivateFieldGet(this, _BridgeController_getQuoteFetchData, "f").call(this),
|
|
674
707
|
...baseProperties,
|
|
@@ -677,7 +710,7 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
677
710
|
// Populate the properties that the error occurred before the tx was submitted
|
|
678
711
|
return {
|
|
679
712
|
...baseProperties,
|
|
680
|
-
...(0, properties_1.getRequestParams)(
|
|
713
|
+
...(0, properties_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
681
714
|
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
682
715
|
...__classPrivateFieldGet(this, _BridgeController_getQuoteFetchData, "f").call(this),
|
|
683
716
|
...propertiesFromClient,
|
|
@@ -704,13 +737,15 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
704
737
|
return baseProperties;
|
|
705
738
|
}
|
|
706
739
|
});
|
|
707
|
-
_BridgeController_trackInputChangedEvents.set(this, (paramsToUpdate) => {
|
|
740
|
+
_BridgeController_trackInputChangedEvents.set(this, (paramsToUpdate, quoteRequestIndex = 0) => {
|
|
708
741
|
Object.entries(paramsToUpdate).forEach(([key, value]) => {
|
|
709
742
|
const inputKey = properties_1.toInputChangedPropertyKey[key];
|
|
710
743
|
const inputValue = properties_1.toInputChangedPropertyValue[key]?.(paramsToUpdate);
|
|
711
744
|
if (inputKey &&
|
|
712
745
|
inputValue !== undefined &&
|
|
713
|
-
|
|
746
|
+
this.state.quoteRequest[quoteRequestIndex] &&
|
|
747
|
+
value !==
|
|
748
|
+
this.state.quoteRequest[quoteRequestIndex][key]) {
|
|
714
749
|
this.trackUnifiedSwapBridgeEvent(constants_1.UnifiedSwapBridgeEventName.InputChanged, {
|
|
715
750
|
input: inputKey,
|
|
716
751
|
input_value: inputValue,
|
|
@@ -724,14 +759,15 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
724
759
|
*
|
|
725
760
|
* @param eventName - The name of the event to track
|
|
726
761
|
* @param propertiesFromClient - Properties that can't be calculated from the event name and need to be provided by the client
|
|
762
|
+
* @param quoteRequestIndex - The index of the quote request to track the event for
|
|
727
763
|
* @example
|
|
728
764
|
* this.trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.ActionOpened, {
|
|
729
765
|
* location: MetaMetricsSwapsEventSource.MainView,
|
|
730
766
|
* });
|
|
731
767
|
*/
|
|
732
|
-
this.trackUnifiedSwapBridgeEvent = (eventName, propertiesFromClient) => {
|
|
768
|
+
this.trackUnifiedSwapBridgeEvent = (eventName, propertiesFromClient, quoteRequestIndex = 0) => {
|
|
733
769
|
try {
|
|
734
|
-
const combinedPropertiesForEvent = __classPrivateFieldGet(this, _BridgeController_getEventProperties, "f").call(this, eventName, propertiesFromClient);
|
|
770
|
+
const combinedPropertiesForEvent = __classPrivateFieldGet(this, _BridgeController_getEventProperties, "f").call(this, eventName, propertiesFromClient, quoteRequestIndex);
|
|
735
771
|
__classPrivateFieldGet(this, _BridgeController_trackMetaMetricsFn, "f").call(this, eventName, combinedPropertiesForEvent);
|
|
736
772
|
}
|
|
737
773
|
catch (error) {
|
|
@@ -773,8 +809,9 @@ class BridgeController extends (0, polling_controller_1.StaticIntervalPollingCon
|
|
|
773
809
|
}
|
|
774
810
|
}
|
|
775
811
|
exports.BridgeController = BridgeController;
|
|
776
|
-
_BridgeController_abortController = new WeakMap(), _BridgeController_quotesFirstFetched = new WeakMap(), _BridgeController_location = new WeakMap(), _BridgeController_clientId = new WeakMap(), _BridgeController_clientVersion = new WeakMap(), _BridgeController_getLayer1GasFee = new WeakMap(), _BridgeController_fetchFn = new WeakMap(), _BridgeController_trackMetaMetricsFn = new WeakMap(), _BridgeController_trace = new WeakMap(), _BridgeController_config = new WeakMap(), _BridgeController_getUseAssetsControllerForRates = new WeakMap(), _BridgeController_trackQuoteValidationFailures = new WeakMap(), _BridgeController_getExchangeRateSources = new WeakMap(), _BridgeController_fetchAssetExchangeRates = new WeakMap(), _BridgeController_hasInsufficientBalance = new WeakMap(), _BridgeController_shouldResetApproval = new WeakMap(), _BridgeController_fetchBridgeQuotes = new WeakMap(), _BridgeController_handleQuoteStreaming = new WeakMap(), _BridgeController_setMinimumBalanceForRentExemptionInLamports = new WeakMap(), _BridgeController_getJwt = new WeakMap(), _BridgeController_getRequestMetadata = new WeakMap(), _BridgeController_getQuoteFetchData = new WeakMap(), _BridgeController_getEventProperties = new WeakMap(), _BridgeController_trackInputChangedEvents = new WeakMap(), _BridgeController_getUSDTMainnetAllowance = new WeakMap(), _BridgeController_instances = new WeakSet(), _BridgeController_getMultichainSelectedAccount = function _BridgeController_getMultichainSelectedAccount(walletAddress) {
|
|
777
|
-
|
|
812
|
+
_BridgeController_abortController = new WeakMap(), _BridgeController_quotesFirstFetched = new WeakMap(), _BridgeController_location = new WeakMap(), _BridgeController_clientId = new WeakMap(), _BridgeController_clientVersion = new WeakMap(), _BridgeController_getLayer1GasFee = new WeakMap(), _BridgeController_fetchFn = new WeakMap(), _BridgeController_trackMetaMetricsFn = new WeakMap(), _BridgeController_trace = new WeakMap(), _BridgeController_config = new WeakMap(), _BridgeController_getUseAssetsControllerForRates = new WeakMap(), _BridgeController_trackQuoteValidationFailures = new WeakMap(), _BridgeController_getExchangeRateSources = new WeakMap(), _BridgeController_fetchAssetExchangeRates = new WeakMap(), _BridgeController_hasInsufficientBalance = new WeakMap(), _BridgeController_appendInsufficientBalAndResetApproval = new WeakMap(), _BridgeController_shouldResetApproval = new WeakMap(), _BridgeController_fetchBridgeQuotes = new WeakMap(), _BridgeController_handleQuoteStreaming = new WeakMap(), _BridgeController_setMinimumBalanceForRentExemptionInLamports = new WeakMap(), _BridgeController_getJwt = new WeakMap(), _BridgeController_getRequestMetadata = new WeakMap(), _BridgeController_getQuoteFetchData = new WeakMap(), _BridgeController_getEventProperties = new WeakMap(), _BridgeController_trackInputChangedEvents = new WeakMap(), _BridgeController_getUSDTMainnetAllowance = new WeakMap(), _BridgeController_instances = new WeakSet(), _BridgeController_getMultichainSelectedAccount = function _BridgeController_getMultichainSelectedAccount(walletAddress) {
|
|
813
|
+
// Assume that all quotes in a batch are for the same account
|
|
814
|
+
const addressToUse = walletAddress ?? this.state.quoteRequest[0].walletAddress;
|
|
778
815
|
if (!addressToUse) {
|
|
779
816
|
throw new Error('Account address is required');
|
|
780
817
|
}
|