@metamask/ramps-controller 15.0.0 → 16.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 +29 -1
- package/LICENSE +1 -0
- package/dist/RampsController-method-action-types.cjs.map +1 -1
- package/dist/RampsController-method-action-types.d.cts +5 -3
- package/dist/RampsController-method-action-types.d.cts.map +1 -1
- package/dist/RampsController-method-action-types.d.mts +5 -3
- package/dist/RampsController-method-action-types.d.mts.map +1 -1
- package/dist/RampsController-method-action-types.mjs.map +1 -1
- package/dist/RampsController.cjs +185 -26
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +38 -5
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +38 -5
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +184 -24
- package/dist/RampsController.mjs.map +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -189,6 +189,16 @@ export type RampsControllerMessenger = Messenger<typeof controllerName, RampsCon
|
|
|
189
189
|
/**
|
|
190
190
|
* Configuration options for the RampsController.
|
|
191
191
|
*/
|
|
192
|
+
/**
|
|
193
|
+
* Provider-class scope for fiat quote widening, resolved per `getQuotes` call.
|
|
194
|
+
*
|
|
195
|
+
* - `off`: native-only auto-selection (default; preserves prior behaviour).
|
|
196
|
+
* - `in-app`: also quote in-app WebView aggregator providers and select the
|
|
197
|
+
* best in-app quote.
|
|
198
|
+
* - `all`: additionally allow external-browser / custom-action providers
|
|
199
|
+
* (Phase 2).
|
|
200
|
+
*/
|
|
201
|
+
export type ProviderScope = 'off' | 'in-app' | 'all';
|
|
192
202
|
export type RampsControllerOptions = {
|
|
193
203
|
/** The messenger suited for this controller. */
|
|
194
204
|
messenger: RampsControllerMessenger;
|
|
@@ -198,8 +208,24 @@ export type RampsControllerOptions = {
|
|
|
198
208
|
requestCacheTTL?: number;
|
|
199
209
|
/** Maximum number of entries in the request cache. Defaults to 250. */
|
|
200
210
|
requestCacheMaxSize?: number;
|
|
211
|
+
/**
|
|
212
|
+
* Optional callback returning the current provider-class scope for fiat quote
|
|
213
|
+
* widening. Read per `getQuotes` call so a host-side toggle takes effect at
|
|
214
|
+
* runtime without reconstructing the controller. Defaults to `off`
|
|
215
|
+
* (native-only) when omitted.
|
|
216
|
+
*/
|
|
217
|
+
getProviderScope?: () => ProviderScope;
|
|
218
|
+
/**
|
|
219
|
+
* Optional callback returning the default redirect URL to use for the widened
|
|
220
|
+
* in-app quote fetch when the caller omits `redirectUrl`. The quotes API only
|
|
221
|
+
* embeds a `buyURL`/`buyWidget` (the WebView page a non-native provider needs)
|
|
222
|
+
* when a `redirectUrl` is present, so supplying this default lets widened
|
|
223
|
+
* in-app aggregator quotes carry a usable widget URL. Only applied on the
|
|
224
|
+
* widened path; an explicit caller `redirectUrl` always wins and scope `off`
|
|
225
|
+
* never injects. Defaults to a callback returning `undefined` when omitted.
|
|
226
|
+
*/
|
|
227
|
+
getDefaultRedirectUrl?: () => string | undefined;
|
|
201
228
|
};
|
|
202
|
-
export declare function normalizeProviderCode(providerCode: string): string;
|
|
203
229
|
/**
|
|
204
230
|
* Returns the internal MetaMask order code used for state lookups and polling.
|
|
205
231
|
* Prefers the code embedded in the canonical order `id` path over `providerOrderId`,
|
|
@@ -230,8 +256,13 @@ export declare class RampsController extends BaseController<typeof controllerNam
|
|
|
230
256
|
* controller. Missing properties will be filled in with defaults.
|
|
231
257
|
* @param args.requestCacheTTL - Time to live for cached requests in milliseconds.
|
|
232
258
|
* @param args.requestCacheMaxSize - Maximum number of entries in the request cache.
|
|
259
|
+
* @param args.getProviderScope - Optional callback returning the current
|
|
260
|
+
* provider-class scope for fiat quote widening. Defaults to `off`.
|
|
261
|
+
* @param args.getDefaultRedirectUrl - Optional callback returning the default
|
|
262
|
+
* redirect URL used for the widened in-app quote fetch when the caller omits
|
|
263
|
+
* `redirectUrl`. Defaults to a callback returning `undefined`.
|
|
233
264
|
*/
|
|
234
|
-
constructor({ messenger, state, requestCacheTTL, requestCacheMaxSize, }: RampsControllerOptions);
|
|
265
|
+
constructor({ messenger, state, requestCacheTTL, requestCacheMaxSize, getProviderScope, getDefaultRedirectUrl, }: RampsControllerOptions);
|
|
235
266
|
/**
|
|
236
267
|
* Executes a request with caching, deduplication, and at most one in-flight
|
|
237
268
|
* request per resource type.
|
|
@@ -301,8 +332,10 @@ export declare class RampsController extends BaseController<typeof controllerNam
|
|
|
301
332
|
* This should be called once at app startup to set up the initial region.
|
|
302
333
|
*
|
|
303
334
|
* Idempotent: subsequent calls return the same promise unless forceRefresh is set.
|
|
304
|
-
*
|
|
305
|
-
*
|
|
335
|
+
* Force-refetches the countries catalog on startup (bypassing the in-session
|
|
336
|
+
* request cache) so region preset amounts stay current. The catalog is not
|
|
337
|
+
* persisted, so a cold start always re-fetches it regardless. Skips
|
|
338
|
+
* geolocation when userRegion already exists.
|
|
306
339
|
*
|
|
307
340
|
* @param options - Options for cache behavior. forceRefresh bypasses idempotency and re-runs the full flow.
|
|
308
341
|
* @returns Promise that resolves when initialization is complete.
|
|
@@ -475,7 +508,7 @@ export declare class RampsController extends BaseController<typeof controllerNam
|
|
|
475
508
|
*
|
|
476
509
|
* @param params - Object containing order identifiers and wallet info.
|
|
477
510
|
* @param params.orderId - Full order ID (e.g. "/providers/paypal/orders/abc123") or order code.
|
|
478
|
-
* @param params.providerCode -
|
|
511
|
+
* @param params.providerCode - Canonical provider code (e.g. "paypal", "transak").
|
|
479
512
|
* @param params.walletAddress - Wallet address for the order.
|
|
480
513
|
* @param params.chainId - Optional chain ID for the order.
|
|
481
514
|
*/
|
|
@@ -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;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAIrD,OAAO,KAAK,EAAE,4BAA4B,EAAE,kDAA8C;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA0B;AAExD,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACP,cAAc,EACd,QAAQ,EACR,KAAK,EACL,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,KAAK,
|
|
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;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAIrD,OAAO,KAAK,EAAE,4BAA4B,EAAE,kDAA8C;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA0B;AAExD,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACP,cAAc,EACd,QAAQ,EACR,KAAK,EACL,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,KAAK,EAGL,UAAU,EACV,mBAAmB,EACnB,UAAU,EACX,2BAAuB;AACxB,OAAO,EAAE,gBAAgB,EAAE,2BAAuB;AAClD,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,2BAA2B,EAC3B,8BAA8B,EAC9B,mCAAmC,EACnC,2BAA2B,EAC3B,iCAAiC,EACjC,0BAA0B,EAC1B,sCAAsC,EACvC,+CAA2C;AAC5C,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,YAAY,EACZ,qBAAqB,EAGtB,2BAAuB;AAWxB,OAAO,KAAK,EACV,kBAAk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BAAoB,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;IAWnC;;;;;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"}
|
|
@@ -189,6 +189,16 @@ export type RampsControllerMessenger = Messenger<typeof controllerName, RampsCon
|
|
|
189
189
|
/**
|
|
190
190
|
* Configuration options for the RampsController.
|
|
191
191
|
*/
|
|
192
|
+
/**
|
|
193
|
+
* Provider-class scope for fiat quote widening, resolved per `getQuotes` call.
|
|
194
|
+
*
|
|
195
|
+
* - `off`: native-only auto-selection (default; preserves prior behaviour).
|
|
196
|
+
* - `in-app`: also quote in-app WebView aggregator providers and select the
|
|
197
|
+
* best in-app quote.
|
|
198
|
+
* - `all`: additionally allow external-browser / custom-action providers
|
|
199
|
+
* (Phase 2).
|
|
200
|
+
*/
|
|
201
|
+
export type ProviderScope = 'off' | 'in-app' | 'all';
|
|
192
202
|
export type RampsControllerOptions = {
|
|
193
203
|
/** The messenger suited for this controller. */
|
|
194
204
|
messenger: RampsControllerMessenger;
|
|
@@ -198,8 +208,24 @@ export type RampsControllerOptions = {
|
|
|
198
208
|
requestCacheTTL?: number;
|
|
199
209
|
/** Maximum number of entries in the request cache. Defaults to 250. */
|
|
200
210
|
requestCacheMaxSize?: number;
|
|
211
|
+
/**
|
|
212
|
+
* Optional callback returning the current provider-class scope for fiat quote
|
|
213
|
+
* widening. Read per `getQuotes` call so a host-side toggle takes effect at
|
|
214
|
+
* runtime without reconstructing the controller. Defaults to `off`
|
|
215
|
+
* (native-only) when omitted.
|
|
216
|
+
*/
|
|
217
|
+
getProviderScope?: () => ProviderScope;
|
|
218
|
+
/**
|
|
219
|
+
* Optional callback returning the default redirect URL to use for the widened
|
|
220
|
+
* in-app quote fetch when the caller omits `redirectUrl`. The quotes API only
|
|
221
|
+
* embeds a `buyURL`/`buyWidget` (the WebView page a non-native provider needs)
|
|
222
|
+
* when a `redirectUrl` is present, so supplying this default lets widened
|
|
223
|
+
* in-app aggregator quotes carry a usable widget URL. Only applied on the
|
|
224
|
+
* widened path; an explicit caller `redirectUrl` always wins and scope `off`
|
|
225
|
+
* never injects. Defaults to a callback returning `undefined` when omitted.
|
|
226
|
+
*/
|
|
227
|
+
getDefaultRedirectUrl?: () => string | undefined;
|
|
201
228
|
};
|
|
202
|
-
export declare function normalizeProviderCode(providerCode: string): string;
|
|
203
229
|
/**
|
|
204
230
|
* Returns the internal MetaMask order code used for state lookups and polling.
|
|
205
231
|
* Prefers the code embedded in the canonical order `id` path over `providerOrderId`,
|
|
@@ -230,8 +256,13 @@ export declare class RampsController extends BaseController<typeof controllerNam
|
|
|
230
256
|
* controller. Missing properties will be filled in with defaults.
|
|
231
257
|
* @param args.requestCacheTTL - Time to live for cached requests in milliseconds.
|
|
232
258
|
* @param args.requestCacheMaxSize - Maximum number of entries in the request cache.
|
|
259
|
+
* @param args.getProviderScope - Optional callback returning the current
|
|
260
|
+
* provider-class scope for fiat quote widening. Defaults to `off`.
|
|
261
|
+
* @param args.getDefaultRedirectUrl - Optional callback returning the default
|
|
262
|
+
* redirect URL used for the widened in-app quote fetch when the caller omits
|
|
263
|
+
* `redirectUrl`. Defaults to a callback returning `undefined`.
|
|
233
264
|
*/
|
|
234
|
-
constructor({ messenger, state, requestCacheTTL, requestCacheMaxSize, }: RampsControllerOptions);
|
|
265
|
+
constructor({ messenger, state, requestCacheTTL, requestCacheMaxSize, getProviderScope, getDefaultRedirectUrl, }: RampsControllerOptions);
|
|
235
266
|
/**
|
|
236
267
|
* Executes a request with caching, deduplication, and at most one in-flight
|
|
237
268
|
* request per resource type.
|
|
@@ -301,8 +332,10 @@ export declare class RampsController extends BaseController<typeof controllerNam
|
|
|
301
332
|
* This should be called once at app startup to set up the initial region.
|
|
302
333
|
*
|
|
303
334
|
* Idempotent: subsequent calls return the same promise unless forceRefresh is set.
|
|
304
|
-
*
|
|
305
|
-
*
|
|
335
|
+
* Force-refetches the countries catalog on startup (bypassing the in-session
|
|
336
|
+
* request cache) so region preset amounts stay current. The catalog is not
|
|
337
|
+
* persisted, so a cold start always re-fetches it regardless. Skips
|
|
338
|
+
* geolocation when userRegion already exists.
|
|
306
339
|
*
|
|
307
340
|
* @param options - Options for cache behavior. forceRefresh bypasses idempotency and re-runs the full flow.
|
|
308
341
|
* @returns Promise that resolves when initialization is complete.
|
|
@@ -475,7 +508,7 @@ export declare class RampsController extends BaseController<typeof controllerNam
|
|
|
475
508
|
*
|
|
476
509
|
* @param params - Object containing order identifiers and wallet info.
|
|
477
510
|
* @param params.orderId - Full order ID (e.g. "/providers/paypal/orders/abc123") or order code.
|
|
478
|
-
* @param params.providerCode -
|
|
511
|
+
* @param params.providerCode - Canonical provider code (e.g. "paypal", "transak").
|
|
479
512
|
* @param params.walletAddress - Wallet address for the order.
|
|
480
513
|
* @param params.chainId - Optional chain ID for the order.
|
|
481
514
|
*/
|
|
@@ -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;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAIrD,OAAO,KAAK,EAAE,4BAA4B,EAAE,kDAA8C;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA0B;AAExD,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACP,cAAc,EACd,QAAQ,EACR,KAAK,EACL,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,KAAK,
|
|
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;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAIrD,OAAO,KAAK,EAAE,4BAA4B,EAAE,kDAA8C;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA0B;AAExD,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACP,cAAc,EACd,QAAQ,EACR,KAAK,EACL,UAAU,EACV,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,KAAK,EAGL,UAAU,EACV,mBAAmB,EACnB,UAAU,EACX,2BAAuB;AACxB,OAAO,EAAE,gBAAgB,EAAE,2BAAuB;AAClD,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,2BAA2B,EAC3B,8BAA8B,EAC9B,mCAAmC,EACnC,2BAA2B,EAC3B,iCAAiC,EACjC,0BAA0B,EAC1B,sCAAsC,EACvC,+CAA2C;AAC5C,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,YAAY,EACZ,qBAAqB,EAGtB,2BAAuB;AAWxB,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,qCAAqC,EACrC,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AAuB,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;IAWnC;;;;;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, _RampsController_pendingResourceGeneration, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_initPromise, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_runInit, _RampsController_getSupportingProvidersForRegion, _RampsController_filterProviderIdsBySupport, _RampsController_resolveProviderIdsForQuote, _RampsController_getPreferredProviderIdsFromOrders, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError, _RampsController_getNormalizedTransakError;
|
|
12
|
+
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_getProviderScope, _RampsController_getDefaultRedirectUrl, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_pendingResourceGeneration, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_initPromise, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_runInit, _RampsController_syncUserRegionFromCountriesCatalog, _RampsController_pickInAppQuote, _RampsController_getSupportingProvidersForRegion, _RampsController_filterProviderIdsBySupport, _RampsController_resolveProviderIdsForQuote, _RampsController_getPreferredProviderIdsFromOrders, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError, _RampsController_getNormalizedTransakError;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
14
|
import { BrokenCircuitError } from "@metamask/controller-utils";
|
|
15
15
|
import { RAMPS_ERROR_CODES } from "./rampsErrorCodes.mjs";
|
|
@@ -132,7 +132,7 @@ const rampsControllerMetadata = {
|
|
|
132
132
|
usedInUi: true,
|
|
133
133
|
},
|
|
134
134
|
countries: {
|
|
135
|
-
persist:
|
|
135
|
+
persist: false,
|
|
136
136
|
includeInDebugSnapshot: true,
|
|
137
137
|
includeInStateLogs: true,
|
|
138
138
|
usedInUi: true,
|
|
@@ -325,9 +325,6 @@ function findRegionFromCode(regionCode, countries) {
|
|
|
325
325
|
regionCode: normalizedCode,
|
|
326
326
|
};
|
|
327
327
|
}
|
|
328
|
-
export function normalizeProviderCode(providerCode) {
|
|
329
|
-
return providerCode.replace(/^\/providers\//u, '');
|
|
330
|
-
}
|
|
331
328
|
/**
|
|
332
329
|
* Returns the internal MetaMask order code used for state lookups and polling.
|
|
333
330
|
* Prefers the code embedded in the canonical order `id` path over `providerOrderId`,
|
|
@@ -435,8 +432,13 @@ export class RampsController extends BaseController {
|
|
|
435
432
|
* controller. Missing properties will be filled in with defaults.
|
|
436
433
|
* @param args.requestCacheTTL - Time to live for cached requests in milliseconds.
|
|
437
434
|
* @param args.requestCacheMaxSize - Maximum number of entries in the request cache.
|
|
435
|
+
* @param args.getProviderScope - Optional callback returning the current
|
|
436
|
+
* provider-class scope for fiat quote widening. Defaults to `off`.
|
|
437
|
+
* @param args.getDefaultRedirectUrl - Optional callback returning the default
|
|
438
|
+
* redirect URL used for the widened in-app quote fetch when the caller omits
|
|
439
|
+
* `redirectUrl`. Defaults to a callback returning `undefined`.
|
|
438
440
|
*/
|
|
439
|
-
constructor({ messenger, state = {}, requestCacheTTL = DEFAULT_REQUEST_CACHE_TTL, requestCacheMaxSize = DEFAULT_REQUEST_CACHE_MAX_SIZE, }) {
|
|
441
|
+
constructor({ messenger, state = {}, requestCacheTTL = DEFAULT_REQUEST_CACHE_TTL, requestCacheMaxSize = DEFAULT_REQUEST_CACHE_MAX_SIZE, getProviderScope, getDefaultRedirectUrl, }) {
|
|
440
442
|
super({
|
|
441
443
|
messenger,
|
|
442
444
|
metadata: rampsControllerMetadata,
|
|
@@ -457,6 +459,17 @@ export class RampsController extends BaseController {
|
|
|
457
459
|
* Maximum number of entries in the request cache.
|
|
458
460
|
*/
|
|
459
461
|
_RampsController_requestCacheMaxSize.set(this, void 0);
|
|
462
|
+
/**
|
|
463
|
+
* Resolves the current provider-class scope for fiat quote widening. Defaults
|
|
464
|
+
* to `() => 'off'` (native-only) when no callback is injected.
|
|
465
|
+
*/
|
|
466
|
+
_RampsController_getProviderScope.set(this, void 0);
|
|
467
|
+
/**
|
|
468
|
+
* Resolves the default redirect URL for the widened in-app quote fetch when
|
|
469
|
+
* the caller omits `redirectUrl`. Defaults to `() => undefined` when no
|
|
470
|
+
* callback is injected.
|
|
471
|
+
*/
|
|
472
|
+
_RampsController_getDefaultRedirectUrl.set(this, void 0);
|
|
460
473
|
/**
|
|
461
474
|
* Map of pending requests for deduplication.
|
|
462
475
|
* Key is the cache key, value is the pending request with abort controller.
|
|
@@ -478,6 +491,8 @@ export class RampsController extends BaseController {
|
|
|
478
491
|
_RampsController_initPromise.set(this, null);
|
|
479
492
|
__classPrivateFieldSet(this, _RampsController_requestCacheTTL, requestCacheTTL, "f");
|
|
480
493
|
__classPrivateFieldSet(this, _RampsController_requestCacheMaxSize, requestCacheMaxSize, "f");
|
|
494
|
+
__classPrivateFieldSet(this, _RampsController_getProviderScope, getProviderScope ?? (() => 'off'), "f");
|
|
495
|
+
__classPrivateFieldSet(this, _RampsController_getDefaultRedirectUrl, getDefaultRedirectUrl ?? (() => undefined), "f");
|
|
481
496
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
482
497
|
}
|
|
483
498
|
/**
|
|
@@ -715,8 +730,10 @@ export class RampsController extends BaseController {
|
|
|
715
730
|
* This should be called once at app startup to set up the initial region.
|
|
716
731
|
*
|
|
717
732
|
* Idempotent: subsequent calls return the same promise unless forceRefresh is set.
|
|
718
|
-
*
|
|
719
|
-
*
|
|
733
|
+
* Force-refetches the countries catalog on startup (bypassing the in-session
|
|
734
|
+
* request cache) so region preset amounts stay current. The catalog is not
|
|
735
|
+
* persisted, so a cold start always re-fetches it regardless. Skips
|
|
736
|
+
* geolocation when userRegion already exists.
|
|
720
737
|
*
|
|
721
738
|
* @param options - Options for cache behavior. forceRefresh bypasses idempotency and re-runs the full flow.
|
|
722
739
|
* @returns Promise that resolves when initialization is complete.
|
|
@@ -753,6 +770,7 @@ export class RampsController extends BaseController {
|
|
|
753
770
|
this.update((state) => {
|
|
754
771
|
state.countries.data = Array.isArray(countries) ? [...countries] : [];
|
|
755
772
|
});
|
|
773
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncUserRegionFromCountriesCatalog).call(this);
|
|
756
774
|
return countries;
|
|
757
775
|
}
|
|
758
776
|
/**
|
|
@@ -989,7 +1007,19 @@ export class RampsController extends BaseController {
|
|
|
989
1007
|
if (normalizedAssetIdForValidation === '') {
|
|
990
1008
|
throw new Error('assetId is required.');
|
|
991
1009
|
}
|
|
1010
|
+
// When a non-`off` provider scope is active, widen the native-only
|
|
1011
|
+
// auto-selection path to every supporting provider and pick the best in-app
|
|
1012
|
+
// quote from the results (in-app vs external is only knowable per-quote via
|
|
1013
|
+
// `buyWidget.browser`). Only the auto-select/restrict path that MM Pay's
|
|
1014
|
+
// `getRampsQuote` uses is affected; explicit-`providers` callers and the
|
|
1015
|
+
// plain all-provider path are untouched.
|
|
1016
|
+
const providerScope = __classPrivateFieldGet(this, _RampsController_getProviderScope, "f").call(this);
|
|
1017
|
+
const widenToInAppProviders = providerScope !== 'off' &&
|
|
1018
|
+
!options.providers &&
|
|
1019
|
+
(options.autoSelectProvider === true ||
|
|
1020
|
+
options.restrictToKnownOrNativeProviders === true);
|
|
992
1021
|
let providersToUse;
|
|
1022
|
+
let inAppProviderCatalog = this.state.providers.data;
|
|
993
1023
|
if (options.providers) {
|
|
994
1024
|
providersToUse = options.restrictToKnownOrNativeProviders
|
|
995
1025
|
? await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_filterProviderIdsBySupport).call(this, {
|
|
@@ -999,6 +1029,17 @@ export class RampsController extends BaseController {
|
|
|
999
1029
|
})
|
|
1000
1030
|
: options.providers;
|
|
1001
1031
|
}
|
|
1032
|
+
else if (widenToInAppProviders) {
|
|
1033
|
+
// `#getSupportingProvidersForRegion` also hydrates the provider catalog
|
|
1034
|
+
// when controller state is empty, so all-provider quoting cannot silently
|
|
1035
|
+
// return zero providers here.
|
|
1036
|
+
const { supporting } = await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getSupportingProvidersForRegion).call(this, {
|
|
1037
|
+
assetId: normalizedAssetIdForValidation,
|
|
1038
|
+
region: regionToUse,
|
|
1039
|
+
});
|
|
1040
|
+
inAppProviderCatalog = supporting;
|
|
1041
|
+
providersToUse = supporting.map((provider) => provider.id);
|
|
1042
|
+
}
|
|
1002
1043
|
else if (options.autoSelectProvider ||
|
|
1003
1044
|
options.restrictToKnownOrNativeProviders) {
|
|
1004
1045
|
// The restriction flag implies resolution: it must narrow the provider
|
|
@@ -1028,8 +1069,12 @@ export class RampsController extends BaseController {
|
|
|
1028
1069
|
// Under headless-buy gating, an empty resolved provider list means no
|
|
1029
1070
|
// eligible (native/supporting) provider exists. Return an empty response
|
|
1030
1071
|
// rather than passing `[]` to the service, which omits the provider filter
|
|
1031
|
-
// and would quote every provider.
|
|
1032
|
-
|
|
1072
|
+
// and would quote every provider. This also guards the widened in-app path:
|
|
1073
|
+
// a caller may trigger widening with `autoSelectProvider` alone (no
|
|
1074
|
+
// `restrictToKnownOrNativeProviders`), and an empty supporting set must not
|
|
1075
|
+
// fall through to unfiltered quotes from providers that do not support the
|
|
1076
|
+
// asset.
|
|
1077
|
+
if ((options.restrictToKnownOrNativeProviders || widenToInAppProviders) &&
|
|
1033
1078
|
providersToUse.length === 0) {
|
|
1034
1079
|
return { success: [], sorted: [], error: [], customActions: [] };
|
|
1035
1080
|
}
|
|
@@ -1037,6 +1082,12 @@ export class RampsController extends BaseController {
|
|
|
1037
1082
|
const normalizedFiat = fiatToUse.toLowerCase().trim();
|
|
1038
1083
|
const normalizedAssetId = normalizedAssetIdForValidation;
|
|
1039
1084
|
const normalizedWalletAddress = options.walletAddress.trim();
|
|
1085
|
+
// The quotes API only embeds a `buyURL`/`buyWidget` when a `redirectUrl` is
|
|
1086
|
+
// present, so on the widened in-app path (where MM Pay omits one) supply the
|
|
1087
|
+
// injected default so aggregator quotes carry a usable widget URL. An
|
|
1088
|
+
// explicit caller `redirectUrl` always wins, and scope `off` never injects.
|
|
1089
|
+
const effectiveRedirectUrl = options.redirectUrl ??
|
|
1090
|
+
(widenToInAppProviders ? __classPrivateFieldGet(this, _RampsController_getDefaultRedirectUrl, "f").call(this) : undefined);
|
|
1040
1091
|
const cacheKey = createCacheKey('getQuotes', [
|
|
1041
1092
|
normalizedRegion,
|
|
1042
1093
|
normalizedFiat,
|
|
@@ -1045,7 +1096,7 @@ export class RampsController extends BaseController {
|
|
|
1045
1096
|
normalizedWalletAddress,
|
|
1046
1097
|
[...paymentMethodsToUse].sort().join(','),
|
|
1047
1098
|
[...providersToUse].sort().join(','),
|
|
1048
|
-
|
|
1099
|
+
effectiveRedirectUrl,
|
|
1049
1100
|
action,
|
|
1050
1101
|
]);
|
|
1051
1102
|
const params = {
|
|
@@ -1056,15 +1107,45 @@ export class RampsController extends BaseController {
|
|
|
1056
1107
|
walletAddress: normalizedWalletAddress,
|
|
1057
1108
|
paymentMethods: paymentMethodsToUse,
|
|
1058
1109
|
providers: providersToUse,
|
|
1059
|
-
redirectUrl:
|
|
1110
|
+
redirectUrl: effectiveRedirectUrl,
|
|
1060
1111
|
action,
|
|
1061
1112
|
};
|
|
1062
|
-
|
|
1113
|
+
const response = await this.executeRequest(cacheKey, async () => {
|
|
1063
1114
|
return this.messenger.call('RampsService:getQuotes', params);
|
|
1064
1115
|
}, {
|
|
1065
1116
|
forceRefresh: options.forceRefresh,
|
|
1066
1117
|
ttl: options.ttl ?? DEFAULT_QUOTES_TTL,
|
|
1067
1118
|
});
|
|
1119
|
+
if (!widenToInAppProviders) {
|
|
1120
|
+
return response;
|
|
1121
|
+
}
|
|
1122
|
+
// Reduce the widened multi-provider result to the single best in-app quote
|
|
1123
|
+
// and place it at `success[0]`, since single-pick consumers
|
|
1124
|
+
// (`getRampsQuote` -> `success?.[0]`) rely on index 0 while `success[]`
|
|
1125
|
+
// order is server-defined rather than ranked.
|
|
1126
|
+
const selectedQuote = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_pickInAppQuote).call(this, response, {
|
|
1127
|
+
scope: providerScope,
|
|
1128
|
+
amount: options.amount,
|
|
1129
|
+
fiat: normalizedFiat,
|
|
1130
|
+
providers: inAppProviderCatalog,
|
|
1131
|
+
});
|
|
1132
|
+
if (!selectedQuote) {
|
|
1133
|
+
// No usable in-app quote: surface "no quote" rather than leaking an
|
|
1134
|
+
// external/custom quote to the single-pick consumer.
|
|
1135
|
+
return {
|
|
1136
|
+
success: [],
|
|
1137
|
+
sorted: response.sorted,
|
|
1138
|
+
error: response.error,
|
|
1139
|
+
customActions: response.customActions,
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
return {
|
|
1143
|
+
...response,
|
|
1144
|
+
success: [
|
|
1145
|
+
selectedQuote,
|
|
1146
|
+
...response.success.filter((quote) => quote !== selectedQuote),
|
|
1147
|
+
],
|
|
1148
|
+
};
|
|
1068
1149
|
}
|
|
1069
1150
|
// === ORDER MANAGEMENT ===
|
|
1070
1151
|
/**
|
|
@@ -1163,7 +1244,7 @@ export class RampsController extends BaseController {
|
|
|
1163
1244
|
*
|
|
1164
1245
|
* @param params - Object containing order identifiers and wallet info.
|
|
1165
1246
|
* @param params.orderId - Full order ID (e.g. "/providers/paypal/orders/abc123") or order code.
|
|
1166
|
-
* @param params.providerCode -
|
|
1247
|
+
* @param params.providerCode - Canonical provider code (e.g. "paypal", "transak").
|
|
1167
1248
|
* @param params.walletAddress - Wallet address for the order.
|
|
1168
1249
|
* @param params.chainId - Optional chain ID for the order.
|
|
1169
1250
|
*/
|
|
@@ -1173,11 +1254,10 @@ export class RampsController extends BaseController {
|
|
|
1173
1254
|
if (!orderCode?.trim()) {
|
|
1174
1255
|
return;
|
|
1175
1256
|
}
|
|
1176
|
-
const normalizedProviderCode = normalizeProviderCode(providerCode);
|
|
1177
1257
|
const stubOrder = {
|
|
1178
1258
|
providerOrderId: orderCode,
|
|
1179
1259
|
provider: {
|
|
1180
|
-
id:
|
|
1260
|
+
id: providerCode,
|
|
1181
1261
|
name: '',
|
|
1182
1262
|
environmentType: '',
|
|
1183
1263
|
description: '',
|
|
@@ -1680,7 +1760,7 @@ export class RampsController extends BaseController {
|
|
|
1680
1760
|
}
|
|
1681
1761
|
}
|
|
1682
1762
|
}
|
|
1683
|
-
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_pendingResourceCount = new WeakMap(), _RampsController_pendingResourceGeneration = new WeakMap(), _RampsController_orderPollingMeta = new WeakMap(), _RampsController_orderPollingTimer = new WeakMap(), _RampsController_isPolling = new WeakMap(), _RampsController_initPromise = new WeakMap(), _RampsController_instances = new WeakSet(), _RampsController_clearPendingResourceCountForDependentResources = function _RampsController_clearPendingResourceCountForDependentResources() {
|
|
1763
|
+
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_getProviderScope = new WeakMap(), _RampsController_getDefaultRedirectUrl = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_pendingResourceCount = new WeakMap(), _RampsController_pendingResourceGeneration = new WeakMap(), _RampsController_orderPollingMeta = new WeakMap(), _RampsController_orderPollingTimer = new WeakMap(), _RampsController_isPolling = new WeakMap(), _RampsController_initPromise = new WeakMap(), _RampsController_instances = new WeakSet(), _RampsController_clearPendingResourceCountForDependentResources = function _RampsController_clearPendingResourceCountForDependentResources() {
|
|
1684
1764
|
for (const resourceType of DEPENDENT_RESOURCE_KEYS) {
|
|
1685
1765
|
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
1686
1766
|
const generation = __classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").get(resourceType) ?? 0;
|
|
@@ -1766,20 +1846,100 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1766
1846
|
}
|
|
1767
1847
|
});
|
|
1768
1848
|
}, _RampsController_runInit = async function _RampsController_runInit(options) {
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
}
|
|
1849
|
+
// Force-refetch the catalog on startup so region preset amounts stay
|
|
1850
|
+
// current, bypassing the in-session request cache. The catalog is not
|
|
1851
|
+
// persisted, so a cold start always re-fetches it regardless.
|
|
1852
|
+
await this.getCountries({ ...options, forceRefresh: true });
|
|
1774
1853
|
// Always prefer the user's persisted region. Geolocation is only used to
|
|
1775
1854
|
// seed the initial value; once the user (or a prior init) has set a region
|
|
1776
1855
|
// we must respect that choice — even on forceRefresh.
|
|
1777
|
-
|
|
1778
|
-
|
|
1856
|
+
const persistedRegionCode = this.state.userRegion?.regionCode;
|
|
1857
|
+
const regionCode = persistedRegionCode ??
|
|
1858
|
+
(await this.messenger.call('RampsService:getGeolocation'));
|
|
1779
1859
|
if (!regionCode) {
|
|
1780
1860
|
throw new Error('Failed to fetch geolocation. Cannot initialize controller without valid region information.');
|
|
1781
1861
|
}
|
|
1862
|
+
// For an already-persisted region, getCountries() has already re-synced it
|
|
1863
|
+
// from the fresh catalog (see #syncUserRegionFromCountriesCatalog). Calling
|
|
1864
|
+
// setUserRegion here would re-validate against that catalog and, if it is
|
|
1865
|
+
// momentarily empty or no longer lists the region (e.g. a transient/partial
|
|
1866
|
+
// catalog response or a region with no current provider coverage), throw and
|
|
1867
|
+
// wipe the persisted region via #cleanupState. Preserve the existing region
|
|
1868
|
+
// instead; only resolve a brand-new region (from geolocation) strictly.
|
|
1869
|
+
if (persistedRegionCode) {
|
|
1870
|
+
return;
|
|
1871
|
+
}
|
|
1782
1872
|
await this.setUserRegion(regionCode, options);
|
|
1873
|
+
}, _RampsController_syncUserRegionFromCountriesCatalog = function _RampsController_syncUserRegionFromCountriesCatalog() {
|
|
1874
|
+
const regionCode = this.state.userRegion?.regionCode;
|
|
1875
|
+
if (!regionCode) {
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1878
|
+
const countriesData = this.state.countries.data;
|
|
1879
|
+
if (!countriesData.length) {
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
const userRegion = findRegionFromCode(regionCode, countriesData);
|
|
1883
|
+
if (!userRegion) {
|
|
1884
|
+
return;
|
|
1885
|
+
}
|
|
1886
|
+
this.update((state) => {
|
|
1887
|
+
state.userRegion = userRegion;
|
|
1888
|
+
});
|
|
1889
|
+
}, _RampsController_pickInAppQuote = function _RampsController_pickInAppQuote(response, { scope, amount, fiat, providers, }) {
|
|
1890
|
+
const providerByCode = new Map(providers.map((provider) => [provider.id, provider]));
|
|
1891
|
+
const customActionProviderCodes = new Set(response.customActions.map((action) => action.buy.providerId));
|
|
1892
|
+
const fitsProviderLimits = (quote) => {
|
|
1893
|
+
const provider = providerByCode.get(quote.provider);
|
|
1894
|
+
const limit = provider?.limits?.fiat?.[fiat]?.[quote.quote.paymentMethod];
|
|
1895
|
+
if (!limit) {
|
|
1896
|
+
// No published limits for this provider/payment method: treat as
|
|
1897
|
+
// eligible and let the provider enforce limits at checkout.
|
|
1898
|
+
return true;
|
|
1899
|
+
}
|
|
1900
|
+
return amount >= limit.minAmount && amount <= limit.maxAmount;
|
|
1901
|
+
};
|
|
1902
|
+
const isEligible = (quote) => {
|
|
1903
|
+
// `all` (Phase 2) skips the in-app-only exclusions; both scopes still
|
|
1904
|
+
// enforce provider limits up front.
|
|
1905
|
+
if (scope !== 'all') {
|
|
1906
|
+
const providerCode = quote.provider;
|
|
1907
|
+
if (customActionProviderCodes.has(providerCode)) {
|
|
1908
|
+
return false;
|
|
1909
|
+
}
|
|
1910
|
+
// Defensive: the wire may carry an inline `isCustomAction` flag that is
|
|
1911
|
+
// absent from the published `Quote` type.
|
|
1912
|
+
if (quote.quote.isCustomAction === true) {
|
|
1913
|
+
return false;
|
|
1914
|
+
}
|
|
1915
|
+
if (quote.quote.buyWidget?.browser === 'IN_APP_OS_BROWSER') {
|
|
1916
|
+
return false;
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
return fitsProviderLimits(quote);
|
|
1920
|
+
};
|
|
1921
|
+
const candidates = response.success.filter(isEligible);
|
|
1922
|
+
if (candidates.length === 0) {
|
|
1923
|
+
return undefined;
|
|
1924
|
+
}
|
|
1925
|
+
const candidateByCode = new Map(candidates.map((quote) => [quote.provider, quote]));
|
|
1926
|
+
const pickBySortOrder = (sortBy) => {
|
|
1927
|
+
const order = response.sorted.find((entry) => entry.sortBy === sortBy)?.ids;
|
|
1928
|
+
if (!order) {
|
|
1929
|
+
return undefined;
|
|
1930
|
+
}
|
|
1931
|
+
for (const providerId of order) {
|
|
1932
|
+
const match = candidateByCode.get(providerId);
|
|
1933
|
+
if (match) {
|
|
1934
|
+
return match;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
return undefined;
|
|
1938
|
+
};
|
|
1939
|
+
// Reliability first, then price, then the first surviving candidate.
|
|
1940
|
+
return (pickBySortOrder('reliability') ??
|
|
1941
|
+
pickBySortOrder('price') ??
|
|
1942
|
+
candidates[0]);
|
|
1783
1943
|
}, _RampsController_getSupportingProvidersForRegion =
|
|
1784
1944
|
/**
|
|
1785
1945
|
* Returns the region's providers that support the given asset, plus the full
|