@metamask-previews/ramps-controller 8.0.0-preview-e7b1aa6 → 8.0.0-preview-27e39dd44

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.
@@ -1 +1 @@
1
- {"version":3,"file":"RampsController.cjs","sourceRoot":"","sources":["../src/RampsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAmC3D,qDASwB;AAExB,kBAAkB;AAElB;;;;GAIG;AACU,QAAA,cAAc,GAAG,iBAAiB,CAAC;AAEhD;;;;GAIG;AACU,QAAA,yCAAyC,GACpD;IACE,6BAA6B;IAC7B,2BAA2B;IAC3B,wBAAwB;IACxB,2BAA2B;IAC3B,gCAAgC;IAChC,wBAAwB;IACxB,8BAA8B;CAC/B,CAAC;AAEJ;;;GAGG;AACH,MAAM,kBAAkB,GAAG,KAAK,CAAC;AA+FjC;;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,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,cAAc,EAAE;QACd,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,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AC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,SAAS,CAAC,SAAS,GAAG,KAAK,CAAC;YAClC,KAAK,CAAC,SAAS,CAAC,KAAK;gBACnB,KAAK,YAAY,KAAK;oBACpB,CAAC,CAAC,KAAK,CAAC,OAAO;oBACf,CAAC,CAAC,4BAA4B,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CACL,CAAC;AACJ,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';\nimport type { Draft } from 'immer';\n\nimport type {\n Country,\n TokensResponse,\n Provider,\n State,\n RampAction,\n PaymentMethod,\n PaymentMethodsResponse,\n QuotesResponse,\n Quote,\n RampsToken,\n RampsServiceActions,\n BuyWidget,\n} from './RampsService';\nimport type {\n RampsServiceGetGeolocationAction,\n RampsServiceGetCountriesAction,\n RampsServiceGetTokensAction,\n RampsServiceGetProvidersAction,\n RampsServiceGetPaymentMethodsAction,\n RampsServiceGetQuotesAction,\n RampsServiceGetBuyWidgetUrlAction,\n} from './RampsService-method-action-types';\nimport type {\n RequestCache as RequestCacheType,\n RequestState,\n ExecuteRequestOptions,\n PendingRequest,\n ResourceType,\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 * RampsService action types that RampsController calls via the messenger.\n * Any host (e.g. mobile) that creates a RampsController messenger must delegate\n * these actions from the root messenger so the controller can function.\n */\nexport const RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS: readonly RampsServiceActions['type'][] =\n [\n 'RampsService:getGeolocation',\n 'RampsService:getCountries',\n 'RampsService:getTokens',\n 'RampsService:getProviders',\n 'RampsService:getPaymentMethods',\n 'RampsService:getQuotes',\n 'RampsService:getBuyWidgetUrl',\n ];\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 * Generic type for resource state that bundles data with loading/error states.\n *\n * @template TData - The type of the resource data\n * @template TSelected - The type of the selected item (defaults to null for resources without selection)\n */\nexport type ResourceState<TData, TSelected = null> = {\n /**\n * The resource data.\n */\n data: TData;\n /**\n * The currently selected item, or null if none selected.\n */\n selected: TSelected;\n /**\n * Whether the resource is currently being fetched.\n */\n isLoading: boolean;\n /**\n * Error message if the fetch failed, or null.\n */\n error: string | null;\n};\n\n/**\n * Describes the shape of the state object for {@link RampsController}.\n */\nexport type RampsControllerState = {\n /**\n * The user's region (full country and state objects).\n * Initially set via geolocation fetch, but can be manually changed by the user.\n */\n userRegion: UserRegion | null;\n /**\n * Countries resource state with data, loading, and error.\n * Data contains the list of countries available for ramp actions.\n */\n countries: ResourceState<Country[]>;\n /**\n * Providers resource state with data, selected, loading, and error.\n * Data contains the list of providers available for the current region.\n */\n providers: ResourceState<Provider[], Provider | null>;\n /**\n * Tokens resource state with data, selected, loading, and error.\n * Data contains topTokens and allTokens arrays.\n */\n tokens: ResourceState<TokensResponse | null, RampsToken | null>;\n /**\n * Payment methods resource state with data, selected, loading, and error.\n * Data contains payment methods filtered by region, fiat, asset, and provider.\n */\n paymentMethods: ResourceState<PaymentMethod[], PaymentMethod | null>;\n /**\n * Quotes resource state with data, selected, loading, and error.\n * Data contains quotes from multiple providers for the given parameters.\n * Selected contains the currently selected quote for the user.\n */\n quotes: ResourceState<QuotesResponse | null, Quote | null>;\n /**\n * Widget URL resource state with data, loading, and error.\n * Contains the buy widget data (URL, browser type, order ID) for the currently selected quote.\n * Automatically fetched whenever a selected quote changes.\n */\n widgetUrl: ResourceState<BuyWidget | 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 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 paymentMethods: {\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 widgetUrl: {\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 * Creates a default resource state object.\n *\n * @template TData - The type of the resource data.\n * @template TSelected - The type of the selected item.\n * @param data - The initial data value.\n * @param selected - The initial selected value.\n * @returns A ResourceState object with default loading and error values.\n */\nfunction createDefaultResourceState<TData, TSelected = null>(\n data: TData,\n selected: TSelected = null as TSelected,\n): ResourceState<TData, TSelected> {\n return {\n data,\n selected,\n isLoading: false,\n error: null,\n };\n}\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 countries: createDefaultResourceState<Country[]>([]),\n providers: createDefaultResourceState<Provider[], Provider | null>(\n [],\n null,\n ),\n tokens: createDefaultResourceState<\n TokensResponse | null,\n RampsToken | null\n >(null, null),\n paymentMethods: createDefaultResourceState<\n PaymentMethod[],\n PaymentMethod | null\n >([], null),\n quotes: createDefaultResourceState<QuotesResponse | null, Quote | null>(\n null,\n null,\n ),\n widgetUrl: createDefaultResourceState<BuyWidget | null>(null),\n requests: {},\n };\n}\n\nconst DEPENDENT_RESOURCE_KEYS = [\n 'providers',\n 'tokens',\n 'paymentMethods',\n 'quotes',\n] as const;\n\ntype DependentResourceKey = (typeof DEPENDENT_RESOURCE_KEYS)[number];\n\nconst DEPENDENT_RESOURCE_KEYS_SET = new Set<string>(DEPENDENT_RESOURCE_KEYS);\n\nfunction resetResource(\n state: Draft<RampsControllerState>,\n resourceType: DependentResourceKey,\n defaultResource?: RampsControllerState[DependentResourceKey],\n): void {\n const def = defaultResource ?? getDefaultRampsControllerState()[resourceType];\n const resource = state[resourceType];\n resource.data = def.data;\n resource.selected = def.selected;\n resource.isLoading = def.isLoading;\n resource.error = def.error;\n}\n\n/**\n * Resets the widgetUrl resource to its default state.\n * Mutates state in place; use from within controller update() for atomic updates.\n *\n * @param state - The state object to mutate.\n */\nfunction resetWidgetUrl(state: Draft<RampsControllerState>): void {\n const def = getDefaultRampsControllerState().widgetUrl;\n state.widgetUrl.data = def.data;\n state.widgetUrl.selected = def.selected;\n state.widgetUrl.isLoading = def.isLoading;\n state.widgetUrl.error = def.error;\n}\n\n/**\n * Resets region-dependent resources (userRegion, providers, tokens, paymentMethods, quotes).\n * Mutates state in place; use from within controller update() for atomic updates.\n *\n * @param state - The state object to mutate.\n * @param options - Options for the reset.\n * @param options.clearUserRegionData - When true, sets userRegion to null (e.g. for full cleanup).\n */\nfunction resetDependentResources(\n state: Draft<RampsControllerState>,\n options?: { clearUserRegionData?: boolean },\n): void {\n if (options?.clearUserRegionData) {\n state.userRegion = null;\n }\n const defaultState = getDefaultRampsControllerState();\n for (const key of DEPENDENT_RESOURCE_KEYS) {\n resetResource(state, key, defaultState[key]);\n }\n resetWidgetUrl(state);\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 | RampsServiceGetBuyWidgetUrlAction;\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 * Count of in-flight requests per resource type.\n * Used so isLoading is only cleared when the last request for that resource finishes.\n */\n readonly #pendingResourceCount: Map<ResourceType, number> = new Map();\n\n /**\n * Interval ID for automatic quote polling.\n * Set when startQuotePolling() is called, cleared when stopQuotePolling() is called.\n */\n #quotePollingInterval: ReturnType<typeof setInterval> | null = null;\n\n /**\n * Options used for quote polling (walletAddress, amount, redirectUrl).\n * Stored so polling can be restarted when dependencies change.\n */\n #quotePollingOptions: {\n walletAddress: string;\n amount: number;\n redirectUrl?: string;\n } | null = null;\n\n /**\n * Clears the pending resource count map. Used only in tests to exercise the\n * defensive path when get() returns undefined in the finally block.\n *\n * @internal\n */\n clearPendingResourceCountForTest(): void {\n this.#pendingResourceCount.clear();\n }\n\n #clearPendingResourceCountForDependentResources(): void {\n for (const resourceType of DEPENDENT_RESOURCE_KEYS) {\n this.#pendingResourceCount.delete(resourceType);\n }\n }\n\n #abortDependentRequests(): void {\n for (const [cacheKey, pending] of this.#pendingRequests.entries()) {\n if (\n pending.resourceType &&\n DEPENDENT_RESOURCE_KEYS_SET.has(pending.resourceType)\n ) {\n pending.abortController.abort();\n this.#pendingRequests.delete(cacheKey);\n this.#removeRequestState(cacheKey);\n }\n }\n }\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, deduplication, and at most one in-flight\n * request per resource type.\n *\n * 1. **Same cache key in flight** – If a request with this cache key is\n * already pending, returns that promise (deduplication; no second request).\n *\n * 2. **Cache hit** – If valid, non-expired data exists in state.requests for\n * this key and forceRefresh is not set, returns that data without fetching.\n *\n * 3. **New request** – Creates an AbortController and fires the fetcher.\n * If options.resourceType is set, tags the pending request with that\n * resource type (so #abortDependentRequests can cancel it on region\n * change or cleanup) and ref-counts resource-level loading state.\n * On success or error, updates request state and resource error;\n * in finally, clears resource loading only if this request was not\n * aborted.\n *\n * @param cacheKey - Unique identifier for this request (e.g. from createCacheKey).\n * @param fetcher - Async function that performs the fetch. Receives an AbortSignal\n * that is aborted when this request is superseded by another for the same resource.\n * @param options - Optional forceRefresh, ttl, and resourceType for loading/error state.\n * @returns The result of the request (from cache, joined promise, or fetcher).\n */\n async executeRequest<TResult>(\n cacheKey: string,\n fetcher: (signal: AbortSignal) => Promise<TResult>,\n options?: ExecuteRequestOptions,\n ): Promise<TResult> {\n // Get TTL for verifying cache expiration\n const ttl = options?.ttl ?? this.#requestCacheTTL;\n\n // DEDUPLICATION:\n // Check if a request is already in flight for this cache key\n // If so, return the original promise for that request\n const pending = this.#pendingRequests.get(cacheKey);\n if (pending) {\n return pending.promise as Promise<TResult>;\n }\n\n // CACHE HIT:\n // If cache is not expired, return the cached data\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 a new abort controller for this request\n // Record the time the request was started\n const abortController = new AbortController();\n const lastFetchedAt = Date.now();\n const { resourceType } = options ?? {};\n\n // Update state to loading\n this.#updateRequestState(cacheKey, createLoadingState());\n\n // Set resource-level loading state (only on cache miss). Ref-count so concurrent\n // requests for the same resource type (different cache keys) keep isLoading true.\n if (resourceType) {\n const count = this.#pendingResourceCount.get(resourceType) ?? 0;\n this.#pendingResourceCount.set(resourceType, count + 1);\n if (count === 0) {\n this.#setResourceLoading(resourceType, true);\n }\n }\n\n // Create the fetch promise\n const promise = (async (): Promise<TResult> => {\n try {\n const data = await fetcher(abortController.signal);\n\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\n if (resourceType) {\n const isCurrent =\n !options?.isResultCurrent || options.isResultCurrent();\n if (isCurrent) {\n this.#setResourceError(resourceType, null);\n }\n }\n return data;\n } catch (error) {\n if (abortController.signal.aborted) {\n throw error;\n }\n\n const errorMessage = (error as Error)?.message ?? 'Unknown error';\n this.#updateRequestState(\n cacheKey,\n createErrorState(errorMessage, lastFetchedAt),\n );\n if (resourceType) {\n const isCurrent =\n !options?.isResultCurrent || options.isResultCurrent();\n if (isCurrent) {\n this.#setResourceError(resourceType, errorMessage);\n }\n }\n throw error;\n } finally {\n if (\n this.#pendingRequests.get(cacheKey)?.abortController ===\n abortController\n ) {\n this.#pendingRequests.delete(cacheKey);\n }\n\n // Clear resource-level loading state only when no requests for this resource remain\n if (resourceType && !abortController.signal.aborted) {\n const count = this.#pendingResourceCount.get(resourceType) ?? 0;\n const next = Math.max(0, count - 1);\n if (next === 0) {\n this.#pendingResourceCount.delete(resourceType);\n this.#setResourceLoading(resourceType, false);\n } else {\n this.#pendingResourceCount.set(resourceType, next);\n }\n }\n }\n })();\n\n this.#pendingRequests.set(cacheKey, {\n promise,\n abortController,\n resourceType,\n });\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 * Mutates state.requests inside update(); cast is centralized here.\n *\n * @param fn - Callback that mutates the requests record.\n */\n #mutateRequests(\n fn: (requests: Record<string, RequestState | undefined>) => void,\n ): void {\n this.update((state) => {\n const requests = state.requests as unknown as Record<\n string,\n RequestState | undefined\n >;\n fn(requests);\n });\n }\n\n #removeRequestState(cacheKey: string): void {\n this.#mutateRequests((requests) => {\n delete requests[cacheKey];\n });\n }\n\n #cleanupState(): void {\n this.stopQuotePolling();\n this.#abortDependentRequests();\n this.#clearPendingResourceCountForDependentResources();\n this.update((state) =>\n resetDependentResources(state, { clearUserRegionData: true }),\n );\n }\n\n /**\n * Executes a promise without awaiting, swallowing errors.\n * Errors are stored in state via executeRequest.\n *\n * @param promise - The promise to execute.\n */\n #fireAndForget<Result>(promise: Promise<Result>): void {\n promise.catch((_error: unknown) => undefined);\n }\n\n /**\n * Restarts quote polling if it's currently active.\n * Used when dependencies change (token, provider, payment method).\n * Will only restart if all dependencies are still met (startQuotePolling validates this).\n */\n #restartPollingIfActive(): void {\n if (this.#quotePollingInterval !== null && this.#quotePollingOptions) {\n const options = this.#quotePollingOptions;\n this.stopQuotePolling();\n try {\n this.startQuotePolling(options);\n } catch {\n // Dependencies not met yet, polling will need to be manually restarted\n // when dependencies are available\n }\n }\n }\n\n #requireRegion(): string {\n const regionCode = this.state.userRegion?.regionCode;\n if (!regionCode) {\n throw new Error(\n 'Region is required. Cannot proceed without valid region information.',\n );\n }\n return regionCode;\n }\n\n #isRegionCurrent(normalizedRegion: string): boolean {\n const current = this.state.userRegion?.regionCode;\n return current === undefined || current === normalizedRegion;\n }\n\n #isTokenCurrent(normalizedAssetId: string): boolean {\n const current = this.state.tokens.selected?.assetId ?? '';\n return current === normalizedAssetId;\n }\n\n #isProviderCurrent(normalizedProviderId: string): boolean {\n const current = this.state.providers.selected?.id ?? '';\n return current === normalizedProviderId;\n }\n\n /**\n * Updates a single field (isLoading or error) on a resource state.\n * All resources share the same ResourceState structure, so we use\n * dynamic property access to avoid duplicating switch statements.\n *\n * @param resourceType - The type of resource.\n * @param field - The field to update ('isLoading' or 'error').\n * @param value - The value to set.\n */\n #updateResourceField(\n resourceType: ResourceType,\n field: 'isLoading' | 'error',\n value: boolean | string | null,\n ): void {\n this.update((state) => {\n const resource = state[resourceType];\n if (resource) {\n (resource as Record<string, unknown>)[field] = value;\n }\n });\n }\n\n /**\n * Sets the loading state for a resource type.\n *\n * @param resourceType - The type of resource.\n * @param loading - Whether the resource is loading.\n */\n #setResourceLoading(resourceType: ResourceType, loading: boolean): void {\n this.#updateResourceField(resourceType, 'isLoading', loading);\n }\n\n /**\n * Sets the error state for a resource type.\n *\n * @param resourceType - The type of resource.\n * @param error - The error message, or null to clear.\n */\n #setResourceError(resourceType: ResourceType, error: string | null): void {\n this.#updateResourceField(resourceType, 'error', error);\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 this.#mutateRequests((requests) => {\n requests[cacheKey] = requestState;\n const keys = Object.keys(requests);\n for (const key of keys) {\n const entry = requests[key];\n if (\n entry?.status === RequestStatus.SUCCESS &&\n isCacheExpired(entry, ttl)\n ) {\n delete requests[key];\n }\n }\n const remainingKeys = Object.keys(requests);\n if (remainingKeys.length > maxSize) {\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 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 countriesData = this.state.countries.data;\n if (!countriesData || countriesData.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, countriesData);\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 const regionChanged =\n normalizedRegion !== this.state.userRegion?.regionCode;\n\n const needsRefetch =\n regionChanged ||\n !this.state.tokens.data ||\n this.state.providers.data.length === 0;\n\n if (regionChanged) {\n this.#abortDependentRequests();\n this.#clearPendingResourceCountForDependentResources();\n this.stopQuotePolling();\n }\n this.update((state) => {\n if (regionChanged) {\n resetDependentResources(state);\n }\n state.userRegion = userRegion;\n });\n\n if (needsRefetch) {\n const refetchPromises: Promise<unknown>[] = [];\n if (regionChanged || !this.state.tokens.data) {\n refetchPromises.push(\n this.getTokens(userRegion.regionCode, 'buy', options),\n );\n }\n if (regionChanged || this.state.providers.data.length === 0) {\n refetchPromises.push(\n this.getProviders(userRegion.regionCode, options),\n );\n }\n if (refetchPromises.length > 0) {\n this.#fireAndForget(Promise.all(refetchPromises));\n }\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.stopQuotePolling();\n this.update((state) => {\n state.providers.selected = null;\n resetResource(state, 'paymentMethods');\n });\n return;\n }\n\n const regionCode = this.#requireRegion();\n const providers = this.state.providers.data;\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.providers.selected = provider;\n resetResource(state, 'paymentMethods');\n state.quotes.selected = null;\n resetWidgetUrl(state);\n });\n\n this.#fireAndForget(\n this.getPaymentMethods(regionCode, { provider: provider.id }).then(() => {\n // Restart quote polling after payment methods are fetched\n this.#restartPollingIfActive();\n return undefined;\n }),\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.#requireRegion();\n\n this.#fireAndForget(this.getTokens(regionCode, 'buy', options));\n this.#fireAndForget(this.getProviders(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, resourceType: 'countries' },\n );\n\n this.update((state) => {\n state.countries.data = Array.isArray(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.#requireRegion();\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 {\n ...options,\n resourceType: 'tokens',\n isResultCurrent: () => this.#isRegionCurrent(normalizedRegion),\n },\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.tokens.data = 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.stopQuotePolling();\n this.update((state) => {\n state.tokens.selected = null;\n resetResource(state, 'paymentMethods');\n });\n return;\n }\n\n const regionCode = this.#requireRegion();\n const tokens = this.state.tokens.data;\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.tokens.selected = token;\n resetResource(state, 'paymentMethods');\n state.quotes.selected = null;\n resetWidgetUrl(state);\n });\n\n this.#fireAndForget(\n this.getPaymentMethods(regionCode, { assetId: token.assetId }).then(\n () => {\n this.#restartPollingIfActive();\n return undefined;\n },\n ),\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.#requireRegion();\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 {\n ...options,\n resourceType: 'providers',\n isResultCurrent: () => this.#isRegionCurrent(normalizedRegion),\n },\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.providers.data = 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.#requireRegion();\n const fiatToUse =\n options?.fiat ?? this.state.userRegion?.country?.currency ?? null;\n const assetIdToUse =\n options?.assetId ?? this.state.tokens.selected?.assetId ?? '';\n const providerToUse =\n options?.provider ?? this.state.providers.selected?.id ?? '';\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 {\n ...options,\n resourceType: 'paymentMethods',\n isResultCurrent: () => {\n const regionMatch = this.#isRegionCurrent(normalizedRegion);\n const tokenMatch = this.#isTokenCurrent(assetIdToUse);\n const providerMatch = this.#isProviderCurrent(providerToUse);\n return regionMatch && tokenMatch && providerMatch;\n },\n },\n );\n\n this.update((state) => {\n const currentAssetId = state.tokens.selected?.assetId ?? '';\n const currentProviderId = state.providers.selected?.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.data = 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.paymentMethods.selected?.id,\n );\n if (!currentSelectionStillValid) {\n state.paymentMethods.selected = 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.paymentMethods.selected = null;\n });\n return;\n }\n\n const paymentMethods = this.state.paymentMethods.data;\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.paymentMethods.selected = paymentMethod;\n });\n\n // Restart quote polling if active\n this.#restartPollingIfActive();\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.providers - Optional provider IDs 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 providers?: string[];\n redirectUrl?: string;\n action?: RampAction;\n forceRefresh?: boolean;\n ttl?: number;\n }): Promise<QuotesResponse> {\n const regionToUse = options.region ?? this.#requireRegion();\n const fiatToUse = options.fiat ?? this.state.userRegion?.country?.currency;\n const paymentMethodsToUse =\n options.paymentMethods ??\n this.state.paymentMethods.data.map((pm: PaymentMethod) => pm.id);\n const providersToUse =\n options.providers ??\n this.state.providers.data.map((provider: Provider) => provider.id);\n const action = options.action ?? 'buy';\n const assetIdToUse = options.assetId ?? this.state.tokens.selected?.assetId;\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 normalizedAssetIdForValidation = (assetIdToUse ?? '').trim();\n if (normalizedAssetIdForValidation === '') {\n throw new Error('assetId is required.');\n }\n\n if (\n !paymentMethodsToUse ||\n paymentMethodsToUse.length === 0 ||\n paymentMethodsToUse.some((pm) => pm.trim() === '')\n ) {\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.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 = normalizedAssetIdForValidation;\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 [...providersToUse].sort().join(','),\n options.redirectUrl,\n action,\n ]);\n\n const params = {\n region: normalizedRegion,\n fiat: normalizedFiat,\n assetId: normalizedAssetId,\n amount: options.amount,\n walletAddress: normalizedWalletAddress,\n paymentMethods: paymentMethodsToUse,\n providers: providersToUse,\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 resourceType: 'quotes',\n isResultCurrent: () => this.#isRegionCurrent(normalizedRegion),\n },\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.quotes.data = response;\n }\n });\n\n return response;\n }\n\n /**\n * Starts automatic quote polling with a 15-second refresh interval.\n * Fetches quotes immediately and then every 15 seconds.\n * If the response contains exactly one quote, it is auto-selected.\n * If multiple quotes are returned, the existing selection is preserved if still valid.\n *\n * @param options - Parameters for fetching quotes.\n * @param options.walletAddress - The destination wallet address.\n * @param options.amount - The amount (in fiat for buy, crypto for sell).\n * @param options.redirectUrl - Optional redirect URL after order completion.\n * @throws If required dependencies (region, token, provider, payment method) are not set.\n */\n startQuotePolling(options: {\n walletAddress: string;\n amount: number;\n redirectUrl?: string;\n }): void {\n this.#requireRegion();\n const token = this.state.tokens.selected;\n const provider = this.state.providers.selected;\n const paymentMethod = this.state.paymentMethods.selected;\n\n if (!token) {\n throw new Error(\n 'Token is required. Cannot start quote polling without a selected token.',\n );\n }\n\n if (!provider) {\n throw new Error(\n 'Provider is required. Cannot start quote polling without a selected provider.',\n );\n }\n\n if (!paymentMethod) {\n return;\n }\n\n // Stop any existing polling first\n this.stopQuotePolling();\n\n // Store options for restarts (must be after stop to avoid being cleared)\n this.#quotePollingOptions = options;\n\n // Define the fetch function\n const fetchQuotes = (): void => {\n this.#fireAndForget(\n this.getQuotes({\n assetId: token.assetId,\n amount: options.amount,\n walletAddress: options.walletAddress,\n redirectUrl: options.redirectUrl,\n paymentMethods: [paymentMethod.id],\n providers: [provider.id],\n forceRefresh: true,\n }).then((response) => {\n let newSelectedQuote: Quote | null = null;\n\n // Auto-select logic: only when exactly one quote is returned\n this.update((state) => {\n if (response.success.length === 1) {\n newSelectedQuote = response.success[0];\n state.quotes.selected = newSelectedQuote;\n } else {\n // Keep existing selection if still valid, but update with fresh data\n const currentSelection = state.quotes.selected;\n if (currentSelection) {\n const freshQuote = response.success.find(\n (quote) =>\n quote.provider === currentSelection.provider &&\n quote.quote.paymentMethod ===\n currentSelection.quote.paymentMethod,\n );\n newSelectedQuote = freshQuote ?? null;\n state.quotes.selected = newSelectedQuote;\n }\n }\n });\n\n this.#syncWidgetUrl(newSelectedQuote);\n return undefined;\n }),\n );\n };\n\n // Fetch immediately\n fetchQuotes();\n\n // Set up 15-second polling\n this.#quotePollingInterval = setInterval(fetchQuotes, 15000);\n }\n\n /**\n * Stops automatic quote polling.\n * Does not clear quotes data or selection, only stops the interval.\n */\n stopQuotePolling(): void {\n if (this.#quotePollingInterval !== null) {\n clearInterval(this.#quotePollingInterval);\n this.#quotePollingInterval = null;\n }\n this.#quotePollingOptions = null;\n }\n\n /**\n * Manually sets the selected quote.\n * Automatically triggers a widget URL fetch for the new quote.\n *\n * @param quote - The quote to select, or null to clear the selection.\n */\n setSelectedQuote(quote: Quote | null): void {\n this.update((state) => {\n state.quotes.selected = quote;\n });\n this.#syncWidgetUrl(quote);\n }\n\n /**\n * Cleans up controller resources.\n * Stops any active quote polling to prevent memory leaks.\n * Should be called when the controller is no longer needed.\n */\n override destroy(): void {\n this.stopQuotePolling();\n super.destroy();\n }\n\n /**\n * Syncs the widget URL state with the given quote.\n * If the quote has a buyURL, fetches the widget URL and stores the result in state.\n * If the quote is null or has no buyURL, resets the widget URL state.\n *\n * When data already exists, skips the loading-state reset so that polling\n * cycles don't cause visible flicker (stale-while-revalidate).\n *\n * @param quote - The quote to fetch the widget URL for, or null to clear.\n */\n #syncWidgetUrl(quote: Quote | null): void {\n const buyUrl = quote?.quote?.buyURL;\n if (!buyUrl) {\n this.update((state) => {\n resetWidgetUrl(state);\n });\n return;\n }\n\n if (this.state.widgetUrl.data === null) {\n this.update((state) => {\n state.widgetUrl.isLoading = true;\n state.widgetUrl.error = null;\n });\n }\n\n this.#fireAndForget(\n this.messenger\n .call('RampsService:getBuyWidgetUrl', buyUrl)\n .then((buyWidget) => {\n this.update((state) => {\n state.widgetUrl.data = buyWidget;\n state.widgetUrl.isLoading = false;\n state.widgetUrl.error = null;\n });\n return undefined;\n })\n .catch((error: unknown) => {\n this.update((state) => {\n state.widgetUrl.isLoading = false;\n state.widgetUrl.error =\n error instanceof Error\n ? error.message\n : 'Failed to fetch widget URL';\n });\n }),\n );\n }\n\n /**\n * Fetches the widget URL from a quote for redirect providers.\n * Makes a request to the buyURL endpoint via the RampsService to get the\n * actual provider widget URL, using the injected fetch and retry policy.\n *\n * @param quote - The quote to fetch the widget URL from.\n * @returns Promise resolving to the widget URL string, or null if not available.\n * @deprecated Read `state.widgetUrl` instead. The widget URL is now automatically\n * fetched and stored in state whenever the selected quote changes.\n */\n async getWidgetUrl(quote: Quote): Promise<string | null> {\n const buyUrl = quote.quote?.buyURL;\n if (!buyUrl) {\n return null;\n }\n\n try {\n const buyWidget = await this.messenger.call(\n 'RampsService:getBuyWidgetUrl',\n buyUrl,\n );\n return buyWidget.url ?? null;\n } catch (error) {\n console.error('Error fetching widget URL:', error);\n return null;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"RampsController.cjs","sourceRoot":"","sources":["../src/RampsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAiC3D,qDASwB;AAExB,kBAAkB;AAElB;;;;GAIG;AACU,QAAA,cAAc,GAAG,iBAAiB,CAAC;AAEhD;;;;GAIG;AACU,QAAA,yCAAyC,GACpD;IACE,6BAA6B;IAC7B,2BAA2B;IAC3B,wBAAwB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AC;YAEH,oDAAoD;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 RampsToken,\n RampsServiceActions,\n} from './RampsService';\nimport type {\n RampsServiceGetGeolocationAction,\n RampsServiceGetCountriesAction,\n RampsServiceGetTokensAction,\n RampsServiceGetProvidersAction,\n RampsServiceGetPaymentMethodsAction,\n RampsServiceGetQuotesAction,\n RampsServiceGetBuyWidgetUrlAction,\n} from './RampsService-method-action-types';\nimport type {\n RequestCache as RequestCacheType,\n RequestState,\n ExecuteRequestOptions,\n PendingRequest,\n ResourceType,\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 * RampsService action types that RampsController calls via the messenger.\n * Any host (e.g. mobile) that creates a RampsController messenger must delegate\n * these actions from the root messenger so the controller can function.\n */\nexport const RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS: readonly RampsServiceActions['type'][] =\n [\n 'RampsService:getGeolocation',\n 'RampsService:getCountries',\n 'RampsService:getTokens',\n 'RampsService:getProviders',\n 'RampsService:getPaymentMethods',\n 'RampsService:getQuotes',\n 'RampsService:getBuyWidgetUrl',\n ];\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 * Generic type for resource state that bundles data with loading/error states.\n *\n * @template TData - The type of the resource data\n * @template TSelected - The type of the selected item (defaults to null for resources without selection)\n */\nexport type ResourceState<TData, TSelected = null> = {\n /**\n * The resource data.\n */\n data: TData;\n /**\n * The currently selected item, or null if none selected.\n */\n selected: TSelected;\n /**\n * Whether the resource is currently being fetched.\n */\n isLoading: boolean;\n /**\n * Error message if the fetch failed, or null.\n */\n error: string | null;\n};\n\n/**\n * Describes the shape of the state object for {@link RampsController}.\n */\nexport type RampsControllerState = {\n /**\n * The user's region (full country and state objects).\n * Initially set via geolocation fetch, but can be manually changed by the user.\n */\n userRegion: UserRegion | null;\n /**\n * Countries resource state with data, loading, and error.\n * Data contains the list of countries available for ramp actions.\n */\n countries: ResourceState<Country[]>;\n /**\n * Providers resource state with data, selected, loading, and error.\n * Data contains the list of providers available for the current region.\n */\n providers: ResourceState<Provider[], Provider | null>;\n /**\n * Tokens resource state with data, selected, loading, and error.\n * Data contains topTokens and allTokens arrays.\n */\n tokens: ResourceState<TokensResponse | null, RampsToken | null>;\n /**\n * Payment methods resource state with data, selected, loading, and error.\n * Data contains payment methods filtered by region, fiat, asset, and provider.\n */\n paymentMethods: ResourceState<PaymentMethod[], PaymentMethod | null>;\n /**\n * Quotes resource state with data, selected, loading, and error.\n * Data contains quotes from multiple providers for the given parameters.\n * Selected contains the currently selected quote for the user.\n */\n quotes: ResourceState<QuotesResponse | null, Quote | 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 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 paymentMethods: {\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 * Creates a default resource state object.\n *\n * @template TData - The type of the resource data.\n * @template TSelected - The type of the selected item.\n * @param data - The initial data value.\n * @param selected - The initial selected value.\n * @returns A ResourceState object with default loading and error values.\n */\nfunction createDefaultResourceState<TData, TSelected = null>(\n data: TData,\n selected: TSelected = null as TSelected,\n): ResourceState<TData, TSelected> {\n return {\n data,\n selected,\n isLoading: false,\n error: null,\n };\n}\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 countries: createDefaultResourceState<Country[]>([]),\n providers: createDefaultResourceState<Provider[], Provider | null>(\n [],\n null,\n ),\n tokens: createDefaultResourceState<\n TokensResponse | null,\n RampsToken | null\n >(null, null),\n paymentMethods: createDefaultResourceState<\n PaymentMethod[],\n PaymentMethod | null\n >([], null),\n quotes: createDefaultResourceState<QuotesResponse | null, Quote | null>(\n null,\n null,\n ),\n requests: {},\n };\n}\n\n/**\n * Resets region-dependent resources (userRegion, providers, tokens, paymentMethods, quotes).\n * Mutates state in place; use from within controller update() for atomic updates.\n *\n * @param state - The state object to mutate.\n * @param options - Options for the reset.\n * @param options.clearUserRegionData - When true, sets userRegion to null (e.g. for full cleanup).\n */\nfunction resetDependentResources(\n state: RampsControllerState,\n options?: { clearUserRegionData?: boolean },\n): void {\n if (options?.clearUserRegionData) {\n state.userRegion = null;\n }\n state.providers.selected = null;\n state.providers.data = [];\n state.providers.isLoading = false;\n state.providers.error = null;\n state.tokens.selected = null;\n state.tokens.data = null;\n state.tokens.isLoading = false;\n state.tokens.error = null;\n state.paymentMethods.data = [];\n state.paymentMethods.selected = null;\n state.paymentMethods.isLoading = false;\n state.paymentMethods.error = null;\n state.quotes.data = null;\n state.quotes.selected = null;\n state.quotes.isLoading = false;\n state.quotes.error = null;\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 | RampsServiceGetBuyWidgetUrlAction;\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 * Count of in-flight requests per resource type.\n * Used so isLoading is only cleared when the last request for that resource finishes.\n */\n readonly #pendingResourceCount: Map<ResourceType, number> = new Map();\n\n /**\n * Interval ID for automatic quote polling.\n * Set when startQuotePolling() is called, cleared when stopQuotePolling() is called.\n */\n #quotePollingInterval: ReturnType<typeof setInterval> | null = null;\n\n /**\n * Options used for quote polling (walletAddress, amount, redirectUrl).\n * Stored so polling can be restarted when dependencies change.\n */\n #quotePollingOptions: {\n walletAddress: string;\n amount: number;\n redirectUrl?: string;\n } | null = null;\n\n /**\n * Clears the pending resource count map. Used only in tests to exercise the\n * defensive path when get() returns undefined in the finally block.\n *\n * @internal\n */\n clearPendingResourceCountForTest(): void {\n this.#pendingResourceCount.clear();\n }\n\n #clearPendingResourceCountForDependentResources(): void {\n const types: ResourceType[] = [\n 'providers',\n 'tokens',\n 'paymentMethods',\n 'quotes',\n ];\n for (const resourceType of types) {\n this.#pendingResourceCount.delete(resourceType);\n }\n }\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 const { resourceType } = options ?? {};\n\n // Update state to loading\n this.#updateRequestState(cacheKey, createLoadingState());\n\n // Set resource-level loading state (only on cache miss). Ref-count so concurrent\n // requests for the same resource type (different cache keys) keep isLoading true.\n if (resourceType) {\n const count = this.#pendingResourceCount.get(resourceType) ?? 0;\n this.#pendingResourceCount.set(resourceType, count + 1);\n if (count === 0) {\n this.#setResourceLoading(resourceType, true);\n }\n }\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\n if (resourceType) {\n // We need the extra logic because there are two situations where we’re allowed to clear the error:\n // No callback → always clear\n // Callback present → clear only when isResultCurrent() returns true.\n const isCurrent =\n !options?.isResultCurrent || options.isResultCurrent();\n if (isCurrent) {\n this.#setResourceError(resourceType, null);\n }\n }\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 ?? 'Unknown error';\n\n this.#updateRequestState(\n cacheKey,\n createErrorState(errorMessage, lastFetchedAt),\n );\n\n if (resourceType) {\n const isCurrent =\n !options?.isResultCurrent || options.isResultCurrent();\n if (isCurrent) {\n this.#setResourceError(resourceType, errorMessage);\n }\n }\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 // Clear resource-level loading state only when no requests for this resource remain\n if (resourceType) {\n const count = this.#pendingResourceCount.get(resourceType) ?? 0;\n const next = Math.max(0, count - 1);\n if (next === 0) {\n this.#pendingResourceCount.delete(resourceType);\n this.#setResourceLoading(resourceType, false);\n } else {\n this.#pendingResourceCount.set(resourceType, next);\n }\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.stopQuotePolling();\n this.#clearPendingResourceCountForDependentResources();\n this.update((state) =>\n resetDependentResources(state as unknown as RampsControllerState, {\n clearUserRegionData: true,\n }),\n );\n }\n\n /**\n * Executes a promise without awaiting, swallowing errors.\n * Errors are stored in state via executeRequest.\n *\n * @param promise - The promise to execute.\n */\n #fireAndForget<Result>(promise: Promise<Result>): void {\n promise.catch((_error: unknown) => undefined);\n }\n\n /**\n * Restarts quote polling if it's currently active.\n * Used when dependencies change (token, provider, payment method).\n * Will only restart if all dependencies are still met (startQuotePolling validates this).\n */\n #restartPollingIfActive(): void {\n if (this.#quotePollingInterval !== null && this.#quotePollingOptions) {\n const options = this.#quotePollingOptions;\n this.stopQuotePolling();\n try {\n this.startQuotePolling(options);\n } catch {\n // Dependencies not met yet, polling will need to be manually restarted\n // when dependencies are available\n }\n }\n }\n\n /**\n * Updates a single field (isLoading or error) on a resource state.\n * All resources share the same ResourceState structure, so we use\n * dynamic property access to avoid duplicating switch statements.\n *\n * @param resourceType - The type of resource.\n * @param field - The field to update ('isLoading' or 'error').\n * @param value - The value to set.\n */\n #updateResourceField(\n resourceType: ResourceType,\n field: 'isLoading' | 'error',\n value: boolean | string | null,\n ): void {\n this.update((state) => {\n const resource = state[resourceType];\n if (resource) {\n (resource as Record<string, unknown>)[field] = value;\n }\n });\n }\n\n /**\n * Sets the loading state for a resource type.\n *\n * @param resourceType - The type of resource.\n * @param loading - Whether the resource is loading.\n */\n #setResourceLoading(resourceType: ResourceType, loading: boolean): void {\n this.#updateResourceField(resourceType, 'isLoading', loading);\n }\n\n /**\n * Sets the error state for a resource type.\n *\n * @param resourceType - The type of resource.\n * @param error - The error message, or null to clear.\n */\n #setResourceError(resourceType: ResourceType, error: string | null): void {\n this.#updateResourceField(resourceType, 'error', error);\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?.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 countriesData = this.state.countries.data;\n if (!countriesData || countriesData.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, countriesData);\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 const regionChanged =\n normalizedRegion !== this.state.userRegion?.regionCode;\n\n const needsRefetch =\n regionChanged ||\n !this.state.tokens.data ||\n this.state.providers.data.length === 0;\n\n if (regionChanged) {\n this.#clearPendingResourceCountForDependentResources();\n }\n if (regionChanged) {\n this.stopQuotePolling();\n }\n this.update((state) => {\n if (regionChanged) {\n resetDependentResources(state as unknown as RampsControllerState);\n }\n state.userRegion = userRegion;\n });\n\n if (needsRefetch) {\n const refetchPromises: Promise<unknown>[] = [];\n if (regionChanged || !this.state.tokens.data) {\n refetchPromises.push(\n this.getTokens(userRegion.regionCode, 'buy', options),\n );\n }\n if (regionChanged || this.state.providers.data.length === 0) {\n refetchPromises.push(\n this.getProviders(userRegion.regionCode, options),\n );\n }\n if (refetchPromises.length > 0) {\n this.#fireAndForget(Promise.all(refetchPromises));\n }\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.stopQuotePolling();\n this.update((state) => {\n state.providers.selected = null;\n state.paymentMethods.data = [];\n state.paymentMethods.selected = 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.providers.data;\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.providers.selected = provider;\n state.paymentMethods.data = [];\n state.paymentMethods.selected = null;\n state.quotes.selected = null;\n });\n\n this.#fireAndForget(\n this.getPaymentMethods(regionCode, { provider: provider.id }).then(() => {\n // Restart quote polling after payment methods are fetched\n this.#restartPollingIfActive();\n return undefined;\n }),\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.#fireAndForget(this.getTokens(regionCode, 'buy', options));\n this.#fireAndForget(this.getProviders(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, resourceType: 'countries' },\n );\n\n this.update((state) => {\n state.countries.data = 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 {\n ...options,\n resourceType: 'tokens',\n isResultCurrent: () =>\n this.state.userRegion?.regionCode === undefined ||\n this.state.userRegion?.regionCode === normalizedRegion,\n },\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.tokens.data = 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.stopQuotePolling();\n this.update((state) => {\n state.tokens.selected = null;\n state.paymentMethods.data = [];\n state.paymentMethods.selected = 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.tokens.data;\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.tokens.selected = token;\n state.paymentMethods.data = [];\n state.paymentMethods.selected = null;\n state.quotes.selected = null;\n });\n\n this.#fireAndForget(\n this.getPaymentMethods(regionCode, { assetId: token.assetId }).then(\n () => {\n this.#restartPollingIfActive();\n return undefined;\n },\n ),\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 {\n ...options,\n resourceType: 'providers',\n isResultCurrent: () =>\n this.state.userRegion?.regionCode === undefined ||\n this.state.userRegion?.regionCode === normalizedRegion,\n },\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.providers.data = 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.tokens.selected?.assetId ?? '';\n const providerToUse =\n options?.provider ?? this.state.providers.selected?.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 {\n ...options,\n resourceType: 'paymentMethods',\n isResultCurrent: () => {\n const regionMatch =\n this.state.userRegion?.regionCode === undefined ||\n this.state.userRegion?.regionCode === normalizedRegion;\n const tokenMatch =\n (this.state.tokens.selected?.assetId ?? '') === assetIdToUse;\n const providerMatch =\n (this.state.providers.selected?.id ?? '') === providerToUse;\n return regionMatch && tokenMatch && providerMatch;\n },\n },\n );\n\n this.update((state) => {\n const currentAssetId = state.tokens.selected?.assetId ?? '';\n const currentProviderId = state.providers.selected?.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.data = 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.paymentMethods.selected?.id,\n );\n if (!currentSelectionStillValid) {\n state.paymentMethods.selected = 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.paymentMethods.selected = null;\n });\n return;\n }\n\n const paymentMethods = this.state.paymentMethods.data;\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.paymentMethods.selected = paymentMethod;\n });\n\n // Restart quote polling if active\n this.#restartPollingIfActive();\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.providers - Optional provider IDs 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 providers?: 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.data.map((pm: PaymentMethod) => pm.id);\n const providersToUse =\n options.providers ??\n this.state.providers.data.map((provider: Provider) => provider.id);\n const action = options.action ?? 'buy';\n const assetIdToUse = options.assetId ?? this.state.tokens.selected?.assetId;\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 const normalizedAssetIdForValidation = (assetIdToUse ?? '').trim();\n if (normalizedAssetIdForValidation === '') {\n throw new Error('assetId is required.');\n }\n\n if (\n !paymentMethodsToUse ||\n paymentMethodsToUse.length === 0 ||\n paymentMethodsToUse.some((pm) => pm.trim() === '')\n ) {\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.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 = normalizedAssetIdForValidation;\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 [...providersToUse].sort().join(','),\n options.redirectUrl,\n action,\n ]);\n\n const params = {\n region: normalizedRegion,\n fiat: normalizedFiat,\n assetId: normalizedAssetId,\n amount: options.amount,\n walletAddress: normalizedWalletAddress,\n paymentMethods: paymentMethodsToUse,\n providers: providersToUse,\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 resourceType: 'quotes',\n isResultCurrent: () =>\n this.state.userRegion?.regionCode === undefined ||\n this.state.userRegion?.regionCode === normalizedRegion,\n },\n );\n\n this.update((state) => {\n const userRegionCode = state.userRegion?.regionCode;\n\n if (userRegionCode === undefined || userRegionCode === normalizedRegion) {\n state.quotes.data = response;\n }\n });\n\n return response;\n }\n\n /**\n * Starts automatic quote polling with a 15-second refresh interval.\n * Fetches quotes immediately and then every 15 seconds.\n * If the response contains exactly one quote, it is auto-selected.\n * If multiple quotes are returned, the existing selection is preserved if still valid.\n *\n * @param options - Parameters for fetching quotes.\n * @param options.walletAddress - The destination wallet address.\n * @param options.amount - The amount (in fiat for buy, crypto for sell).\n * @param options.redirectUrl - Optional redirect URL after order completion.\n * @throws If required dependencies (region, token, provider, payment method) are not set.\n */\n startQuotePolling(options: {\n walletAddress: string;\n amount: number;\n redirectUrl?: string;\n }): void {\n // Validate required dependencies\n const regionCode = this.state.userRegion?.regionCode;\n const token = this.state.tokens.selected;\n const provider = this.state.providers.selected;\n const paymentMethod = this.state.paymentMethods.selected;\n\n if (!regionCode) {\n throw new Error(\n 'Region is required. Cannot start quote polling without valid region information.',\n );\n }\n\n if (!token) {\n throw new Error(\n 'Token is required. Cannot start quote polling without a selected token.',\n );\n }\n\n if (!provider) {\n throw new Error(\n 'Provider is required. Cannot start quote polling without a selected provider.',\n );\n }\n\n if (!paymentMethod) {\n return;\n }\n\n // Stop any existing polling first\n this.stopQuotePolling();\n\n // Store options for restarts (must be after stop to avoid being cleared)\n this.#quotePollingOptions = options;\n\n // Define the fetch function\n const fetchQuotes = (): void => {\n this.#fireAndForget(\n this.getQuotes({\n assetId: token.assetId,\n amount: options.amount,\n walletAddress: options.walletAddress,\n redirectUrl: options.redirectUrl,\n paymentMethods: [paymentMethod.id],\n providers: [provider.id],\n forceRefresh: true,\n }).then((response) => {\n // Auto-select logic: only when exactly one quote is returned\n this.update((state) => {\n if (response.success.length === 1) {\n state.quotes.selected = response.success[0];\n } else {\n // Keep existing selection if still valid, but update with fresh data\n const currentSelection = state.quotes.selected;\n if (currentSelection) {\n const freshQuote = response.success.find(\n (quote) =>\n quote.provider === currentSelection.provider &&\n quote.quote.paymentMethod ===\n currentSelection.quote.paymentMethod,\n );\n // Update with fresh quote data, or clear if no longer valid\n state.quotes.selected = freshQuote ?? null;\n }\n }\n });\n return undefined;\n }),\n );\n };\n\n // Fetch immediately\n fetchQuotes();\n\n // Set up 15-second polling\n this.#quotePollingInterval = setInterval(fetchQuotes, 15000);\n }\n\n /**\n * Stops automatic quote polling.\n * Does not clear quotes data or selection, only stops the interval.\n */\n stopQuotePolling(): void {\n if (this.#quotePollingInterval !== null) {\n clearInterval(this.#quotePollingInterval);\n this.#quotePollingInterval = null;\n }\n this.#quotePollingOptions = null;\n }\n\n /**\n * Manually sets the selected quote.\n *\n * @param quote - The quote to select, or null to clear the selection.\n */\n setSelectedQuote(quote: Quote | null): void {\n this.update((state) => {\n state.quotes.selected = quote;\n });\n }\n\n /**\n * Cleans up controller resources.\n * Stops any active quote polling to prevent memory leaks.\n * Should be called when the controller is no longer needed.\n */\n override destroy(): void {\n this.stopQuotePolling();\n super.destroy();\n }\n\n /**\n * Fetches the widget URL from a quote for redirect providers.\n * Makes a request to the buyURL endpoint via the RampsService to get the\n * actual provider widget URL, using the injected fetch and retry policy.\n *\n * @param quote - The quote to fetch the widget URL from.\n * @returns Promise resolving to the widget URL string, or null if not available.\n */\n async getWidgetUrl(quote: Quote): Promise<string | null> {\n const buyUrl = quote.quote?.buyURL;\n if (!buyUrl) {\n return null;\n }\n\n try {\n const buyWidget = await this.messenger.call(\n 'RampsService:getBuyWidgetUrl',\n buyUrl,\n );\n return buyWidget.url ?? null;\n } catch (error) {\n console.error('Error fetching widget URL:', error);\n return null;\n }\n }\n}\n"]}
@@ -1,7 +1,7 @@
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, QuotesResponse, Quote, RampsToken, RampsServiceActions, BuyWidget } from "./RampsService.cjs";
4
+ import type { Country, TokensResponse, Provider, State, RampAction, PaymentMethod, PaymentMethodsResponse, QuotesResponse, Quote, RampsToken, RampsServiceActions } from "./RampsService.cjs";
5
5
  import type { RampsServiceGetGeolocationAction, RampsServiceGetCountriesAction, RampsServiceGetTokensAction, RampsServiceGetProvidersAction, RampsServiceGetPaymentMethodsAction, RampsServiceGetQuotesAction, RampsServiceGetBuyWidgetUrlAction } from "./RampsService-method-action-types.cjs";
6
6
  import type { RequestCache as RequestCacheType, RequestState, ExecuteRequestOptions } from "./RequestCache.cjs";
7
7
  /**
@@ -92,12 +92,6 @@ export type RampsControllerState = {
92
92
  * Selected contains the currently selected quote for the user.
93
93
  */
94
94
  quotes: ResourceState<QuotesResponse | null, Quote | null>;
95
- /**
96
- * Widget URL resource state with data, loading, and error.
97
- * Contains the buy widget data (URL, browser type, order ID) for the currently selected quote.
98
- * Automatically fetched whenever a selected quote changes.
99
- */
100
- widgetUrl: ResourceState<BuyWidget | null>;
101
95
  /**
102
96
  * Cache of request states, keyed by cache key.
103
97
  * This stores loading, success, and error states for API requests.
@@ -179,28 +173,16 @@ export declare class RampsController extends BaseController<typeof controllerNam
179
173
  */
180
174
  constructor({ messenger, state, requestCacheTTL, requestCacheMaxSize, }: RampsControllerOptions);
181
175
  /**
182
- * Executes a request with caching, deduplication, and at most one in-flight
183
- * request per resource type.
184
- *
185
- * 1. **Same cache key in flight** – If a request with this cache key is
186
- * already pending, returns that promise (deduplication; no second request).
176
+ * Executes a request with caching and deduplication.
187
177
  *
188
- * 2. **Cache hit** – If valid, non-expired data exists in state.requests for
189
- * this key and forceRefresh is not set, returns that data without fetching.
178
+ * If a request with the same cache key is already in flight, returns the
179
+ * existing promise. If valid cached data exists, returns it without making
180
+ * a new request.
190
181
  *
191
- * 3. **New request** – Creates an AbortController and fires the fetcher.
192
- * If options.resourceType is set, tags the pending request with that
193
- * resource type (so #abortDependentRequests can cancel it on region
194
- * change or cleanup) and ref-counts resource-level loading state.
195
- * On success or error, updates request state and resource error;
196
- * in finally, clears resource loading only if this request was not
197
- * aborted.
198
- *
199
- * @param cacheKey - Unique identifier for this request (e.g. from createCacheKey).
200
- * @param fetcher - Async function that performs the fetch. Receives an AbortSignal
201
- * that is aborted when this request is superseded by another for the same resource.
202
- * @param options - Optional forceRefresh, ttl, and resourceType for loading/error state.
203
- * @returns The result of the request (from cache, joined promise, or fetcher).
182
+ * @param cacheKey - Unique identifier for this request.
183
+ * @param fetcher - Function that performs the actual fetch. Receives an AbortSignal.
184
+ * @param options - Options for cache behavior.
185
+ * @returns The result of the request.
204
186
  */
205
187
  executeRequest<TResult>(cacheKey: string, fetcher: (signal: AbortSignal) => Promise<TResult>, options?: ExecuteRequestOptions): Promise<TResult>;
206
188
  /**
@@ -377,7 +359,6 @@ export declare class RampsController extends BaseController<typeof controllerNam
377
359
  stopQuotePolling(): void;
378
360
  /**
379
361
  * Manually sets the selected quote.
380
- * Automatically triggers a widget URL fetch for the new quote.
381
362
  *
382
363
  * @param quote - The quote to select, or null to clear the selection.
383
364
  */
@@ -395,8 +376,6 @@ export declare class RampsController extends BaseController<typeof controllerNam
395
376
  *
396
377
  * @param quote - The quote to fetch the widget URL from.
397
378
  * @returns Promise resolving to the widget URL string, or null if not available.
398
- * @deprecated Read `state.widgetUrl` instead. The widget URL is now automatically
399
- * fetched and stored in state whenever the selected quote changes.
400
379
  */
401
380
  getWidgetUrl(quote: Quote): Promise<string | null>;
402
381
  }
@@ -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;AAIrD,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,QAAQ,EACR,KAAK,EACL,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,KAAK,EACL,UAAU,EACV,mBAAmB,EACnB,SAAS,EACV,2BAAuB;AACxB,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,2BAA2B,EAC3B,8BAA8B,EAC9B,mCAAmC,EACnC,2BAA2B,EAC3B,iCAAiC,EAClC,+CAA2C;AAC5C,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,YAAY,EACZ,qBAAqB,EAGtB,2BAAuB;AAcxB;;;;GAIG;AACH,eAAO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AAM,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,IAAI;IA4ER;;;OAGG;IACH,gBAAgB,IAAI,IAAI;IAQxB;;;;;OAKG;IACH,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI;IAO3C;;;;OAIG;IACM,OAAO,IAAI,IAAI;IAsDxB;;;;;;;;;OASG;IACG,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAiBzD"}
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,cAAc,EACd,KAAK,EACL,UAAU,EACV,mBAAmB,EACpB,2BAAuB;AACxB,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,2BAA2B,EAC3B,8BAA8B,EAC9B,mCAAmC,EACnC,2BAA2B,EAC3B,iCAAiC,EAClC,+CAA2C;AAC5C,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,YAAY,EACZ,qBAAqB,EAGtB,2BAAuB;AAcxB;;;;GAIG;AACH,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,yCAAyC,EAAE,SAAS,mBAAmB,CAAC,MAAM,CAAC,EASzF,CAAC;AAUJ;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,KAAK,EAAE,KAA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AM,GAAG,IAAI,CAAC;CAiBzD"}
@@ -1,7 +1,7 @@
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, QuotesResponse, Quote, RampsToken, RampsServiceActions, BuyWidget } from "./RampsService.mjs";
4
+ import type { Country, TokensResponse, Provider, State, RampAction, PaymentMethod, PaymentMethodsResponse, QuotesResponse, Quote, RampsToken, RampsServiceActions } from "./RampsService.mjs";
5
5
  import type { RampsServiceGetGeolocationAction, RampsServiceGetCountriesAction, RampsServiceGetTokensAction, RampsServiceGetProvidersAction, RampsServiceGetPaymentMethodsAction, RampsServiceGetQuotesAction, RampsServiceGetBuyWidgetUrlAction } from "./RampsService-method-action-types.mjs";
