@metamask/ramps-controller 18.0.0 → 19.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -1
- package/dist/RampsController-method-action-types.cjs.map +1 -1
- package/dist/RampsController-method-action-types.d.cts +30 -1
- package/dist/RampsController-method-action-types.d.cts.map +1 -1
- package/dist/RampsController-method-action-types.d.mts +30 -1
- package/dist/RampsController-method-action-types.d.mts.map +1 -1
- package/dist/RampsController-method-action-types.mjs.map +1 -1
- package/dist/RampsController.cjs +60 -18
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +31 -17
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +31 -17
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +61 -19
- package/dist/RampsController.mjs.map +1 -1
- package/dist/RampsService-method-action-types.cjs.map +1 -1
- package/dist/RampsService-method-action-types.d.cts +31 -1
- package/dist/RampsService-method-action-types.d.cts.map +1 -1
- package/dist/RampsService-method-action-types.d.mts +31 -1
- package/dist/RampsService-method-action-types.d.mts.map +1 -1
- package/dist/RampsService-method-action-types.mjs.map +1 -1
- package/dist/RampsService.cjs +75 -1
- package/dist/RampsService.cjs.map +1 -1
- package/dist/RampsService.d.cts +52 -0
- package/dist/RampsService.d.cts.map +1 -1
- package/dist/RampsService.d.mts +52 -0
- package/dist/RampsService.d.mts.map +1 -1
- package/dist/RampsService.mjs +73 -0
- package/dist/RampsService.mjs.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providerAvailability.cjs +1 -1
- package/dist/providerAvailability.cjs.map +1 -1
- package/dist/providerAvailability.d.cts.map +1 -1
- package/dist/providerAvailability.d.mts.map +1 -1
- package/dist/providerAvailability.mjs +1 -1
- package/dist/providerAvailability.mjs.map +1 -1
- package/package.json +2 -2
package/dist/RampsController.cjs
CHANGED
|
@@ -10,7 +10,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
11
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
12
|
};
|
|
13
|
-
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize,
|
|
13
|
+
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_pendingResourceGeneration, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_initPromise, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_resolveAllProvidersFlag, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_runInit, _RampsController_syncUserRegionFromCountriesCatalog, _RampsController_pickWidenedQuote, _RampsController_getSupportingProvidersForRegion, _RampsController_filterProviderIdsBySupport, _RampsController_resolveProviderIdsForQuote, _RampsController_getPreferredProviderIdsFromOrders, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError, _RampsController_getNormalizedTransakError;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.RampsController = exports.getInternalOrderCode = exports.getDefaultRampsControllerState = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.controllerName = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -33,6 +33,7 @@ exports.controllerName = 'RampsController';
|
|
|
33
33
|
* these actions from the root messenger so the controller can function.
|
|
34
34
|
*/
|
|
35
35
|
exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = [
|
|
36
|
+
'RampsService:getDefaultRedirectCallbackUrl',
|
|
36
37
|
'RampsService:getGeolocation',
|
|
37
38
|
'RampsService:getCountries',
|
|
38
39
|
'RampsService:getTokens',
|
|
@@ -375,6 +376,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
375
376
|
'getRequestState',
|
|
376
377
|
'setUserRegion',
|
|
377
378
|
'setSelectedProvider',
|
|
379
|
+
'setSelectedProviderForAsset',
|
|
378
380
|
'init',
|
|
379
381
|
'getCountries',
|
|
380
382
|
'getTokens',
|
|
@@ -441,11 +443,8 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
441
443
|
* controller. Missing properties will be filled in with defaults.
|
|
442
444
|
* @param args.requestCacheTTL - Time to live for cached requests in milliseconds.
|
|
443
445
|
* @param args.requestCacheMaxSize - Maximum number of entries in the request cache.
|
|
444
|
-
* @param args.getDefaultRedirectUrl - Optional callback returning the default
|
|
445
|
-
* redirect URL used for the widened quote fetch when the caller omits
|
|
446
|
-
* `redirectUrl`. Defaults to a callback returning `undefined`.
|
|
447
446
|
*/
|
|
448
|
-
constructor({ messenger, state = {}, requestCacheTTL = RequestCache_js_1.DEFAULT_REQUEST_CACHE_TTL, requestCacheMaxSize = RequestCache_js_1.DEFAULT_REQUEST_CACHE_MAX_SIZE,
|
|
447
|
+
constructor({ messenger, state = {}, requestCacheTTL = RequestCache_js_1.DEFAULT_REQUEST_CACHE_TTL, requestCacheMaxSize = RequestCache_js_1.DEFAULT_REQUEST_CACHE_MAX_SIZE, }) {
|
|
449
448
|
super({
|
|
450
449
|
messenger,
|
|
451
450
|
metadata: rampsControllerMetadata,
|
|
@@ -466,12 +465,6 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
466
465
|
* Maximum number of entries in the request cache.
|
|
467
466
|
*/
|
|
468
467
|
_RampsController_requestCacheMaxSize.set(this, void 0);
|
|
469
|
-
/**
|
|
470
|
-
* Resolves the default redirect URL for the widened quote fetch when
|
|
471
|
-
* the caller omits `redirectUrl`. Defaults to `() => undefined` when no
|
|
472
|
-
* callback is injected.
|
|
473
|
-
*/
|
|
474
|
-
_RampsController_getDefaultRedirectUrl.set(this, void 0);
|
|
475
468
|
/**
|
|
476
469
|
* Map of pending requests for deduplication.
|
|
477
470
|
* Key is the cache key, value is the pending request with abort controller.
|
|
@@ -493,7 +486,6 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
493
486
|
_RampsController_initPromise.set(this, null);
|
|
494
487
|
__classPrivateFieldSet(this, _RampsController_requestCacheTTL, requestCacheTTL, "f");
|
|
495
488
|
__classPrivateFieldSet(this, _RampsController_requestCacheMaxSize, requestCacheMaxSize, "f");
|
|
496
|
-
__classPrivateFieldSet(this, _RampsController_getDefaultRedirectUrl, getDefaultRedirectUrl ?? (() => undefined), "f");
|
|
497
489
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
498
490
|
}
|
|
499
491
|
/**
|
|
@@ -726,6 +718,52 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
726
718
|
});
|
|
727
719
|
}
|
|
728
720
|
}
|
|
721
|
+
/**
|
|
722
|
+
* Switches to the first provider in state that serves the given asset,
|
|
723
|
+
* when the currently selected provider does not.
|
|
724
|
+
*
|
|
725
|
+
* This is the controller-level equivalent of UB2's BuildQuote tier-1
|
|
726
|
+
* silent-switch effect and MMPay's `useEnsureCompatibleProvider` hook: it
|
|
727
|
+
* keeps provider-asset compatibility logic in one place rather than
|
|
728
|
+
* duplicating `providerServesAsset` + find-and-switch across multiple UI
|
|
729
|
+
* layers.
|
|
730
|
+
*
|
|
731
|
+
* The compatibility check prefers the current provider's entry in
|
|
732
|
+
* `providers.data` over the `providers.selected` copy, which can be stale
|
|
733
|
+
* once a fresh providers list arrives.
|
|
734
|
+
*
|
|
735
|
+
* No-op when:
|
|
736
|
+
* - `providers.data` is empty (providers not yet loaded)
|
|
737
|
+
* - the currently selected provider already serves the asset
|
|
738
|
+
* - no provider in the list serves the asset (no safe fallback)
|
|
739
|
+
*
|
|
740
|
+
* @param assetId - CAIP-19 asset id of the deposit asset.
|
|
741
|
+
* @param options - Optional settings forwarded to `setSelectedProvider`.
|
|
742
|
+
* @param options.autoSelected - When true, marks the new selection as
|
|
743
|
+
* system-guessed (soft selection). Defaults to true.
|
|
744
|
+
* @returns `true` if the selected provider was changed, `false` otherwise.
|
|
745
|
+
*/
|
|
746
|
+
setSelectedProviderForAsset(assetId, options) {
|
|
747
|
+
const providers = this.state.providers.data;
|
|
748
|
+
if (!providers?.length) {
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
const selectedId = this.state.providers.selected?.id;
|
|
752
|
+
const currentProvider = providers.find((provider) => provider.id === selectedId) ??
|
|
753
|
+
this.state.providers.selected;
|
|
754
|
+
if (currentProvider && (0, providerAvailability_js_1.providerServesAsset)(currentProvider, assetId)) {
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
const compatible = providers.find((provider) => provider.id !== selectedId && (0, providerAvailability_js_1.providerServesAsset)(provider, assetId));
|
|
758
|
+
if (!compatible) {
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
761
|
+
this.setSelectedProvider(compatible, {
|
|
762
|
+
autoSelected: true,
|
|
763
|
+
...options,
|
|
764
|
+
});
|
|
765
|
+
return true;
|
|
766
|
+
}
|
|
729
767
|
/**
|
|
730
768
|
* Initializes the controller by fetching the user's region from geolocation.
|
|
731
769
|
* This should be called once at app startup to set up the initial region.
|
|
@@ -1088,12 +1126,16 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1088
1126
|
const normalizedAssetId = normalizedAssetIdForValidation;
|
|
1089
1127
|
const normalizedWalletAddress = options.walletAddress.trim();
|
|
1090
1128
|
// The quotes API only embeds a `buyURL`/`buyWidget` when a `redirectUrl` is
|
|
1091
|
-
// present, so on the widened path (where MM Pay omits one)
|
|
1092
|
-
//
|
|
1093
|
-
//
|
|
1094
|
-
//
|
|
1129
|
+
// present, so on the widened path (where MM Pay omits one) ask the service
|
|
1130
|
+
// for the callback URL of the environment it is configured with, so
|
|
1131
|
+
// aggregator quotes carry a usable widget URL that always matches the
|
|
1132
|
+
// environment the quotes came from. An explicit caller `redirectUrl`
|
|
1133
|
+
// always wins, and the native-only path (flag off) never injects, so
|
|
1134
|
+
// neither reaches the service.
|
|
1095
1135
|
const effectiveRedirectUrl = options.redirectUrl ??
|
|
1096
|
-
(widenToAllProviders
|
|
1136
|
+
(widenToAllProviders
|
|
1137
|
+
? this.messenger.call('RampsService:getDefaultRedirectCallbackUrl')
|
|
1138
|
+
: undefined);
|
|
1097
1139
|
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getQuotes', [
|
|
1098
1140
|
normalizedRegion,
|
|
1099
1141
|
normalizedFiat,
|
|
@@ -1786,7 +1828,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1786
1828
|
}
|
|
1787
1829
|
}
|
|
1788
1830
|
exports.RampsController = RampsController;
|
|
1789
|
-
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(),
|
|
1831
|
+
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_pendingResourceCount = new WeakMap(), _RampsController_pendingResourceGeneration = new WeakMap(), _RampsController_orderPollingMeta = new WeakMap(), _RampsController_orderPollingTimer = new WeakMap(), _RampsController_isPolling = new WeakMap(), _RampsController_initPromise = new WeakMap(), _RampsController_instances = new WeakSet(), _RampsController_clearPendingResourceCountForDependentResources = function _RampsController_clearPendingResourceCountForDependentResources() {
|
|
1790
1832
|
for (const resourceType of DEPENDENT_RESOURCE_KEYS) {
|
|
1791
1833
|
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
1792
1834
|
const generation = __classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").get(resourceType) ?? 0;
|