@metamask/ramps-controller 9.0.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -1
- package/dist/RampsController.cjs +8 -217
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +3 -50
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +3 -50
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +8 -217
- package/dist/RampsController.mjs.map +1 -1
- package/dist/RequestCache.cjs.map +1 -1
- package/dist/RequestCache.d.cts +1 -1
- package/dist/RequestCache.d.cts.map +1 -1
- package/dist/RequestCache.d.mts +1 -1
- package/dist/RequestCache.d.mts.map +1 -1
- package/dist/RequestCache.mjs.map +1 -1
- package/dist/TransakService.cjs +17 -15
- package/dist/TransakService.cjs.map +1 -1
- package/dist/TransakService.d.cts.map +1 -1
- package/dist/TransakService.d.mts.map +1 -1
- package/dist/TransakService.mjs +17 -15
- package/dist/TransakService.mjs.map +1 -1
- package/package.json +1 -2
|
@@ -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,
|
|
4
|
+
import type { Country, TokensResponse, Provider, State, RampAction, PaymentMethod, PaymentMethodsResponse, QuotesResponse, Quote, RampsToken, RampsServiceActions, RampsOrder } from "./RampsService.cjs";
|
|
5
5
|
import type { RampsServiceGetGeolocationAction, RampsServiceGetCountriesAction, RampsServiceGetTokensAction, RampsServiceGetProvidersAction, RampsServiceGetPaymentMethodsAction, RampsServiceGetQuotesAction, RampsServiceGetBuyWidgetUrlAction, RampsServiceGetOrderAction, RampsServiceGetOrderFromCallbackAction } from "./RampsService-method-action-types.cjs";
|
|
6
6
|
import type { RequestCache as RequestCacheType, RequestState, ExecuteRequestOptions } from "./RequestCache.cjs";
|
|
7
7
|
import type { TransakAccessToken, TransakUserDetails, TransakBuyQuote, TransakKycRequirement, TransakAdditionalRequirementsResponse, TransakDepositOrder, TransakUserLimits, TransakOttResponse, TransakQuoteTranslation, TransakTranslationRequest, TransakIdProofStatus, TransakOrderPaymentMethod, PatchUserRequestBody, TransakOrder } from "./TransakService.cjs";
|
|
@@ -106,18 +106,6 @@ export type RampsControllerState = {
|
|
|
106
106
|
* Data contains payment methods filtered by region, fiat, asset, and provider.
|
|
107
107
|
*/
|
|
108
108
|
paymentMethods: ResourceState<PaymentMethod[], PaymentMethod | null>;
|
|
109
|
-
/**
|
|
110
|
-
* Quotes resource state with data, selected, loading, and error.
|
|
111
|
-
* Data contains quotes from multiple providers for the given parameters.
|
|
112
|
-
* Selected contains the currently selected quote for the user.
|
|
113
|
-
*/
|
|
114
|
-
quotes: ResourceState<QuotesResponse | null, Quote | null>;
|
|
115
|
-
/**
|
|
116
|
-
* Widget URL resource state with data, loading, and error.
|
|
117
|
-
* Contains the buy widget data (URL, browser type, order ID) for the currently selected quote.
|
|
118
|
-
* Automatically fetched whenever a selected quote changes.
|
|
119
|
-
*/
|
|
120
|
-
widgetUrl: ResourceState<BuyWidget | null>;
|
|
121
109
|
/**
|
|
122
110
|
* Cache of request states, keyed by cache key.
|
|
123
111
|
* This stores loading, success, and error states for API requests.
|
|
@@ -350,7 +338,7 @@ export declare class RampsController extends BaseController<typeof controllerNam
|
|
|
350
338
|
setSelectedPaymentMethod(paymentMethodId?: string): void;
|
|
351
339
|
/**
|
|
352
340
|
* Fetches quotes from all providers for a given set of parameters.
|
|
353
|
-
*
|
|
341
|
+
* Uses the controller's request cache; callers manage the response in local state.
|
|
354
342
|
*
|
|
355
343
|
* @param options - The parameters for fetching quotes.
|
|
356
344
|
* @param options.region - User's region code. If not provided, uses userRegion from state.
|
|
@@ -379,53 +367,18 @@ export declare class RampsController extends BaseController<typeof controllerNam
|
|
|
379
367
|
forceRefresh?: boolean;
|
|
380
368
|
ttl?: number;
|
|
381
369
|
}): Promise<QuotesResponse>;
|
|
382
|
-
/**
|
|
383
|
-
* Starts automatic quote polling with a 15-second refresh interval.
|
|
384
|
-
* Fetches quotes immediately and then every 15 seconds.
|
|
385
|
-
* If the response contains exactly one quote, it is auto-selected.
|
|
386
|
-
* If multiple quotes are returned, the existing selection is preserved if still valid.
|
|
387
|
-
*
|
|
388
|
-
* Returns early (no-op) if the selected payment method is not yet set,
|
|
389
|
-
* allowing callers to invoke this before payment-method selection is finalized.
|
|
390
|
-
*
|
|
391
|
-
* @param options - Parameters for fetching quotes.
|
|
392
|
-
* @param options.walletAddress - The destination wallet address.
|
|
393
|
-
* @param options.amount - The amount (in fiat for buy, crypto for sell).
|
|
394
|
-
* @param options.redirectUrl - Optional redirect URL after order completion.
|
|
395
|
-
* @throws If required dependencies (region, token, provider) are not set.
|
|
396
|
-
*/
|
|
397
|
-
startQuotePolling(options: {
|
|
398
|
-
walletAddress: string;
|
|
399
|
-
amount: number;
|
|
400
|
-
redirectUrl?: string;
|
|
401
|
-
}): void;
|
|
402
|
-
/**
|
|
403
|
-
* Stops automatic quote polling.
|
|
404
|
-
* Does not clear quotes data or selection, only stops the interval.
|
|
405
|
-
*/
|
|
406
|
-
stopQuotePolling(): void;
|
|
407
|
-
/**
|
|
408
|
-
* Manually sets the selected quote.
|
|
409
|
-
* Automatically triggers a widget URL fetch for the new quote.
|
|
410
|
-
*
|
|
411
|
-
* @param quote - The quote to select, or null to clear the selection.
|
|
412
|
-
*/
|
|
413
|
-
setSelectedQuote(quote: Quote | null): void;
|
|
414
370
|
/**
|
|
415
371
|
* Cleans up controller resources.
|
|
416
|
-
* Stops any active quote polling to prevent memory leaks.
|
|
417
372
|
* Should be called when the controller is no longer needed.
|
|
418
373
|
*/
|
|
419
374
|
destroy(): void;
|
|
420
375
|
/**
|
|
421
376
|
* Fetches the widget URL from a quote for redirect providers.
|
|
422
377
|
* Makes a request to the buyURL endpoint via the RampsService to get the
|
|
423
|
-
* actual provider widget URL
|
|
378
|
+
* actual provider widget URL.
|
|
424
379
|
*
|
|
425
380
|
* @param quote - The quote to fetch the widget URL from.
|
|
426
381
|
* @returns Promise resolving to the widget URL string, or null if not available.
|
|
427
|
-
* @deprecated Read `state.widgetUrl` instead. The widget URL is now automatically
|
|
428
|
-
* fetched and stored in state whenever the selected quote changes.
|
|
429
382
|
*/
|
|
430
383
|
getWidgetUrl(quote: Quote): Promise<string | null>;
|
|
431
384
|
/**
|
|
@@ -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,
|
|
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,UAAU,EACX,2BAAuB;AACxB,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,2BAA2B,EAC3B,8BAA8B,EAC9B,mCA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AAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAYvE;;;;;OAKG;IACG,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IASpE;;;;;;OAMG;IACG,uBAAuB,CAC3B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC;IAanB;;;;;;OAMG;IACG,qBAAqB,CACzB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAahC;;;;;OAKG;IACG,qBAAqB,CACzB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,uBAAuB,CAAC;IAInC;;;;;OAKG;IACG,uBAAuB,CAC3B,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,oBAAoB,CAAC;IAYhC;;;;;OAKG;IACG,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/D;;;;;OAKG;IACG,4BAA4B,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAStD;;;;OAIG;IACG,sBAAsB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;CAQxD"}
|
|
@@ -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,
|
|
4
|
+
import type { Country, TokensResponse, Provider, State, RampAction, PaymentMethod, PaymentMethodsResponse, QuotesResponse, Quote, RampsToken, RampsServiceActions, RampsOrder } from "./RampsService.mjs";
|
|
5
5
|
import type { RampsServiceGetGeolocationAction, RampsServiceGetCountriesAction, RampsServiceGetTokensAction, RampsServiceGetProvidersAction, RampsServiceGetPaymentMethodsAction, RampsServiceGetQuotesAction, RampsServiceGetBuyWidgetUrlAction, RampsServiceGetOrderAction, RampsServiceGetOrderFromCallbackAction } from "./RampsService-method-action-types.mjs";
|
|
6
6
|
import type { RequestCache as RequestCacheType, RequestState, ExecuteRequestOptions } from "./RequestCache.mjs";
|
|
7
7
|
import type { TransakAccessToken, TransakUserDetails, TransakBuyQuote, TransakKycRequirement, TransakAdditionalRequirementsResponse, TransakDepositOrder, TransakUserLimits, TransakOttResponse, TransakQuoteTranslation, TransakTranslationRequest, TransakIdProofStatus, TransakOrderPaymentMethod, PatchUserRequestBody, TransakOrder } from "./TransakService.mjs";
|
|
@@ -106,18 +106,6 @@ export type RampsControllerState = {
|
|
|
106
106
|
* Data contains payment methods filtered by region, fiat, asset, and provider.
|
|
107
107
|
*/
|
|
108
108
|
paymentMethods: ResourceState<PaymentMethod[], PaymentMethod | null>;
|
|
109
|
-
/**
|
|
110
|
-
* Quotes resource state with data, selected, loading, and error.
|
|
111
|
-
* Data contains quotes from multiple providers for the given parameters.
|
|
112
|
-
* Selected contains the currently selected quote for the user.
|
|
113
|
-
*/
|
|
114
|
-
quotes: ResourceState<QuotesResponse | null, Quote | null>;
|
|
115
|
-
/**
|
|
116
|
-
* Widget URL resource state with data, loading, and error.
|
|
117
|
-
* Contains the buy widget data (URL, browser type, order ID) for the currently selected quote.
|
|
118
|
-
* Automatically fetched whenever a selected quote changes.
|
|
119
|
-
*/
|
|
120
|
-
widgetUrl: ResourceState<BuyWidget | null>;
|
|
121
109
|
/**
|
|
122
110
|
* Cache of request states, keyed by cache key.
|
|
123
111
|
* This stores loading, success, and error states for API requests.
|
|
@@ -350,7 +338,7 @@ export declare class RampsController extends BaseController<typeof controllerNam
|
|
|
350
338
|
setSelectedPaymentMethod(paymentMethodId?: string): void;
|
|
351
339
|
/**
|
|
352
340
|
* Fetches quotes from all providers for a given set of parameters.
|
|
353
|
-
*
|
|
341
|
+
* Uses the controller's request cache; callers manage the response in local state.
|
|
354
342
|
*
|
|
355
343
|
* @param options - The parameters for fetching quotes.
|
|
356
344
|
* @param options.region - User's region code. If not provided, uses userRegion from state.
|
|
@@ -379,53 +367,18 @@ export declare class RampsController extends BaseController<typeof controllerNam
|
|
|
379
367
|
forceRefresh?: boolean;
|
|
380
368
|
ttl?: number;
|
|
381
369
|
}): Promise<QuotesResponse>;
|
|
382
|
-
/**
|
|
383
|
-
* Starts automatic quote polling with a 15-second refresh interval.
|
|
384
|
-
* Fetches quotes immediately and then every 15 seconds.
|
|
385
|
-
* If the response contains exactly one quote, it is auto-selected.
|
|
386
|
-
* If multiple quotes are returned, the existing selection is preserved if still valid.
|
|
387
|
-
*
|
|
388
|
-
* Returns early (no-op) if the selected payment method is not yet set,
|
|
389
|
-
* allowing callers to invoke this before payment-method selection is finalized.
|
|
390
|
-
*
|
|
391
|
-
* @param options - Parameters for fetching quotes.
|
|
392
|
-
* @param options.walletAddress - The destination wallet address.
|
|
393
|
-
* @param options.amount - The amount (in fiat for buy, crypto for sell).
|
|
394
|
-
* @param options.redirectUrl - Optional redirect URL after order completion.
|
|
395
|
-
* @throws If required dependencies (region, token, provider) are not set.
|
|
396
|
-
*/
|
|
397
|
-
startQuotePolling(options: {
|
|
398
|
-
walletAddress: string;
|
|
399
|
-
amount: number;
|
|
400
|
-
redirectUrl?: string;
|
|
401
|
-
}): void;
|
|
402
|
-
/**
|
|
403
|
-
* Stops automatic quote polling.
|
|
404
|
-
* Does not clear quotes data or selection, only stops the interval.
|
|
405
|
-
*/
|
|
406
|
-
stopQuotePolling(): void;
|
|
407
|
-
/**
|
|
408
|
-
* Manually sets the selected quote.
|
|
409
|
-
* Automatically triggers a widget URL fetch for the new quote.
|
|
410
|
-
*
|
|
411
|
-
* @param quote - The quote to select, or null to clear the selection.
|
|
412
|
-
*/
|
|
413
|
-
setSelectedQuote(quote: Quote | null): void;
|
|
414
370
|
/**
|
|
415
371
|
* Cleans up controller resources.
|
|
416
|
-
* Stops any active quote polling to prevent memory leaks.
|
|
417
372
|
* Should be called when the controller is no longer needed.
|
|
418
373
|
*/
|
|
419
374
|
destroy(): void;
|
|
420
375
|
/**
|
|
421
376
|
* Fetches the widget URL from a quote for redirect providers.
|
|
422
377
|
* Makes a request to the buyURL endpoint via the RampsService to get the
|
|
423
|
-
* actual provider widget URL
|
|
378
|
+
* actual provider widget URL.
|
|
424
379
|
*
|
|
425
380
|
* @param quote - The quote to fetch the widget URL from.
|
|
426
381
|
* @returns Promise resolving to the widget URL string, or null if not available.
|
|
427
|
-
* @deprecated Read `state.widgetUrl` instead. The widget URL is now automatically
|
|
428
|
-
* fetched and stored in state whenever the selected quote changes.
|
|
429
382
|
*/
|
|
430
383
|
getWidgetUrl(quote: Quote): Promise<string | null>;
|
|
431
384
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RampsController.d.mts","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,
|
|
1
|
+
{"version":3,"file":"RampsController.d.mts","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,UAAU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AAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,MAAM;IAUT;;;;;OAKG;IACG,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAYvE;;;;;OAKG;IACG,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IASpE;;;;;;OAMG;IACG,uBAAuB,CAC3B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC;IAanB;;;;;;OAMG;IACG,qBAAqB,CACzB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAahC;;;;;OAKG;IACG,qBAAqB,CACzB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,uBAAuB,CAAC;IAInC;;;;;OAKG;IACG,uBAAuB,CAC3B,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,oBAAoB,CAAC;IAYhC;;;;;OAKG;IACG,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/D;;;;;OAKG;IACG,4BAA4B,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAStD;;;;OAIG;IACG,sBAAsB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;CAQxD"}
|
package/dist/RampsController.mjs
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount,
|
|
12
|
+
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_fireAndForget, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_syncTransakAuthOnError;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
14
|
import { DEFAULT_REQUEST_CACHE_TTL, DEFAULT_REQUEST_CACHE_MAX_SIZE, createCacheKey, isCacheExpired, createLoadingState, createSuccessState, createErrorState, RequestStatus } from "./RequestCache.mjs";
|
|
15
15
|
// === GENERAL ===
|
|
@@ -98,18 +98,6 @@ const rampsControllerMetadata = {
|
|
|
98
98
|
includeInStateLogs: true,
|
|
99
99
|
usedInUi: true,
|
|
100
100
|
},
|
|
101
|
-
quotes: {
|
|
102
|
-
persist: false,
|
|
103
|
-
includeInDebugSnapshot: true,
|
|
104
|
-
includeInStateLogs: false,
|
|
105
|
-
usedInUi: true,
|
|
106
|
-
},
|
|
107
|
-
widgetUrl: {
|
|
108
|
-
persist: false,
|
|
109
|
-
includeInDebugSnapshot: true,
|
|
110
|
-
includeInStateLogs: false,
|
|
111
|
-
usedInUi: true,
|
|
112
|
-
},
|
|
113
101
|
requests: {
|
|
114
102
|
persist: false,
|
|
115
103
|
includeInDebugSnapshot: true,
|
|
@@ -155,8 +143,6 @@ export function getDefaultRampsControllerState() {
|
|
|
155
143
|
providers: createDefaultResourceState([], null),
|
|
156
144
|
tokens: createDefaultResourceState(null, null),
|
|
157
145
|
paymentMethods: createDefaultResourceState([], null),
|
|
158
|
-
quotes: createDefaultResourceState(null, null),
|
|
159
|
-
widgetUrl: createDefaultResourceState(null),
|
|
160
146
|
requests: {},
|
|
161
147
|
nativeProviders: {
|
|
162
148
|
transak: {
|
|
@@ -172,7 +158,6 @@ const DEPENDENT_RESOURCE_KEYS = [
|
|
|
172
158
|
'providers',
|
|
173
159
|
'tokens',
|
|
174
160
|
'paymentMethods',
|
|
175
|
-
'quotes',
|
|
176
161
|
];
|
|
177
162
|
const DEPENDENT_RESOURCE_KEYS_SET = new Set(DEPENDENT_RESOURCE_KEYS);
|
|
178
163
|
function resetResource(state, resourceType, defaultResource) {
|
|
@@ -184,20 +169,7 @@ function resetResource(state, resourceType, defaultResource) {
|
|
|
184
169
|
resource.error = def.error;
|
|
185
170
|
}
|
|
186
171
|
/**
|
|
187
|
-
* Resets
|
|
188
|
-
* Mutates state in place; use from within controller update() for atomic updates.
|
|
189
|
-
*
|
|
190
|
-
* @param state - The state object to mutate.
|
|
191
|
-
*/
|
|
192
|
-
function resetWidgetUrl(state) {
|
|
193
|
-
const def = getDefaultRampsControllerState().widgetUrl;
|
|
194
|
-
state.widgetUrl.data = def.data;
|
|
195
|
-
state.widgetUrl.selected = def.selected;
|
|
196
|
-
state.widgetUrl.isLoading = def.isLoading;
|
|
197
|
-
state.widgetUrl.error = def.error;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Resets region-dependent resources (userRegion, providers, tokens, paymentMethods, quotes).
|
|
172
|
+
* Resets region-dependent resources (userRegion, providers, tokens, paymentMethods).
|
|
201
173
|
* Mutates state in place; use from within controller update() for atomic updates.
|
|
202
174
|
*
|
|
203
175
|
* @param state - The state object to mutate.
|
|
@@ -212,7 +184,6 @@ function resetDependentResources(state, options) {
|
|
|
212
184
|
for (const key of DEPENDENT_RESOURCE_KEYS) {
|
|
213
185
|
resetResource(state, key, defaultState[key]);
|
|
214
186
|
}
|
|
215
|
-
resetWidgetUrl(state);
|
|
216
187
|
}
|
|
217
188
|
// === HELPER FUNCTIONS ===
|
|
218
189
|
/**
|
|
@@ -322,16 +293,6 @@ export class RampsController extends BaseController {
|
|
|
322
293
|
* Used so isLoading is only cleared when the last request for that resource finishes.
|
|
323
294
|
*/
|
|
324
295
|
_RampsController_pendingResourceCount.set(this, new Map());
|
|
325
|
-
/**
|
|
326
|
-
* Interval ID for automatic quote polling.
|
|
327
|
-
* Set when startQuotePolling() is called, cleared when stopQuotePolling() is called.
|
|
328
|
-
*/
|
|
329
|
-
_RampsController_quotePollingInterval.set(this, null);
|
|
330
|
-
/**
|
|
331
|
-
* Options used for quote polling (walletAddress, amount, redirectUrl).
|
|
332
|
-
* Stored so polling can be restarted when dependencies change.
|
|
333
|
-
*/
|
|
334
|
-
_RampsController_quotePollingOptions.set(this, null);
|
|
335
296
|
__classPrivateFieldSet(this, _RampsController_requestCacheTTL, requestCacheTTL, "f");
|
|
336
297
|
__classPrivateFieldSet(this, _RampsController_requestCacheMaxSize, requestCacheMaxSize, "f");
|
|
337
298
|
}
|
|
@@ -502,7 +463,6 @@ export class RampsController extends BaseController {
|
|
|
502
463
|
if (regionChanged) {
|
|
503
464
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_abortDependentRequests).call(this);
|
|
504
465
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_clearPendingResourceCountForDependentResources).call(this);
|
|
505
|
-
this.stopQuotePolling();
|
|
506
466
|
}
|
|
507
467
|
this.update((state) => {
|
|
508
468
|
if (regionChanged) {
|
|
@@ -539,7 +499,6 @@ export class RampsController extends BaseController {
|
|
|
539
499
|
*/
|
|
540
500
|
setSelectedProvider(providerId) {
|
|
541
501
|
if (providerId === null) {
|
|
542
|
-
this.stopQuotePolling();
|
|
543
502
|
this.update((state) => {
|
|
544
503
|
state.providers.selected = null;
|
|
545
504
|
resetResource(state, 'paymentMethods');
|
|
@@ -558,14 +517,8 @@ export class RampsController extends BaseController {
|
|
|
558
517
|
this.update((state) => {
|
|
559
518
|
state.providers.selected = provider;
|
|
560
519
|
resetResource(state, 'paymentMethods');
|
|
561
|
-
state.quotes.selected = null;
|
|
562
|
-
resetWidgetUrl(state);
|
|
563
520
|
});
|
|
564
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { provider: provider.id })
|
|
565
|
-
// Restart quote polling after payment methods are fetched
|
|
566
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_restartPollingIfActive).call(this);
|
|
567
|
-
return undefined;
|
|
568
|
-
}));
|
|
521
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { provider: provider.id }));
|
|
569
522
|
}
|
|
570
523
|
/**
|
|
571
524
|
* Initializes the controller by fetching the user's region from geolocation.
|
|
@@ -654,7 +607,6 @@ export class RampsController extends BaseController {
|
|
|
654
607
|
*/
|
|
655
608
|
setSelectedToken(assetId) {
|
|
656
609
|
if (!assetId) {
|
|
657
|
-
this.stopQuotePolling();
|
|
658
610
|
this.update((state) => {
|
|
659
611
|
state.tokens.selected = null;
|
|
660
612
|
resetResource(state, 'paymentMethods');
|
|
@@ -674,13 +626,8 @@ export class RampsController extends BaseController {
|
|
|
674
626
|
this.update((state) => {
|
|
675
627
|
state.tokens.selected = token;
|
|
676
628
|
resetResource(state, 'paymentMethods');
|
|
677
|
-
state.quotes.selected = null;
|
|
678
|
-
resetWidgetUrl(state);
|
|
679
629
|
});
|
|
680
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { assetId: token.assetId })
|
|
681
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_restartPollingIfActive).call(this);
|
|
682
|
-
return undefined;
|
|
683
|
-
}));
|
|
630
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { assetId: token.assetId }));
|
|
684
631
|
}
|
|
685
632
|
/**
|
|
686
633
|
* Fetches the list of providers for a given region.
|
|
@@ -812,12 +759,10 @@ export class RampsController extends BaseController {
|
|
|
812
759
|
this.update((state) => {
|
|
813
760
|
state.paymentMethods.selected = paymentMethod;
|
|
814
761
|
});
|
|
815
|
-
// Restart quote polling if active
|
|
816
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_restartPollingIfActive).call(this);
|
|
817
762
|
}
|
|
818
763
|
/**
|
|
819
764
|
* Fetches quotes from all providers for a given set of parameters.
|
|
820
|
-
*
|
|
765
|
+
* Uses the controller's request cache; callers manage the response in local state.
|
|
821
766
|
*
|
|
822
767
|
* @param options - The parameters for fetching quotes.
|
|
823
768
|
* @param options.region - User's region code. If not provided, uses userRegion from state.
|
|
@@ -886,135 +831,27 @@ export class RampsController extends BaseController {
|
|
|
886
831
|
redirectUrl: options.redirectUrl,
|
|
887
832
|
action,
|
|
888
833
|
};
|
|
889
|
-
|
|
834
|
+
return this.executeRequest(cacheKey, async () => {
|
|
890
835
|
return this.messenger.call('RampsService:getQuotes', params);
|
|
891
836
|
}, {
|
|
892
837
|
forceRefresh: options.forceRefresh,
|
|
893
838
|
ttl: options.ttl ?? DEFAULT_QUOTES_TTL,
|
|
894
|
-
resourceType: 'quotes',
|
|
895
|
-
isResultCurrent: () => __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isRegionCurrent).call(this, normalizedRegion),
|
|
896
|
-
});
|
|
897
|
-
this.update((state) => {
|
|
898
|
-
const userRegionCode = state.userRegion?.regionCode;
|
|
899
|
-
if (userRegionCode === undefined || userRegionCode === normalizedRegion) {
|
|
900
|
-
state.quotes.data = response;
|
|
901
|
-
}
|
|
902
|
-
});
|
|
903
|
-
return response;
|
|
904
|
-
}
|
|
905
|
-
/**
|
|
906
|
-
* Starts automatic quote polling with a 15-second refresh interval.
|
|
907
|
-
* Fetches quotes immediately and then every 15 seconds.
|
|
908
|
-
* If the response contains exactly one quote, it is auto-selected.
|
|
909
|
-
* If multiple quotes are returned, the existing selection is preserved if still valid.
|
|
910
|
-
*
|
|
911
|
-
* Returns early (no-op) if the selected payment method is not yet set,
|
|
912
|
-
* allowing callers to invoke this before payment-method selection is finalized.
|
|
913
|
-
*
|
|
914
|
-
* @param options - Parameters for fetching quotes.
|
|
915
|
-
* @param options.walletAddress - The destination wallet address.
|
|
916
|
-
* @param options.amount - The amount (in fiat for buy, crypto for sell).
|
|
917
|
-
* @param options.redirectUrl - Optional redirect URL after order completion.
|
|
918
|
-
* @throws If required dependencies (region, token, provider) are not set.
|
|
919
|
-
*/
|
|
920
|
-
startQuotePolling(options) {
|
|
921
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
922
|
-
const token = this.state.tokens.selected;
|
|
923
|
-
const provider = this.state.providers.selected;
|
|
924
|
-
const paymentMethod = this.state.paymentMethods.selected;
|
|
925
|
-
if (!token) {
|
|
926
|
-
throw new Error('Token is required. Cannot start quote polling without a selected token.');
|
|
927
|
-
}
|
|
928
|
-
if (!provider) {
|
|
929
|
-
throw new Error('Provider is required. Cannot start quote polling without a selected provider.');
|
|
930
|
-
}
|
|
931
|
-
if (!paymentMethod) {
|
|
932
|
-
return;
|
|
933
|
-
}
|
|
934
|
-
// Stop any existing polling first
|
|
935
|
-
this.stopQuotePolling();
|
|
936
|
-
// Store options for restarts (must be after stop to avoid being cleared)
|
|
937
|
-
__classPrivateFieldSet(this, _RampsController_quotePollingOptions, options, "f");
|
|
938
|
-
// Define the fetch function
|
|
939
|
-
const fetchQuotes = () => {
|
|
940
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getQuotes({
|
|
941
|
-
assetId: token.assetId,
|
|
942
|
-
amount: options.amount,
|
|
943
|
-
walletAddress: options.walletAddress,
|
|
944
|
-
redirectUrl: options.redirectUrl,
|
|
945
|
-
paymentMethods: [paymentMethod.id],
|
|
946
|
-
providers: [provider.id],
|
|
947
|
-
forceRefresh: true,
|
|
948
|
-
}).then((response) => {
|
|
949
|
-
let newSelectedQuote = null;
|
|
950
|
-
// Auto-select logic: only when exactly one quote is returned
|
|
951
|
-
this.update((state) => {
|
|
952
|
-
if (response.success.length === 1) {
|
|
953
|
-
newSelectedQuote = response.success[0];
|
|
954
|
-
state.quotes.selected = newSelectedQuote;
|
|
955
|
-
}
|
|
956
|
-
else {
|
|
957
|
-
// Keep existing selection if still valid, but update with fresh data
|
|
958
|
-
const currentSelection = state.quotes.selected;
|
|
959
|
-
if (currentSelection) {
|
|
960
|
-
const freshQuote = response.success.find((quote) => quote.provider === currentSelection.provider &&
|
|
961
|
-
quote.quote.paymentMethod ===
|
|
962
|
-
currentSelection.quote.paymentMethod);
|
|
963
|
-
newSelectedQuote = freshQuote ?? null;
|
|
964
|
-
state.quotes.selected = newSelectedQuote;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
});
|
|
968
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncWidgetUrl).call(this, newSelectedQuote);
|
|
969
|
-
return undefined;
|
|
970
|
-
}));
|
|
971
|
-
};
|
|
972
|
-
// Fetch immediately
|
|
973
|
-
fetchQuotes();
|
|
974
|
-
// Set up 15-second polling
|
|
975
|
-
__classPrivateFieldSet(this, _RampsController_quotePollingInterval, setInterval(fetchQuotes, 15000), "f");
|
|
976
|
-
}
|
|
977
|
-
/**
|
|
978
|
-
* Stops automatic quote polling.
|
|
979
|
-
* Does not clear quotes data or selection, only stops the interval.
|
|
980
|
-
*/
|
|
981
|
-
stopQuotePolling() {
|
|
982
|
-
if (__classPrivateFieldGet(this, _RampsController_quotePollingInterval, "f") !== null) {
|
|
983
|
-
clearInterval(__classPrivateFieldGet(this, _RampsController_quotePollingInterval, "f"));
|
|
984
|
-
__classPrivateFieldSet(this, _RampsController_quotePollingInterval, null, "f");
|
|
985
|
-
}
|
|
986
|
-
__classPrivateFieldSet(this, _RampsController_quotePollingOptions, null, "f");
|
|
987
|
-
}
|
|
988
|
-
/**
|
|
989
|
-
* Manually sets the selected quote.
|
|
990
|
-
* Automatically triggers a widget URL fetch for the new quote.
|
|
991
|
-
*
|
|
992
|
-
* @param quote - The quote to select, or null to clear the selection.
|
|
993
|
-
*/
|
|
994
|
-
setSelectedQuote(quote) {
|
|
995
|
-
this.update((state) => {
|
|
996
|
-
state.quotes.selected = quote;
|
|
997
839
|
});
|
|
998
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncWidgetUrl).call(this, quote);
|
|
999
840
|
}
|
|
1000
841
|
/**
|
|
1001
842
|
* Cleans up controller resources.
|
|
1002
|
-
* Stops any active quote polling to prevent memory leaks.
|
|
1003
843
|
* Should be called when the controller is no longer needed.
|
|
1004
844
|
*/
|
|
1005
845
|
destroy() {
|
|
1006
|
-
this.stopQuotePolling();
|
|
1007
846
|
super.destroy();
|
|
1008
847
|
}
|
|
1009
848
|
/**
|
|
1010
849
|
* Fetches the widget URL from a quote for redirect providers.
|
|
1011
850
|
* Makes a request to the buyURL endpoint via the RampsService to get the
|
|
1012
|
-
* actual provider widget URL
|
|
851
|
+
* actual provider widget URL.
|
|
1013
852
|
*
|
|
1014
853
|
* @param quote - The quote to fetch the widget URL from.
|
|
1015
854
|
* @returns Promise resolving to the widget URL string, or null if not available.
|
|
1016
|
-
* @deprecated Read `state.widgetUrl` instead. The widget URL is now automatically
|
|
1017
|
-
* fetched and stored in state whenever the selected quote changes.
|
|
1018
855
|
*/
|
|
1019
856
|
async getWidgetUrl(quote) {
|
|
1020
857
|
const buyUrl = quote.quote?.buyURL;
|
|
@@ -1450,7 +1287,7 @@ export class RampsController extends BaseController {
|
|
|
1450
1287
|
}
|
|
1451
1288
|
}
|
|
1452
1289
|
}
|
|
1453
|
-
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_pendingResourceCount = new WeakMap(),
|
|
1290
|
+
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_pendingResourceCount = new WeakMap(), _RampsController_instances = new WeakSet(), _RampsController_clearPendingResourceCountForDependentResources = function _RampsController_clearPendingResourceCountForDependentResources() {
|
|
1454
1291
|
for (const resourceType of DEPENDENT_RESOURCE_KEYS) {
|
|
1455
1292
|
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
1456
1293
|
}
|
|
@@ -1473,24 +1310,11 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1473
1310
|
delete requests[cacheKey];
|
|
1474
1311
|
});
|
|
1475
1312
|
}, _RampsController_cleanupState = function _RampsController_cleanupState() {
|
|
1476
|
-
this.stopQuotePolling();
|
|
1477
1313
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_abortDependentRequests).call(this);
|
|
1478
1314
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_clearPendingResourceCountForDependentResources).call(this);
|
|
1479
1315
|
this.update((state) => resetDependentResources(state, { clearUserRegionData: true }));
|
|
1480
1316
|
}, _RampsController_fireAndForget = function _RampsController_fireAndForget(promise) {
|
|
1481
1317
|
promise.catch((_error) => undefined);
|
|
1482
|
-
}, _RampsController_restartPollingIfActive = function _RampsController_restartPollingIfActive() {
|
|
1483
|
-
if (__classPrivateFieldGet(this, _RampsController_quotePollingInterval, "f") !== null && __classPrivateFieldGet(this, _RampsController_quotePollingOptions, "f")) {
|
|
1484
|
-
const options = __classPrivateFieldGet(this, _RampsController_quotePollingOptions, "f");
|
|
1485
|
-
this.stopQuotePolling();
|
|
1486
|
-
try {
|
|
1487
|
-
this.startQuotePolling(options);
|
|
1488
|
-
}
|
|
1489
|
-
catch {
|
|
1490
|
-
// Dependencies not met yet, polling will need to be manually restarted
|
|
1491
|
-
// when dependencies are available
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
1318
|
}, _RampsController_requireRegion = function _RampsController_requireRegion() {
|
|
1495
1319
|
const regionCode = this.state.userRegion?.regionCode;
|
|
1496
1320
|
if (!regionCode) {
|
|
@@ -1546,39 +1370,6 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1546
1370
|
}
|
|
1547
1371
|
}
|
|
1548
1372
|
});
|
|
1549
|
-
}, _RampsController_syncWidgetUrl = function _RampsController_syncWidgetUrl(quote) {
|
|
1550
|
-
const buyUrl = quote?.quote?.buyURL;
|
|
1551
|
-
if (!buyUrl) {
|
|
1552
|
-
this.update((state) => {
|
|
1553
|
-
resetWidgetUrl(state);
|
|
1554
|
-
});
|
|
1555
|
-
return;
|
|
1556
|
-
}
|
|
1557
|
-
if (this.state.widgetUrl.data === null) {
|
|
1558
|
-
this.update((state) => {
|
|
1559
|
-
state.widgetUrl.isLoading = true;
|
|
1560
|
-
state.widgetUrl.error = null;
|
|
1561
|
-
});
|
|
1562
|
-
}
|
|
1563
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.messenger
|
|
1564
|
-
.call('RampsService:getBuyWidgetUrl', buyUrl)
|
|
1565
|
-
.then((buyWidget) => {
|
|
1566
|
-
this.update((state) => {
|
|
1567
|
-
state.widgetUrl.data = buyWidget;
|
|
1568
|
-
state.widgetUrl.isLoading = false;
|
|
1569
|
-
state.widgetUrl.error = null;
|
|
1570
|
-
});
|
|
1571
|
-
return undefined;
|
|
1572
|
-
})
|
|
1573
|
-
.catch((error) => {
|
|
1574
|
-
this.update((state) => {
|
|
1575
|
-
state.widgetUrl.isLoading = false;
|
|
1576
|
-
state.widgetUrl.error =
|
|
1577
|
-
error instanceof Error
|
|
1578
|
-
? error.message
|
|
1579
|
-
: 'Failed to fetch widget URL';
|
|
1580
|
-
});
|
|
1581
|
-
}));
|
|
1582
1373
|
}, _RampsController_syncTransakAuthOnError = function _RampsController_syncTransakAuthOnError(error) {
|
|
1583
1374
|
if (error instanceof Error &&
|
|
1584
1375
|
'httpStatus' in error &&
|