@metamask-previews/ramps-controller 15.0.0-preview-2855dbf4e → 15.0.0-preview-3c77342c3

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 CHANGED
@@ -7,10 +7,6 @@ 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
- - Add an optional `getProviderScope` callback to `RampsControllerOptions` and export the `ProviderScope` type (`'off' | 'in-app' | 'all'`); when it returns a non-`off` scope, `RampsController.getQuotes` widens its native-only auto-selection (the `autoSelectProvider` / `restrictToKnownOrNativeProviders` path) to every supporting provider and returns the best in-app quote at `success[0]`, excluding external-browser and custom-action quotes and enforcing per-provider fiat limits, while the default stays native-only and explicit-`providers` callers are unaffected ([#9353](https://github.com/MetaMask/core/pull/9353))
13
-
14
10
  ## [15.0.0]
15
11
 
16
12
  ### 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, _RampsController_getProviderScope, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_pendingResourceGeneration, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_initPromise, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _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_pickInAppQuote, _RampsController_getSupportingProvidersForRegion, _RampsController_filterProviderIdsBySupport, _RampsController_resolveProviderIdsForQuote, _RampsController_getPreferredProviderIdsFromOrders, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError, _RampsController_getNormalizedTransakError;
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_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_runInit, _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.normalizeProviderCode = exports.getDefaultRampsControllerState = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.controllerName = void 0;
16
16
  const base_controller_1 = require("@metamask/base-controller");
@@ -441,10 +441,8 @@ class RampsController extends base_controller_1.BaseController {
441
441
  * controller. Missing properties will be filled in with defaults.
442
442
  * @param args.requestCacheTTL - Time to live for cached requests in milliseconds.
443
443
  * @param args.requestCacheMaxSize - Maximum number of entries in the request cache.
444
- * @param args.getProviderScope - Optional callback returning the current
445
- * provider-class scope for fiat quote widening. Defaults to `off`.
446
444
  */
447
- constructor({ messenger, state = {}, requestCacheTTL = RequestCache_1.DEFAULT_REQUEST_CACHE_TTL, requestCacheMaxSize = RequestCache_1.DEFAULT_REQUEST_CACHE_MAX_SIZE, getProviderScope, }) {
445
+ constructor({ messenger, state = {}, requestCacheTTL = RequestCache_1.DEFAULT_REQUEST_CACHE_TTL, requestCacheMaxSize = RequestCache_1.DEFAULT_REQUEST_CACHE_MAX_SIZE, }) {
448
446
  super({
449
447
  messenger,
450
448
  metadata: rampsControllerMetadata,
@@ -465,11 +463,6 @@ class RampsController extends base_controller_1.BaseController {
465
463
  * Maximum number of entries in the request cache.
466
464
  */
467
465
  _RampsController_requestCacheMaxSize.set(this, void 0);
468
- /**
469
- * Resolves the current provider-class scope for fiat quote widening. Defaults
470
- * to `() => 'off'` (native-only) when no callback is injected.
471
- */
472
- _RampsController_getProviderScope.set(this, void 0);
473
466
  /**
474
467
  * Map of pending requests for deduplication.
475
468
  * Key is the cache key, value is the pending request with abort controller.
@@ -491,7 +484,6 @@ class RampsController extends base_controller_1.BaseController {
491
484
  _RampsController_initPromise.set(this, null);
492
485
  __classPrivateFieldSet(this, _RampsController_requestCacheTTL, requestCacheTTL, "f");
493
486
  __classPrivateFieldSet(this, _RampsController_requestCacheMaxSize, requestCacheMaxSize, "f");
494
- __classPrivateFieldSet(this, _RampsController_getProviderScope, getProviderScope ?? (() => 'off'), "f");
495
487
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
496
488
  }
497
489
  /**
@@ -1003,19 +995,7 @@ class RampsController extends base_controller_1.BaseController {
1003
995
  if (normalizedAssetIdForValidation === '') {
1004
996
  throw new Error('assetId is required.');
1005
997
  }
1006
- // When a non-`off` provider scope is active, widen the native-only
1007
- // auto-selection path to every supporting provider and pick the best in-app
1008
- // quote from the results (in-app vs external is only knowable per-quote via
1009
- // `buyWidget.browser`). Only the auto-select/restrict path that MM Pay's
1010
- // `getRampsQuote` uses is affected; explicit-`providers` callers and the
1011
- // plain all-provider path are untouched.
1012
- const providerScope = __classPrivateFieldGet(this, _RampsController_getProviderScope, "f").call(this);
1013
- const widenToInAppProviders = providerScope !== 'off' &&
1014
- !options.providers &&
1015
- (options.autoSelectProvider === true ||
1016
- options.restrictToKnownOrNativeProviders === true);
1017
998
  let providersToUse;
1018
- let inAppProviderCatalog = this.state.providers.data;
1019
999
  if (options.providers) {
1020
1000
  providersToUse = options.restrictToKnownOrNativeProviders
1021
1001
  ? await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_filterProviderIdsBySupport).call(this, {
@@ -1025,17 +1005,6 @@ class RampsController extends base_controller_1.BaseController {
1025
1005
  })
1026
1006
  : options.providers;
1027
1007
  }
1028
- else if (widenToInAppProviders) {
1029
- // `#getSupportingProvidersForRegion` also hydrates the provider catalog
1030
- // when controller state is empty, so all-provider quoting cannot silently
1031
- // return zero providers here.
1032
- const { supporting } = await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getSupportingProvidersForRegion).call(this, {
1033
- assetId: normalizedAssetIdForValidation,
1034
- region: regionToUse,
1035
- });
1036
- inAppProviderCatalog = supporting;
1037
- providersToUse = supporting.map((provider) => provider.id);
1038
- }
1039
1008
  else if (options.autoSelectProvider ||
1040
1009
  options.restrictToKnownOrNativeProviders) {
1041
1010
  // The restriction flag implies resolution: it must narrow the provider
@@ -1096,42 +1065,12 @@ class RampsController extends base_controller_1.BaseController {
1096
1065
  redirectUrl: options.redirectUrl,
1097
1066
  action,
1098
1067
  };
1099
- const response = await this.executeRequest(cacheKey, async () => {
1068
+ return this.executeRequest(cacheKey, async () => {
1100
1069
  return this.messenger.call('RampsService:getQuotes', params);
1101
1070
  }, {
1102
1071
  forceRefresh: options.forceRefresh,
1103
1072
  ttl: options.ttl ?? DEFAULT_QUOTES_TTL,
1104
1073
  });
1105
- if (!widenToInAppProviders) {
1106
- return response;
1107
- }
1108
- // Reduce the widened multi-provider result to the single best in-app quote
1109
- // and place it at `success[0]`, since single-pick consumers
1110
- // (`getRampsQuote` -> `success?.[0]`) rely on index 0 while `success[]`
1111
- // order is server-defined rather than ranked.
1112
- const selectedQuote = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_pickInAppQuote).call(this, response, {
1113
- scope: providerScope,
1114
- amount: options.amount,
1115
- fiat: normalizedFiat,
1116
- providers: inAppProviderCatalog,
1117
- });
1118
- if (!selectedQuote) {
1119
- // No usable in-app quote: surface "no quote" rather than leaking an
1120
- // external/custom quote to the single-pick consumer.
1121
- return {
1122
- success: [],
1123
- sorted: response.sorted,
1124
- error: response.error,
1125
- customActions: response.customActions,
1126
- };
1127
- }
1128
- return {
1129
- ...response,
1130
- success: [
1131
- selectedQuote,
1132
- ...response.success.filter((quote) => quote !== selectedQuote),
1133
- ],
1134
- };
1135
1074
  }
1136
1075
  // === ORDER MANAGEMENT ===
1137
1076
  /**
@@ -1748,7 +1687,7 @@ class RampsController extends base_controller_1.BaseController {
1748
1687
  }
1749
1688
  }
1750
1689
  exports.RampsController = RampsController;
1751
- _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_getProviderScope = 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() {
1690
+ _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() {
1752
1691
  for (const resourceType of DEPENDENT_RESOURCE_KEYS) {
1753
1692
  __classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
1754
1693
  const generation = __classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").get(resourceType) ?? 0;
@@ -1848,63 +1787,6 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
1848
1787
  throw new Error('Failed to fetch geolocation. Cannot initialize controller without valid region information.');
1849
1788
  }
1850
1789
  await this.setUserRegion(regionCode, options);
1851
- }, _RampsController_pickInAppQuote = function _RampsController_pickInAppQuote(response, { scope, amount, fiat, providers, }) {
1852
- const providerByCode = new Map(providers.map((provider) => [
1853
- normalizeProviderCode(provider.id),
1854
- provider,
1855
- ]));
1856
- const customActionProviderCodes = new Set(response.customActions.map((action) => normalizeProviderCode(action.buy.providerId)));
1857
- const fitsProviderLimits = (quote) => {
1858
- const provider = providerByCode.get(normalizeProviderCode(quote.provider));
1859
- const limit = provider?.limits?.fiat?.[fiat]?.[quote.quote.paymentMethod];
1860
- if (!limit) {
1861
- // No published limits for this provider/payment method: treat as
1862
- // eligible and let the provider enforce limits at checkout.
1863
- return true;
1864
- }
1865
- return amount >= limit.minAmount && amount <= limit.maxAmount;
1866
- };
1867
- const isEligible = (quote) => {
1868
- // `all` (Phase 2) skips the in-app-only exclusions; both scopes still
1869
- // enforce provider limits up front.
1870
- if (scope !== 'all') {
1871
- const providerCode = normalizeProviderCode(quote.provider);
1872
- if (customActionProviderCodes.has(providerCode)) {
1873
- return false;
1874
- }
1875
- // Defensive: the wire may carry an inline `isCustomAction` flag that is
1876
- // absent from the published `Quote` type.
1877
- if (quote.quote.isCustomAction === true) {
1878
- return false;
1879
- }
1880
- if (quote.quote.buyWidget?.browser === 'IN_APP_OS_BROWSER') {
1881
- return false;
1882
- }
1883
- }
1884
- return fitsProviderLimits(quote);
1885
- };
1886
- const candidates = response.success.filter(isEligible);
1887
- if (candidates.length === 0) {
1888
- return undefined;
1889
- }
1890
- const candidateByCode = new Map(candidates.map((quote) => [normalizeProviderCode(quote.provider), quote]));
1891
- const pickBySortOrder = (sortBy) => {
1892
- const order = response.sorted.find((entry) => entry.sortBy === sortBy)?.ids;
1893
- if (!order) {
1894
- return undefined;
1895
- }
1896
- for (const providerId of order) {
1897
- const match = candidateByCode.get(normalizeProviderCode(providerId));
1898
- if (match) {
1899
- return match;
1900
- }
1901
- }
1902
- return undefined;
1903
- };
1904
- // Reliability first, then price, then the first surviving candidate.
1905
- return (pickBySortOrder('reliability') ??
1906
- pickBySortOrder('price') ??
1907
- candidates[0]);
1908
1790
  }, _RampsController_getSupportingProvidersForRegion =
1909
1791
  /**
1910
1792
  * Returns the region's providers that support the given asset, plus the full