@metamask/ramps-controller 5.0.0 → 5.1.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 CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [5.1.0]
11
+
12
+ ### Added
13
+
14
+ - Add quotes functionality to RampsController ([#7747](https://github.com/MetaMask/core/pull/7747))
15
+
16
+ ### Fixed
17
+
18
+ - Fix `getQuotes()` to trim `assetId` and `walletAddress` parameters before use ([#7793](https://github.com/MetaMask/core/pull/7793))
19
+
10
20
  ## [5.0.0]
11
21
 
12
22
  ### Added
@@ -112,7 +122,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
112
122
  - Add `OnRampService` for interacting with the OnRamp API
113
123
  - Add geolocation detection via IP address lookup
114
124
 
115
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@5.0.0...HEAD
125
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@5.1.0...HEAD
126
+ [5.1.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@5.0.0...@metamask/ramps-controller@5.1.0
116
127
  [5.0.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@4.1.0...@metamask/ramps-controller@5.0.0
117
128
  [4.1.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@4.0.0...@metamask/ramps-controller@4.1.0
118
129
  [4.0.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@3.0.0...@metamask/ramps-controller@4.0.0
@@ -22,6 +22,11 @@ const RequestCache_1 = require("./RequestCache.cjs");
22
22
  * when composed with other controllers.
23
23
  */
24
24
  exports.controllerName = 'RampsController';
25
+ /**
26
+ * Default TTL for quotes requests (15 seconds).
27
+ * Quotes are time-sensitive and should have a shorter cache duration.
28
+ */
29
+ const DEFAULT_QUOTES_TTL = 15000;
25
30
  /**
26
31
  * The metadata for each property in {@link RampsControllerState}.
27
32
  */
@@ -74,6 +79,12 @@ const rampsControllerMetadata = {
74
79
  includeInStateLogs: true,
75
80
  usedInUi: true,
76
81
  },
82
+ quotes: {
83
+ persist: false,
84
+ includeInDebugSnapshot: true,
85
+ includeInStateLogs: false,
86
+ usedInUi: true,
87
+ },
77
88
  requests: {
78
89
  persist: false,
79
90
  includeInDebugSnapshot: true,
@@ -99,6 +110,7 @@ function getDefaultRampsControllerState() {
99
110
  selectedToken: null,
100
111
  paymentMethods: [],
101
112
  selectedPaymentMethod: null,
113
+ quotes: null,
102
114
  requests: {},
103
115
  };
104
116
  }
@@ -319,6 +331,7 @@ class RampsController extends base_controller_1.BaseController {
319
331
  state.providers = [];
320
332
  state.paymentMethods = [];
321
333
  state.selectedPaymentMethod = null;
334
+ state.quotes = null;
322
335
  }
323
336
  state.userRegion = userRegion;
324
337
  });
@@ -619,6 +632,98 @@ class RampsController extends base_controller_1.BaseController {
619
632
  state.selectedPaymentMethod = paymentMethod;
620
633
  });
621
634
  }
635
+ /**
636
+ * Fetches quotes from all providers for a given set of parameters.
637
+ * The quotes are saved in the controller state once fetched.
638
+ *
639
+ * @param options - The parameters for fetching quotes.
640
+ * @param options.region - User's region code. If not provided, uses userRegion from state.
641
+ * @param options.fiat - Fiat currency code. If not provided, uses userRegion currency.
642
+ * @param options.assetId - CAIP-19 cryptocurrency identifier.
643
+ * @param options.amount - The amount (in fiat for buy, crypto for sell).
644
+ * @param options.walletAddress - The destination wallet address.
645
+ * @param options.paymentMethods - Array of payment method IDs. If not provided, uses paymentMethods from state.
646
+ * @param options.provider - Optional provider ID to filter quotes.
647
+ * @param options.redirectUrl - Optional redirect URL after order completion.
648
+ * @param options.action - The ramp action type. Defaults to 'buy'.
649
+ * @param options.forceRefresh - Whether to bypass cache.
650
+ * @param options.ttl - Custom TTL for this request.
651
+ * @returns The quotes response containing success, sorted, error, and customActions.
652
+ */
653
+ async getQuotes(options) {
654
+ const regionToUse = options.region ?? this.state.userRegion?.regionCode;
655
+ const fiatToUse = options.fiat ?? this.state.userRegion?.country?.currency;
656
+ const paymentMethodsToUse = options.paymentMethods ??
657
+ this.state.paymentMethods.map((pm) => pm.id);
658
+ const action = options.action ?? 'buy';
659
+ if (!regionToUse) {
660
+ throw new Error('Region is required. Either provide a region parameter or ensure userRegion is set in controller state.');
661
+ }
662
+ if (!fiatToUse) {
663
+ throw new Error('Fiat currency is required. Either provide a fiat parameter or ensure userRegion is set in controller state.');
664
+ }
665
+ if (!paymentMethodsToUse || paymentMethodsToUse.length === 0) {
666
+ throw new Error('Payment methods are required. Either provide paymentMethods parameter or ensure paymentMethods are set in controller state.');
667
+ }
668
+ if (options.amount <= 0 || !Number.isFinite(options.amount)) {
669
+ throw new Error('Amount must be a positive finite number.');
670
+ }
671
+ if (!options.assetId || options.assetId.trim() === '') {
672
+ throw new Error('assetId is required.');
673
+ }
674
+ if (!options.walletAddress || options.walletAddress.trim() === '') {
675
+ throw new Error('walletAddress is required.');
676
+ }
677
+ const normalizedRegion = regionToUse.toLowerCase().trim();
678
+ const normalizedFiat = fiatToUse.toLowerCase().trim();
679
+ const normalizedAssetId = options.assetId.trim();
680
+ const normalizedWalletAddress = options.walletAddress.trim();
681
+ const cacheKey = (0, RequestCache_1.createCacheKey)('getQuotes', [
682
+ normalizedRegion,
683
+ normalizedFiat,
684
+ normalizedAssetId,
685
+ options.amount,
686
+ normalizedWalletAddress,
687
+ [...paymentMethodsToUse].sort().join(','),
688
+ options.provider,
689
+ options.redirectUrl,
690
+ action,
691
+ ]);
692
+ const params = {
693
+ region: normalizedRegion,
694
+ fiat: normalizedFiat,
695
+ assetId: normalizedAssetId,
696
+ amount: options.amount,
697
+ walletAddress: normalizedWalletAddress,
698
+ paymentMethods: paymentMethodsToUse,
699
+ provider: options.provider,
700
+ redirectUrl: options.redirectUrl,
701
+ action,
702
+ };
703
+ const response = await this.executeRequest(cacheKey, async () => {
704
+ return this.messenger.call('RampsService:getQuotes', params);
705
+ }, {
706
+ forceRefresh: options.forceRefresh,
707
+ ttl: options.ttl ?? DEFAULT_QUOTES_TTL,
708
+ });
709
+ this.update((state) => {
710
+ const userRegionCode = state.userRegion?.regionCode;
711
+ if (userRegionCode === undefined || userRegionCode === normalizedRegion) {
712
+ state.quotes = response;
713
+ }
714
+ });
715
+ return response;
716
+ }
717
+ /**
718
+ * Extracts the widget URL from a quote for redirect providers.
719
+ * Returns the widget URL if available, or null if the quote doesn't have one.
720
+ *
721
+ * @param quote - The quote to extract the widget URL from.
722
+ * @returns The widget URL string, or null if not available.
723
+ */
724
+ getWidgetUrl(quote) {
725
+ return quote.quote?.widgetUrl ?? null;
726
+ }
622
727
  // ============================================================
623
728
  // Sync Trigger Methods
624
729
  // These fire-and-forget methods are for use in React effects.
@@ -682,6 +787,27 @@ class RampsController extends base_controller_1.BaseController {
682
787
  // Error stored in state
683
788
  });
684
789
  }
790
+ /**
791
+ * Triggers fetching quotes without throwing.
792
+ *
793
+ * @param options - The parameters for fetching quotes.
794
+ * @param options.region - User's region code. If not provided, uses userRegion from state.
795
+ * @param options.fiat - Fiat currency code. If not provided, uses userRegion currency.
796
+ * @param options.assetId - CAIP-19 cryptocurrency identifier.
797
+ * @param options.amount - The amount (in fiat for buy, crypto for sell).
798
+ * @param options.walletAddress - The destination wallet address.
799
+ * @param options.paymentMethods - Array of payment method IDs. If not provided, uses paymentMethods from state.
800
+ * @param options.provider - Optional provider ID to filter quotes.
801
+ * @param options.redirectUrl - Optional redirect URL after order completion.
802
+ * @param options.action - The ramp action type. Defaults to 'buy'.
803
+ * @param options.forceRefresh - Whether to bypass cache.
804
+ * @param options.ttl - Custom TTL for this request.
805
+ */
806
+ triggerGetQuotes(options) {
807
+ this.getQuotes(options).catch(() => {
808
+ // Error stored in state
809
+ });
810
+ }
685
811
  }
686
812
  exports.RampsController = RampsController;
687
813
  _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_instances = new WeakSet(), _RampsController_removeRequestState = function _RampsController_removeRequestState(cacheKey) {
@@ -698,6 +824,7 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
698
824
  state.providers = [];
699
825
  state.paymentMethods = [];
700
826
  state.selectedPaymentMethod = null;
827
+ state.quotes = null;
701
828
  });