6
6
  import type { RequestCache as RequestCacheType, RequestState, ExecuteRequestOptions } from "./RequestCache.mjs";
7
7
  /**
@@ -92,12 +92,6 @@ export type RampsControllerState = {
92
92
  * Selected contains the currently selected quote for the user.
93
93
  */
94
94
  quotes: ResourceState<QuotesResponse | null, Quote | null>;
95
- /**
96
- * Widget URL resource state with data, loading, and error.
97
- * Contains the buy widget data (URL, browser type, order ID) for the currently selected quote.
98
- * Automatically fetched whenever a selected quote changes.
99
- */
100
- widgetUrl: ResourceState<BuyWidget | null>;
101
95
  /**
102
96
  * Cache of request states, keyed by cache key.
103
97
  * This stores loading, success, and error states for API requests.
@@ -179,28 +173,16 @@ export declare class RampsController extends BaseController<typeof controllerNam
179
173
  */
180
174
  constructor({ messenger, state, requestCacheTTL, requestCacheMaxSize, }: RampsControllerOptions);
181
175
  /**
182
- * Executes a request with caching, deduplication, and at most one in-flight
183
- * request per resource type.
184
- *
185
- * 1. **Same cache key in flight** – If a request with this cache key is
186
- * already pending, returns that promise (deduplication; no second request).
176
+ * Executes a request with caching and deduplication.
187
177
  *
188
- * 2. **Cache hit** – If valid, non-expired data exists in state.requests for
189
- * this key and forceRefresh is not set, returns that data without fetching.
178
+ * If a request with the same cache key is already in flight, returns the
179
+ * existing promise. If valid cached data exists, returns it without making
180
+ * a new request.
190
181
  *
191
- * 3. **New request** – Creates an AbortController and fires the fetcher.
192
- * If options.resourceType is set, tags the pending request with that
193
- * resource type (so #abortDependentRequests can cancel it on region
194
- * change or cleanup) and ref-counts resource-level loading state.
195
- * On success or error, updates request state and resource error;
196
- * in finally, clears resource loading only if this request was not
197
- * aborted.
198
- *
199
- * @param cacheKey - Unique identifier for this request (e.g. from createCacheKey).
200
- * @param fetcher - Async function that performs the fetch. Receives an AbortSignal
201
- * that is aborted when this request is superseded by another for the same resource.
202
- * @param options - Optional forceRefresh, ttl, and resourceType for loading/error state.
203
- * @returns The result of the request (from cache, joined promise, or fetcher).
182
+ * @param cacheKey - Unique identifier for this request.
183
+ * @param fetcher - Function that performs the actual fetch. Receives an AbortSignal.
184
+ * @param options - Options for cache behavior.
185
+ * @returns The result of the request.
204
186
  */
205
187
  executeRequest<TResult>(cacheKey: string, fetcher: (signal: AbortSignal) => Promise<TResult>, options?: ExecuteRequestOptions): Promise<TResult>;
206
188
  /**
@@ -377,7 +359,6 @@ export declare class RampsController extends BaseController<typeof controllerNam
377
359
  stopQuotePolling(): void;
378
360
  /**
379
361
  * Manually sets the selected quote.
380
- * Automatically triggers a widget URL fetch for the new quote.
381
362
  *
382
363
  * @param quote - The quote to select, or null to clear the selection.
383
364
  */
@@ -395,8 +376,6 @@ export declare class RampsController extends BaseController<typeof controllerNam
395
376
  *
396
377
  * @param quote - The quote to fetch the widget URL from.
397
378
  * @returns Promise resolving to the widget URL string, or null if not available.
398
- * @deprecated Read `state.widgetUrl` instead. The widget URL is now automatically
399
- * fetched and stored in state whenever the selected quote changes.
400
379
  */
401
380
  getWidgetUrl(quote: Quote): Promise<string | null>;
402
381
  }