702
829
  }, _RampsController_updateRequestState = function _RampsController_updateRequestState(cacheKey, requestState) {
703
830
  const maxSize = __classPrivateFieldGet(this, _RampsController_requestCacheMaxSize, "f");
@@ -1 +1 @@
1
- {"version":3,"file":"RampsController.cjs","sourceRoot":"","sources":["../src/RampsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AA2B3D,qDASwB;AAExB,kBAAkB;AAElB;;;;GAIG;AACU,QAAA,cAAc,GAAG,iBAAiB,CAAC;AAyEhD;;GAEG;AACH,MAAM,uBAAuB,GAAG;IAC9B,UAAU,EAAE;QACV,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;IACD,gBAAgB,EAAE;QAChB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;IACD,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;IACD,SAAS,EAAE;QACT,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,OAAO,E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type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport type {\n Country,\n TokensResponse,\n Provider,\n State,\n RampAction,\n PaymentMethod,\n PaymentMethodsResponse,\n RampsToken,\n} from './RampsService';\nimport type {\n RampsServiceGetGeolocationAction,\n RampsServiceGetCountriesAction,\n RampsServiceGetTokensAction,\n RampsServiceGetProvidersAction,\n RampsServiceGetPaymentMethodsAction,\n} from './RampsService-method-action-types';\nimport type {\n RequestCache as RequestCacheType,\n RequestState,\n ExecuteRequestOptions,\n PendingRequest,\n} from './RequestCache';\nimport {\n DEFAULT_REQUEST_CACHE_TTL,\n DEFAULT_REQUEST_CACHE_MAX_SIZE,\n createCacheKey,\n isCacheExpired,\n createLoadingState,\n createSuccessState,\n createErrorState,\n RequestStatus,\n} from './RequestCache';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link RampsController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'RampsController';\n\n// === STATE ===\n\n/**\n * Represents the user's selected region with full country and state objects.\n */\nexport type UserRegion = {\n /**\n * The country object for the selected region.\n */\n country: Country;\n /**\n * The state object if a state was selected, null if only country was selected.\n */\n state: State | null;\n /**\n * The region code string (e.g., \"us-ut\" or \"fr\") used for API calls.\n */\n regionCode: string;\n};\n\n/**\n * Describes the shape of the state object for {@link RampsController}.\n */\nexport type RampsControllerState = {\n /**\n * The user's selected region with full country and state objects.\n * Initially set via geolocation fetch, but can be manually changed by the user.\n * Once set (either via geolocation or manual selection), it will not be overwritten\n * by subsequent geolocation fetches.\n */\n userRegion: UserRegion | null;\n /**\n * The user's selected provider.\n * Can be manually set by the user.\n */\n selectedProvider: Provider | null;\n /**\n * List of countries available for ramp actions.\n */\n countries: Country[];\n /**\n * List of providers available for the current region.\n */\n providers: Provider[];\n /**\n * Tokens fetched for the current region and action.\n * Contains topTokens and allTokens arrays.\n */\n tokens: TokensResponse | null;\n /**\n * The user's selected token.\n * When set, automatically fetches and sets payment methods for that token.\n */\n selectedToken: RampsToken | null;\n /**\n * Payment methods available for the current context.\n * Filtered by region, fiat, asset, and provider.\n */\n paymentMethods: PaymentMethod[];\n /**\n * The user's selected payment method.\n * Can be manually set by the user.\n */\n selectedPaymentMethod: PaymentMethod | null;\n /**\n * Cache of request states, keyed by cache key.\n * This stores loading, success, and error states for API requests.\n */\n requests: RequestCacheType;\n};\n\n/**\n * The metadata for each property in {@link RampsControllerState}.\n */\nconst rampsControllerMetadata = {\n userRegion: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n selectedProvider: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n countries: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n providers: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n tokens: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n selectedToken: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n paymentMethods: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n selectedPaymentMethod: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n requests: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: false,\n usedInUi: true,\n },\n} satisfies StateMetadata<RampsControllerState>;\n\n/**\n * Constructs the default {@link RampsController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link RampsController} state.\n */\nexport function getDefaultRampsControllerState(): RampsControllerState {\n return {\n userRegion: null,\n selectedProvider: null,\n countries: [],\n providers: [],\n tokens: null,\n selectedToken: null,\n paymentMethods: [],\n selectedPaymentMethod: null,\n requests: {},\n };\n}\n\n// === MESSENGER ===\n\n/**\n * Retrieves the state of the {@link RampsController}.\n */\nexport type RampsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n RampsControllerState\n>;\n\n/**\n * Actions that {@link RampsControllerMessenger} exposes to other consumers.\n */\nexport type RampsControllerActions = RampsControllerGetStateAction;\n\n/**\n * Actions from other messengers that {@link RampsController} calls.\n */\ntype AllowedActions =\n | RampsServiceGetGeolocationAction\n | RampsServiceGetCountriesAction\n | RampsServiceGetTokensAction\n | RampsServiceGetProvidersAction\n | RampsServiceGetPaymentMethodsAction;\n\n/**\n * Published when the state of {@link RampsController} changes.\n */\nexport type RampsControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n RampsControllerState\n>;\n\n/**\n * Events that {@link RampsControllerMessenger} exposes to other consumers.\n */\nexport type RampsControllerEvents = RampsControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link RampsController} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link RampsController}.\n */\nexport type RampsControllerMessenger = Messenger<\n typeof controllerName,\n RampsControllerActions | AllowedActions,\n RampsControllerEvents | AllowedEvents\n>;\n\n/**\n * Configuration options for the RampsController.\n */\nexport type RampsControllerOptions = {\n /** The messenger suited for this controller. */\n messenger: RampsControllerMessenger;\n /** The desired state with which to initialize this controller. */\n state?: Partial<RampsControllerState>;\n /** Time to live for cached requests in milliseconds. Defaults to 15 minutes. */\n requestCacheTTL?: number;\n /** Maximum number of entries in the request cache. Defaults to 250. */\n requestCacheMaxSize?: number;\n};\n\n// === HELPER FUNCTIONS ===\n\n/**\n * Finds a country and state from a region code string.\n *\n * @param regionCode - The region code (e.g., \"us-ca\" or \"us\").\n * @param countries - Array of countries to search.\n * @returns UserRegion object with country and state, or null if not found.\n */\nfunction findRegionFromCode(\n regionCode: string,\n countries: Country[],\n): UserRegion | null {\n const normalizedCode = regionCode.toLowerCase().trim();\n const parts = normalizedCode.split('-');\n const countryCode = parts[0];\n const stateCode = parts[1];\n\n const country = countries.find((countryItem) => {\n if (countryItem.isoCode?.toLowerCase() === countryCode) {\n return true;\n }\n if (countryItem.id) {\n const id = countryItem.id.toLowerCase();\n if (id.startsWith('/regions/')) {\n const extractedCode = id.replace('/regions/', '').split('/')[0];\n return extractedCode === countryCode;\n }\n return id === countryCode || id.endsWith(`/${countryCode}`);\n }\n return false;\n });\n\n if (!country) {\n return null;\n }\n\n let state: State | null = null;\n if (stateCode && country.states) {\n state =\n country.states.find((stateItem) => {\n if (stateItem.stateId?.toLowerCase() === stateCode) {\n return true;\n }\n if (stateItem.id) {\n const stateId = stateItem.id.toLowerCase();\n if (\n stateId.includes(`-${stateCode}`) ||\n stateId.endsWith(`/${stateCode}`)\n ) {\n return true;\n }\n }\n return false;\n }) ?? null;\n }\n\n return {\n country,\n state,\n regionCode: normalizedCode,\n };\n}\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * Manages cryptocurrency on/off ramps functionality.\n */\nexport class RampsController extends BaseController<\n typeof controllerName,\n RampsControllerState,\n RampsControllerMessenger\n> {\n /**\n * Default TTL for cached requests.\n */\n readonly #requestCacheTTL: number;\n\n /**\n * Maximum number of entries in the request cache.\n */\n readonly #requestCacheMaxSize: number;\n\n /**\n * Map of pending requests for deduplication.\n * Key is the cache key, value is the pending request with abort controller.\n */\n readonly #pendingRequests: Map<string, PendingRequest> = new Map();\n\n /**\n * Constructs a new {@link RampsController}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to initialize this\n * controller. Missing properties will be filled in with defaults.\n * @param args.requestCacheTTL - Time to live for cached requests in milliseconds.\n * @param args.requestCacheMaxSize - Maximum number of entries in the request cache.\n */\n constructor({\n messenger,\n state = {},\n requestCacheTTL = DEFAULT_REQUEST_CACHE_TTL,\n requestCacheMaxSize = DEFAULT_REQUEST_CACHE_MAX_SIZE,\n }: RampsControllerOptions) {\n super({\n messenger,\n metadata: rampsControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultRampsControllerState(),\n ...state,\n // Always reset requests cache on initialization (non-persisted)\n requests: {},\n },\n });\n\n this.#requestCacheTTL = requestCacheTTL;\n this.#requestCacheMaxSize = requestCacheMaxSize;\n }\n\n /**\n * Executes a request with caching and deduplication.\n *\n * If a request with the same cache key is already in flight, returns the\n * existing promise. If valid cached data exists, returns it without making\n * a new request.\n *\n * @param cacheKey - Unique identifier for this request.\n * @param fetcher - Function that performs the actual fetch. Receives an AbortSignal.\n * @param options - Options for cache behavior.\n * @returns The result of the request.\n */\n async executeRequest<TResult>(\n cacheKey: string,\n fetcher: (signal: AbortSignal) => Promise<TResult>,\n options?: ExecuteRequestOptions,\n ): Promise<TResult> {\n const ttl = options?.ttl ?? this.#requestCacheTTL;\n\n // Check for existing pending request - join it instead of making a duplicate\n const pending = this.#pendingRequests.get(cacheKey);\n if (pending) {\n return pending.promise as Promise<TResult>;\n }\n\n if (!options?.forceRefresh) {\n const cached = this.state.requests[cacheKey];\n if (cached && !isCacheExpired(cached, ttl)) {\n return cached.data as TResult;\n }\n }\n\n // Create abort controller for this request\n const abortController = new AbortController();\n const lastFetchedAt = Date.now();\n\n // Update state to loading\n this.#updateRequestState(cacheKey, createLoadingState());\n\n // Create the fetch promise\n const promise = (async (): Promise<TResult> => {\n try {\n const data = await fetcher(abortController.signal);\n\n // Don't update state if aborted\n if (abortController.signal.aborted) {\n throw new Error('Request was aborted');\n }\n\n this.#updateRequestState(\n cacheKey,\n createSuccessState(data as Json, lastFetchedAt),\n );\n return data;\n } catch (error) {\n // Don't update state if aborted\n if (abortController.signal.aborted) {\n throw error;\n }\n\n const errorMessage = (error as Error)?.message;\n\n this.#updateRequestState(\n cacheKey,\n createErrorState(errorMessage ?? 'Unknown error', lastFetchedAt),\n );\n throw error;\n } finally {\n // Only delete if this is still our entry (not replaced by a new request)\n const currentPending = this.#pendingRequests.get(cacheKey);\n if (currentPending?.abortController === abortController) {\n this.#pendingRequests.delete(cacheKey);\n }\n }\n })();\n\n // Store pending request for deduplication\n this.#pendingRequests.set(cacheKey, { promise, abortController });\n\n return promise;\n }\n\n /**\n * Aborts a pending request if one exists.\n *\n * @param cacheKey - The cache key of the request to abort.\n * @returns True if a request was aborted.\n */\n abortRequest(cacheKey: string): boolean {\n const pending = this.#pendingRequests.get(cacheKey);\n if (pending) {\n pending.abortController.abort();\n this.#pendingRequests.delete(cacheKey);\n this.#removeRequestState(cacheKey);\n return true;\n }\n return false;\n }\n\n /**\n * Removes a request state from the cache.\n *\n * @param cacheKey - The cache key to remove.\n */\n #removeRequestState(cacheKey: string): void {\n this.update((state) => {\n const requests = state.requests as unknown as Record<\n string,\n RequestState | undefined\n >;\n delete requests[cacheKey];\n });\n }\n\n #cleanupState(): void {\n this.update((state) => {\n state.userRegion = null;\n state.selectedProvider = null;\n state.selectedToken = null;\n state.tokens = null;\n state.providers = [];\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n });\n }\n\n /**\n * Gets the state of a specific cached request.\n *\n * @param cacheKey - The cache key to look up.\n * @returns The request state, or undefined if not cached.\n */\n getRequestState(cacheKey: string): RequestState | undefined {\n return this.state.requests[cacheKey];\n }\n\n /**\n * Updates the state for a specific request.\n *\n * @param cacheKey - The cache key.\n * @param requestState - The new state for the request.\n */\n #updateRequestState(cacheKey: string, requestState: RequestState): void {\n const maxSize = this.#requestCacheMaxSize;\n const ttl = this.#requestCacheTTL;\n\n this.update((state) => {\n const requests = state.requests as unknown as Record<\n string,\n RequestState | undefined\n >;\n requests[cacheKey] = requestState;\n\n // Evict expired entries based on TTL\n // Only evict SUCCESS states that have exceeded their TTL\n const keys = Object.keys(requests);\n for (const key of keys) {\n const entry = requests[key];\n if (\n entry &&\n entry.status === RequestStatus.SUCCESS &&\n isCacheExpired(entry, ttl)\n ) {\n delete requests[key];\n }\n }\n\n // Evict oldest entries if cache still exceeds max size\n const remainingKeys = Object.keys(requests);\n if (remainingKeys.length > maxSize) {\n // Sort by timestamp (oldest first)\n const sortedKeys = remainingKeys.sort((a, b) => {\n const aTime = requests[a]?.timestamp ?? 0;\n const bTime = requests[b]?.timestamp ?? 0;\n return aTime - bTime;\n });\n\n // Remove oldest entries until we're under the limit\n const entriesToRemove = remainingKeys.length - maxSize;\n for (let i = 0; i < entriesToRemove; i++) {\n const keyToRemove = sortedKeys[i];\n if (keyToRemove) {\n delete requests[keyToRemove];\n }\n }\n }\n });\n }\n\n /**\n * Sets the user's region manually (without fetching geolocation).\n * This allows users to override the detected region.\n *\n * @param region - The region code to set (e.g., \"US-CA\").\n * @param options - Options for cache behavior.\n * @returns The user region object.\n */\n async setUserRegion(\n region: string,\n options?: ExecuteRequestOptions,\n ): Promise<UserRegion> {\n const normalizedRegion = region.toLowerCase().trim();\n\n try {\n const { countries } = this.state;\n if (!countries || countries.length === 0) {\n this.#cleanupState();\n throw new Error(\n 'No countries found. Cannot set user region without valid country information.',\n );\n }\n\n const userRegion = findRegionFromCode(normalizedRegion, countries);\n\n if (!userRegion) {\n this.#cleanupState();\n throw new Error(\n `Region \"${normalizedRegion}\" not found in countries data. Cannot set user region without valid country information.`,\n );\n }\n\n // Only cleanup state if region is actually changing\n const regionChanged =\n normalizedRegion !== this.state.userRegion?.regionCode;\n\n // Set the new region atomically with cleanup to avoid intermediate null state\n this.update((state) => {\n if (regionChanged) {\n state.selectedProvider = null;\n state.selectedToken = null;\n state.tokens = null;\n state.providers = [];\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n }\n state.userRegion = userRegion;\n });\n\n // Only trigger fetches if region changed or if data is missing\n if (regionChanged || !this.state.tokens) {\n this.triggerGetTokens(userRegion.regionCode, 'buy', options);\n }\n if (regionChanged || this.state.providers.length === 0) {\n this.triggerGetProviders(userRegion.regionCode, options);\n }\n\n return userRegion;\n } catch (error) {\n this.#cleanupState();\n throw error;\n }\n }\n\n /**\n * Sets the user's selected provider by ID, or clears the selection.\n * Looks up the provider from the current providers in state and automatically\n * fetches payment methods for that provider.\n *\n * @param providerId - The provider ID (e.g., \"/providers/moonpay\"), or null to clear.\n * @throws If region is not set, providers are not loaded, or provider is not found.\n */\n setSelectedProvider(providerId: string | null): void {\n if (providerId === null) {\n this.update((state) => {\n state.selectedProvider = null;\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n });\n return;\n }\n\n const regionCode = this.state.userRegion?.regionCode;\n if (!regionCode) {\n throw new Error(\n 'Region is required. Cannot set selected provider without valid region information.',\n );\n }\n\n const { providers } = this.state;\n if (!providers || providers.length === 0) {\n throw new Error(\n 'Providers not loaded. Cannot set selected provider before providers are fetched.',\n );\n }\n\n const provider = providers.find((prov) => prov.id === providerId);\n if (!provider) {\n throw new Error(\n `Provider with ID \"${providerId}\" not found in available providers.`,\n );\n }\n\n this.update((state) => {\n state.selectedProvider = provider;\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n });\n\n // fetch payment methods for the new provider\n // this is needed because you can change providers without changing the token\n // (getPaymentMethods will use state as its default)\n this.triggerGetPaymentMethods(regionCode, {\n provider: provider.id,\n });\n }\n\n /**\n * Initializes the controller by fetching the user's region from geolocation.\n * This should be called once at app startup to set up the initial region.\n *\n * If a userRegion already exists (from persistence or manual selection),\n * this method will skip geolocation fetch and use the existing region.\n *\n * @param options - Options for cache behavior.\n * @returns Promise that resolves when initialization is complete.\n */\n async init(options?: ExecuteRequestOptions): Promise<void> {\n await this.getCountries(options);\n\n let regionCode = this.state.userRegion?.regionCode;\n regionCode ??= await this.messenger.call('RampsService:getGeolocation');\n\n if (!regionCode) {\n throw new Error(\n 'Failed to fetch geolocation. Cannot initialize controller without valid region information.',\n );\n }\n\n await this.setUserRegion(regionCode, options);\n }\n\n hydrateState(options?: ExecuteRequestOptions): void {\n const regionCode = this.state.userRegion?.regionCode;\n if (!regionCode) {\n throw new Error(\n 'Region code is required. Cannot hydrate state without valid region information.',\n );\n }\n\n this.triggerGetTokens(regionCode, 'buy', options);\n this.triggerGetProviders(regionCode, options);\n }\n\n /**\n * Fetches the list of supported countries.\n * The API returns countries with support information for both buy and sell actions.\n * The countries are saved in the controller state once fetched.\n *\n * @param options - Options for cache behavior.\n * @returns An array of countries.\n */\n async getCountries(options?: ExecuteRequestOptions): Promise<Country[]> {\n const cacheKey = createCacheKey('getCountries', []);\n\n const countries = await this.executeRequest(\n cacheKey,\n async () => {\n return this.messenger.call('RampsService:getCountries');\n },\n options,\n );\n\n this.update((state) => {\n state.countries = countries;\n });\n\n return countries;\n }\n\n /**\n * Fetches the list of available tokens for a given region and action.\n * The tokens are saved in the controller state once fetched.\n *\n * @param region - The region code (e.g., \"us\", \"fr\", \"us-ny\"). If not provided, uses the user's region from controller state.\n * @param action - The ramp action type ('buy' or 'sell').\n * @param options - Options for cache behavior and query filters.\n * @param options.provider - Provider ID(s) to filter by.\n * @returns The tokens response containing topTokens and allTokens.\n */\n async getTokens(\n region?: string,\n action: RampAction = 'buy',\n options?: ExecuteRequestOptions & {\n provider?: string | string[];\n },\n ): Promise<TokensResponse> {\n const regionToUse = region ?? this.state.userRegion?.regionCode;\n\n if (!regionToUse) {\n throw new Error(\n 'Region is required. Either provide a region parameter or ensure userRegion is set in controller state.',\n );\n }\n\n const normalizedRegion = regionToUse.toLowerCase().trim();\n const cacheKey = createCacheKey('getTokens', [\n normalizedRegion,\n action,\n options?.provider,\n ]);\n\n const tokens = await this.executeRequest(\n cacheKey,\n async () => {\n return this.messenger.call(\n 'RampsService:getTokens',\n normalizedRegion,\n action,\n {\n provider: options?.provider,\n },\n );\n },\n options,\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.tokens = tokens;\n }\n });\n\n return tokens;\n }\n\n /**\n * Sets the user's selected token by asset ID.\n * Looks up the token from the current tokens in state and automatically\n * fetches payment methods for that token.\n *\n * @param assetId - The asset identifier in CAIP-19 format (e.g., \"eip155:1/erc20:0x...\"), or undefined to clear.\n * @throws If region is not set, tokens are not loaded, or token is not found.\n */\n setSelectedToken(assetId?: string): void {\n if (!assetId) {\n this.update((state) => {\n state.selectedToken = null;\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n });\n return;\n }\n\n const regionCode = this.state.userRegion?.regionCode;\n if (!regionCode) {\n throw new Error(\n 'Region is required. Cannot set selected token without valid region information.',\n );\n }\n\n const { tokens } = this.state;\n if (!tokens) {\n throw new Error(\n 'Tokens not loaded. Cannot set selected token before tokens are fetched.',\n );\n }\n\n const token =\n tokens.allTokens.find((tok) => tok.assetId === assetId) ??\n tokens.topTokens.find((tok) => tok.assetId === assetId);\n\n if (!token) {\n throw new Error(\n `Token with asset ID \"${assetId}\" not found in available tokens.`,\n );\n }\n\n this.update((state) => {\n state.selectedToken = token;\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n });\n\n this.triggerGetPaymentMethods(regionCode, {\n assetId: token.assetId,\n });\n }\n\n /**\n * Fetches the list of providers for a given region.\n * The providers are saved in the controller state once fetched.\n *\n * @param region - The region code (e.g., \"us\", \"fr\", \"us-ny\"). If not provided, uses the user's region from controller state.\n * @param options - Options for cache behavior and query filters.\n * @param options.provider - Provider ID(s) to filter by.\n * @param options.crypto - Crypto currency ID(s) to filter by.\n * @param options.fiat - Fiat currency ID(s) to filter by.\n * @param options.payments - Payment method ID(s) to filter by.\n * @returns The providers response containing providers array.\n */\n async getProviders(\n region?: string,\n options?: ExecuteRequestOptions & {\n provider?: string | string[];\n crypto?: string | string[];\n fiat?: string | string[];\n payments?: string | string[];\n },\n ): Promise<{ providers: Provider[] }> {\n const regionToUse = region ?? this.state.userRegion?.regionCode;\n\n if (!regionToUse) {\n throw new Error(\n 'Region is required. Either provide a region parameter or ensure userRegion is set in controller state.',\n );\n }\n\n const normalizedRegion = regionToUse.toLowerCase().trim();\n const cacheKey = createCacheKey('getProviders', [\n normalizedRegion,\n options?.provider,\n options?.crypto,\n options?.fiat,\n options?.payments,\n ]);\n\n const { providers } = await this.executeRequest(\n cacheKey,\n async () => {\n return this.messenger.call(\n 'RampsService:getProviders',\n normalizedRegion,\n {\n provider: options?.provider,\n crypto: options?.crypto,\n fiat: options?.fiat,\n payments: options?.payments,\n },\n );\n },\n options,\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.providers = providers;\n }\n });\n\n return { providers };\n }\n\n /**\n * Fetches the list of payment methods for a given context.\n * The payment methods are saved in the controller state once fetched.\n *\n * @param region - User's region code (e.g. \"fr\", \"us-ny\").\n * @param options - Query parameters for filtering payment methods.\n * @param options.fiat - Fiat currency code (e.g., \"usd\"). If not provided, uses the user's region currency.\n * @param options.assetId - CAIP-19 cryptocurrency identifier.\n * @param options.provider - Provider ID path.\n * @returns The payment methods response containing payments array.\n */\n async getPaymentMethods(\n region?: string,\n options?: ExecuteRequestOptions & {\n fiat?: string;\n assetId?: string;\n provider?: string;\n },\n ): Promise<PaymentMethodsResponse> {\n const regionCode = region ?? this.state.userRegion?.regionCode ?? null;\n const fiatToUse =\n options?.fiat ?? this.state.userRegion?.country?.currency ?? null;\n const assetIdToUse =\n options?.assetId ?? this.state.selectedToken?.assetId ?? '';\n const providerToUse =\n options?.provider ?? this.state.selectedProvider?.id ?? '';\n\n if (!regionCode) {\n throw new Error(\n 'Region is required. Either provide a region parameter or ensure userRegion is set in controller state.',\n );\n }\n\n if (!fiatToUse) {\n throw new Error(\n 'Fiat currency is required. Either provide a fiat parameter or ensure userRegion is set in controller state.',\n );\n }\n\n const normalizedRegion = regionCode.toLowerCase().trim();\n const normalizedFiat = fiatToUse.toLowerCase().trim();\n const cacheKey = createCacheKey('getPaymentMethods', [\n normalizedRegion,\n normalizedFiat,\n assetIdToUse,\n providerToUse,\n ]);\n\n const response = await this.executeRequest(\n cacheKey,\n async () => {\n return this.messenger.call('RampsService:getPaymentMethods', {\n region: normalizedRegion,\n fiat: normalizedFiat,\n assetId: assetIdToUse,\n provider: providerToUse,\n });\n },\n options,\n );\n\n this.update((state) => {\n const currentAssetId = state.selectedToken?.assetId ?? '';\n const currentProviderId = state.selectedProvider?.id ?? '';\n\n const tokenSelectionUnchanged = assetIdToUse === currentAssetId;\n const providerSelectionUnchanged = providerToUse === currentProviderId;\n\n // this is a race condition check to ensure that the selected token and provider in state are the same as the tokens we're requesting for\n // ex: if the user rapidly changes the token or provider, the in-flight payment methods might not be valid\n // so this check will ensure that the payment methods are still valid for the token and provider that were requested\n if (tokenSelectionUnchanged && providerSelectionUnchanged) {\n state.paymentMethods = response.payments;\n\n // this will auto-select the first payment method if the selected payment method is not in the new payment methods\n const currentSelectionStillValid = response.payments.some(\n (pm: PaymentMethod) => pm.id === state.selectedPaymentMethod?.id,\n );\n if (!currentSelectionStillValid) {\n state.selectedPaymentMethod = response.payments[0] ?? null;\n }\n }\n });\n\n return response;\n }\n\n /**\n * Sets the user's selected payment method by ID.\n * Looks up the payment method from the current payment methods in state.\n *\n * @param paymentMethodId - The payment method ID (e.g., \"/payments/debit-credit-card\"), or null to clear.\n * @throws If payment methods are not loaded or payment method is not found.\n */\n setSelectedPaymentMethod(paymentMethodId?: string): void {\n if (!paymentMethodId) {\n this.update((state) => {\n state.selectedPaymentMethod = null;\n });\n return;\n }\n\n const { paymentMethods } = this.state;\n if (!paymentMethods || paymentMethods.length === 0) {\n throw new Error(\n 'Payment methods not loaded. Cannot set selected payment method before payment methods are fetched.',\n );\n }\n\n const paymentMethod = paymentMethods.find(\n (pm) => pm.id === paymentMethodId,\n );\n if (!paymentMethod) {\n throw new Error(\n `Payment method with ID \"${paymentMethodId}\" not found in available payment methods.`,\n );\n }\n\n this.update((state) => {\n state.selectedPaymentMethod = paymentMethod;\n });\n }\n\n // ============================================================\n // Sync Trigger Methods\n // These fire-and-forget methods are for use in React effects.\n // Errors are stored in state and available via selectors.\n // ============================================================\n\n /**\n * Triggers setting the user region without throwing.\n *\n * @param region - The region code to set (e.g., \"US-CA\").\n * @param options - Options for cache behavior.\n */\n triggerSetUserRegion(region: string, options?: ExecuteRequestOptions): void {\n this.setUserRegion(region, options).catch(() => {\n // Error stored in state\n });\n }\n\n /**\n * Triggers fetching countries without throwing.\n *\n * @param options - Options for cache behavior.\n */\n triggerGetCountries(options?: ExecuteRequestOptions): void {\n this.getCountries(options).catch(() => {\n // Error stored in state\n });\n }\n\n /**\n * Triggers fetching tokens without throwing.\n *\n * @param region - The region code. If not provided, uses userRegion from state.\n * @param action - The ramp action type ('buy' or 'sell').\n * @param options - Options for cache behavior.\n */\n triggerGetTokens(\n region?: string,\n action: 'buy' | 'sell' = 'buy',\n options?: ExecuteRequestOptions,\n ): void {\n this.getTokens(region, action, options).catch(() => {\n // Error stored in state\n });\n }\n\n /**\n * Triggers fetching providers without throwing.\n *\n * @param region - The region code. If not provided, uses userRegion from state.\n * @param options - Options for cache behavior and query filters.\n */\n triggerGetProviders(\n region?: string,\n options?: ExecuteRequestOptions & {\n provider?: string | string[];\n crypto?: string | string[];\n fiat?: string | string[];\n payments?: string | string[];\n },\n ): void {\n this.getProviders(region, options).catch(() => {\n // Error stored in state\n });\n }\n\n /**\n * Triggers fetching payment methods without throwing.\n *\n * @param region - User's region code (e.g., \"us\", \"fr\", \"us-ny\").\n * @param options - Query parameters for filtering payment methods.\n * @param options.fiat - Fiat currency code. If not provided, uses userRegion currency.\n * @param options.assetId - CAIP-19 cryptocurrency identifier.\n * @param options.provider - Provider ID path.\n */\n triggerGetPaymentMethods(\n region?: string,\n options?: ExecuteRequestOptions & {\n fiat?: string;\n assetId?: string;\n provider?: string;\n },\n ): void {\n this.getPaymentMethods(region, options).catch(() => {\n // Error stored in state\n });\n }\n}\n"]}
1
+ {"version":3,"file":"RampsController.cjs","sourceRoot":"","sources":["../src/RampsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AA+B3D,qDASwB;AAExB,kBAAkB;AAElB;;;;GAIG;AACU,QAAA,cAAc,GAAG,iBAAiB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AoD;YACpD,MAAM,eAAe,GAAG,aAAa,CAAC,MAAM,GAAG,OAAO,CAAC;YACvD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;gBACzC,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,WAAW,EAAE,CAAC;oBAChB,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport type {\n Country,\n TokensResponse,\n Provider,\n State,\n RampAction,\n PaymentMethod,\n PaymentMethodsResponse,\n QuotesResponse,\n Quote,\n GetQuotesParams,\n RampsToken,\n} from './RampsService';\nimport type {\n RampsServiceGetGeolocationAction,\n RampsServiceGetCountriesAction,\n RampsServiceGetTokensAction,\n RampsServiceGetProvidersAction,\n RampsServiceGetPaymentMethodsAction,\n RampsServiceGetQuotesAction,\n} from './RampsService-method-action-types';\nimport type {\n RequestCache as RequestCacheType,\n RequestState,\n ExecuteRequestOptions,\n PendingRequest,\n} from './RequestCache';\nimport {\n DEFAULT_REQUEST_CACHE_TTL,\n DEFAULT_REQUEST_CACHE_MAX_SIZE,\n createCacheKey,\n isCacheExpired,\n createLoadingState,\n createSuccessState,\n createErrorState,\n RequestStatus,\n} from './RequestCache';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link RampsController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'RampsController';\n\n/**\n * Default TTL for quotes requests (15 seconds).\n * Quotes are time-sensitive and should have a shorter cache duration.\n */\nconst DEFAULT_QUOTES_TTL = 15000;\n\n// === STATE ===\n\n/**\n * Represents the user's selected region with full country and state objects.\n */\nexport type UserRegion = {\n /**\n * The country object for the selected region.\n */\n country: Country;\n /**\n * The state object if a state was selected, null if only country was selected.\n */\n state: State | null;\n /**\n * The region code string (e.g., \"us-ut\" or \"fr\") used for API calls.\n */\n regionCode: string;\n};\n\n/**\n * Describes the shape of the state object for {@link RampsController}.\n */\nexport type RampsControllerState = {\n /**\n * The user's selected region with full country and state objects.\n * Initially set via geolocation fetch, but can be manually changed by the user.\n * Once set (either via geolocation or manual selection), it will not be overwritten\n * by subsequent geolocation fetches.\n */\n userRegion: UserRegion | null;\n /**\n * The user's selected provider.\n * Can be manually set by the user.\n */\n selectedProvider: Provider | null;\n /**\n * List of countries available for ramp actions.\n */\n countries: Country[];\n /**\n * List of providers available for the current region.\n */\n providers: Provider[];\n /**\n * Tokens fetched for the current region and action.\n * Contains topTokens and allTokens arrays.\n */\n tokens: TokensResponse | null;\n /**\n * The user's selected token.\n * When set, automatically fetches and sets payment methods for that token.\n */\n selectedToken: RampsToken | null;\n /**\n * Payment methods available for the current context.\n * Filtered by region, fiat, asset, and provider.\n */\n paymentMethods: PaymentMethod[];\n /**\n * The user's selected payment method.\n * Can be manually set by the user.\n */\n selectedPaymentMethod: PaymentMethod | null;\n /**\n * Quotes fetched for the current context.\n * Contains quotes from multiple providers for the given parameters.\n */\n quotes: QuotesResponse | null;\n /**\n * Cache of request states, keyed by cache key.\n * This stores loading, success, and error states for API requests.\n */\n requests: RequestCacheType;\n};\n\n/**\n * The metadata for each property in {@link RampsControllerState}.\n */\nconst rampsControllerMetadata = {\n userRegion: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n selectedProvider: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n countries: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n providers: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n tokens: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n selectedToken: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n paymentMethods: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n selectedPaymentMethod: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n quotes: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: false,\n usedInUi: true,\n },\n requests: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: false,\n usedInUi: true,\n },\n} satisfies StateMetadata<RampsControllerState>;\n\n/**\n * Constructs the default {@link RampsController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link RampsController} state.\n */\nexport function getDefaultRampsControllerState(): RampsControllerState {\n return {\n userRegion: null,\n selectedProvider: null,\n countries: [],\n providers: [],\n tokens: null,\n selectedToken: null,\n paymentMethods: [],\n selectedPaymentMethod: null,\n quotes: null,\n requests: {},\n };\n}\n\n// === MESSENGER ===\n\n/**\n * Retrieves the state of the {@link RampsController}.\n */\nexport type RampsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n RampsControllerState\n>;\n\n/**\n * Actions that {@link RampsControllerMessenger} exposes to other consumers.\n */\nexport type RampsControllerActions = RampsControllerGetStateAction;\n\n/**\n * Actions from other messengers that {@link RampsController} calls.\n */\ntype AllowedActions =\n | RampsServiceGetGeolocationAction\n | RampsServiceGetCountriesAction\n | RampsServiceGetTokensAction\n | RampsServiceGetProvidersAction\n | RampsServiceGetPaymentMethodsAction\n | RampsServiceGetQuotesAction;\n\n/**\n * Published when the state of {@link RampsController} changes.\n */\nexport type RampsControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n RampsControllerState\n>;\n\n/**\n * Events that {@link RampsControllerMessenger} exposes to other consumers.\n */\nexport type RampsControllerEvents = RampsControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link RampsController} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link RampsController}.\n */\nexport type RampsControllerMessenger = Messenger<\n typeof controllerName,\n RampsControllerActions | AllowedActions,\n RampsControllerEvents | AllowedEvents\n>;\n\n/**\n * Configuration options for the RampsController.\n */\nexport type RampsControllerOptions = {\n /** The messenger suited for this controller. */\n messenger: RampsControllerMessenger;\n /** The desired state with which to initialize this controller. */\n state?: Partial<RampsControllerState>;\n /** Time to live for cached requests in milliseconds. Defaults to 15 minutes. */\n requestCacheTTL?: number;\n /** Maximum number of entries in the request cache. Defaults to 250. */\n requestCacheMaxSize?: number;\n};\n\n// === HELPER FUNCTIONS ===\n\n/**\n * Finds a country and state from a region code string.\n *\n * @param regionCode - The region code (e.g., \"us-ca\" or \"us\").\n * @param countries - Array of countries to search.\n * @returns UserRegion object with country and state, or null if not found.\n */\nfunction findRegionFromCode(\n regionCode: string,\n countries: Country[],\n): UserRegion | null {\n const normalizedCode = regionCode.toLowerCase().trim();\n const parts = normalizedCode.split('-');\n const countryCode = parts[0];\n const stateCode = parts[1];\n\n const country = countries.find((countryItem) => {\n if (countryItem.isoCode?.toLowerCase() === countryCode) {\n return true;\n }\n if (countryItem.id) {\n const id = countryItem.id.toLowerCase();\n if (id.startsWith('/regions/')) {\n const extractedCode = id.replace('/regions/', '').split('/')[0];\n return extractedCode === countryCode;\n }\n return id === countryCode || id.endsWith(`/${countryCode}`);\n }\n return false;\n });\n\n if (!country) {\n return null;\n }\n\n let state: State | null = null;\n if (stateCode && country.states) {\n state =\n country.states.find((stateItem) => {\n if (stateItem.stateId?.toLowerCase() === stateCode) {\n return true;\n }\n if (stateItem.id) {\n const stateId = stateItem.id.toLowerCase();\n if (\n stateId.includes(`-${stateCode}`) ||\n stateId.endsWith(`/${stateCode}`)\n ) {\n return true;\n }\n }\n return false;\n }) ?? null;\n }\n\n return {\n country,\n state,\n regionCode: normalizedCode,\n };\n}\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * Manages cryptocurrency on/off ramps functionality.\n */\nexport class RampsController extends BaseController<\n typeof controllerName,\n RampsControllerState,\n RampsControllerMessenger\n> {\n /**\n * Default TTL for cached requests.\n */\n readonly #requestCacheTTL: number;\n\n /**\n * Maximum number of entries in the request cache.\n */\n readonly #requestCacheMaxSize: number;\n\n /**\n * Map of pending requests for deduplication.\n * Key is the cache key, value is the pending request with abort controller.\n */\n readonly #pendingRequests: Map<string, PendingRequest> = new Map();\n\n /**\n * Constructs a new {@link RampsController}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to initialize this\n * controller. Missing properties will be filled in with defaults.\n * @param args.requestCacheTTL - Time to live for cached requests in milliseconds.\n * @param args.requestCacheMaxSize - Maximum number of entries in the request cache.\n */\n constructor({\n messenger,\n state = {},\n requestCacheTTL = DEFAULT_REQUEST_CACHE_TTL,\n requestCacheMaxSize = DEFAULT_REQUEST_CACHE_MAX_SIZE,\n }: RampsControllerOptions) {\n super({\n messenger,\n metadata: rampsControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultRampsControllerState(),\n ...state,\n // Always reset requests cache on initialization (non-persisted)\n requests: {},\n },\n });\n\n this.#requestCacheTTL = requestCacheTTL;\n this.#requestCacheMaxSize = requestCacheMaxSize;\n }\n\n /**\n * Executes a request with caching and deduplication.\n *\n * If a request with the same cache key is already in flight, returns the\n * existing promise. If valid cached data exists, returns it without making\n * a new request.\n *\n * @param cacheKey - Unique identifier for this request.\n * @param fetcher - Function that performs the actual fetch. Receives an AbortSignal.\n * @param options - Options for cache behavior.\n * @returns The result of the request.\n */\n async executeRequest<TResult>(\n cacheKey: string,\n fetcher: (signal: AbortSignal) => Promise<TResult>,\n options?: ExecuteRequestOptions,\n ): Promise<TResult> {\n const ttl = options?.ttl ?? this.#requestCacheTTL;\n\n // Check for existing pending request - join it instead of making a duplicate\n const pending = this.#pendingRequests.get(cacheKey);\n if (pending) {\n return pending.promise as Promise<TResult>;\n }\n\n if (!options?.forceRefresh) {\n const cached = this.state.requests[cacheKey];\n if (cached && !isCacheExpired(cached, ttl)) {\n return cached.data as TResult;\n }\n }\n\n // Create abort controller for this request\n const abortController = new AbortController();\n const lastFetchedAt = Date.now();\n\n // Update state to loading\n this.#updateRequestState(cacheKey, createLoadingState());\n\n // Create the fetch promise\n const promise = (async (): Promise<TResult> => {\n try {\n const data = await fetcher(abortController.signal);\n\n // Don't update state if aborted\n if (abortController.signal.aborted) {\n throw new Error('Request was aborted');\n }\n\n this.#updateRequestState(\n cacheKey,\n createSuccessState(data as Json, lastFetchedAt),\n );\n return data;\n } catch (error) {\n // Don't update state if aborted\n if (abortController.signal.aborted) {\n throw error;\n }\n\n const errorMessage = (error as Error)?.message;\n\n this.#updateRequestState(\n cacheKey,\n createErrorState(errorMessage ?? 'Unknown error', lastFetchedAt),\n );\n throw error;\n } finally {\n // Only delete if this is still our entry (not replaced by a new request)\n const currentPending = this.#pendingRequests.get(cacheKey);\n if (currentPending?.abortController === abortController) {\n this.#pendingRequests.delete(cacheKey);\n }\n }\n })();\n\n // Store pending request for deduplication\n this.#pendingRequests.set(cacheKey, { promise, abortController });\n\n return promise;\n }\n\n /**\n * Aborts a pending request if one exists.\n *\n * @param cacheKey - The cache key of the request to abort.\n * @returns True if a request was aborted.\n */\n abortRequest(cacheKey: string): boolean {\n const pending = this.#pendingRequests.get(cacheKey);\n if (pending) {\n pending.abortController.abort();\n this.#pendingRequests.delete(cacheKey);\n this.#removeRequestState(cacheKey);\n return true;\n }\n return false;\n }\n\n /**\n * Removes a request state from the cache.\n *\n * @param cacheKey - The cache key to remove.\n */\n #removeRequestState(cacheKey: string): void {\n this.update((state) => {\n const requests = state.requests as unknown as Record<\n string,\n RequestState | undefined\n >;\n delete requests[cacheKey];\n });\n }\n\n #cleanupState(): void {\n this.update((state) => {\n state.userRegion = null;\n state.selectedProvider = null;\n state.selectedToken = null;\n state.tokens = null;\n state.providers = [];\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n state.quotes = null;\n });\n }\n\n /**\n * Gets the state of a specific cached request.\n *\n * @param cacheKey - The cache key to look up.\n * @returns The request state, or undefined if not cached.\n */\n getRequestState(cacheKey: string): RequestState | undefined {\n return this.state.requests[cacheKey];\n }\n\n /**\n * Updates the state for a specific request.\n *\n * @param cacheKey - The cache key.\n * @param requestState - The new state for the request.\n */\n #updateRequestState(cacheKey: string, requestState: RequestState): void {\n const maxSize = this.#requestCacheMaxSize;\n const ttl = this.#requestCacheTTL;\n\n this.update((state) => {\n const requests = state.requests as unknown as Record<\n string,\n RequestState | undefined\n >;\n requests[cacheKey] = requestState;\n\n // Evict expired entries based on TTL\n // Only evict SUCCESS states that have exceeded their TTL\n const keys = Object.keys(requests);\n for (const key of keys) {\n const entry = requests[key];\n if (\n entry &&\n entry.status === RequestStatus.SUCCESS &&\n isCacheExpired(entry, ttl)\n ) {\n delete requests[key];\n }\n }\n\n // Evict oldest entries if cache still exceeds max size\n const remainingKeys = Object.keys(requests);\n if (remainingKeys.length > maxSize) {\n // Sort by timestamp (oldest first)\n const sortedKeys = remainingKeys.sort((a, b) => {\n const aTime = requests[a]?.timestamp ?? 0;\n const bTime = requests[b]?.timestamp ?? 0;\n return aTime - bTime;\n });\n\n // Remove oldest entries until we're under the limit\n const entriesToRemove = remainingKeys.length - maxSize;\n for (let i = 0; i < entriesToRemove; i++) {\n const keyToRemove = sortedKeys[i];\n if (keyToRemove) {\n delete requests[keyToRemove];\n }\n }\n }\n });\n }\n\n /**\n * Sets the user's region manually (without fetching geolocation).\n * This allows users to override the detected region.\n *\n * @param region - The region code to set (e.g., \"US-CA\").\n * @param options - Options for cache behavior.\n * @returns The user region object.\n */\n async setUserRegion(\n region: string,\n options?: ExecuteRequestOptions,\n ): Promise<UserRegion> {\n const normalizedRegion = region.toLowerCase().trim();\n\n try {\n const { countries } = this.state;\n if (!countries || countries.length === 0) {\n this.#cleanupState();\n throw new Error(\n 'No countries found. Cannot set user region without valid country information.',\n );\n }\n\n const userRegion = findRegionFromCode(normalizedRegion, countries);\n\n if (!userRegion) {\n this.#cleanupState();\n throw new Error(\n `Region \"${normalizedRegion}\" not found in countries data. Cannot set user region without valid country information.`,\n );\n }\n\n // Only cleanup state if region is actually changing\n const regionChanged =\n normalizedRegion !== this.state.userRegion?.regionCode;\n\n // Set the new region atomically with cleanup to avoid intermediate null state\n this.update((state) => {\n if (regionChanged) {\n state.selectedProvider = null;\n state.selectedToken = null;\n state.tokens = null;\n state.providers = [];\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n state.quotes = null;\n }\n state.userRegion = userRegion;\n });\n\n // Only trigger fetches if region changed or if data is missing\n if (regionChanged || !this.state.tokens) {\n this.triggerGetTokens(userRegion.regionCode, 'buy', options);\n }\n if (regionChanged || this.state.providers.length === 0) {\n this.triggerGetProviders(userRegion.regionCode, options);\n }\n\n return userRegion;\n } catch (error) {\n this.#cleanupState();\n throw error;\n }\n }\n\n /**\n * Sets the user's selected provider by ID, or clears the selection.\n * Looks up the provider from the current providers in state and automatically\n * fetches payment methods for that provider.\n *\n * @param providerId - The provider ID (e.g., \"/providers/moonpay\"), or null to clear.\n * @throws If region is not set, providers are not loaded, or provider is not found.\n */\n setSelectedProvider(providerId: string | null): void {\n if (providerId === null) {\n this.update((state) => {\n state.selectedProvider = null;\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n });\n return;\n }\n\n const regionCode = this.state.userRegion?.regionCode;\n if (!regionCode) {\n throw new Error(\n 'Region is required. Cannot set selected provider without valid region information.',\n );\n }\n\n const { providers } = this.state;\n if (!providers || providers.length === 0) {\n throw new Error(\n 'Providers not loaded. Cannot set selected provider before providers are fetched.',\n );\n }\n\n const provider = providers.find((prov) => prov.id === providerId);\n if (!provider) {\n throw new Error(\n `Provider with ID \"${providerId}\" not found in available providers.`,\n );\n }\n\n this.update((state) => {\n state.selectedProvider = provider;\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n });\n\n // fetch payment methods for the new provider\n // this is needed because you can change providers without changing the token\n // (getPaymentMethods will use state as its default)\n this.triggerGetPaymentMethods(regionCode, {\n provider: provider.id,\n });\n }\n\n /**\n * Initializes the controller by fetching the user's region from geolocation.\n * This should be called once at app startup to set up the initial region.\n *\n * If a userRegion already exists (from persistence or manual selection),\n * this method will skip geolocation fetch and use the existing region.\n *\n * @param options - Options for cache behavior.\n * @returns Promise that resolves when initialization is complete.\n */\n async init(options?: ExecuteRequestOptions): Promise<void> {\n await this.getCountries(options);\n\n let regionCode = this.state.userRegion?.regionCode;\n regionCode ??= await this.messenger.call('RampsService:getGeolocation');\n\n if (!regionCode) {\n throw new Error(\n 'Failed to fetch geolocation. Cannot initialize controller without valid region information.',\n );\n }\n\n await this.setUserRegion(regionCode, options);\n }\n\n hydrateState(options?: ExecuteRequestOptions): void {\n const regionCode = this.state.userRegion?.regionCode;\n if (!regionCode) {\n throw new Error(\n 'Region code is required. Cannot hydrate state without valid region information.',\n );\n }\n\n this.triggerGetTokens(regionCode, 'buy', options);\n this.triggerGetProviders(regionCode, options);\n }\n\n /**\n * Fetches the list of supported countries.\n * The API returns countries with support information for both buy and sell actions.\n * The countries are saved in the controller state once fetched.\n *\n * @param options - Options for cache behavior.\n * @returns An array of countries.\n */\n async getCountries(options?: ExecuteRequestOptions): Promise<Country[]> {\n const cacheKey = createCacheKey('getCountries', []);\n\n const countries = await this.executeRequest(\n cacheKey,\n async () => {\n return this.messenger.call('RampsService:getCountries');\n },\n options,\n );\n\n this.update((state) => {\n state.countries = countries;\n });\n\n return countries;\n }\n\n /**\n * Fetches the list of available tokens for a given region and action.\n * The tokens are saved in the controller state once fetched.\n *\n * @param region - The region code (e.g., \"us\", \"fr\", \"us-ny\"). If not provided, uses the user's region from controller state.\n * @param action - The ramp action type ('buy' or 'sell').\n * @param options - Options for cache behavior and query filters.\n * @param options.provider - Provider ID(s) to filter by.\n * @returns The tokens response containing topTokens and allTokens.\n */\n async getTokens(\n region?: string,\n action: RampAction = 'buy',\n options?: ExecuteRequestOptions & {\n provider?: string | string[];\n },\n ): Promise<TokensResponse> {\n const regionToUse = region ?? this.state.userRegion?.regionCode;\n\n if (!regionToUse) {\n throw new Error(\n 'Region is required. Either provide a region parameter or ensure userRegion is set in controller state.',\n );\n }\n\n const normalizedRegion = regionToUse.toLowerCase().trim();\n const cacheKey = createCacheKey('getTokens', [\n normalizedRegion,\n action,\n options?.provider,\n ]);\n\n const tokens = await this.executeRequest(\n cacheKey,\n async () => {\n return this.messenger.call(\n 'RampsService:getTokens',\n normalizedRegion,\n action,\n {\n provider: options?.provider,\n },\n );\n },\n options,\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.tokens = tokens;\n }\n });\n\n return tokens;\n }\n\n /**\n * Sets the user's selected token by asset ID.\n * Looks up the token from the current tokens in state and automatically\n * fetches payment methods for that token.\n *\n * @param assetId - The asset identifier in CAIP-19 format (e.g., \"eip155:1/erc20:0x...\"), or undefined to clear.\n * @throws If region is not set, tokens are not loaded, or token is not found.\n */\n setSelectedToken(assetId?: string): void {\n if (!assetId) {\n this.update((state) => {\n state.selectedToken = null;\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n });\n return;\n }\n\n const regionCode = this.state.userRegion?.regionCode;\n if (!regionCode) {\n throw new Error(\n 'Region is required. Cannot set selected token without valid region information.',\n );\n }\n\n const { tokens } = this.state;\n if (!tokens) {\n throw new Error(\n 'Tokens not loaded. Cannot set selected token before tokens are fetched.',\n );\n }\n\n const token =\n tokens.allTokens.find((tok) => tok.assetId === assetId) ??\n tokens.topTokens.find((tok) => tok.assetId === assetId);\n\n if (!token) {\n throw new Error(\n `Token with asset ID \"${assetId}\" not found in available tokens.`,\n );\n }\n\n this.update((state) => {\n state.selectedToken = token;\n state.paymentMethods = [];\n state.selectedPaymentMethod = null;\n });\n\n this.triggerGetPaymentMethods(regionCode, {\n assetId: token.assetId,\n });\n }\n\n /**\n * Fetches the list of providers for a given region.\n * The providers are saved in the controller state once fetched.\n *\n * @param region - The region code (e.g., \"us\", \"fr\", \"us-ny\"). If not provided, uses the user's region from controller state.\n * @param options - Options for cache behavior and query filters.\n * @param options.provider - Provider ID(s) to filter by.\n * @param options.crypto - Crypto currency ID(s) to filter by.\n * @param options.fiat - Fiat currency ID(s) to filter by.\n * @param options.payments - Payment method ID(s) to filter by.\n * @returns The providers response containing providers array.\n */\n async getProviders(\n region?: string,\n options?: ExecuteRequestOptions & {\n provider?: string | string[];\n crypto?: string | string[];\n fiat?: string | string[];\n payments?: string | string[];\n },\n ): Promise<{ providers: Provider[] }> {\n const regionToUse = region ?? this.state.userRegion?.regionCode;\n\n if (!regionToUse) {\n throw new Error(\n 'Region is required. Either provide a region parameter or ensure userRegion is set in controller state.',\n );\n }\n\n const normalizedRegion = regionToUse.toLowerCase().trim();\n const cacheKey = createCacheKey('getProviders', [\n normalizedRegion,\n options?.provider,\n options?.crypto,\n options?.fiat,\n options?.payments,\n ]);\n\n const { providers } = await this.executeRequest(\n cacheKey,\n async () => {\n return this.messenger.call(\n 'RampsService:getProviders',\n normalizedRegion,\n {\n provider: options?.provider,\n crypto: options?.crypto,\n fiat: options?.fiat,\n payments: options?.payments,\n },\n );\n },\n options,\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.providers = providers;\n }\n });\n\n return { providers };\n }\n\n /**\n * Fetches the list of payment methods for a given context.\n * The payment methods are saved in the controller state once fetched.\n *\n * @param region - User's region code (e.g. \"fr\", \"us-ny\").\n * @param options - Query parameters for filtering payment methods.\n * @param options.fiat - Fiat currency code (e.g., \"usd\"). If not provided, uses the user's region currency.\n * @param options.assetId - CAIP-19 cryptocurrency identifier.\n * @param options.provider - Provider ID path.\n * @returns The payment methods response containing payments array.\n */\n async getPaymentMethods(\n region?: string,\n options?: ExecuteRequestOptions & {\n fiat?: string;\n assetId?: string;\n provider?: string;\n },\n ): Promise<PaymentMethodsResponse> {\n const regionCode = region ?? this.state.userRegion?.regionCode ?? null;\n const fiatToUse =\n options?.fiat ?? this.state.userRegion?.country?.currency ?? null;\n const assetIdToUse =\n options?.assetId ?? this.state.selectedToken?.assetId ?? '';\n const providerToUse =\n options?.provider ?? this.state.selectedProvider?.id ?? '';\n\n if (!regionCode) {\n throw new Error(\n 'Region is required. Either provide a region parameter or ensure userRegion is set in controller state.',\n );\n }\n\n if (!fiatToUse) {\n throw new Error(\n 'Fiat currency is required. Either provide a fiat parameter or ensure userRegion is set in controller state.',\n );\n }\n\n const normalizedRegion = regionCode.toLowerCase().trim();\n const normalizedFiat = fiatToUse.toLowerCase().trim();\n const cacheKey = createCacheKey('getPaymentMethods', [\n normalizedRegion,\n normalizedFiat,\n assetIdToUse,\n providerToUse,\n ]);\n\n const response = await this.executeRequest(\n cacheKey,\n async () => {\n return this.messenger.call('RampsService:getPaymentMethods', {\n region: normalizedRegion,\n fiat: normalizedFiat,\n assetId: assetIdToUse,\n provider: providerToUse,\n });\n },\n options,\n );\n\n this.update((state) => {\n const currentAssetId = state.selectedToken?.assetId ?? '';\n const currentProviderId = state.selectedProvider?.id ?? '';\n\n const tokenSelectionUnchanged = assetIdToUse === currentAssetId;\n const providerSelectionUnchanged = providerToUse === currentProviderId;\n\n // this is a race condition check to ensure that the selected token and provider in state are the same as the tokens we're requesting for\n // ex: if the user rapidly changes the token or provider, the in-flight payment methods might not be valid\n // so this check will ensure that the payment methods are still valid for the token and provider that were requested\n if (tokenSelectionUnchanged && providerSelectionUnchanged) {\n state.paymentMethods = response.payments;\n\n // this will auto-select the first payment method if the selected payment method is not in the new payment methods\n const currentSelectionStillValid = response.payments.some(\n (pm: PaymentMethod) => pm.id === state.selectedPaymentMethod?.id,\n );\n if (!currentSelectionStillValid) {\n state.selectedPaymentMethod = response.payments[0] ?? null;\n }\n }\n });\n\n return response;\n }\n\n /**\n * Sets the user's selected payment method by ID.\n * Looks up the payment method from the current payment methods in state.\n *\n * @param paymentMethodId - The payment method ID (e.g., \"/payments/debit-credit-card\"), or null to clear.\n * @throws If payment methods are not loaded or payment method is not found.\n */\n setSelectedPaymentMethod(paymentMethodId?: string): void {\n if (!paymentMethodId) {\n this.update((state) => {\n state.selectedPaymentMethod = null;\n });\n return;\n }\n\n const { paymentMethods } = this.state;\n if (!paymentMethods || paymentMethods.length === 0) {\n throw new Error(\n 'Payment methods not loaded. Cannot set selected payment method before payment methods are fetched.',\n );\n }\n\n const paymentMethod = paymentMethods.find(\n (pm) => pm.id === paymentMethodId,\n );\n if (!paymentMethod) {\n throw new Error(\n `Payment method with ID \"${paymentMethodId}\" not found in available payment methods.`,\n );\n }\n\n this.update((state) => {\n state.selectedPaymentMethod = paymentMethod;\n });\n }\n\n /**\n * Fetches quotes from all providers for a given set of parameters.\n * The quotes are saved in the controller state once fetched.\n *\n * @param options - The parameters for fetching quotes.\n * @param options.region - User's region code. If not provided, uses userRegion from state.\n * @param options.fiat - Fiat currency code. If not provided, uses userRegion currency.\n * @param options.assetId - CAIP-19 cryptocurrency identifier.\n * @param options.amount - The amount (in fiat for buy, crypto for sell).\n * @param options.walletAddress - The destination wallet address.\n * @param options.paymentMethods - Array of payment method IDs. If not provided, uses paymentMethods from state.\n * @param options.provider - Optional provider ID to filter quotes.\n * @param options.redirectUrl - Optional redirect URL after order completion.\n * @param options.action - The ramp action type. Defaults to 'buy'.\n * @param options.forceRefresh - Whether to bypass cache.\n * @param options.ttl - Custom TTL for this request.\n * @returns The quotes response containing success, sorted, error, and customActions.\n */\n async getQuotes(options: {\n region?: string;\n fiat?: string;\n assetId: string;\n amount: number;\n walletAddress: string;\n paymentMethods?: string[];\n provider?: string;\n redirectUrl?: string;\n action?: RampAction;\n forceRefresh?: boolean;\n ttl?: number;\n }): Promise<QuotesResponse> {\n const regionToUse = options.region ?? this.state.userRegion?.regionCode;\n const fiatToUse = options.fiat ?? this.state.userRegion?.country?.currency;\n const paymentMethodsToUse =\n options.paymentMethods ??\n this.state.paymentMethods.map((pm: PaymentMethod) => pm.id);\n const action = options.action ?? 'buy';\n\n if (!regionToUse) {\n throw new Error(\n 'Region is required. Either provide a region parameter or ensure userRegion is set in controller state.',\n );\n }\n\n if (!fiatToUse) {\n throw new Error(\n 'Fiat currency is required. Either provide a fiat parameter or ensure userRegion is set in controller state.',\n );\n }\n\n if (!paymentMethodsToUse || paymentMethodsToUse.length === 0) {\n throw new Error(\n 'Payment methods are required. Either provide paymentMethods parameter or ensure paymentMethods are set in controller state.',\n );\n }\n\n if (options.amount <= 0 || !Number.isFinite(options.amount)) {\n throw new Error('Amount must be a positive finite number.');\n }\n\n if (!options.assetId || options.assetId.trim() === '') {\n throw new Error('assetId is required.');\n }\n\n if (!options.walletAddress || options.walletAddress.trim() === '') {\n throw new Error('walletAddress is required.');\n }\n\n const normalizedRegion = regionToUse.toLowerCase().trim();\n const normalizedFiat = fiatToUse.toLowerCase().trim();\n const normalizedAssetId = options.assetId.trim();\n const normalizedWalletAddress = options.walletAddress.trim();\n\n const cacheKey = createCacheKey('getQuotes', [\n normalizedRegion,\n normalizedFiat,\n normalizedAssetId,\n options.amount,\n normalizedWalletAddress,\n [...paymentMethodsToUse].sort().join(','),\n options.provider,\n options.redirectUrl,\n action,\n ]);\n\n const params: GetQuotesParams = {\n region: normalizedRegion,\n fiat: normalizedFiat,\n assetId: normalizedAssetId,\n amount: options.amount,\n walletAddress: normalizedWalletAddress,\n paymentMethods: paymentMethodsToUse,\n provider: options.provider,\n redirectUrl: options.redirectUrl,\n action,\n };\n\n const response = await this.executeRequest(\n cacheKey,\n async () => {\n return this.messenger.call('RampsService:getQuotes', params);\n },\n {\n forceRefresh: options.forceRefresh,\n ttl: options.ttl ?? DEFAULT_QUOTES_TTL,\n },\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.quotes = response;\n }\n });\n\n return response;\n }\n\n /**\n * Extracts the widget URL from a quote for redirect providers.\n * Returns the widget URL if available, or null if the quote doesn't have one.\n *\n * @param quote - The quote to extract the widget URL from.\n * @returns The widget URL string, or null if not available.\n */\n getWidgetUrl(quote: Quote): string | null {\n return quote.quote?.widgetUrl ?? null;\n }\n\n // ============================================================\n // Sync Trigger Methods\n // These fire-and-forget methods are for use in React effects.\n // Errors are stored in state and available via selectors.\n // ============================================================\n\n /**\n * Triggers setting the user region without throwing.\n *\n * @param region - The region code to set (e.g., \"US-CA\").\n * @param options - Options for cache behavior.\n */\n triggerSetUserRegion(region: string, options?: ExecuteRequestOptions): void {\n this.setUserRegion(region, options).catch(() => {\n // Error stored in state\n });\n }\n\n /**\n * Triggers fetching countries without throwing.\n *\n * @param options - Options for cache behavior.\n */\n triggerGetCountries(options?: ExecuteRequestOptions): void {\n this.getCountries(options).catch(() => {\n // Error stored in state\n });\n }\n\n /**\n * Triggers fetching tokens without throwing.\n *\n * @param region - The region code. If not provided, uses userRegion from state.\n * @param action - The ramp action type ('buy' or 'sell').\n * @param options - Options for cache behavior.\n */\n triggerGetTokens(\n region?: string,\n action: 'buy' | 'sell' = 'buy',\n options?: ExecuteRequestOptions,\n ): void {\n this.getTokens(region, action, options).catch(() => {\n // Error stored in state\n });\n }\n\n /**\n * Triggers fetching providers without throwing.\n *\n * @param region - The region code. If not provided, uses userRegion from state.\n * @param options - Options for cache behavior and query filters.\n */\n triggerGetProviders(\n region?: string,\n options?: ExecuteRequestOptions & {\n provider?: string | string[];\n crypto?: string | string[];\n fiat?: string | string[];\n payments?: string | string[];\n },\n ): void {\n this.getProviders(region, options).catch(() => {\n // Error stored in state\n });\n }\n\n /**\n * Triggers fetching payment methods without throwing.\n *\n * @param region - User's region code (e.g., \"us\", \"fr\", \"us-ny\").\n * @param options - Query parameters for filtering payment methods.\n * @param options.fiat - Fiat currency code. If not provided, uses userRegion currency.\n * @param options.assetId - CAIP-19 cryptocurrency identifier.\n * @param options.provider - Provider ID path.\n */\n triggerGetPaymentMethods(\n region?: string,\n options?: ExecuteRequestOptions & {\n fiat?: string;\n assetId?: string;\n provider?: string;\n },\n ): void {\n this.getPaymentMethods(region, options).catch(() => {\n // Error stored in state\n });\n }\n\n /**\n * Triggers fetching quotes without throwing.\n *\n * @param options - The parameters for fetching quotes.\n * @param options.region - User's region code. If not provided, uses userRegion from state.\n * @param options.fiat - Fiat currency code. If not provided, uses userRegion currency.\n * @param options.assetId - CAIP-19 cryptocurrency identifier.\n * @param options.amount - The amount (in fiat for buy, crypto for sell).\n * @param options.walletAddress - The destination wallet address.\n * @param options.paymentMethods - Array of payment method IDs. If not provided, uses paymentMethods from state.\n * @param options.provider - Optional provider ID to filter quotes.\n * @param options.redirectUrl - Optional redirect URL after order completion.\n * @param options.action - The ramp action type. Defaults to 'buy'.\n * @param options.forceRefresh - Whether to bypass cache.\n * @param options.ttl - Custom TTL for this request.\n */\n triggerGetQuotes(options: {\n region?: string;\n fiat?: string;\n assetId: string;\n amount: number;\n walletAddress: string;\n paymentMethods?: string[];\n provider?: string;\n redirectUrl?: string;\n action?: RampAction;\n forceRefresh?: boolean;\n ttl?: number;\n }): void {\n this.getQuotes(options).catch(() => {\n // Error stored in state\n });\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
- import type { Country, TokensResponse, Provider, State, RampAction, PaymentMethod, PaymentMethodsResponse, RampsToken } from "./RampsService.cjs";
5
- import type { RampsServiceGetGeolocationAction, RampsServiceGetCountriesAction, RampsServiceGetTokensAction, RampsServiceGetProvidersAction, RampsServiceGetPaymentMethodsAction } from "./RampsService-method-action-types.cjs";
4
+ import type { Country, TokensResponse, Provider, State, RampAction, PaymentMethod, PaymentMethodsResponse, QuotesResponse, Quote, RampsToken } from "./RampsService.cjs";
5
+ import type { RampsServiceGetGeolocationAction, RampsServiceGetCountriesAction, RampsServiceGetTokensAction, RampsServiceGetProvidersAction, RampsServiceGetPaymentMethodsAction, RampsServiceGetQuotesAction } from "./RampsService-method-action-types.cjs";
6
6
  import type { RequestCache as RequestCacheType, RequestState, ExecuteRequestOptions } from "./RequestCache.cjs";
7
7
  /**
8
8
  * The name of the {@link RampsController}, used to namespace the
@@ -71,6 +71,11 @@ export type RampsControllerState = {
71
71
  * Can be manually set by the user.
72
72
  */
73
73
  selectedPaymentMethod: PaymentMethod | null;
74
+ /**
75
+ * Quotes fetched for the current context.
76
+ * Contains quotes from multiple providers for the given parameters.
77
+ */
78
+ quotes: QuotesResponse | null;
74
79
  /**
75
80
  * Cache of request states, keyed by cache key.
76
81
  * This stores loading, success, and error states for API requests.
@@ -97,7 +102,7 @@ export type RampsControllerActions = RampsControllerGetStateAction;
97
102
  /**
98
103
  * Actions from other messengers that {@link RampsController} calls.
99
104
  */
100
- type AllowedActions = RampsServiceGetGeolocationAction | RampsServiceGetCountriesAction | RampsServiceGetTokensAction | RampsServiceGetProvidersAction | RampsServiceGetPaymentMethodsAction;
105
+ type AllowedActions = RampsServiceGetGeolocationAction | RampsServiceGetCountriesAction | RampsServiceGetTokensAction | RampsServiceGetProvidersAction | RampsServiceGetPaymentMethodsAction | RampsServiceGetQuotesAction;
101
106
  /**
102
107
  * Published when the state of {@link RampsController} changes.
103
108
  */
@@ -276,6 +281,45 @@ export declare class RampsController extends BaseController<typeof controllerNam
276
281
  * @throws If payment methods are not loaded or payment method is not found.
277
282
  */
278
283
  setSelectedPaymentMethod(paymentMethodId?: string): void;
284
+ /**
285
+ * Fetches quotes from all providers for a given set of parameters.
286
+ * The quotes are saved in the controller state once fetched.
287
+ *
288
+ * @param options - The parameters for fetching quotes.
289
+ * @param options.region - User's region code. If not provided, uses userRegion from state.
290
+ * @param options.fiat - Fiat currency code. If not provided, uses userRegion currency.
291
+ * @param options.assetId - CAIP-19 cryptocurrency identifier.
292
+ * @param options.amount - The amount (in fiat for buy, crypto for sell).
293
+ * @param options.walletAddress - The destination wallet address.
294
+ * @param options.paymentMethods - Array of payment method IDs. If not provided, uses paymentMethods from state.
295
+ * @param options.provider - Optional provider ID to filter quotes.
296
+ * @param options.redirectUrl - Optional redirect URL after order completion.
297
+ * @param options.action - The ramp action type. Defaults to 'buy'.
298
+ * @param options.forceRefresh - Whether to bypass cache.
299
+ * @param options.ttl - Custom TTL for this request.
300
+ * @returns The quotes response containing success, sorted, error, and customActions.
301
+ */
302
+ getQuotes(options: {
303
+ region?: string;
304
+ fiat?: string;
305
+ assetId: string;
306
+ amount: number;
307
+ walletAddress: string;
308
+ paymentMethods?: string[];
309
+ provider?: string;
310
+ redirectUrl?: string;
311
+ action?: RampAction;
312
+ forceRefresh?: boolean;
313
+ ttl?: number;
314
+ }): Promise<QuotesResponse>;
315
+ /**
316
+ * Extracts the widget URL from a quote for redirect providers.
317
+ * Returns the widget URL if available, or null if the quote doesn't have one.
318
+ *
319
+ * @param quote - The quote to extract the widget URL from.
320
+ * @returns The widget URL string, or null if not available.
321
+ */
322
+ getWidgetUrl(quote: Quote): string | null;
279
323
  /**
280
324
  * Triggers setting the user region without throwing.
281
325
  *
@@ -323,6 +367,35 @@ export declare class RampsController extends BaseController<typeof controllerNam
323
367
  assetId?: string;
324
368
  provider?: string;
325
369
  }): void;
370
+ /**
371
+ * Triggers fetching quotes without throwing.
372
+ *
373
+ * @param options - The parameters for fetching quotes.
374
+ * @param options.region - User's region code. If not provided, uses userRegion from state.
375
+ * @param options.fiat - Fiat currency code. If not provided, uses userRegion currency.
376
+ * @param options.assetId - CAIP-19 cryptocurrency identifier.
377
+ * @param options.amount - The amount (in fiat for buy, crypto for sell).
378
+ * @param options.walletAddress - The destination wallet address.
379
+ * @param options.paymentMethods - Array of payment method IDs. If not provided, uses paymentMethods from state.
380
+ * @param options.provider - Optional provider ID to filter quotes.
381
+ * @param options.redirectUrl - Optional redirect URL after order completion.
382
+ * @param options.action - The ramp action type. Defaults to 'buy'.
383
+ * @param options.forceRefresh - Whether to bypass cache.
384
+ * @param options.ttl - Custom TTL for this request.
385
+ */
386
+ triggerGetQuotes(options: {
387
+ region?: string;
388
+ fiat?: string;
389
+ assetId: string;
390
+ amount: number;
391
+ walletAddress: string;
392
+ paymentMethods?: string[];
393
+ provider?: string;
394
+ redirectUrl?: string;
395
+ action?: RampAction;
396
+ forceRefresh?: boolean;
397
+ ttl?: number;
398
+ }): void;
326
399
  }
327
400
  export {};
328
401
  //# sourceMappingURL=RampsController.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RampsController.d.cts","sourceRoot":"","sources":["../src/RampsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,QAAQ,EACR,KAAK,EACL,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,UAAU,EACX,2BAAuB;AACxB,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,2BAA2B,EAC3B,8BAA8B,EAC9B,mCAAmC,EACpC,+CAA2C;AAC5C,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,YAAY,EACZ,qBAAqB,EAEtB,2BAAuB;AAcxB;;;;GAIG;AACH,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAIhD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;;OAKG;IAC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