@metamask/ramps-controller 20.3.0 → 21.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 +17 -1
- package/dist/{NeoBankService-method-action-types.d.mts → NeoBankService-method-action-types.d.ts} +2 -2
- package/dist/NeoBankService-method-action-types.d.ts.map +1 -0
- package/dist/{NeoBankService-method-action-types.mjs → NeoBankService-method-action-types.js} +1 -1
- package/dist/NeoBankService-method-action-types.js.map +1 -0
- package/dist/{NeoBankService.d.cts → NeoBankService.d.ts} +8 -8
- package/dist/NeoBankService.d.ts.map +1 -0
- package/dist/NeoBankService.js +380 -0
- package/dist/NeoBankService.js.map +1 -0
- package/dist/{RampsController-method-action-types.d.mts → RampsController-method-action-types.d.ts} +2 -2
- package/dist/RampsController-method-action-types.d.ts.map +1 -0
- package/dist/{TransakService-method-action-types.mjs → RampsController-method-action-types.js} +1 -1
- package/dist/RampsController-method-action-types.js.map +1 -0
- package/dist/{RampsController.d.cts → RampsController.d.ts} +19 -19
- package/dist/RampsController.d.ts.map +1 -0
- package/dist/{RampsController.mjs → RampsController.js} +725 -613
- package/dist/RampsController.js.map +1 -0
- package/dist/{RampsService-method-action-types.d.cts → RampsService-method-action-types.d.ts} +2 -2
- package/dist/RampsService-method-action-types.d.ts.map +1 -0
- package/dist/{RampsService-method-action-types.mjs → RampsService-method-action-types.js} +1 -1
- package/dist/RampsService-method-action-types.js.map +1 -0
- package/dist/{RampsService.d.mts → RampsService.d.ts} +5 -5
- package/dist/RampsService.d.ts.map +1 -0
- package/dist/{RampsService.mjs → RampsService.js} +159 -147
- package/dist/RampsService.js.map +1 -0
- package/dist/{RequestCache.d.mts → RequestCache.d.ts} +3 -3
- package/dist/RequestCache.d.ts.map +1 -0
- package/dist/{RequestCache.mjs → RequestCache.js} +1 -1
- package/dist/RequestCache.js.map +1 -0
- package/dist/{TransakService-method-action-types.d.cts → TransakService-method-action-types.d.ts} +2 -2
- package/dist/TransakService-method-action-types.d.ts.map +1 -0
- package/dist/{RampsController-method-action-types.mjs → TransakService-method-action-types.js} +1 -1
- package/dist/TransakService-method-action-types.js.map +1 -0
- package/dist/{TransakService.d.cts → TransakService.d.ts} +6 -6
- package/dist/TransakService.d.ts.map +1 -0
- package/dist/TransakService.js +746 -0
- package/dist/TransakService.js.map +1 -0
- package/dist/{autoramp-types.d.cts → autoramp-types.d.ts} +1 -1
- package/dist/autoramp-types.d.ts.map +1 -0
- package/dist/autoramp-types.js +2 -0
- package/dist/autoramp-types.js.map +1 -0
- package/dist/{autorampAccount.d.mts → autorampAccount.d.ts} +3 -3
- package/dist/autorampAccount.d.ts.map +1 -0
- package/dist/{autorampAccount.mjs → autorampAccount.js} +1 -1
- package/dist/autorampAccount.js.map +1 -0
- package/dist/{client-identity.d.mts → client-identity.d.ts} +1 -1
- package/dist/client-identity.d.ts.map +1 -0
- package/dist/{client-identity.mjs → client-identity.js} +1 -1
- package/dist/client-identity.js.map +1 -0
- package/dist/{errorNormalization.d.mts → errorNormalization.d.ts} +1 -1
- package/dist/errorNormalization.d.ts.map +1 -0
- package/dist/{errorNormalization.mjs → errorNormalization.js} +1 -1
- package/dist/errorNormalization.js.map +1 -0
- package/dist/{featureFlags.d.mts → featureFlags.d.ts} +2 -2
- package/dist/featureFlags.d.ts.map +1 -0
- package/dist/{featureFlags.mjs → featureFlags.js} +1 -1
- package/dist/featureFlags.js.map +1 -0
- package/dist/{index.d.mts → index.d.ts} +35 -35
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/{orderStatus.d.mts → orderStatus.d.ts} +2 -2
- package/dist/orderStatus.d.ts.map +1 -0
- package/dist/{orderStatus.mjs → orderStatus.js} +2 -2
- package/dist/orderStatus.js.map +1 -0
- package/dist/{ownership-message.d.cts → ownership-message.d.ts} +1 -1
- package/dist/ownership-message.d.ts.map +1 -0
- package/dist/{ownership-message.mjs → ownership-message.js} +1 -1
- package/dist/ownership-message.js.map +1 -0
- package/dist/{paymentMethodMerge.d.cts → paymentMethodMerge.d.ts} +2 -2
- package/dist/paymentMethodMerge.d.ts.map +1 -0
- package/dist/{paymentMethodMerge.mjs → paymentMethodMerge.js} +1 -1
- package/dist/paymentMethodMerge.js.map +1 -0
- package/dist/{providerAvailability.d.cts → providerAvailability.d.ts} +2 -2
- package/dist/providerAvailability.d.ts.map +1 -0
- package/dist/{providerAvailability.mjs → providerAvailability.js} +1 -1
- package/dist/providerAvailability.js.map +1 -0
- package/dist/{quoteClassification.d.cts → quoteClassification.d.ts} +2 -2
- package/dist/quoteClassification.d.ts.map +1 -0
- package/dist/{quoteClassification.mjs → quoteClassification.js} +1 -1
- package/dist/quoteClassification.js.map +1 -0
- package/dist/{rampsErrorCodes.d.cts → rampsErrorCodes.d.ts} +2 -2
- package/dist/rampsErrorCodes.d.ts.map +1 -0
- package/dist/{rampsErrorCodes.mjs → rampsErrorCodes.js} +1 -1
- package/dist/rampsErrorCodes.js.map +1 -0
- package/dist/{selectors.d.mts → selectors.d.ts} +3 -3
- package/dist/selectors.d.ts.map +1 -0
- package/dist/{selectors.mjs → selectors.js} +2 -2
- package/dist/selectors.js.map +1 -0
- package/dist/{transakApiErrorUtils.d.cts → transakApiErrorUtils.d.ts} +1 -1
- package/dist/transakApiErrorUtils.d.ts.map +1 -0
- package/dist/{transakApiErrorUtils.mjs → transakApiErrorUtils.js} +3 -3
- package/dist/transakApiErrorUtils.js.map +1 -0
- package/dist/{transakErrorCodes.d.cts → transakErrorCodes.d.ts} +3 -3
- package/dist/transakErrorCodes.d.ts.map +1 -0
- package/dist/{transakErrorCodes.mjs → transakErrorCodes.js} +1 -1
- package/dist/transakErrorCodes.js.map +1 -0
- package/dist/{wallet-registration-machine.d.cts → wallet-registration-machine.d.ts} +1 -1
- package/dist/wallet-registration-machine.d.ts.map +1 -0
- package/dist/{wallet-registration-machine.mjs → wallet-registration-machine.js} +1 -1
- package/dist/wallet-registration-machine.js.map +1 -0
- package/dist/{wallet-registration-service.d.cts → wallet-registration-service.d.ts} +1 -1
- package/dist/wallet-registration-service.d.ts.map +1 -0
- package/dist/{wallet-registration-service.mjs → wallet-registration-service.js} +60 -69
- package/dist/wallet-registration-service.js.map +1 -0
- package/package.json +17 -21
- package/dist/NeoBankService-method-action-types.cjs +0 -7
- package/dist/NeoBankService-method-action-types.cjs.map +0 -1
- package/dist/NeoBankService-method-action-types.d.cts +0 -126
- package/dist/NeoBankService-method-action-types.d.cts.map +0 -1
- package/dist/NeoBankService-method-action-types.d.mts.map +0 -1
- package/dist/NeoBankService-method-action-types.mjs.map +0 -1
- package/dist/NeoBankService.cjs +0 -387
- package/dist/NeoBankService.cjs.map +0 -1
- package/dist/NeoBankService.d.cts.map +0 -1
- package/dist/NeoBankService.d.mts +0 -191
- package/dist/NeoBankService.d.mts.map +0 -1
- package/dist/NeoBankService.mjs +0 -379
- package/dist/NeoBankService.mjs.map +0 -1
- package/dist/RampsController-method-action-types.cjs +0 -7
- package/dist/RampsController-method-action-types.cjs.map +0 -1
- package/dist/RampsController-method-action-types.d.cts +0 -758
- package/dist/RampsController-method-action-types.d.cts.map +0 -1
- package/dist/RampsController-method-action-types.d.mts.map +0 -1
- package/dist/RampsController-method-action-types.mjs.map +0 -1
- package/dist/RampsController.cjs +0 -2799
- package/dist/RampsController.cjs.map +0 -1
- package/dist/RampsController.d.cts.map +0 -1
- package/dist/RampsController.d.mts +0 -968
- package/dist/RampsController.d.mts.map +0 -1
- package/dist/RampsController.mjs.map +0 -1
- package/dist/RampsService-method-action-types.cjs +0 -7
- package/dist/RampsService-method-action-types.cjs.map +0 -1
- package/dist/RampsService-method-action-types.d.cts.map +0 -1
- package/dist/RampsService-method-action-types.d.mts +0 -171
- package/dist/RampsService-method-action-types.d.mts.map +0 -1
- package/dist/RampsService-method-action-types.mjs.map +0 -1
- package/dist/RampsService.cjs +0 -708
- package/dist/RampsService.cjs.map +0 -1
- package/dist/RampsService.d.cts +0 -944
- package/dist/RampsService.d.cts.map +0 -1
- package/dist/RampsService.d.mts.map +0 -1
- package/dist/RampsService.mjs.map +0 -1
- package/dist/RequestCache.cjs +0 -103
- package/dist/RequestCache.cjs.map +0 -1
- package/dist/RequestCache.d.cts +0 -110
- package/dist/RequestCache.d.cts.map +0 -1
- package/dist/RequestCache.d.mts.map +0 -1
- package/dist/RequestCache.mjs.map +0 -1
- package/dist/TransakService-method-action-types.cjs +0 -7
- package/dist/TransakService-method-action-types.cjs.map +0 -1
- package/dist/TransakService-method-action-types.d.cts.map +0 -1
- package/dist/TransakService-method-action-types.d.mts +0 -140
- package/dist/TransakService-method-action-types.d.mts.map +0 -1
- package/dist/TransakService-method-action-types.mjs.map +0 -1
- package/dist/TransakService.cjs +0 -743
- package/dist/TransakService.cjs.map +0 -1
- package/dist/TransakService.d.cts.map +0 -1
- package/dist/TransakService.d.mts +0 -370
- package/dist/TransakService.d.mts.map +0 -1
- package/dist/TransakService.mjs +0 -734
- package/dist/TransakService.mjs.map +0 -1
- package/dist/autoramp-types.cjs +0 -3
- package/dist/autoramp-types.cjs.map +0 -1
- package/dist/autoramp-types.d.cts.map +0 -1
- package/dist/autoramp-types.d.mts +0 -22
- package/dist/autoramp-types.d.mts.map +0 -1
- package/dist/autoramp-types.mjs +0 -2
- package/dist/autoramp-types.mjs.map +0 -1
- package/dist/autorampAccount.cjs +0 -155
- package/dist/autorampAccount.cjs.map +0 -1
- package/dist/autorampAccount.d.cts +0 -126
- package/dist/autorampAccount.d.cts.map +0 -1
- package/dist/autorampAccount.d.mts.map +0 -1
- package/dist/autorampAccount.mjs.map +0 -1
- package/dist/client-identity.cjs +0 -28
- package/dist/client-identity.cjs.map +0 -1
- package/dist/client-identity.d.cts +0 -24
- package/dist/client-identity.d.cts.map +0 -1
- package/dist/client-identity.d.mts.map +0 -1
- package/dist/client-identity.mjs.map +0 -1
- package/dist/errorNormalization.cjs +0 -84
- package/dist/errorNormalization.cjs.map +0 -1
- package/dist/errorNormalization.d.cts +0 -56
- package/dist/errorNormalization.d.cts.map +0 -1
- package/dist/errorNormalization.d.mts.map +0 -1
- package/dist/errorNormalization.mjs.map +0 -1
- package/dist/featureFlags.cjs +0 -144
- package/dist/featureFlags.cjs.map +0 -1
- package/dist/featureFlags.d.cts +0 -82
- package/dist/featureFlags.d.cts.map +0 -1
- package/dist/featureFlags.d.mts.map +0 -1
- package/dist/featureFlags.mjs.map +0 -1
- package/dist/index.cjs +0 -82
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -35
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -18
- package/dist/index.mjs.map +0 -1
- package/dist/orderStatus.cjs +0 -34
- package/dist/orderStatus.cjs.map +0 -1
- package/dist/orderStatus.d.cts +0 -18
- package/dist/orderStatus.d.cts.map +0 -1
- package/dist/orderStatus.d.mts.map +0 -1
- package/dist/orderStatus.mjs.map +0 -1
- package/dist/ownership-message.cjs +0 -26
- package/dist/ownership-message.cjs.map +0 -1
- package/dist/ownership-message.d.cts.map +0 -1
- package/dist/ownership-message.d.mts +0 -22
- package/dist/ownership-message.d.mts.map +0 -1
- package/dist/ownership-message.mjs.map +0 -1
- package/dist/paymentMethodMerge.cjs +0 -51
- package/dist/paymentMethodMerge.cjs.map +0 -1
- package/dist/paymentMethodMerge.d.cts.map +0 -1
- package/dist/paymentMethodMerge.d.mts +0 -26
- package/dist/paymentMethodMerge.d.mts.map +0 -1
- package/dist/paymentMethodMerge.mjs.map +0 -1
- package/dist/providerAvailability.cjs +0 -134
- package/dist/providerAvailability.cjs.map +0 -1
- package/dist/providerAvailability.d.cts.map +0 -1
- package/dist/providerAvailability.d.mts +0 -101
- package/dist/providerAvailability.d.mts.map +0 -1
- package/dist/providerAvailability.mjs.map +0 -1
- package/dist/quoteClassification.cjs +0 -44
- package/dist/quoteClassification.cjs.map +0 -1
- package/dist/quoteClassification.d.cts.map +0 -1
- package/dist/quoteClassification.d.mts +0 -33
- package/dist/quoteClassification.d.mts.map +0 -1
- package/dist/quoteClassification.mjs.map +0 -1
- package/dist/rampsErrorCodes.cjs +0 -11
- package/dist/rampsErrorCodes.cjs.map +0 -1
- package/dist/rampsErrorCodes.d.cts.map +0 -1
- package/dist/rampsErrorCodes.d.mts +0 -9
- package/dist/rampsErrorCodes.d.mts.map +0 -1
- package/dist/rampsErrorCodes.mjs.map +0 -1
- package/dist/selectors.cjs +0 -85
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -78
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs.map +0 -1
- package/dist/transakApiErrorUtils.cjs +0 -15
- package/dist/transakApiErrorUtils.cjs.map +0 -1
- package/dist/transakApiErrorUtils.d.cts.map +0 -1
- package/dist/transakApiErrorUtils.d.mts +0 -3
- package/dist/transakApiErrorUtils.d.mts.map +0 -1
- package/dist/transakApiErrorUtils.mjs.map +0 -1
- package/dist/transakErrorCodes.cjs +0 -14
- package/dist/transakErrorCodes.cjs.map +0 -1
- package/dist/transakErrorCodes.d.cts.map +0 -1
- package/dist/transakErrorCodes.d.mts +0 -12
- package/dist/transakErrorCodes.d.mts.map +0 -1
- package/dist/transakErrorCodes.mjs.map +0 -1
- package/dist/wallet-registration-machine.cjs +0 -144
- package/dist/wallet-registration-machine.cjs.map +0 -1
- package/dist/wallet-registration-machine.d.cts.map +0 -1
- package/dist/wallet-registration-machine.d.mts +0 -81
- package/dist/wallet-registration-machine.d.mts.map +0 -1
- package/dist/wallet-registration-machine.mjs.map +0 -1
- package/dist/wallet-registration-service.cjs +0 -351
- package/dist/wallet-registration-service.cjs.map +0 -1
- package/dist/wallet-registration-service.d.cts.map +0 -1
- package/dist/wallet-registration-service.d.mts +0 -144
- package/dist/wallet-registration-service.d.mts.map +0 -1
- package/dist/wallet-registration-service.mjs.map +0 -1
package/dist/RampsController.cjs
DELETED
|
@@ -1,2799 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
-
};
|
|
13
|
-
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_pendingResourceGeneration, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_initPromise, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_resolveAllProvidersFlag, _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_pickWidenedQuote, _RampsController_getSupportingProvidersForRegion, _RampsController_filterProviderIdsBySupport, _RampsController_resolveProviderIdsForQuote, _RampsController_resolveProviderIdsForPaymentMethods, _RampsController_getPreferredProviderIdsFromOrders, _RampsController_applyAutorampRemoteSnapshot, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError, _RampsController_getNormalizedTransakError;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.RampsController = exports.getInternalOrderCode = exports.getDefaultRampsControllerState = exports.RAMPS_CONTROLLER_REQUIRED_CONTROLLER_ACTIONS = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.controllerName = void 0;
|
|
16
|
-
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
18
|
-
const autorampAccount_js_1 = require("./autorampAccount.cjs");
|
|
19
|
-
const featureFlags_js_1 = require("./featureFlags.cjs");
|
|
20
|
-
const orderStatus_js_1 = require("./orderStatus.cjs");
|
|
21
|
-
const ownership_message_js_1 = require("./ownership-message.cjs");
|
|
22
|
-
const paymentMethodMerge_js_1 = require("./paymentMethodMerge.cjs");
|
|
23
|
-
const providerAvailability_js_1 = require("./providerAvailability.cjs");
|
|
24
|
-
const rampsErrorCodes_js_1 = require("./rampsErrorCodes.cjs");
|
|
25
|
-
const RampsService_js_1 = require("./RampsService.cjs");
|
|
26
|
-
const RequestCache_js_1 = require("./RequestCache.cjs");
|
|
27
|
-
const wallet_registration_machine_js_1 = require("./wallet-registration-machine.cjs");
|
|
28
|
-
const wallet_registration_service_js_1 = require("./wallet-registration-service.cjs");
|
|
29
|
-
// === GENERAL ===
|
|
30
|
-
/**
|
|
31
|
-
* The name of the {@link RampsController}, used to namespace the
|
|
32
|
-
* controller's actions and events and to namespace the controller's state data
|
|
33
|
-
* when composed with other controllers.
|
|
34
|
-
*/
|
|
35
|
-
exports.controllerName = 'RampsController';
|
|
36
|
-
/**
|
|
37
|
-
* RampsService action types that RampsController calls via the messenger.
|
|
38
|
-
* Any host (e.g. mobile) that creates a RampsController messenger must delegate
|
|
39
|
-
* these actions from the root messenger so the controller can function.
|
|
40
|
-
*/
|
|
41
|
-
exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = [
|
|
42
|
-
'RampsService:getDefaultRedirectCallbackUrl',
|
|
43
|
-
'RampsService:getGeolocation',
|
|
44
|
-
'RampsService:getCountries',
|
|
45
|
-
'RampsService:getTokens',
|
|
46
|
-
'RampsService:getProviders',
|
|
47
|
-
'RampsService:getPaymentMethods',
|
|
48
|
-
'RampsService:getQuotes',
|
|
49
|
-
'RampsService:getBuyWidgetUrl',
|
|
50
|
-
'RampsService:getOrder',
|
|
51
|
-
'RampsService:getOrderFromCallback',
|
|
52
|
-
'TransakService:setApiKey',
|
|
53
|
-
'TransakService:setAccessToken',
|
|
54
|
-
'TransakService:clearAccessToken',
|
|
55
|
-
'TransakService:sendUserOtp',
|
|
56
|
-
'TransakService:verifyUserOtp',
|
|
57
|
-
'TransakService:logout',
|
|
58
|
-
'TransakService:getUserDetails',
|
|
59
|
-
'TransakService:getBuyQuote',
|
|
60
|
-
'TransakService:getKycRequirement',
|
|
61
|
-
'TransakService:getAdditionalRequirements',
|
|
62
|
-
'TransakService:createOrder',
|
|
63
|
-
'TransakService:getOrder',
|
|
64
|
-
'TransakService:getUserLimits',
|
|
65
|
-
'TransakService:requestOtt',
|
|
66
|
-
'TransakService:generatePaymentWidgetUrl',
|
|
67
|
-
'TransakService:createWidgetUrl',
|
|
68
|
-
'TransakService:submitPurposeOfUsageForm',
|
|
69
|
-
'TransakService:patchUser',
|
|
70
|
-
'TransakService:submitSsnDetails',
|
|
71
|
-
'TransakService:confirmPayment',
|
|
72
|
-
'TransakService:getTranslation',
|
|
73
|
-
'TransakService:getIdProofStatus',
|
|
74
|
-
'TransakService:cancelOrder',
|
|
75
|
-
'TransakService:cancelAllActiveOrders',
|
|
76
|
-
'TransakService:getActiveOrders',
|
|
77
|
-
'NeoBankService:getAutoramp',
|
|
78
|
-
'NeoBankService:createAutoramp',
|
|
79
|
-
'NeoBankService:getCustomerByExternalId',
|
|
80
|
-
'NeoBankService:getWalletRegistrationStatus',
|
|
81
|
-
'NeoBankService:registerSelfHostedWallet',
|
|
82
|
-
];
|
|
83
|
-
/**
|
|
84
|
-
* Every external controller action RampsController calls via the messenger,
|
|
85
|
-
* which hosts must delegate from the root messenger.
|
|
86
|
-
* `AuthenticationController:getSessionProfile` resolves the vendor customer
|
|
87
|
-
* identity from Profile Sync, and `KeyringController:signPersonalMessage` signs
|
|
88
|
-
* the EIP-191 ownership proof for Money Account self-hosted wallet
|
|
89
|
-
* registration; both are only exercised by the autoramp paths.
|
|
90
|
-
*/
|
|
91
|
-
exports.RAMPS_CONTROLLER_REQUIRED_CONTROLLER_ACTIONS = [
|
|
92
|
-
'AuthenticationController:getSessionProfile',
|
|
93
|
-
'KeyringController:signPersonalMessage',
|
|
94
|
-
'RemoteFeatureFlagController:getState',
|
|
95
|
-
];
|
|
96
|
-
/**
|
|
97
|
-
* Distinguishes an already-materialized {@link AutorampAccount} from the
|
|
98
|
-
* create-fields shape accepted by {@link RampsController.addAutoramp}.
|
|
99
|
-
*
|
|
100
|
-
* @param value - Full account or create fields.
|
|
101
|
-
* @returns Whether the value already carries the derived account fields.
|
|
102
|
-
*/
|
|
103
|
-
function isFullAutorampAccount(value) {
|
|
104
|
-
return (typeof value.updatedAt === 'number' &&
|
|
105
|
-
value.lastSeenStatus !== undefined);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Default TTL for quotes requests (15 seconds).
|
|
109
|
-
* Quotes are time-sensitive and should have a shorter cache duration.
|
|
110
|
-
*/
|
|
111
|
-
const DEFAULT_QUOTES_TTL = 15000;
|
|
112
|
-
const CIRCUIT_BREAKER_OPEN_ERROR = 'Execution prevented because the circuit breaker is open';
|
|
113
|
-
function hasStringMessage(error) {
|
|
114
|
-
return (typeof error === 'object' &&
|
|
115
|
-
error !== null &&
|
|
116
|
-
typeof error.message === 'string');
|
|
117
|
-
}
|
|
118
|
-
function hasHttpStatus(error) {
|
|
119
|
-
return (error instanceof Error &&
|
|
120
|
-
typeof error.httpStatus === 'number');
|
|
121
|
-
}
|
|
122
|
-
function getRampsErrorInfo(error) {
|
|
123
|
-
if (error instanceof controller_utils_1.BrokenCircuitError && hasStringMessage(error)) {
|
|
124
|
-
return {
|
|
125
|
-
errorKey: rampsErrorCodes_js_1.RAMPS_ERROR_CODES.CIRCUIT_BREAKER_OPEN,
|
|
126
|
-
message: error.message,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
let rawMessage;
|
|
130
|
-
if (hasStringMessage(error)) {
|
|
131
|
-
rawMessage = error.message;
|
|
132
|
-
}
|
|
133
|
-
else if (typeof error === 'string') {
|
|
134
|
-
rawMessage = error;
|
|
135
|
-
}
|
|
136
|
-
if (rawMessage?.includes(CIRCUIT_BREAKER_OPEN_ERROR)) {
|
|
137
|
-
return {
|
|
138
|
-
errorKey: rampsErrorCodes_js_1.RAMPS_ERROR_CODES.CIRCUIT_BREAKER_OPEN,
|
|
139
|
-
message: rawMessage,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
errorKey: null,
|
|
144
|
-
message: rawMessage ?? 'Unknown error',
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function getNormalizedRampsError(error) {
|
|
148
|
-
const errorInfo = getRampsErrorInfo(error);
|
|
149
|
-
return {
|
|
150
|
-
errorInfo,
|
|
151
|
-
normalizedError: normalizeRampsErrorForRethrow(error, errorInfo),
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function normalizeRampsErrorForRethrow(error, errorInfo) {
|
|
155
|
-
if (!errorInfo.errorKey) {
|
|
156
|
-
return error;
|
|
157
|
-
}
|
|
158
|
-
if (error instanceof Error) {
|
|
159
|
-
error.errorKey = errorInfo.errorKey;
|
|
160
|
-
return error;
|
|
161
|
-
}
|
|
162
|
-
return Object.assign(new Error(errorInfo.message), {
|
|
163
|
-
errorKey: errorInfo.errorKey,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* The metadata for each property in {@link RampsControllerState}.
|
|
168
|
-
*/
|
|
169
|
-
const rampsControllerMetadata = {
|
|
170
|
-
userRegion: {
|
|
171
|
-
persist: true,
|
|
172
|
-
includeInDebugSnapshot: true,
|
|
173
|
-
includeInStateLogs: true,
|
|
174
|
-
usedInUi: true,
|
|
175
|
-
},
|
|
176
|
-
countries: {
|
|
177
|
-
persist: false,
|
|
178
|
-
includeInDebugSnapshot: true,
|
|
179
|
-
includeInStateLogs: true,
|
|
180
|
-
usedInUi: true,
|
|
181
|
-
},
|
|
182
|
-
providers: {
|
|
183
|
-
persist: false,
|
|
184
|
-
includeInDebugSnapshot: true,
|
|
185
|
-
includeInStateLogs: true,
|
|
186
|
-
usedInUi: true,
|
|
187
|
-
},
|
|
188
|
-
tokens: {
|
|
189
|
-
persist: false,
|
|
190
|
-
includeInDebugSnapshot: true,
|
|
191
|
-
includeInStateLogs: true,
|
|
192
|
-
usedInUi: true,
|
|
193
|
-
},
|
|
194
|
-
paymentMethods: {
|
|
195
|
-
persist: false,
|
|
196
|
-
includeInDebugSnapshot: true,
|
|
197
|
-
includeInStateLogs: true,
|
|
198
|
-
usedInUi: true,
|
|
199
|
-
},
|
|
200
|
-
requests: {
|
|
201
|
-
persist: false,
|
|
202
|
-
includeInDebugSnapshot: true,
|
|
203
|
-
includeInStateLogs: false,
|
|
204
|
-
usedInUi: true,
|
|
205
|
-
},
|
|
206
|
-
nativeProviders: {
|
|
207
|
-
persist: false,
|
|
208
|
-
includeInDebugSnapshot: true,
|
|
209
|
-
includeInStateLogs: false,
|
|
210
|
-
usedInUi: true,
|
|
211
|
-
},
|
|
212
|
-
orders: {
|
|
213
|
-
persist: true,
|
|
214
|
-
includeInDebugSnapshot: true,
|
|
215
|
-
includeInStateLogs: true,
|
|
216
|
-
usedInUi: true,
|
|
217
|
-
},
|
|
218
|
-
autoramps: {
|
|
219
|
-
persist: true,
|
|
220
|
-
includeInDebugSnapshot: true,
|
|
221
|
-
includeInStateLogs: true,
|
|
222
|
-
usedInUi: true,
|
|
223
|
-
},
|
|
224
|
-
providerAutoSelected: {
|
|
225
|
-
persist: true,
|
|
226
|
-
includeInDebugSnapshot: true,
|
|
227
|
-
includeInStateLogs: true,
|
|
228
|
-
usedInUi: true,
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Creates a default resource state object.
|
|
233
|
-
*
|
|
234
|
-
* @template TData - The type of the resource data.
|
|
235
|
-
* @template TSelected - The type of the selected item.
|
|
236
|
-
* @param data - The initial data value.
|
|
237
|
-
* @param selected - The initial selected value.
|
|
238
|
-
* @returns A ResourceState object with default loading and error values.
|
|
239
|
-
*/
|
|
240
|
-
function createDefaultResourceState(data, selected = null) {
|
|
241
|
-
return {
|
|
242
|
-
data,
|
|
243
|
-
selected,
|
|
244
|
-
isLoading: false,
|
|
245
|
-
error: null,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Constructs the default {@link RampsController} state. This allows
|
|
250
|
-
* consumers to provide a partial state object when initializing the controller
|
|
251
|
-
* and also helps in constructing complete state objects for this controller in
|
|
252
|
-
* tests.
|
|
253
|
-
*
|
|
254
|
-
* @returns The default {@link RampsController} state.
|
|
255
|
-
*/
|
|
256
|
-
function getDefaultRampsControllerState() {
|
|
257
|
-
return {
|
|
258
|
-
userRegion: null,
|
|
259
|
-
countries: createDefaultResourceState([]),
|
|
260
|
-
providers: createDefaultResourceState([], null),
|
|
261
|
-
tokens: createDefaultResourceState(null, null),
|
|
262
|
-
paymentMethods: createDefaultResourceState([], null),
|
|
263
|
-
requests: {},
|
|
264
|
-
nativeProviders: {
|
|
265
|
-
transak: {
|
|
266
|
-
isAuthenticated: false,
|
|
267
|
-
userDetails: createDefaultResourceState(null),
|
|
268
|
-
buyQuote: createDefaultResourceState(null),
|
|
269
|
-
kycRequirement: createDefaultResourceState(null),
|
|
270
|
-
},
|
|
271
|
-
},
|
|
272
|
-
orders: [],
|
|
273
|
-
autoramps: [],
|
|
274
|
-
providerAutoSelected: false,
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
exports.getDefaultRampsControllerState = getDefaultRampsControllerState;
|
|
278
|
-
const DEPENDENT_RESOURCE_KEYS = [
|
|
279
|
-
'providers',
|
|
280
|
-
'tokens',
|
|
281
|
-
'paymentMethods',
|
|
282
|
-
];
|
|
283
|
-
const DEPENDENT_RESOURCE_KEYS_SET = new Set(DEPENDENT_RESOURCE_KEYS);
|
|
284
|
-
function getResourceState(state, resourceType) {
|
|
285
|
-
switch (resourceType) {
|
|
286
|
-
case 'countries':
|
|
287
|
-
return state.countries;
|
|
288
|
-
case 'providers':
|
|
289
|
-
return state.providers;
|
|
290
|
-
case 'tokens':
|
|
291
|
-
return state.tokens;
|
|
292
|
-
case 'paymentMethods':
|
|
293
|
-
return state.paymentMethods;
|
|
294
|
-
/* istanbul ignore next -- ResourceType is a closed internal union. */
|
|
295
|
-
default:
|
|
296
|
-
throw new Error(`Unsupported resource type: ${resourceType}`);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
function resetResource(state, resourceType, defaultResource) {
|
|
300
|
-
const resource = getResourceState(state, resourceType);
|
|
301
|
-
resource.data = defaultResource.data;
|
|
302
|
-
resource.selected = defaultResource.selected;
|
|
303
|
-
resource.isLoading = defaultResource.isLoading;
|
|
304
|
-
resource.error = defaultResource.error;
|
|
305
|
-
resource.errorKey = defaultResource.errorKey ?? null;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Resets region-dependent resources (userRegion, providers, tokens, paymentMethods).
|
|
309
|
-
* Mutates state in place; use from within controller update() for atomic updates.
|
|
310
|
-
*
|
|
311
|
-
* @param state - The state object to mutate.
|
|
312
|
-
* @param options - Options for the reset.
|
|
313
|
-
* @param options.clearUserRegionData - When true, sets userRegion to null (e.g. for full cleanup).
|
|
314
|
-
*/
|
|
315
|
-
function resetDependentResources(state, options) {
|
|
316
|
-
if (options?.clearUserRegionData) {
|
|
317
|
-
state.userRegion = null;
|
|
318
|
-
}
|
|
319
|
-
const defaultState = getDefaultRampsControllerState();
|
|
320
|
-
for (const key of DEPENDENT_RESOURCE_KEYS) {
|
|
321
|
-
resetResource(state, key, defaultState[key]);
|
|
322
|
-
}
|
|
323
|
-
state.providerAutoSelected = false;
|
|
324
|
-
}
|
|
325
|
-
// === HELPER FUNCTIONS ===
|
|
326
|
-
/**
|
|
327
|
-
* Finds a country and state from a region code string.
|
|
328
|
-
*
|
|
329
|
-
* @param regionCode - The region code (e.g., "us-ca" or "us").
|
|
330
|
-
* @param countries - Array of countries to search.
|
|
331
|
-
* @returns UserRegion object with country and state, or null if not found.
|
|
332
|
-
*/
|
|
333
|
-
function findRegionFromCode(regionCode, countries) {
|
|
334
|
-
const normalizedCode = regionCode.toLowerCase().trim();
|
|
335
|
-
const parts = normalizedCode.split('-');
|
|
336
|
-
const countryCode = parts[0];
|
|
337
|
-
const stateCode = parts[1];
|
|
338
|
-
const country = countries.find((countryItem) => {
|
|
339
|
-
if (countryItem.isoCode?.toLowerCase() === countryCode) {
|
|
340
|
-
return true;
|
|
341
|
-
}
|
|
342
|
-
if (countryItem.id) {
|
|
343
|
-
const id = countryItem.id.toLowerCase();
|
|
344
|
-
if (id.startsWith('/regions/')) {
|
|
345
|
-
const extractedCode = id.replace('/regions/', '').split('/')[0];
|
|
346
|
-
return extractedCode === countryCode;
|
|
347
|
-
}
|
|
348
|
-
return id === countryCode || id.endsWith(`/${countryCode}`);
|
|
349
|
-
}
|
|
350
|
-
return false;
|
|
351
|
-
});
|
|
352
|
-
if (!country) {
|
|
353
|
-
return null;
|
|
354
|
-
}
|
|
355
|
-
let state = null;
|
|
356
|
-
if (stateCode && country.states) {
|
|
357
|
-
state =
|
|
358
|
-
country.states.find((stateItem) => {
|
|
359
|
-
if (stateItem.stateId?.toLowerCase() === stateCode) {
|
|
360
|
-
return true;
|
|
361
|
-
}
|
|
362
|
-
if (stateItem.id) {
|
|
363
|
-
const stateId = stateItem.id.toLowerCase();
|
|
364
|
-
if (stateId.includes(`-${stateCode}`) ||
|
|
365
|
-
stateId.endsWith(`/${stateCode}`)) {
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return false;
|
|
370
|
-
}) ?? null;
|
|
371
|
-
}
|
|
372
|
-
return {
|
|
373
|
-
country,
|
|
374
|
-
state,
|
|
375
|
-
regionCode: normalizedCode,
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Returns the internal MetaMask order code used for state lookups and polling.
|
|
380
|
-
* Prefers the code embedded in the canonical order `id` path over `providerOrderId`,
|
|
381
|
-
* which may contain the provider's native order identifier.
|
|
382
|
-
*
|
|
383
|
-
* @param orderOrId - Order fields or a full order id / order code string.
|
|
384
|
-
* @returns The internal order code.
|
|
385
|
-
*/
|
|
386
|
-
function getInternalOrderCode(orderOrId) {
|
|
387
|
-
if (typeof orderOrId === 'string') {
|
|
388
|
-
return orderOrId.includes('/orders/')
|
|
389
|
-
? orderOrId.split('/orders/')[1]
|
|
390
|
-
: orderOrId;
|
|
391
|
-
}
|
|
392
|
-
const { id, providerOrderId } = orderOrId;
|
|
393
|
-
if (id?.includes('/orders/')) {
|
|
394
|
-
return id.split('/orders/')[1];
|
|
395
|
-
}
|
|
396
|
-
return providerOrderId;
|
|
397
|
-
}
|
|
398
|
-
exports.getInternalOrderCode = getInternalOrderCode;
|
|
399
|
-
// === ORDER POLLING CONSTANTS ===
|
|
400
|
-
const DEFAULT_POLLING_INTERVAL_MS = 30000;
|
|
401
|
-
const MAX_ERROR_COUNT = 5;
|
|
402
|
-
// === CONTROLLER DEFINITION ===
|
|
403
|
-
const MESSENGER_EXPOSED_METHODS = [
|
|
404
|
-
'executeRequest',
|
|
405
|
-
'abortRequest',
|
|
406
|
-
'getRequestState',
|
|
407
|
-
'setUserRegion',
|
|
408
|
-
'setSelectedProvider',
|
|
409
|
-
'setSelectedProviderForAsset',
|
|
410
|
-
'init',
|
|
411
|
-
'getCountries',
|
|
412
|
-
'getTokens',
|
|
413
|
-
'setSelectedToken',
|
|
414
|
-
'getProviders',
|
|
415
|
-
'getPaymentMethods',
|
|
416
|
-
'getPaymentMethodsForContext',
|
|
417
|
-
'setSelectedPaymentMethod',
|
|
418
|
-
'getQuotes',
|
|
419
|
-
'addOrder',
|
|
420
|
-
'removeOrder',
|
|
421
|
-
'addAutoramp',
|
|
422
|
-
'createAutoramp',
|
|
423
|
-
'removeAutoramp',
|
|
424
|
-
'registerMoneyAccountWallet',
|
|
425
|
-
'markAutorampAsNotified',
|
|
426
|
-
'applyAutorampStatusFromPush',
|
|
427
|
-
'refreshAutoramp',
|
|
428
|
-
'refreshAutoramps',
|
|
429
|
-
'startOrderPolling',
|
|
430
|
-
'stopOrderPolling',
|
|
431
|
-
'getBuyWidgetData',
|
|
432
|
-
'addPrecreatedOrder',
|
|
433
|
-
'getOrder',
|
|
434
|
-
'getOrderFromCallback',
|
|
435
|
-
'transakSetApiKey',
|
|
436
|
-
'transakSetAccessToken',
|
|
437
|
-
'transakClearAccessToken',
|
|
438
|
-
'transakSetAuthenticated',
|
|
439
|
-
'transakResetState',
|
|
440
|
-
'transakSendUserOtp',
|
|
441
|
-
'transakVerifyUserOtp',
|
|
442
|
-
'transakLogout',
|
|
443
|
-
'transakGetUserDetails',
|
|
444
|
-
'transakGetBuyQuote',
|
|
445
|
-
'transakGetKycRequirement',
|
|
446
|
-
'transakGetAdditionalRequirements',
|
|
447
|
-
'transakCreateOrder',
|
|
448
|
-
'transakGetOrder',
|
|
449
|
-
'transakGetUserLimits',
|
|
450
|
-
'transakRequestOtt',
|
|
451
|
-
'transakGeneratePaymentWidgetUrl',
|
|
452
|
-
'transakCreateWidgetUrl',
|
|
453
|
-
'transakSubmitPurposeOfUsageForm',
|
|
454
|
-
'transakPatchUser',
|
|
455
|
-
'transakSubmitSsnDetails',
|
|
456
|
-
'transakConfirmPayment',
|
|
457
|
-
'transakGetTranslation',
|
|
458
|
-
'transakGetIdProofStatus',
|
|
459
|
-
'transakCancelOrder',
|
|
460
|
-
'transakCancelAllActiveOrders',
|
|
461
|
-
'transakGetActiveOrders',
|
|
462
|
-
];
|
|
463
|
-
/**
|
|
464
|
-
* Whether controller state still describes the context a payment-method
|
|
465
|
-
* request was issued for, so a completed request may write the Buy catalog.
|
|
466
|
-
*
|
|
467
|
-
* Compared at commit time rather than against a snapshot, so an older request
|
|
468
|
-
* that returns after the context moved on is dropped.
|
|
469
|
-
*
|
|
470
|
-
* @param state - Controller state at commit time.
|
|
471
|
-
* @param context - The context the request was issued for.
|
|
472
|
-
* @param context.region - Normalized region code.
|
|
473
|
-
* @param context.assetId - Canonicalized CAIP-19 asset id.
|
|
474
|
-
* @param context.providerId - Trimmed provider id, or an empty string.
|
|
475
|
-
* @returns Whether the write may proceed.
|
|
476
|
-
*/
|
|
477
|
-
function contextStillMatches(state, context) {
|
|
478
|
-
return (state.userRegion?.regionCode?.trim().toLowerCase() === context.region &&
|
|
479
|
-
(0, providerAvailability_js_1.normalizeRampsAssetId)(state.tokens.selected?.assetId ?? '') ===
|
|
480
|
-
context.assetId &&
|
|
481
|
-
(state.providers.selected?.id.trim() ?? '') === context.providerId);
|
|
482
|
-
}
|
|
483
|
-
class RampsController extends base_controller_1.BaseController {
|
|
484
|
-
/**
|
|
485
|
-
* Clears the pending resource count map. Used only in tests to exercise the
|
|
486
|
-
* defensive path when get() returns undefined in the finally block.
|
|
487
|
-
*
|
|
488
|
-
* @internal
|
|
489
|
-
*/
|
|
490
|
-
clearPendingResourceCountForTest() {
|
|
491
|
-
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").clear();
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* Constructs a new {@link RampsController}.
|
|
495
|
-
*
|
|
496
|
-
* @param args - The constructor arguments.
|
|
497
|
-
* @param args.messenger - The messenger suited for this controller.
|
|
498
|
-
* @param args.state - The desired state with which to initialize this
|
|
499
|
-
* controller. Missing properties will be filled in with defaults.
|
|
500
|
-
* @param args.requestCacheTTL - Time to live for cached requests in milliseconds.
|
|
501
|
-
* @param args.requestCacheMaxSize - Maximum number of entries in the request cache.
|
|
502
|
-
*/
|
|
503
|
-
constructor({ messenger, state = {}, requestCacheTTL = RequestCache_js_1.DEFAULT_REQUEST_CACHE_TTL, requestCacheMaxSize = RequestCache_js_1.DEFAULT_REQUEST_CACHE_MAX_SIZE, }) {
|
|
504
|
-
super({
|
|
505
|
-
messenger,
|
|
506
|
-
metadata: rampsControllerMetadata,
|
|
507
|
-
name: exports.controllerName,
|
|
508
|
-
state: {
|
|
509
|
-
...getDefaultRampsControllerState(),
|
|
510
|
-
...state,
|
|
511
|
-
// Always reset requests cache on initialization (non-persisted)
|
|
512
|
-
requests: {},
|
|
513
|
-
},
|
|
514
|
-
});
|
|
515
|
-
_RampsController_instances.add(this);
|
|
516
|
-
/**
|
|
517
|
-
* Default TTL for cached requests.
|
|
518
|
-
*/
|
|
519
|
-
_RampsController_requestCacheTTL.set(this, void 0);
|
|
520
|
-
/**
|
|
521
|
-
* Maximum number of entries in the request cache.
|
|
522
|
-
*/
|
|
523
|
-
_RampsController_requestCacheMaxSize.set(this, void 0);
|
|
524
|
-
/**
|
|
525
|
-
* Map of pending requests for deduplication.
|
|
526
|
-
* Key is the cache key, value is the pending request with abort controller.
|
|
527
|
-
*/
|
|
528
|
-
_RampsController_pendingRequests.set(this, new Map());
|
|
529
|
-
/**
|
|
530
|
-
* Count of in-flight requests per resource type.
|
|
531
|
-
* Used so isLoading is only cleared when the last request for that resource finishes.
|
|
532
|
-
*/
|
|
533
|
-
_RampsController_pendingResourceCount.set(this, new Map());
|
|
534
|
-
/**
|
|
535
|
-
* Monotonic generation per resource type used to invalidate stale in-flight
|
|
536
|
-
* requests after region/token/provider dependent-resource resets.
|
|
537
|
-
*/
|
|
538
|
-
_RampsController_pendingResourceGeneration.set(this, new Map());
|
|
539
|
-
_RampsController_orderPollingMeta.set(this, new Map());
|
|
540
|
-
_RampsController_orderPollingTimer.set(this, null);
|
|
541
|
-
_RampsController_isPolling.set(this, false);
|
|
542
|
-
_RampsController_initPromise.set(this, null);
|
|
543
|
-
__classPrivateFieldSet(this, _RampsController_requestCacheTTL, requestCacheTTL, "f");
|
|
544
|
-
__classPrivateFieldSet(this, _RampsController_requestCacheMaxSize, requestCacheMaxSize, "f");
|
|
545
|
-
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Executes a request with caching, deduplication, and at most one in-flight
|
|
549
|
-
* request per resource type.
|
|
550
|
-
*
|
|
551
|
-
* 1. **Same cache key in flight** – If a request with this cache key is
|
|
552
|
-
* already pending, returns that promise (deduplication; no second request).
|
|
553
|
-
*
|
|
554
|
-
* 2. **Cache hit** – If valid, non-expired data exists in state.requests for
|
|
555
|
-
* this key and forceRefresh is not set, returns that data without fetching.
|
|
556
|
-
*
|
|
557
|
-
* 3. **New request** – Creates an AbortController and fires the fetcher.
|
|
558
|
-
* If options.resourceType is set, tags the pending request with that
|
|
559
|
-
* resource type (so #abortDependentRequests can cancel it on region
|
|
560
|
-
* change or cleanup) and ref-counts resource-level loading state.
|
|
561
|
-
* On success or error, updates request state and resource error;
|
|
562
|
-
* in finally, clears resource loading only if this request was not
|
|
563
|
-
* aborted.
|
|
564
|
-
*
|
|
565
|
-
* @param cacheKey - Unique identifier for this request (e.g. from createCacheKey).
|
|
566
|
-
* @param fetcher - Async function that performs the fetch. Receives an AbortSignal
|
|
567
|
-
* that is aborted when this request is superseded by another for the same resource.
|
|
568
|
-
* @param options - Optional forceRefresh, ttl, and resourceType for loading/error state.
|
|
569
|
-
* @returns The result of the request (from cache, joined promise, or fetcher).
|
|
570
|
-
*/
|
|
571
|
-
async executeRequest(cacheKey, fetcher, options) {
|
|
572
|
-
// Get TTL for verifying cache expiration
|
|
573
|
-
const ttl = options?.ttl ?? __classPrivateFieldGet(this, _RampsController_requestCacheTTL, "f");
|
|
574
|
-
// DEDUPLICATION:
|
|
575
|
-
// Check if a request is already in flight for this cache key
|
|
576
|
-
// If so, return the original promise for that request
|
|
577
|
-
const pending = __classPrivateFieldGet(this, _RampsController_pendingRequests, "f").get(cacheKey);
|
|
578
|
-
if (pending) {
|
|
579
|
-
return pending.promise;
|
|
580
|
-
}
|
|
581
|
-
// CACHE HIT:
|
|
582
|
-
// If cache is not expired, return the cached data
|
|
583
|
-
if (!options?.forceRefresh) {
|
|
584
|
-
const cached = this.state.requests[cacheKey];
|
|
585
|
-
if (cached && !(0, RequestCache_js_1.isCacheExpired)(cached, ttl)) {
|
|
586
|
-
return cached.data;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
// Create a new abort controller for this request
|
|
590
|
-
// Record the time the request was started
|
|
591
|
-
const abortController = new AbortController();
|
|
592
|
-
const lastFetchedAt = Date.now();
|
|
593
|
-
const { resourceType } = options ?? {};
|
|
594
|
-
const resourceGeneration = resourceType
|
|
595
|
-
? (__classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").get(resourceType) ?? 0)
|
|
596
|
-
: undefined;
|
|
597
|
-
// Update state to loading
|
|
598
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, (0, RequestCache_js_1.createLoadingState)());
|
|
599
|
-
// Set resource-level loading state (only on cache miss). Ref-count so concurrent
|
|
600
|
-
// requests for the same resource type (different cache keys) keep isLoading true.
|
|
601
|
-
if (resourceType) {
|
|
602
|
-
const count = __classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").get(resourceType) ?? 0;
|
|
603
|
-
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").set(resourceType, count + 1);
|
|
604
|
-
if (count === 0) {
|
|
605
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_setResourceLoading).call(this, resourceType, true);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
// Create the fetch promise
|
|
609
|
-
const promise = (async () => {
|
|
610
|
-
try {
|
|
611
|
-
const data = await fetcher(abortController.signal);
|
|
612
|
-
if (abortController.signal.aborted) {
|
|
613
|
-
throw new Error('Request was aborted');
|
|
614
|
-
}
|
|
615
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, (0, RequestCache_js_1.createSuccessState)(data, lastFetchedAt));
|
|
616
|
-
if (resourceType) {
|
|
617
|
-
const isCurrent = !options?.isResultCurrent || options.isResultCurrent();
|
|
618
|
-
if (isCurrent) {
|
|
619
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_setResourceError).call(this, resourceType, null);
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
return data;
|
|
623
|
-
}
|
|
624
|
-
catch (error) {
|
|
625
|
-
if (abortController.signal.aborted) {
|
|
626
|
-
throw error;
|
|
627
|
-
}
|
|
628
|
-
const { errorInfo, normalizedError } = getNormalizedRampsError(error);
|
|
629
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, (0, RequestCache_js_1.createErrorState)(errorInfo.message, lastFetchedAt, errorInfo.errorKey));
|
|
630
|
-
if (resourceType) {
|
|
631
|
-
const isCurrent = !options?.isResultCurrent || options.isResultCurrent();
|
|
632
|
-
if (isCurrent) {
|
|
633
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_setResourceError).call(this, resourceType, errorInfo);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
throw normalizedError;
|
|
637
|
-
}
|
|
638
|
-
finally {
|
|
639
|
-
if (__classPrivateFieldGet(this, _RampsController_pendingRequests, "f").get(cacheKey)?.abortController ===
|
|
640
|
-
abortController) {
|
|
641
|
-
__classPrivateFieldGet(this, _RampsController_pendingRequests, "f").delete(cacheKey);
|
|
642
|
-
}
|
|
643
|
-
// Clear resource-level loading state only when no requests for this resource remain
|
|
644
|
-
if (resourceType && !abortController.signal.aborted) {
|
|
645
|
-
const currentGeneration = __classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").get(resourceType) ?? 0;
|
|
646
|
-
if (currentGeneration === resourceGeneration) {
|
|
647
|
-
const count = __classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").get(resourceType) ?? 0;
|
|
648
|
-
const next = Math.max(0, count - 1);
|
|
649
|
-
if (next === 0) {
|
|
650
|
-
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
651
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_setResourceLoading).call(this, resourceType, false);
|
|
652
|
-
}
|
|
653
|
-
else {
|
|
654
|
-
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").set(resourceType, next);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
})();
|
|
660
|
-
__classPrivateFieldGet(this, _RampsController_pendingRequests, "f").set(cacheKey, {
|
|
661
|
-
promise,
|
|
662
|
-
abortController,
|
|
663
|
-
resourceType,
|
|
664
|
-
});
|
|
665
|
-
return promise;
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Aborts a pending request if one exists.
|
|
669
|
-
*
|
|
670
|
-
* @param cacheKey - The cache key of the request to abort.
|
|
671
|
-
* @returns True if a request was aborted.
|
|
672
|
-
*/
|
|
673
|
-
abortRequest(cacheKey) {
|
|
674
|
-
const pending = __classPrivateFieldGet(this, _RampsController_pendingRequests, "f").get(cacheKey);
|
|
675
|
-
if (pending) {
|
|
676
|
-
pending.abortController.abort();
|
|
677
|
-
__classPrivateFieldGet(this, _RampsController_pendingRequests, "f").delete(cacheKey);
|
|
678
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_removeRequestState).call(this, cacheKey);
|
|
679
|
-
return true;
|
|
680
|
-
}
|
|
681
|
-
return false;
|
|
682
|
-
}
|
|
683
|
-
/**
|
|
684
|
-
* Gets the state of a specific cached request.
|
|
685
|
-
*
|
|
686
|
-
* @param cacheKey - The cache key to look up.
|
|
687
|
-
* @returns The request state, or undefined if not cached.
|
|
688
|
-
*/
|
|
689
|
-
getRequestState(cacheKey) {
|
|
690
|
-
return this.state.requests[cacheKey];
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* Sets the user's region manually (without fetching geolocation).
|
|
694
|
-
* This allows users to override the detected region.
|
|
695
|
-
*
|
|
696
|
-
* @param region - The region code to set (e.g., "US-CA").
|
|
697
|
-
* @param options - Options for cache behavior.
|
|
698
|
-
* @returns The user region object.
|
|
699
|
-
*/
|
|
700
|
-
async setUserRegion(region, options) {
|
|
701
|
-
const normalizedRegion = region.toLowerCase().trim();
|
|
702
|
-
try {
|
|
703
|
-
const countriesData = this.state.countries.data;
|
|
704
|
-
if (!countriesData || countriesData.length === 0) {
|
|
705
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_cleanupState).call(this);
|
|
706
|
-
throw new Error('No countries found. Cannot set user region without valid country information.');
|
|
707
|
-
}
|
|
708
|
-
const userRegion = findRegionFromCode(normalizedRegion, countriesData);
|
|
709
|
-
if (!userRegion) {
|
|
710
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_cleanupState).call(this);
|
|
711
|
-
throw new Error(`Region "${normalizedRegion}" not found in countries data. Cannot set user region without valid country information.`);
|
|
712
|
-
}
|
|
713
|
-
const regionChanged = Boolean(options?.forceRefresh) ||
|
|
714
|
-
normalizedRegion !== this.state.userRegion?.regionCode;
|
|
715
|
-
if (regionChanged) {
|
|
716
|
-
// Note: we intentionally do NOT abort in-flight requests here.
|
|
717
|
-
// Aborting causes data loss during rapid region switching (e.g.
|
|
718
|
-
// user taps France → Finland → France quickly). Instead we let
|
|
719
|
-
// old requests complete naturally; isResultCurrent guards in
|
|
720
|
-
// getProviders/getPaymentMethods discard stale results.
|
|
721
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_clearPendingResourceCountForDependentResources).call(this);
|
|
722
|
-
}
|
|
723
|
-
this.update((state) => {
|
|
724
|
-
if (regionChanged) {
|
|
725
|
-
resetDependentResources(state);
|
|
726
|
-
}
|
|
727
|
-
state.userRegion = userRegion;
|
|
728
|
-
});
|
|
729
|
-
return userRegion;
|
|
730
|
-
}
|
|
731
|
-
catch (error) {
|
|
732
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_cleanupState).call(this);
|
|
733
|
-
throw error;
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
/**
|
|
737
|
-
* Sets the user's selected provider.
|
|
738
|
-
*
|
|
739
|
-
* Accepts either a Provider object (stored directly) or a provider ID
|
|
740
|
-
* string (looked up from state). The object form is preferred when the
|
|
741
|
-
* caller already has the full data (e.g. from React Query cache).
|
|
742
|
-
*
|
|
743
|
-
* @param providerOrId - A Provider object, a provider ID string (e.g., "/providers/moonpay"), or null to clear.
|
|
744
|
-
* @param options - Optional settings for the selection.
|
|
745
|
-
* @param options.autoSelected - When true, marks the provider as system-guessed
|
|
746
|
-
* (soft selection). The UI will silently auto-switch on token conflict instead
|
|
747
|
-
* of showing the "Token Not Available" modal. Defaults to false.
|
|
748
|
-
*/
|
|
749
|
-
setSelectedProvider(providerOrId, options) {
|
|
750
|
-
if (providerOrId === null) {
|
|
751
|
-
this.update((state) => {
|
|
752
|
-
state.providers.selected = null;
|
|
753
|
-
state.providerAutoSelected = false;
|
|
754
|
-
});
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
758
|
-
// If a full Provider object is passed, store it directly (avoids
|
|
759
|
-
// depending on state.providers.data being populated).
|
|
760
|
-
if (typeof providerOrId !== 'string') {
|
|
761
|
-
this.update((state) => {
|
|
762
|
-
state.providers.selected = providerOrId;
|
|
763
|
-
state.providerAutoSelected = options?.autoSelected ?? false;
|
|
764
|
-
});
|
|
765
|
-
return;
|
|
766
|
-
}
|
|
767
|
-
// ID string: look up from state
|
|
768
|
-
const providers = this.state.providers.data;
|
|
769
|
-
const provider = providers?.find((prov) => prov.id === providerOrId);
|
|
770
|
-
if (provider) {
|
|
771
|
-
this.update((state) => {
|
|
772
|
-
state.providers.selected = provider;
|
|
773
|
-
state.providerAutoSelected = options?.autoSelected ?? false;
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Switches to the first provider in state that serves the given asset,
|
|
779
|
-
* when the currently selected provider does not.
|
|
780
|
-
*
|
|
781
|
-
* This is the controller-level equivalent of UB2's BuildQuote tier-1
|
|
782
|
-
* silent-switch effect and MMPay's `useEnsureCompatibleProvider` hook: it
|
|
783
|
-
* keeps provider-asset compatibility logic in one place rather than
|
|
784
|
-
* duplicating `providerServesAsset` + find-and-switch across multiple UI
|
|
785
|
-
* layers.
|
|
786
|
-
*
|
|
787
|
-
* The compatibility check prefers the current provider's entry in
|
|
788
|
-
* `providers.data` over the `providers.selected` copy, which can be stale
|
|
789
|
-
* once a fresh providers list arrives.
|
|
790
|
-
*
|
|
791
|
-
* No-op when:
|
|
792
|
-
* - `providers.data` is empty (providers not yet loaded)
|
|
793
|
-
* - the currently selected provider already serves the asset
|
|
794
|
-
* - no provider in the list serves the asset (no safe fallback)
|
|
795
|
-
*
|
|
796
|
-
* @param assetId - CAIP-19 asset id of the deposit asset.
|
|
797
|
-
* @param options - Optional settings forwarded to `setSelectedProvider`.
|
|
798
|
-
* @param options.autoSelected - When true, marks the new selection as
|
|
799
|
-
* system-guessed (soft selection). Defaults to true.
|
|
800
|
-
* @returns `true` if the selected provider was changed, `false` otherwise.
|
|
801
|
-
*/
|
|
802
|
-
setSelectedProviderForAsset(assetId, options) {
|
|
803
|
-
const providers = this.state.providers.data;
|
|
804
|
-
if (!providers?.length) {
|
|
805
|
-
return false;
|
|
806
|
-
}
|
|
807
|
-
const selectedId = this.state.providers.selected?.id;
|
|
808
|
-
const currentProvider = providers.find((provider) => provider.id === selectedId) ??
|
|
809
|
-
this.state.providers.selected;
|
|
810
|
-
if (currentProvider && (0, providerAvailability_js_1.providerServesAsset)(currentProvider, assetId)) {
|
|
811
|
-
return false;
|
|
812
|
-
}
|
|
813
|
-
const compatible = providers.find((provider) => provider.id !== selectedId && (0, providerAvailability_js_1.providerServesAsset)(provider, assetId));
|
|
814
|
-
if (!compatible) {
|
|
815
|
-
return false;
|
|
816
|
-
}
|
|
817
|
-
this.setSelectedProvider(compatible, {
|
|
818
|
-
autoSelected: true,
|
|
819
|
-
...options,
|
|
820
|
-
});
|
|
821
|
-
return true;
|
|
822
|
-
}
|
|
823
|
-
/**
|
|
824
|
-
* Initializes the controller by fetching the user's region from geolocation.
|
|
825
|
-
* This should be called once at app startup to set up the initial region.
|
|
826
|
-
*
|
|
827
|
-
* Idempotent: subsequent calls return the same promise unless forceRefresh is set.
|
|
828
|
-
* Force-refetches the countries catalog on startup (bypassing the in-session
|
|
829
|
-
* request cache) so region preset amounts stay current. The catalog is not
|
|
830
|
-
* persisted, so a cold start always re-fetches it regardless. Skips
|
|
831
|
-
* geolocation when userRegion already exists.
|
|
832
|
-
*
|
|
833
|
-
* @param options - Options for cache behavior. forceRefresh bypasses idempotency and re-runs the full flow.
|
|
834
|
-
* @returns Promise that resolves when initialization is complete.
|
|
835
|
-
*/
|
|
836
|
-
async init(options) {
|
|
837
|
-
if (!options?.forceRefresh && __classPrivateFieldGet(this, _RampsController_initPromise, "f") !== null) {
|
|
838
|
-
return __classPrivateFieldGet(this, _RampsController_initPromise, "f");
|
|
839
|
-
}
|
|
840
|
-
if (options?.forceRefresh) {
|
|
841
|
-
__classPrivateFieldSet(this, _RampsController_initPromise, null, "f");
|
|
842
|
-
}
|
|
843
|
-
const initPromise = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_runInit).call(this, options).then(() => undefined, (error) => {
|
|
844
|
-
if (__classPrivateFieldGet(this, _RampsController_initPromise, "f") === initPromise) {
|
|
845
|
-
__classPrivateFieldSet(this, _RampsController_initPromise, null, "f");
|
|
846
|
-
}
|
|
847
|
-
throw error;
|
|
848
|
-
});
|
|
849
|
-
__classPrivateFieldSet(this, _RampsController_initPromise, initPromise, "f");
|
|
850
|
-
return initPromise;
|
|
851
|
-
}
|
|
852
|
-
/**
|
|
853
|
-
* Fetches the list of supported countries.
|
|
854
|
-
* The API returns countries with support information for both buy and sell actions.
|
|
855
|
-
* The countries are saved in the controller state once fetched.
|
|
856
|
-
*
|
|
857
|
-
* @param options - Options for cache behavior.
|
|
858
|
-
* @returns An array of countries.
|
|
859
|
-
*/
|
|
860
|
-
async getCountries(options) {
|
|
861
|
-
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getCountries', []);
|
|
862
|
-
const countries = await this.executeRequest(cacheKey, async () => {
|
|
863
|
-
return this.messenger.call('RampsService:getCountries');
|
|
864
|
-
}, { ...options, resourceType: 'countries' });
|
|
865
|
-
this.update((state) => {
|
|
866
|
-
state.countries.data = Array.isArray(countries) ? [...countries] : [];
|
|
867
|
-
});
|
|
868
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncUserRegionFromCountriesCatalog).call(this);
|
|
869
|
-
return countries;
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
|
-
* Fetches the list of available tokens for a given region and action.
|
|
873
|
-
* The tokens are saved in the controller state once fetched.
|
|
874
|
-
*
|
|
875
|
-
* @param region - The region code (e.g., "us", "fr", "us-ny"). If not provided, uses the user's region from controller state.
|
|
876
|
-
* @param action - The ramp action type ('buy' or 'sell').
|
|
877
|
-
* @param options - Options for cache behavior and query filters.
|
|
878
|
-
* @param options.provider - Provider ID(s) to filter by.
|
|
879
|
-
* @returns The tokens response containing topTokens and allTokens.
|
|
880
|
-
*/
|
|
881
|
-
async getTokens(region, action = 'buy', options) {
|
|
882
|
-
const regionToUse = region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
883
|
-
const normalizedRegion = regionToUse.toLowerCase().trim();
|
|
884
|
-
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getTokens', [
|
|
885
|
-
normalizedRegion,
|
|
886
|
-
action,
|
|
887
|
-
options?.provider,
|
|
888
|
-
]);
|
|
889
|
-
const tokens = await this.executeRequest(cacheKey, async () => {
|
|
890
|
-
return this.messenger.call('RampsService:getTokens', normalizedRegion, action, {
|
|
891
|
-
provider: options?.provider,
|
|
892
|
-
});
|
|
893
|
-
}, {
|
|
894
|
-
...options,
|
|
895
|
-
resourceType: 'tokens',
|
|
896
|
-
isResultCurrent: () => __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isRegionCurrent).call(this, normalizedRegion),
|
|
897
|
-
});
|
|
898
|
-
this.update((state) => {
|
|
899
|
-
const userRegionCode = state.userRegion?.regionCode;
|
|
900
|
-
if (userRegionCode === undefined || userRegionCode === normalizedRegion) {
|
|
901
|
-
state.tokens.data = tokens;
|
|
902
|
-
}
|
|
903
|
-
});
|
|
904
|
-
return tokens;
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Sets the user's selected token by asset ID.
|
|
908
|
-
* Looks up the token from the current tokens in state and automatically
|
|
909
|
-
* fetches payment methods for that token.
|
|
910
|
-
*
|
|
911
|
-
* @param assetId - The asset identifier in CAIP-19 format (e.g., "eip155:1/erc20:0x..."), or undefined to clear.
|
|
912
|
-
* @throws If region is not set, tokens are not loaded, or token is not found.
|
|
913
|
-
*/
|
|
914
|
-
setSelectedToken(assetId) {
|
|
915
|
-
if (!assetId) {
|
|
916
|
-
this.update((state) => {
|
|
917
|
-
state.tokens.selected = null;
|
|
918
|
-
});
|
|
919
|
-
return;
|
|
920
|
-
}
|
|
921
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
922
|
-
const tokens = this.state.tokens.data;
|
|
923
|
-
if (!tokens) {
|
|
924
|
-
throw new Error('Tokens not loaded. Cannot set selected token before tokens are fetched.');
|
|
925
|
-
}
|
|
926
|
-
const token = tokens.allTokens.find((tok) => tok.assetId === assetId) ??
|
|
927
|
-
tokens.topTokens.find((tok) => tok.assetId === assetId);
|
|
928
|
-
if (!token) {
|
|
929
|
-
throw new Error(`Token with asset ID "${assetId}" not found in available tokens.`);
|
|
930
|
-
}
|
|
931
|
-
this.update((state) => {
|
|
932
|
-
state.tokens.selected = token;
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
/**
|
|
936
|
-
* Fetches the list of providers for a given region.
|
|
937
|
-
* The providers are saved in the controller state once fetched.
|
|
938
|
-
*
|
|
939
|
-
* @param region - The region code (e.g., "us", "fr", "us-ny"). If not provided, uses the user's region from controller state.
|
|
940
|
-
* @param options - Options for cache behavior and query filters.
|
|
941
|
-
* @param options.provider - Provider ID(s) to filter by.
|
|
942
|
-
* @param options.crypto - Crypto currency ID(s) to filter by.
|
|
943
|
-
* @param options.payments - Payment method ID(s) to filter by.
|
|
944
|
-
* @returns The providers response containing providers array.
|
|
945
|
-
*/
|
|
946
|
-
async getProviders(region, options) {
|
|
947
|
-
const regionToUse = region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
948
|
-
const normalizedRegion = regionToUse.toLowerCase().trim();
|
|
949
|
-
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getProviders', [
|
|
950
|
-
normalizedRegion,
|
|
951
|
-
options?.provider,
|
|
952
|
-
options?.crypto,
|
|
953
|
-
options?.payments,
|
|
954
|
-
]);
|
|
955
|
-
const response = await this.executeRequest(cacheKey, async () => {
|
|
956
|
-
return this.messenger.call('RampsService:getProviders', normalizedRegion, {
|
|
957
|
-
provider: options?.provider,
|
|
958
|
-
crypto: options?.crypto,
|
|
959
|
-
payments: options?.payments,
|
|
960
|
-
});
|
|
961
|
-
}, {
|
|
962
|
-
...options,
|
|
963
|
-
resourceType: 'providers',
|
|
964
|
-
isResultCurrent: () => __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isRegionCurrent).call(this, normalizedRegion),
|
|
965
|
-
});
|
|
966
|
-
const { providers } = response;
|
|
967
|
-
this.update((state) => {
|
|
968
|
-
const userRegionCode = state.userRegion?.regionCode;
|
|
969
|
-
if (userRegionCode === undefined || userRegionCode === normalizedRegion) {
|
|
970
|
-
state.providers.data = providers;
|
|
971
|
-
}
|
|
972
|
-
});
|
|
973
|
-
return response;
|
|
974
|
-
}
|
|
975
|
-
/**
|
|
976
|
-
* Fetches the list of payment methods for a given context.
|
|
977
|
-
* The payment methods are saved in the controller state once fetched.
|
|
978
|
-
*
|
|
979
|
-
* @param region - User's region code (e.g. "fr", "us-ny").
|
|
980
|
-
* @param options - Query parameters for filtering payment methods.
|
|
981
|
-
* @param options.assetId - CAIP-19 cryptocurrency identifier.
|
|
982
|
-
* @param options.provider - Provider ID path.
|
|
983
|
-
* @returns The payment methods response containing payments array.
|
|
984
|
-
*/
|
|
985
|
-
async getPaymentMethods(region, options) {
|
|
986
|
-
const regionCode = region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
987
|
-
const assetIdToUse = options?.assetId ?? this.state.tokens.selected?.assetId ?? '';
|
|
988
|
-
const providerToUse = options?.provider ?? this.state.providers.selected?.id ?? '';
|
|
989
|
-
const normalizedRegion = regionCode.toLowerCase().trim();
|
|
990
|
-
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getPaymentMethods', [
|
|
991
|
-
normalizedRegion,
|
|
992
|
-
assetIdToUse,
|
|
993
|
-
providerToUse,
|
|
994
|
-
]);
|
|
995
|
-
const response = await this.executeRequest(cacheKey, async () => {
|
|
996
|
-
return this.messenger.call('RampsService:getPaymentMethods', {
|
|
997
|
-
region: normalizedRegion,
|
|
998
|
-
assetId: assetIdToUse,
|
|
999
|
-
provider: providerToUse,
|
|
1000
|
-
});
|
|
1001
|
-
}, {
|
|
1002
|
-
...options,
|
|
1003
|
-
resourceType: 'paymentMethods',
|
|
1004
|
-
isResultCurrent: () => {
|
|
1005
|
-
const regionMatch = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isRegionCurrent).call(this, normalizedRegion);
|
|
1006
|
-
const tokenMatch = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isTokenCurrent).call(this, assetIdToUse);
|
|
1007
|
-
const providerMatch = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isProviderCurrent).call(this, providerToUse);
|
|
1008
|
-
return regionMatch && tokenMatch && providerMatch;
|
|
1009
|
-
},
|
|
1010
|
-
});
|
|
1011
|
-
this.update((state) => {
|
|
1012
|
-
const currentAssetId = state.tokens.selected?.assetId ?? '';
|
|
1013
|
-
const currentProviderId = state.providers.selected?.id ?? '';
|
|
1014
|
-
const tokenSelectionUnchanged = assetIdToUse === currentAssetId;
|
|
1015
|
-
const providerSelectionUnchanged = providerToUse === currentProviderId;
|
|
1016
|
-
// 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
|
|
1017
|
-
// ex: if the user rapidly changes the token or provider, the in-flight payment methods might not be valid
|
|
1018
|
-
// so this check will ensure that the payment methods are still valid for the token and provider that were requested
|
|
1019
|
-
if (tokenSelectionUnchanged && providerSelectionUnchanged) {
|
|
1020
|
-
state.paymentMethods.data = response.payments;
|
|
1021
|
-
// this will auto-select the first payment method if the selected payment method is not in the new payment methods
|
|
1022
|
-
const currentSelectionStillValid = response.payments.some((pm) => pm.id === state.paymentMethods.selected?.id);
|
|
1023
|
-
if (!currentSelectionStillValid) {
|
|
1024
|
-
state.paymentMethods.selected = response.payments[0] ?? null;
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
});
|
|
1028
|
-
return response;
|
|
1029
|
-
}
|
|
1030
|
-
/**
|
|
1031
|
-
* Fetches payment methods for a quoting context without coupling callers to
|
|
1032
|
-
* the Buy flow's globally selected provider/token catalog.
|
|
1033
|
-
*
|
|
1034
|
-
* Provider contribution mirrors {@link getQuotes}:
|
|
1035
|
-
* - explicit `providers` (optionally filtered when
|
|
1036
|
-
* `restrictToKnownOrNativeProviders` is set)
|
|
1037
|
-
* - auto-select / restrict path, including `moneyHeadlessAllProviders`
|
|
1038
|
-
* widening: flag off uses the restricted/native resolver; flag on uses
|
|
1039
|
-
* supporting providers, intersected with the flag allowlist when that
|
|
1040
|
-
* allowlist is non-empty (pick-survivor set for picker methods)
|
|
1041
|
-
* - when those resolution flags and `providers` are omitted, uses only
|
|
1042
|
-
* `providers.selected` (UB2 selected-provider context)
|
|
1043
|
-
*
|
|
1044
|
-
* By default this is request-only: it does **not** mutate
|
|
1045
|
-
* `paymentMethods.data` or `paymentMethods.selected`. Pass `updateState:
|
|
1046
|
-
* true` only when the caller explicitly wants Buy-catalog write semantics
|
|
1047
|
-
* (UB2). Headless / MM Pay selection stays TPC-owned. `updateState: true`
|
|
1048
|
-
* throws when the resolved provider set holds more than one provider, because
|
|
1049
|
-
* the write guards cannot tell two such requests apart.
|
|
1050
|
-
*
|
|
1051
|
-
* Methods are request-eligible for the resolved provider set; they are not
|
|
1052
|
-
* guaranteed to produce a quote for every amount (provider fiat limits still
|
|
1053
|
-
* apply at quote time).
|
|
1054
|
-
*
|
|
1055
|
-
* @param options - Context for the payment-method fetch.
|
|
1056
|
-
* @param options.region - Region code. Defaults to `userRegion`.
|
|
1057
|
-
* @param options.assetId - Required CAIP-19 quoting asset.
|
|
1058
|
-
* @param options.providers - Explicit provider ids.
|
|
1059
|
-
* @param options.autoSelectProvider - Resolve providers like `getQuotes`.
|
|
1060
|
-
* @param options.preferredProviderIds - Preferred ids for auto-selection.
|
|
1061
|
-
* @param options.restrictToKnownOrNativeProviders - Headless gating.
|
|
1062
|
-
* @param options.updateState - When true, write `paymentMethods` state.
|
|
1063
|
-
* @param options.preferPaymentMethodId - Preserve this id when still present.
|
|
1064
|
-
* @param options.forceRefresh - Bypass request cache for provider fetches.
|
|
1065
|
-
* @param options.ttl - Custom TTL for provider payment-method fetches.
|
|
1066
|
-
* @returns Deduped methods, a request-only suggested selection, and the
|
|
1067
|
-
* provider ids that contributed.
|
|
1068
|
-
*/
|
|
1069
|
-
async getPaymentMethodsForContext(options) {
|
|
1070
|
-
const regionToUse = options.region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
1071
|
-
const normalizedRegion = regionToUse.toLowerCase().trim();
|
|
1072
|
-
const assetId = options.assetId.trim();
|
|
1073
|
-
if (assetId === '') {
|
|
1074
|
-
throw new Error('assetId is required.');
|
|
1075
|
-
}
|
|
1076
|
-
const normalizedAssetContext = (0, providerAvailability_js_1.normalizeRampsAssetId)(assetId);
|
|
1077
|
-
const updateState = options.updateState === true;
|
|
1078
|
-
const providerIdForState = options.providers?.length === 1
|
|
1079
|
-
? options.providers[0].trim()
|
|
1080
|
-
: (this.state.providers.selected?.id.trim() ?? '');
|
|
1081
|
-
const providerIds = await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_resolveProviderIdsForPaymentMethods).call(this, {
|
|
1082
|
-
assetId,
|
|
1083
|
-
region: normalizedRegion,
|
|
1084
|
-
providers: options.providers,
|
|
1085
|
-
autoSelectProvider: options.autoSelectProvider,
|
|
1086
|
-
preferredProviderIds: options.preferredProviderIds,
|
|
1087
|
-
restrictToKnownOrNativeProviders: options.restrictToKnownOrNativeProviders,
|
|
1088
|
-
});
|
|
1089
|
-
// A fan-out across several providers produces a merged catalog whose value
|
|
1090
|
-
// depends on the provider set, but the write guards below only compare
|
|
1091
|
-
// region, selected token, and selected provider. Two concurrent
|
|
1092
|
-
// multi-provider requests share all three, so nothing distinguishes them
|
|
1093
|
-
// and the slower one would silently overwrite the faster one.
|
|
1094
|
-
if (updateState && providerIds.length > 1) {
|
|
1095
|
-
throw new Error(`getPaymentMethodsForContext cannot write paymentMethods state for ${providerIds.length} resolved providers. Use updateState: false, or request exactly one provider.`);
|
|
1096
|
-
}
|
|
1097
|
-
const writeContext = {
|
|
1098
|
-
region: normalizedRegion,
|
|
1099
|
-
assetId: normalizedAssetContext,
|
|
1100
|
-
providerId: providerIdForState,
|
|
1101
|
-
};
|
|
1102
|
-
if (providerIds.length === 0) {
|
|
1103
|
-
if (updateState) {
|
|
1104
|
-
this.update((state) => {
|
|
1105
|
-
if (contextStillMatches(state, writeContext)) {
|
|
1106
|
-
state.paymentMethods.data = [];
|
|
1107
|
-
state.paymentMethods.selected = null;
|
|
1108
|
-
}
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
|
-
return { methods: [], selected: null, providerIds };
|
|
1112
|
-
}
|
|
1113
|
-
const settled = await Promise.allSettled(providerIds.map(async (providerId) => {
|
|
1114
|
-
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getPaymentMethodsForContext', [
|
|
1115
|
-
normalizedRegion,
|
|
1116
|
-
assetId,
|
|
1117
|
-
providerId,
|
|
1118
|
-
]);
|
|
1119
|
-
return this.executeRequest(cacheKey, async () => {
|
|
1120
|
-
return this.messenger.call('RampsService:getPaymentMethods', {
|
|
1121
|
-
region: normalizedRegion,
|
|
1122
|
-
assetId,
|
|
1123
|
-
provider: providerId,
|
|
1124
|
-
});
|
|
1125
|
-
}, {
|
|
1126
|
-
forceRefresh: options.forceRefresh,
|
|
1127
|
-
ttl: options.ttl,
|
|
1128
|
-
// Intentionally omit resourceType / isResultCurrent so this
|
|
1129
|
-
// request-only path never drives Buy paymentMethods loading or
|
|
1130
|
-
// selection state unless `updateState` is explicitly set below.
|
|
1131
|
-
});
|
|
1132
|
-
}));
|
|
1133
|
-
const successfulLists = [];
|
|
1134
|
-
const failures = [];
|
|
1135
|
-
for (const result of settled) {
|
|
1136
|
-
if (result.status === 'fulfilled') {
|
|
1137
|
-
successfulLists.push(result.value.payments);
|
|
1138
|
-
}
|
|
1139
|
-
else {
|
|
1140
|
-
failures.push(result.reason);
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
if (successfulLists.length === 0) {
|
|
1144
|
-
const firstFailure = failures[0];
|
|
1145
|
-
throw firstFailure instanceof Error
|
|
1146
|
-
? firstFailure
|
|
1147
|
-
: new Error('Failed to fetch payment methods for context.');
|
|
1148
|
-
}
|
|
1149
|
-
const methods = (0, paymentMethodMerge_js_1.mergePaymentMethodsById)(successfulLists);
|
|
1150
|
-
let selected = (0, paymentMethodMerge_js_1.pickPaymentMethod)(methods, [
|
|
1151
|
-
options.preferPaymentMethodId,
|
|
1152
|
-
this.state.paymentMethods.selected?.id,
|
|
1153
|
-
]);
|
|
1154
|
-
if (updateState) {
|
|
1155
|
-
this.update((state) => {
|
|
1156
|
-
if (contextStillMatches(state, writeContext)) {
|
|
1157
|
-
// The stored selection outranks the caller's preference: the user may
|
|
1158
|
-
// have picked a method while this request was in flight.
|
|
1159
|
-
selected = (0, paymentMethodMerge_js_1.pickPaymentMethod)(methods, [
|
|
1160
|
-
state.paymentMethods.selected?.id,
|
|
1161
|
-
options.preferPaymentMethodId,
|
|
1162
|
-
]);
|
|
1163
|
-
state.paymentMethods.data = methods;
|
|
1164
|
-
state.paymentMethods.selected = selected;
|
|
1165
|
-
}
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
return { methods, selected, providerIds };
|
|
1169
|
-
}
|
|
1170
|
-
/**
|
|
1171
|
-
* Sets the user's selected payment method.
|
|
1172
|
-
*
|
|
1173
|
-
* Accepts either a payment method ID (looked up from state) or a full
|
|
1174
|
-
* PaymentMethod object (stored directly). The object form is preferred
|
|
1175
|
-
* when the caller already has the full data (e.g. from React Query cache),
|
|
1176
|
-
* as it avoids depending on controller state being populated.
|
|
1177
|
-
*
|
|
1178
|
-
* @param paymentMethodOrId - A PaymentMethod object, a payment method ID string, or undefined/null to clear.
|
|
1179
|
-
*/
|
|
1180
|
-
setSelectedPaymentMethod(paymentMethodOrId) {
|
|
1181
|
-
if (!paymentMethodOrId) {
|
|
1182
|
-
this.update((state) => {
|
|
1183
|
-
state.paymentMethods.selected = null;
|
|
1184
|
-
});
|
|
1185
|
-
return;
|
|
1186
|
-
}
|
|
1187
|
-
// If a full object is passed, store it directly
|
|
1188
|
-
if (typeof paymentMethodOrId !== 'string') {
|
|
1189
|
-
this.update((state) => {
|
|
1190
|
-
state.paymentMethods.selected = paymentMethodOrId;
|
|
1191
|
-
});
|
|
1192
|
-
return;
|
|
1193
|
-
}
|
|
1194
|
-
// ID string: look up from state
|
|
1195
|
-
const paymentMethodId = paymentMethodOrId;
|
|
1196
|
-
const paymentMethods = this.state.paymentMethods.data;
|
|
1197
|
-
const paymentMethod = paymentMethods?.find((pm) => pm.id === paymentMethodId);
|
|
1198
|
-
this.update((state) => {
|
|
1199
|
-
state.paymentMethods.selected = paymentMethod ?? null;
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Fetches quotes from all providers for a given set of parameters.
|
|
1204
|
-
* Uses the controller's request cache; callers manage the response in local state.
|
|
1205
|
-
*
|
|
1206
|
-
* @param options - The parameters for fetching quotes.
|
|
1207
|
-
* @param options.region - User's region code. If not provided, uses userRegion from state.
|
|
1208
|
-
* @param options.fiat - Fiat currency code. If not provided, uses userRegion currency.
|
|
1209
|
-
* @param options.assetId - CAIP-19 cryptocurrency identifier.
|
|
1210
|
-
* @param options.amount - The amount (in fiat for buy, crypto for sell).
|
|
1211
|
-
* @param options.walletAddress - The destination wallet address.
|
|
1212
|
-
* @param options.paymentMethods - Array of payment method IDs. If not provided, uses paymentMethods from state.
|
|
1213
|
-
* @param options.providers - Optional provider IDs to filter quotes.
|
|
1214
|
-
* @param options.autoSelectProvider - When true and `providers` is omitted,
|
|
1215
|
-
* resolves a provider that supports `assetId` for this request only (no
|
|
1216
|
-
* state mutation). Ignored when `providers` is passed.
|
|
1217
|
-
* @param options.preferredProviderIds - Optional provider IDs to prefer
|
|
1218
|
-
* during auto-selection, in priority order (e.g. derived by the caller
|
|
1219
|
-
* from completed-order history). Only used when `autoSelectProvider` is
|
|
1220
|
-
* true and `providers` is omitted.
|
|
1221
|
-
* @param options.restrictToKnownOrNativeProviders - Headless-buy v0 gating. When
|
|
1222
|
-
* true, auto-selection resolves only a native provider, and an explicitly
|
|
1223
|
-
* passed `providers` list is filtered to those supporting the region and
|
|
1224
|
-
* asset. If nothing qualifies, `getQuotes` returns an empty response
|
|
1225
|
-
* instead of quoting other providers.
|
|
1226
|
-
* @param options.redirectUrl - Optional redirect URL after order completion.
|
|
1227
|
-
* @param options.action - The ramp action type. Defaults to 'buy'.
|
|
1228
|
-
* @param options.forceRefresh - Whether to bypass cache.
|
|
1229
|
-
* @param options.ttl - Custom TTL for this request.
|
|
1230
|
-
* @returns The quotes response containing success, sorted, error, and customActions.
|
|
1231
|
-
*/
|
|
1232
|
-
async getQuotes(options) {
|
|
1233
|
-
const regionToUse = options.region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
1234
|
-
const fiatToUse = options.fiat ?? this.state.userRegion?.country?.currency;
|
|
1235
|
-
const paymentMethodsToUse = options.paymentMethods ??
|
|
1236
|
-
this.state.paymentMethods.data.map((pm) => pm.id);
|
|
1237
|
-
const action = options.action ?? 'buy';
|
|
1238
|
-
const assetIdToUse = options.assetId ?? this.state.tokens.selected?.assetId;
|
|
1239
|
-
if (!fiatToUse) {
|
|
1240
|
-
throw new Error('Fiat currency is required. Either provide a fiat parameter or ensure userRegion is set in controller state.');
|
|
1241
|
-
}
|
|
1242
|
-
const normalizedAssetIdForValidation = (assetIdToUse ?? '').trim();
|
|
1243
|
-
if (normalizedAssetIdForValidation === '') {
|
|
1244
|
-
throw new Error('assetId is required.');
|
|
1245
|
-
}
|
|
1246
|
-
// When the all-providers feature flag is enabled, widen the native-only
|
|
1247
|
-
// auto-selection path to every supporting provider and pick the best
|
|
1248
|
-
// quote from the results. Only the auto-select/restrict path that MM Pay's
|
|
1249
|
-
// `getRampsQuote` uses is affected; explicit-`providers` callers and the
|
|
1250
|
-
// plain all-provider path are untouched (and never read the flag).
|
|
1251
|
-
const wantsAutoSelection = !options.providers &&
|
|
1252
|
-
(options.autoSelectProvider === true ||
|
|
1253
|
-
options.restrictToKnownOrNativeProviders === true);
|
|
1254
|
-
// Single flag read per call: the enabled bit and the allowlist come from
|
|
1255
|
-
// the same `RemoteFeatureFlagController` state snapshot, so a flag edit
|
|
1256
|
-
// during the awaited quote fetch cannot produce a mixed read.
|
|
1257
|
-
const { enabled: allProvidersEnabled, allowlist: providerAllowlist } = wantsAutoSelection
|
|
1258
|
-
? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_resolveAllProvidersFlag).call(this)
|
|
1259
|
-
: { enabled: false, allowlist: undefined };
|
|
1260
|
-
const widenToAllProviders = wantsAutoSelection && allProvidersEnabled;
|
|
1261
|
-
let providersToUse;
|
|
1262
|
-
let widenedProviderCatalog = this.state.providers.data;
|
|
1263
|
-
if (options.providers) {
|
|
1264
|
-
providersToUse = options.restrictToKnownOrNativeProviders
|
|
1265
|
-
? await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_filterProviderIdsBySupport).call(this, {
|
|
1266
|
-
providerIds: options.providers,
|
|
1267
|
-
assetId: normalizedAssetIdForValidation,
|
|
1268
|
-
region: regionToUse,
|
|
1269
|
-
})
|
|
1270
|
-
: options.providers;
|
|
1271
|
-
}
|
|
1272
|
-
else if (widenToAllProviders) {
|
|
1273
|
-
// `#getSupportingProvidersForRegion` also hydrates the provider catalog
|
|
1274
|
-
// when controller state is empty, so all-provider quoting cannot silently
|
|
1275
|
-
// return zero providers here.
|
|
1276
|
-
const { supporting } = await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getSupportingProvidersForRegion).call(this, {
|
|
1277
|
-
assetId: normalizedAssetIdForValidation,
|
|
1278
|
-
region: regionToUse,
|
|
1279
|
-
});
|
|
1280
|
-
widenedProviderCatalog = supporting;
|
|
1281
|
-
providersToUse = supporting.map((provider) => provider.id);
|
|
1282
|
-
}
|
|
1283
|
-
else if (options.autoSelectProvider ||
|
|
1284
|
-
options.restrictToKnownOrNativeProviders) {
|
|
1285
|
-
// The restriction flag implies resolution: it must narrow the provider
|
|
1286
|
-
// set even when `autoSelectProvider` was not explicitly passed, otherwise
|
|
1287
|
-
// it would be silently ignored and every provider quoted.
|
|
1288
|
-
providersToUse = await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_resolveProviderIdsForQuote).call(this, {
|
|
1289
|
-
assetId: normalizedAssetIdForValidation,
|
|
1290
|
-
region: regionToUse,
|
|
1291
|
-
preferredProviderIds: options.preferredProviderIds,
|
|
1292
|
-
restrictToKnownOrNative: options.restrictToKnownOrNativeProviders,
|
|
1293
|
-
});
|
|
1294
|
-
}
|
|
1295
|
-
else {
|
|
1296
|
-
providersToUse = this.state.providers.data.map((provider) => provider.id);
|
|
1297
|
-
}
|
|
1298
|
-
if (!paymentMethodsToUse ||
|
|
1299
|
-
paymentMethodsToUse.length === 0 ||
|
|
1300
|
-
paymentMethodsToUse.some((pm) => pm.trim() === '')) {
|
|
1301
|
-
throw new Error('Payment methods are required. Either provide paymentMethods parameter or ensure paymentMethods are set in controller state.');
|
|
1302
|
-
}
|
|
1303
|
-
if (options.amount <= 0 || !Number.isFinite(options.amount)) {
|
|
1304
|
-
throw new Error('Amount must be a positive finite number.');
|
|
1305
|
-
}
|
|
1306
|
-
if (!options.walletAddress || options.walletAddress.trim() === '') {
|
|
1307
|
-
throw new Error('walletAddress is required.');
|
|
1308
|
-
}
|
|
1309
|
-
// Under headless-buy gating, an empty resolved provider list means no
|
|
1310
|
-
// eligible (native/supporting) provider exists. Return an empty response
|
|
1311
|
-
// rather than passing `[]` to the service, which omits the provider filter
|
|
1312
|
-
// and would quote every provider. This also guards the widened path:
|
|
1313
|
-
// a caller may trigger widening with `autoSelectProvider` alone (no
|
|
1314
|
-
// `restrictToKnownOrNativeProviders`), and an empty supporting set must not
|
|
1315
|
-
// fall through to unfiltered quotes from providers that do not support the
|
|
1316
|
-
// asset.
|
|
1317
|
-
if ((options.restrictToKnownOrNativeProviders || widenToAllProviders) &&
|
|
1318
|
-
providersToUse.length === 0) {
|
|
1319
|
-
return { success: [], sorted: [], error: [], customActions: [] };
|
|
1320
|
-
}
|
|
1321
|
-
const normalizedRegion = regionToUse.toLowerCase().trim();
|
|
1322
|
-
const normalizedFiat = fiatToUse.toLowerCase().trim();
|
|
1323
|
-
const normalizedAssetId = normalizedAssetIdForValidation;
|
|
1324
|
-
const normalizedWalletAddress = options.walletAddress.trim();
|
|
1325
|
-
// The quotes API only embeds a `buyURL`/`buyWidget` when a `redirectUrl` is
|
|
1326
|
-
// present, so on the widened path (where MM Pay omits one) ask the service
|
|
1327
|
-
// for the callback URL of the environment it is configured with, so
|
|
1328
|
-
// aggregator quotes carry a usable widget URL that always matches the
|
|
1329
|
-
// environment the quotes came from. An explicit caller `redirectUrl`
|
|
1330
|
-
// always wins, and the native-only path (flag off) never injects, so
|
|
1331
|
-
// neither reaches the service.
|
|
1332
|
-
const effectiveRedirectUrl = options.redirectUrl ??
|
|
1333
|
-
(widenToAllProviders
|
|
1334
|
-
? this.messenger.call('RampsService:getDefaultRedirectCallbackUrl')
|
|
1335
|
-
: undefined);
|
|
1336
|
-
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getQuotes', [
|
|
1337
|
-
normalizedRegion,
|
|
1338
|
-
normalizedFiat,
|
|
1339
|
-
normalizedAssetId,
|
|
1340
|
-
options.amount,
|
|
1341
|
-
normalizedWalletAddress,
|
|
1342
|
-
[...paymentMethodsToUse].sort().join(','),
|
|
1343
|
-
[...providersToUse].sort().join(','),
|
|
1344
|
-
effectiveRedirectUrl,
|
|
1345
|
-
action,
|
|
1346
|
-
]);
|
|
1347
|
-
const params = {
|
|
1348
|
-
region: normalizedRegion,
|
|
1349
|
-
fiat: normalizedFiat,
|
|
1350
|
-
assetId: normalizedAssetId,
|
|
1351
|
-
amount: options.amount,
|
|
1352
|
-
walletAddress: normalizedWalletAddress,
|
|
1353
|
-
paymentMethods: paymentMethodsToUse,
|
|
1354
|
-
providers: providersToUse,
|
|
1355
|
-
redirectUrl: effectiveRedirectUrl,
|
|
1356
|
-
action,
|
|
1357
|
-
};
|
|
1358
|
-
const response = await this.executeRequest(cacheKey, async () => {
|
|
1359
|
-
return this.messenger.call('RampsService:getQuotes', params);
|
|
1360
|
-
}, {
|
|
1361
|
-
forceRefresh: options.forceRefresh,
|
|
1362
|
-
ttl: options.ttl ?? DEFAULT_QUOTES_TTL,
|
|
1363
|
-
});
|
|
1364
|
-
if (!widenToAllProviders) {
|
|
1365
|
-
return response;
|
|
1366
|
-
}
|
|
1367
|
-
// Reduce the widened multi-provider result to the single best quote
|
|
1368
|
-
// and place it at `success[0]`, since single-pick consumers
|
|
1369
|
-
// (`getRampsQuote` -> `success?.[0]`) rely on index 0 while `success[]`
|
|
1370
|
-
// order is server-defined rather than ranked.
|
|
1371
|
-
const selectedQuote = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_pickWidenedQuote).call(this, response, {
|
|
1372
|
-
amount: options.amount,
|
|
1373
|
-
fiat: normalizedFiat,
|
|
1374
|
-
providers: widenedProviderCatalog,
|
|
1375
|
-
allowlist: providerAllowlist,
|
|
1376
|
-
});
|
|
1377
|
-
if (!selectedQuote) {
|
|
1378
|
-
// No quote fits the published provider limits: surface "no quote"
|
|
1379
|
-
// rather than handing the single-pick consumer an out-of-limits quote.
|
|
1380
|
-
return {
|
|
1381
|
-
success: [],
|
|
1382
|
-
sorted: response.sorted,
|
|
1383
|
-
error: response.error,
|
|
1384
|
-
customActions: response.customActions,
|
|
1385
|
-
};
|
|
1386
|
-
}
|
|
1387
|
-
return {
|
|
1388
|
-
...response,
|
|
1389
|
-
success: [
|
|
1390
|
-
selectedQuote,
|
|
1391
|
-
...response.success.filter((quote) => quote !== selectedQuote),
|
|
1392
|
-
],
|
|
1393
|
-
};
|
|
1394
|
-
}
|
|
1395
|
-
// === ORDER MANAGEMENT ===
|
|
1396
|
-
/**
|
|
1397
|
-
* Adds or updates a V2 order in controller state.
|
|
1398
|
-
* If an order with the same internal order code already exists, the incoming
|
|
1399
|
-
* fields are merged on top of the existing order so that fields not present
|
|
1400
|
-
* in the update (e.g. paymentDetails from the Transak API) are preserved.
|
|
1401
|
-
*
|
|
1402
|
-
* @param order - The RampsOrder to add or update.
|
|
1403
|
-
*/
|
|
1404
|
-
addOrder(order) {
|
|
1405
|
-
const internalOrderCode = getInternalOrderCode(order);
|
|
1406
|
-
const healedOrder = {
|
|
1407
|
-
...order,
|
|
1408
|
-
providerOrderId: internalOrderCode,
|
|
1409
|
-
};
|
|
1410
|
-
this.update((state) => {
|
|
1411
|
-
const idx = state.orders.findIndex((existing) => getInternalOrderCode(existing) === internalOrderCode);
|
|
1412
|
-
if (idx === -1) {
|
|
1413
|
-
state.orders.push(healedOrder);
|
|
1414
|
-
}
|
|
1415
|
-
else {
|
|
1416
|
-
state.orders[idx] = {
|
|
1417
|
-
...state.orders[idx],
|
|
1418
|
-
...healedOrder,
|
|
1419
|
-
};
|
|
1420
|
-
}
|
|
1421
|
-
});
|
|
1422
|
-
}
|
|
1423
|
-
/**
|
|
1424
|
-
* Removes a V2 order from controller state by providerOrderId.
|
|
1425
|
-
*
|
|
1426
|
-
* @param providerOrderId - The provider order ID to remove.
|
|
1427
|
-
*/
|
|
1428
|
-
removeOrder(providerOrderId) {
|
|
1429
|
-
this.update((state) => {
|
|
1430
|
-
state.orders = state.orders.filter((order) => order.providerOrderId !== providerOrderId);
|
|
1431
|
-
});
|
|
1432
|
-
__classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").delete(providerOrderId);
|
|
1433
|
-
}
|
|
1434
|
-
/**
|
|
1435
|
-
* Adds or updates a local autoramp last-seen cursor (e.g. after create).
|
|
1436
|
-
*
|
|
1437
|
-
* @param accountOrInput - Full account or create fields.
|
|
1438
|
-
* @returns The upserted {@link AutorampAccount}.
|
|
1439
|
-
*/
|
|
1440
|
-
addAutoramp(accountOrInput) {
|
|
1441
|
-
const account = isFullAutorampAccount(accountOrInput)
|
|
1442
|
-
? accountOrInput
|
|
1443
|
-
: (0, autorampAccount_js_1.createAutorampAccount)(accountOrInput);
|
|
1444
|
-
this.update((state) => {
|
|
1445
|
-
const idx = state.autoramps.findIndex((existing) => existing.id === account.id);
|
|
1446
|
-
if (idx === -1) {
|
|
1447
|
-
state.autoramps.push(account);
|
|
1448
|
-
}
|
|
1449
|
-
else {
|
|
1450
|
-
state.autoramps[idx] = {
|
|
1451
|
-
...state.autoramps[idx],
|
|
1452
|
-
...account,
|
|
1453
|
-
};
|
|
1454
|
-
}
|
|
1455
|
-
});
|
|
1456
|
-
return (this.state.autoramps.find((existing) => existing.id === account.id) ??
|
|
1457
|
-
account);
|
|
1458
|
-
}
|
|
1459
|
-
/**
|
|
1460
|
-
* Creates an autoramp via the neo-bank proxy and applies the returned
|
|
1461
|
-
* snapshot as the local last-seen cursor.
|
|
1462
|
-
*
|
|
1463
|
-
* The vendor `customer_id` is resolved via
|
|
1464
|
-
* {@link RampsController.resolveAutorampCustomerId} and injected into the
|
|
1465
|
-
* request (any caller-supplied `customer_id` is overwritten).
|
|
1466
|
-
*
|
|
1467
|
-
* @param request - CreateAutoramp payload.
|
|
1468
|
-
* @param options - Optional idempotency key forwarded to the proxy.
|
|
1469
|
-
* @param options.idempotencyKey - Value sent as `Idempotency-Key`.
|
|
1470
|
-
* @returns The created/updated local {@link AutorampAccount}.
|
|
1471
|
-
*/
|
|
1472
|
-
async createAutoramp(request, options = {}) {
|
|
1473
|
-
const customerId = await this.resolveAutorampCustomerId();
|
|
1474
|
-
const body = { ...request, customer_id: customerId };
|
|
1475
|
-
const remote = await this.messenger.call('NeoBankService:createAutoramp', body, options);
|
|
1476
|
-
return __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_applyAutorampRemoteSnapshot).call(this, remote);
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* Resolves the vendor `customer_id` for autoramp / Money Account operations.
|
|
1480
|
-
*
|
|
1481
|
-
* Maps the wallet's Profile Sync id (the partner `external_id`) to the
|
|
1482
|
-
* vendor customer via `GET /neobank/customers/{external_id}/external`.
|
|
1483
|
-
*
|
|
1484
|
-
* @returns The vendor customer id.
|
|
1485
|
-
*/
|
|
1486
|
-
async resolveAutorampCustomerId() {
|
|
1487
|
-
const profile = await this.messenger.call('AuthenticationController:getSessionProfile');
|
|
1488
|
-
const canonical = profile?.canonicalProfileId;
|
|
1489
|
-
const externalId = typeof canonical === 'string' && canonical.length > 0
|
|
1490
|
-
? canonical
|
|
1491
|
-
: profile?.profileId;
|
|
1492
|
-
if (typeof externalId !== 'string' || externalId.length === 0) {
|
|
1493
|
-
throw new Error('Cannot resolve MoonPay customer id: wallet is not signed in to Profile Sync.');
|
|
1494
|
-
}
|
|
1495
|
-
const customer = await this.messenger.call('NeoBankService:getCustomerByExternalId', externalId);
|
|
1496
|
-
const customerId = customer &&
|
|
1497
|
-
typeof customer === 'object' &&
|
|
1498
|
-
typeof customer.id === 'string'
|
|
1499
|
-
? customer.id
|
|
1500
|
-
: null;
|
|
1501
|
-
if (!customerId) {
|
|
1502
|
-
throw new Error(`Cannot resolve MoonPay customer id: no MoonPay customer is mapped to external id "${externalId}".`);
|
|
1503
|
-
}
|
|
1504
|
-
return customerId;
|
|
1505
|
-
}
|
|
1506
|
-
/**
|
|
1507
|
-
* Registers a Money Account wallet with MoonPay Iron via neobank-proxy.
|
|
1508
|
-
*
|
|
1509
|
-
* @param params - Money Account wallet registration parameters.
|
|
1510
|
-
* @param params.address - Monad Money Account address.
|
|
1511
|
-
* @returns The registration state, or `{ type: 'lookupUnavailable' }` when
|
|
1512
|
-
* the address-list lookup fails (never treated as unregistered).
|
|
1513
|
-
*/
|
|
1514
|
-
async registerMoneyAccountWallet({ address, }) {
|
|
1515
|
-
let machine = (0, wallet_registration_machine_js_1.transition)((0, wallet_registration_machine_js_1.createInitialState)(), { type: 'START' });
|
|
1516
|
-
const toExistingResult = (status) => {
|
|
1517
|
-
if (status.type === 'active') {
|
|
1518
|
-
return { type: 'alreadyRegistered', registration: status.registration };
|
|
1519
|
-
}
|
|
1520
|
-
if (status.type === 'disabled') {
|
|
1521
|
-
return {
|
|
1522
|
-
type: 'registeredDisabled',
|
|
1523
|
-
registration: status.registration,
|
|
1524
|
-
};
|
|
1525
|
-
}
|
|
1526
|
-
return undefined;
|
|
1527
|
-
};
|
|
1528
|
-
const customerId = await this.resolveAutorampCustomerId();
|
|
1529
|
-
const toLookupUnavailableResult = (error) => {
|
|
1530
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, {
|
|
1531
|
-
type: 'LOOKUP_FAILED',
|
|
1532
|
-
});
|
|
1533
|
-
return {
|
|
1534
|
-
type: 'lookupUnavailable',
|
|
1535
|
-
error: error instanceof wallet_registration_service_js_1.WalletRegistrationError
|
|
1536
|
-
? error
|
|
1537
|
-
: new wallet_registration_service_js_1.WalletRegistrationError('lookupUnavailable', {
|
|
1538
|
-
message: 'self-hosted address lookup failed',
|
|
1539
|
-
body: error instanceof Error ? error.message : undefined,
|
|
1540
|
-
}),
|
|
1541
|
-
};
|
|
1542
|
-
};
|
|
1543
|
-
const lookup = async () => {
|
|
1544
|
-
try {
|
|
1545
|
-
return await this.messenger.call('NeoBankService:getWalletRegistrationStatus', { customerId, address });
|
|
1546
|
-
}
|
|
1547
|
-
catch (error) {
|
|
1548
|
-
return toLookupUnavailableResult(error);
|
|
1549
|
-
}
|
|
1550
|
-
};
|
|
1551
|
-
const applyLookup = (status) => {
|
|
1552
|
-
let eventType = 'LOOKUP_ABSENT';
|
|
1553
|
-
if (status.type === 'active') {
|
|
1554
|
-
eventType = 'LOOKUP_ACTIVE';
|
|
1555
|
-
}
|
|
1556
|
-
else if (status.type === 'disabled') {
|
|
1557
|
-
eventType = 'LOOKUP_DISABLED';
|
|
1558
|
-
}
|
|
1559
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, {
|
|
1560
|
-
type: eventType,
|
|
1561
|
-
});
|
|
1562
|
-
return toExistingResult(status);
|
|
1563
|
-
};
|
|
1564
|
-
const resolveLookup = async () => {
|
|
1565
|
-
const status = await lookup();
|
|
1566
|
-
if (status.type === 'lookupUnavailable') {
|
|
1567
|
-
return status;
|
|
1568
|
-
}
|
|
1569
|
-
return applyLookup(status);
|
|
1570
|
-
};
|
|
1571
|
-
const existingResult = await resolveLookup();
|
|
1572
|
-
if (existingResult) {
|
|
1573
|
-
return existingResult;
|
|
1574
|
-
}
|
|
1575
|
-
let idempotencyKey = (0, wallet_registration_service_js_1.createIdempotencyKey)();
|
|
1576
|
-
let lastMessage;
|
|
1577
|
-
while (true) {
|
|
1578
|
-
const message = (0, ownership_message_js_1.buildOwnershipMessage)({
|
|
1579
|
-
address,
|
|
1580
|
-
customerId,
|
|
1581
|
-
now: new Date(),
|
|
1582
|
-
});
|
|
1583
|
-
if (lastMessage !== undefined && message !== lastMessage) {
|
|
1584
|
-
idempotencyKey = (0, wallet_registration_service_js_1.createIdempotencyKey)();
|
|
1585
|
-
}
|
|
1586
|
-
lastMessage = message;
|
|
1587
|
-
let signature;
|
|
1588
|
-
try {
|
|
1589
|
-
signature = await this.messenger.call('KeyringController:signPersonalMessage', { data: message, from: address });
|
|
1590
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, { type: 'SIGN_OK' });
|
|
1591
|
-
}
|
|
1592
|
-
catch (error) {
|
|
1593
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, {
|
|
1594
|
-
type: 'SIGN_FAILED',
|
|
1595
|
-
retryable: false,
|
|
1596
|
-
});
|
|
1597
|
-
throw error;
|
|
1598
|
-
}
|
|
1599
|
-
try {
|
|
1600
|
-
const result = await this.messenger.call('NeoBankService:registerSelfHostedWallet', {
|
|
1601
|
-
address,
|
|
1602
|
-
customerId,
|
|
1603
|
-
message,
|
|
1604
|
-
signature,
|
|
1605
|
-
idempotencyKey,
|
|
1606
|
-
});
|
|
1607
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, { type: 'SUBMIT_OK' });
|
|
1608
|
-
return result;
|
|
1609
|
-
}
|
|
1610
|
-
catch (error) {
|
|
1611
|
-
if (!(error instanceof wallet_registration_service_js_1.WalletRegistrationError)) {
|
|
1612
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, {
|
|
1613
|
-
type: 'SUBMIT_TERMINAL',
|
|
1614
|
-
});
|
|
1615
|
-
throw error;
|
|
1616
|
-
}
|
|
1617
|
-
if (error.kind === 'conflict') {
|
|
1618
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, {
|
|
1619
|
-
type: 'SUBMIT_CONFLICT',
|
|
1620
|
-
});
|
|
1621
|
-
}
|
|
1622
|
-
else if (error.kind === 'transient') {
|
|
1623
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, {
|
|
1624
|
-
type: 'SUBMIT_TRANSIENT',
|
|
1625
|
-
});
|
|
1626
|
-
}
|
|
1627
|
-
else if (error.kind === 'validation') {
|
|
1628
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, {
|
|
1629
|
-
type: 'SUBMIT_VALIDATION',
|
|
1630
|
-
utcRollover: (0, ownership_message_js_1.buildOwnershipMessage)({
|
|
1631
|
-
address,
|
|
1632
|
-
customerId,
|
|
1633
|
-
now: new Date(),
|
|
1634
|
-
}) !== message,
|
|
1635
|
-
});
|
|
1636
|
-
}
|
|
1637
|
-
else if (error.kind === 'rateLimited') {
|
|
1638
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, {
|
|
1639
|
-
type: 'SUBMIT_RATE_LIMITED',
|
|
1640
|
-
});
|
|
1641
|
-
}
|
|
1642
|
-
else {
|
|
1643
|
-
machine = (0, wallet_registration_machine_js_1.transition)(machine, {
|
|
1644
|
-
type: 'SUBMIT_TERMINAL',
|
|
1645
|
-
});
|
|
1646
|
-
}
|
|
1647
|
-
if (machine.status === 'disambiguate409' ||
|
|
1648
|
-
machine.status === 'checkThenRetry') {
|
|
1649
|
-
const reconciledResult = await resolveLookup();
|
|
1650
|
-
if (reconciledResult) {
|
|
1651
|
-
return reconciledResult;
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
if (machine.status !== 'signing') {
|
|
1655
|
-
throw error;
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
/**
|
|
1661
|
-
* Removes a local autoramp last-seen cursor by id.
|
|
1662
|
-
*
|
|
1663
|
-
* @param autorampId - MoonPay autoramp id.
|
|
1664
|
-
*/
|
|
1665
|
-
removeAutoramp(autorampId) {
|
|
1666
|
-
this.update((state) => {
|
|
1667
|
-
state.autoramps = state.autoramps.filter((autoramp) => autoramp.id !== autorampId);
|
|
1668
|
-
});
|
|
1669
|
-
}
|
|
1670
|
-
/**
|
|
1671
|
-
* Marks that the UI has already notified for the autoramp's current status.
|
|
1672
|
-
*
|
|
1673
|
-
* @param autorampId - MoonPay autoramp id.
|
|
1674
|
-
*/
|
|
1675
|
-
markAutorampAsNotified(autorampId) {
|
|
1676
|
-
const existing = this.state.autoramps.find((autoramp) => autoramp.id === autorampId);
|
|
1677
|
-
if (!existing) {
|
|
1678
|
-
return;
|
|
1679
|
-
}
|
|
1680
|
-
const notified = (0, autorampAccount_js_1.markAutorampNotified)(existing);
|
|
1681
|
-
this.update((state) => {
|
|
1682
|
-
const idx = state.autoramps.findIndex((autoramp) => autoramp.id === autorampId);
|
|
1683
|
-
if (idx !== -1) {
|
|
1684
|
-
state.autoramps[idx] = notified;
|
|
1685
|
-
}
|
|
1686
|
-
});
|
|
1687
|
-
}
|
|
1688
|
-
/**
|
|
1689
|
-
* Applies a remote autoramp snapshot from a websocket / webhook push.
|
|
1690
|
-
*
|
|
1691
|
-
* @param remote - Remote autoramp snapshot.
|
|
1692
|
-
* @returns The updated local account.
|
|
1693
|
-
*/
|
|
1694
|
-
applyAutorampStatusFromPush(remote) {
|
|
1695
|
-
return __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_applyAutorampRemoteSnapshot).call(this, remote);
|
|
1696
|
-
}
|
|
1697
|
-
/**
|
|
1698
|
-
* Fetches one autoramp from the neo-bank proxy and applies it to the
|
|
1699
|
-
* last-seen cursor. Does not recreate a cursor that was removed while the
|
|
1700
|
-
* request was in flight.
|
|
1701
|
-
*
|
|
1702
|
-
* @param autorampId - MoonPay autoramp id.
|
|
1703
|
-
* @returns The updated local account, or an unpersisted snapshot if the
|
|
1704
|
-
* cursor was removed during the fetch.
|
|
1705
|
-
*/
|
|
1706
|
-
async refreshAutoramp(autorampId) {
|
|
1707
|
-
const remote = await this.messenger.call('NeoBankService:getAutoramp', autorampId);
|
|
1708
|
-
return __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_applyAutorampRemoteSnapshot).call(this, remote, { allowInsert: false });
|
|
1709
|
-
}
|
|
1710
|
-
/**
|
|
1711
|
-
* Refreshes all known local autoramps from MoonPay.
|
|
1712
|
-
* Intended for app resume / unlock catch-up when webhooks were missed.
|
|
1713
|
-
*
|
|
1714
|
-
* @returns Updated autoramp accounts (failed fetches are skipped).
|
|
1715
|
-
*/
|
|
1716
|
-
async refreshAutoramps() {
|
|
1717
|
-
const ids = this.state.autoramps.map((autoramp) => autoramp.id);
|
|
1718
|
-
const updated = [];
|
|
1719
|
-
for (const id of ids) {
|
|
1720
|
-
try {
|
|
1721
|
-
const account = await this.refreshAutoramp(id);
|
|
1722
|
-
if (this.state.autoramps.some((autoramp) => autoramp.id === account.id)) {
|
|
1723
|
-
updated.push(account);
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
catch {
|
|
1727
|
-
// Keep local cursor for this id; continue remaining refreshes.
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
return updated;
|
|
1731
|
-
}
|
|
1732
|
-
/**
|
|
1733
|
-
* Starts polling all pending V2 orders at a fixed interval.
|
|
1734
|
-
* Each poll cycle iterates orders with non-terminal statuses,
|
|
1735
|
-
* respects pollingSecondsMinimum and backoff from error count.
|
|
1736
|
-
*/
|
|
1737
|
-
startOrderPolling() {
|
|
1738
|
-
if (__classPrivateFieldGet(this, _RampsController_orderPollingTimer, "f")) {
|
|
1739
|
-
return;
|
|
1740
|
-
}
|
|
1741
|
-
__classPrivateFieldSet(this, _RampsController_orderPollingTimer, setInterval(() => {
|
|
1742
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_pollPendingOrders).call(this).catch(() => undefined);
|
|
1743
|
-
}, DEFAULT_POLLING_INTERVAL_MS), "f");
|
|
1744
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_pollPendingOrders).call(this).catch(() => undefined);
|
|
1745
|
-
}
|
|
1746
|
-
/**
|
|
1747
|
-
* Stops order polling and clears the interval.
|
|
1748
|
-
*/
|
|
1749
|
-
stopOrderPolling() {
|
|
1750
|
-
if (__classPrivateFieldGet(this, _RampsController_orderPollingTimer, "f")) {
|
|
1751
|
-
clearInterval(__classPrivateFieldGet(this, _RampsController_orderPollingTimer, "f"));
|
|
1752
|
-
__classPrivateFieldSet(this, _RampsController_orderPollingTimer, null, "f");
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
/**
|
|
1756
|
-
* Cleans up controller resources.
|
|
1757
|
-
* Should be called when the controller is no longer needed.
|
|
1758
|
-
*/
|
|
1759
|
-
destroy() {
|
|
1760
|
-
this.stopOrderPolling();
|
|
1761
|
-
super.destroy();
|
|
1762
|
-
}
|
|
1763
|
-
/**
|
|
1764
|
-
* Fetches the widget data from a quote for redirect providers.
|
|
1765
|
-
* Makes a request to the buyURL endpoint via the RampsService to get the
|
|
1766
|
-
* actual provider widget URL and optional order ID for polling.
|
|
1767
|
-
*
|
|
1768
|
-
* @param quote - The quote to fetch the widget URL from.
|
|
1769
|
-
* @returns Promise resolving to the full BuyWidget (url, browser, orderId), or null if not available (missing buyURL or empty url in response).
|
|
1770
|
-
* @throws Rethrows errors from the RampsService (e.g. HttpError, network failures) so clients can react to fetch failures.
|
|
1771
|
-
*/
|
|
1772
|
-
async getBuyWidgetData(quote) {
|
|
1773
|
-
const buyUrl = quote.quote?.buyURL;
|
|
1774
|
-
if (!buyUrl) {
|
|
1775
|
-
return null;
|
|
1776
|
-
}
|
|
1777
|
-
const buyWidget = await this.messenger.call('RampsService:getBuyWidgetUrl', buyUrl);
|
|
1778
|
-
if (!buyWidget?.url) {
|
|
1779
|
-
return null;
|
|
1780
|
-
}
|
|
1781
|
-
return buyWidget;
|
|
1782
|
-
}
|
|
1783
|
-
/**
|
|
1784
|
-
* Registers an order ID for polling until the order is created or resolved.
|
|
1785
|
-
* Adds a minimal stub order to controller state; the existing order polling
|
|
1786
|
-
* will fetch the full order when the provider has created it.
|
|
1787
|
-
*
|
|
1788
|
-
* @param params - Object containing order identifiers and wallet info.
|
|
1789
|
-
* @param params.orderId - Full order ID (e.g. "/providers/paypal/orders/abc123") or order code.
|
|
1790
|
-
* @param params.providerCode - Canonical provider code (e.g. "paypal", "transak").
|
|
1791
|
-
* @param params.walletAddress - Wallet address for the order.
|
|
1792
|
-
* @param params.chainId - Chain ID for the order (decimal, hex, or CAIP-2). Must be non-empty.
|
|
1793
|
-
*/
|
|
1794
|
-
addPrecreatedOrder(params) {
|
|
1795
|
-
const { orderId, providerCode, walletAddress, chainId } = params;
|
|
1796
|
-
const orderCode = getInternalOrderCode(orderId);
|
|
1797
|
-
if (!orderCode?.trim()) {
|
|
1798
|
-
return;
|
|
1799
|
-
}
|
|
1800
|
-
if (!chainId.trim()) {
|
|
1801
|
-
return;
|
|
1802
|
-
}
|
|
1803
|
-
const stubOrder = {
|
|
1804
|
-
providerOrderId: orderCode,
|
|
1805
|
-
provider: {
|
|
1806
|
-
id: providerCode,
|
|
1807
|
-
name: '',
|
|
1808
|
-
environmentType: '',
|
|
1809
|
-
description: '',
|
|
1810
|
-
hqAddress: '',
|
|
1811
|
-
links: [],
|
|
1812
|
-
logos: { light: '', dark: '', height: 0, width: 0 },
|
|
1813
|
-
},
|
|
1814
|
-
walletAddress,
|
|
1815
|
-
status: RampsService_js_1.RampsOrderStatus.Precreated,
|
|
1816
|
-
orderType: 'buy',
|
|
1817
|
-
createdAt: Date.now(),
|
|
1818
|
-
isOnlyLink: false,
|
|
1819
|
-
success: false,
|
|
1820
|
-
cryptoAmount: 0,
|
|
1821
|
-
fiatAmount: 0,
|
|
1822
|
-
providerOrderLink: '',
|
|
1823
|
-
totalFeesFiat: 0,
|
|
1824
|
-
txHash: '',
|
|
1825
|
-
network: { chainId, name: '' },
|
|
1826
|
-
canBeUpdated: true,
|
|
1827
|
-
idHasExpired: false,
|
|
1828
|
-
excludeFromPurchases: false,
|
|
1829
|
-
timeDescriptionPending: '',
|
|
1830
|
-
};
|
|
1831
|
-
this.addOrder(stubOrder);
|
|
1832
|
-
}
|
|
1833
|
-
/**
|
|
1834
|
-
* Fetches an order from the unified V2 API endpoint.
|
|
1835
|
-
* Returns a normalized RampsOrder for all provider types (aggregator and native).
|
|
1836
|
-
*
|
|
1837
|
-
* @param providerCode - The provider code (e.g., "transak", "transak-native", "moonpay").
|
|
1838
|
-
* @param orderCode - The order identifier.
|
|
1839
|
-
* @param wallet - The wallet address associated with the order.
|
|
1840
|
-
* @returns The unified order data.
|
|
1841
|
-
*/
|
|
1842
|
-
async getOrder(providerCode, orderCode, wallet) {
|
|
1843
|
-
const order = await this.messenger.call('RampsService:getOrder', providerCode, orderCode, wallet);
|
|
1844
|
-
const healedWalletAddress = order.walletAddress || wallet;
|
|
1845
|
-
const internalOrderCode = getInternalOrderCode({
|
|
1846
|
-
id: order.id,
|
|
1847
|
-
providerOrderId: orderCode,
|
|
1848
|
-
});
|
|
1849
|
-
const healedOrder = {
|
|
1850
|
-
...order,
|
|
1851
|
-
walletAddress: healedWalletAddress,
|
|
1852
|
-
providerOrderId: internalOrderCode,
|
|
1853
|
-
};
|
|
1854
|
-
this.update((state) => {
|
|
1855
|
-
const idx = state.orders.findIndex((existing) => getInternalOrderCode(existing) === internalOrderCode);
|
|
1856
|
-
if (idx === -1) {
|
|
1857
|
-
state.orders.push(healedOrder);
|
|
1858
|
-
}
|
|
1859
|
-
else {
|
|
1860
|
-
state.orders[idx] = {
|
|
1861
|
-
...state.orders[idx],
|
|
1862
|
-
...healedOrder,
|
|
1863
|
-
};
|
|
1864
|
-
}
|
|
1865
|
-
});
|
|
1866
|
-
return healedOrder;
|
|
1867
|
-
}
|
|
1868
|
-
/**
|
|
1869
|
-
* Extracts an order from a provider callback URL.
|
|
1870
|
-
* Sends the callback URL to the V2 backend for provider-specific parsing,
|
|
1871
|
-
* then fetches the full order. This is the V2 equivalent of the aggregator
|
|
1872
|
-
* SDK's `getOrderFromCallback`.
|
|
1873
|
-
*
|
|
1874
|
-
* @param providerCode - The provider code (e.g., "transak", "moonpay").
|
|
1875
|
-
* @param callbackUrl - The full callback URL the provider redirected to.
|
|
1876
|
-
* @param wallet - The wallet address associated with the order.
|
|
1877
|
-
* @returns The unified order data.
|
|
1878
|
-
*/
|
|
1879
|
-
async getOrderFromCallback(providerCode, callbackUrl, wallet) {
|
|
1880
|
-
const order = await this.messenger.call('RampsService:getOrderFromCallback', providerCode, callbackUrl, wallet);
|
|
1881
|
-
return order;
|
|
1882
|
-
}
|
|
1883
|
-
/**
|
|
1884
|
-
* Sets the Transak API key used for all Transak API requests.
|
|
1885
|
-
*
|
|
1886
|
-
* @param apiKey - The Transak API key.
|
|
1887
|
-
*/
|
|
1888
|
-
transakSetApiKey(apiKey) {
|
|
1889
|
-
this.messenger.call('TransakService:setApiKey', apiKey);
|
|
1890
|
-
}
|
|
1891
|
-
/**
|
|
1892
|
-
* Sets the Transak access token and marks the user as authenticated.
|
|
1893
|
-
*
|
|
1894
|
-
* @param token - The access token received from Transak auth.
|
|
1895
|
-
*/
|
|
1896
|
-
transakSetAccessToken(token) {
|
|
1897
|
-
this.messenger.call('TransakService:setAccessToken', token);
|
|
1898
|
-
this.transakSetAuthenticated(true);
|
|
1899
|
-
}
|
|
1900
|
-
/**
|
|
1901
|
-
* Clears the Transak access token and marks the user as unauthenticated.
|
|
1902
|
-
*/
|
|
1903
|
-
transakClearAccessToken() {
|
|
1904
|
-
this.messenger.call('TransakService:clearAccessToken');
|
|
1905
|
-
this.transakSetAuthenticated(false);
|
|
1906
|
-
}
|
|
1907
|
-
/**
|
|
1908
|
-
* Updates the Transak authentication flag in controller state.
|
|
1909
|
-
*
|
|
1910
|
-
* @param isAuthenticated - Whether the user is authenticated with Transak.
|
|
1911
|
-
*/
|
|
1912
|
-
transakSetAuthenticated(isAuthenticated) {
|
|
1913
|
-
this.update((state) => {
|
|
1914
|
-
state.nativeProviders.transak.isAuthenticated = isAuthenticated;
|
|
1915
|
-
});
|
|
1916
|
-
}
|
|
1917
|
-
/**
|
|
1918
|
-
* Resets all Transak state back to defaults (unauthenticated, no data).
|
|
1919
|
-
*/
|
|
1920
|
-
transakResetState() {
|
|
1921
|
-
this.messenger.call('TransakService:clearAccessToken');
|
|
1922
|
-
this.update((state) => {
|
|
1923
|
-
state.nativeProviders.transak =
|
|
1924
|
-
getDefaultRampsControllerState().nativeProviders.transak;
|
|
1925
|
-
});
|
|
1926
|
-
}
|
|
1927
|
-
/**
|
|
1928
|
-
* Sends a one-time password to the user's email for Transak authentication.
|
|
1929
|
-
*
|
|
1930
|
-
* @param email - The user's email address.
|
|
1931
|
-
* @returns The OTP response containing a state token for verification.
|
|
1932
|
-
*/
|
|
1933
|
-
async transakSendUserOtp(email) {
|
|
1934
|
-
try {
|
|
1935
|
-
return await this.messenger.call('TransakService:sendUserOtp', email);
|
|
1936
|
-
}
|
|
1937
|
-
catch (error) {
|
|
1938
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error).normalizedError;
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
/**
|
|
1942
|
-
* Verifies a one-time password and authenticates the user with Transak.
|
|
1943
|
-
* Updates the controller's authentication state on success.
|
|
1944
|
-
*
|
|
1945
|
-
* @param email - The user's email address.
|
|
1946
|
-
* @param verificationCode - The OTP code entered by the user.
|
|
1947
|
-
* @param stateToken - The state token from the sendUserOtp response.
|
|
1948
|
-
* @returns The access token for subsequent authenticated requests.
|
|
1949
|
-
*/
|
|
1950
|
-
async transakVerifyUserOtp(email, verificationCode, stateToken) {
|
|
1951
|
-
try {
|
|
1952
|
-
const token = await this.messenger.call('TransakService:verifyUserOtp', email, verificationCode, stateToken);
|
|
1953
|
-
this.transakSetAuthenticated(true);
|
|
1954
|
-
return token;
|
|
1955
|
-
}
|
|
1956
|
-
catch (error) {
|
|
1957
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error).normalizedError;
|
|
1958
|
-
}
|
|
1959
|
-
}
|
|
1960
|
-
/**
|
|
1961
|
-
* Logs the user out of Transak. Clears authentication state and user details
|
|
1962
|
-
* regardless of whether the API call succeeds or fails.
|
|
1963
|
-
*
|
|
1964
|
-
* @returns A message indicating the logout result.
|
|
1965
|
-
*/
|
|
1966
|
-
async transakLogout() {
|
|
1967
|
-
try {
|
|
1968
|
-
return await this.messenger.call('TransakService:logout');
|
|
1969
|
-
}
|
|
1970
|
-
catch (error) {
|
|
1971
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error).normalizedError;
|
|
1972
|
-
}
|
|
1973
|
-
finally {
|
|
1974
|
-
this.transakClearAccessToken();
|
|
1975
|
-
this.update((state) => {
|
|
1976
|
-
state.nativeProviders.transak.userDetails.data = null;
|
|
1977
|
-
});
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
/**
|
|
1981
|
-
* Fetches the authenticated user's details from Transak.
|
|
1982
|
-
* Updates the userDetails resource state with loading/success/error states.
|
|
1983
|
-
*
|
|
1984
|
-
* @returns The user's profile and KYC details.
|
|
1985
|
-
*/
|
|
1986
|
-
async transakGetUserDetails() {
|
|
1987
|
-
this.update((state) => {
|
|
1988
|
-
state.nativeProviders.transak.userDetails.isLoading = true;
|
|
1989
|
-
state.nativeProviders.transak.userDetails.error = null;
|
|
1990
|
-
delete state.nativeProviders.transak.userDetails.errorKey;
|
|
1991
|
-
});
|
|
1992
|
-
try {
|
|
1993
|
-
const details = await this.messenger.call('TransakService:getUserDetails');
|
|
1994
|
-
this.update((state) => {
|
|
1995
|
-
state.nativeProviders.transak.userDetails.data = details;
|
|
1996
|
-
state.nativeProviders.transak.userDetails.isLoading = false;
|
|
1997
|
-
});
|
|
1998
|
-
return details;
|
|
1999
|
-
}
|
|
2000
|
-
catch (error) {
|
|
2001
|
-
const { errorInfo, normalizedError } = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, {
|
|
2002
|
-
syncAuth: true,
|
|
2003
|
-
});
|
|
2004
|
-
this.update((state) => {
|
|
2005
|
-
state.nativeProviders.transak.userDetails.isLoading = false;
|
|
2006
|
-
state.nativeProviders.transak.userDetails.error = errorInfo.message;
|
|
2007
|
-
state.nativeProviders.transak.userDetails.errorKey = errorInfo.errorKey;
|
|
2008
|
-
});
|
|
2009
|
-
throw normalizedError;
|
|
2010
|
-
}
|
|
2011
|
-
}
|
|
2012
|
-
/**
|
|
2013
|
-
* Fetches a buy quote from Transak for the given parameters.
|
|
2014
|
-
* Updates the buyQuote resource state with loading/success/error states.
|
|
2015
|
-
*
|
|
2016
|
-
* @param fiatCurrency - The fiat currency code (e.g., "USD").
|
|
2017
|
-
* @param cryptoCurrency - The cryptocurrency identifier.
|
|
2018
|
-
* @param network - The blockchain network identifier.
|
|
2019
|
-
* @param paymentMethod - The payment method identifier.
|
|
2020
|
-
* @param fiatAmount - The fiat amount as a string.
|
|
2021
|
-
* @returns The buy quote with pricing and fee details.
|
|
2022
|
-
*/
|
|
2023
|
-
async transakGetBuyQuote(fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount) {
|
|
2024
|
-
this.update((state) => {
|
|
2025
|
-
state.nativeProviders.transak.buyQuote.isLoading = true;
|
|
2026
|
-
state.nativeProviders.transak.buyQuote.error = null;
|
|
2027
|
-
delete state.nativeProviders.transak.buyQuote.errorKey;
|
|
2028
|
-
});
|
|
2029
|
-
try {
|
|
2030
|
-
const quote = await this.messenger.call('TransakService:getBuyQuote', fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount);
|
|
2031
|
-
this.update((state) => {
|
|
2032
|
-
state.nativeProviders.transak.buyQuote.data = quote;
|
|
2033
|
-
state.nativeProviders.transak.buyQuote.isLoading = false;
|
|
2034
|
-
});
|
|
2035
|
-
return quote;
|
|
2036
|
-
}
|
|
2037
|
-
catch (error) {
|
|
2038
|
-
const { errorInfo, normalizedError } = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error);
|
|
2039
|
-
this.update((state) => {
|
|
2040
|
-
state.nativeProviders.transak.buyQuote.isLoading = false;
|
|
2041
|
-
state.nativeProviders.transak.buyQuote.error = errorInfo.message;
|
|
2042
|
-
state.nativeProviders.transak.buyQuote.errorKey = errorInfo.errorKey;
|
|
2043
|
-
});
|
|
2044
|
-
throw normalizedError;
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
/**
|
|
2048
|
-
* Fetches the KYC requirement for a given quote.
|
|
2049
|
-
* Updates the kycRequirement resource state with loading/success/error states.
|
|
2050
|
-
*
|
|
2051
|
-
* @param quoteId - The quote ID to check KYC requirements for.
|
|
2052
|
-
* @returns The KYC requirement status and whether the user can place an order.
|
|
2053
|
-
*/
|
|
2054
|
-
async transakGetKycRequirement(quoteId) {
|
|
2055
|
-
this.update((state) => {
|
|
2056
|
-
state.nativeProviders.transak.kycRequirement.isLoading = true;
|
|
2057
|
-
state.nativeProviders.transak.kycRequirement.error = null;
|
|
2058
|
-
delete state.nativeProviders.transak.kycRequirement.errorKey;
|
|
2059
|
-
});
|
|
2060
|
-
try {
|
|
2061
|
-
const requirement = await this.messenger.call('TransakService:getKycRequirement', quoteId);
|
|
2062
|
-
this.update((state) => {
|
|
2063
|
-
state.nativeProviders.transak.kycRequirement.data = requirement;
|
|
2064
|
-
state.nativeProviders.transak.kycRequirement.isLoading = false;
|
|
2065
|
-
});
|
|
2066
|
-
return requirement;
|
|
2067
|
-
}
|
|
2068
|
-
catch (error) {
|
|
2069
|
-
const { errorInfo, normalizedError } = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, {
|
|
2070
|
-
syncAuth: true,
|
|
2071
|
-
});
|
|
2072
|
-
this.update((state) => {
|
|
2073
|
-
state.nativeProviders.transak.kycRequirement.isLoading = false;
|
|
2074
|
-
state.nativeProviders.transak.kycRequirement.error = errorInfo.message;
|
|
2075
|
-
state.nativeProviders.transak.kycRequirement.errorKey =
|
|
2076
|
-
errorInfo.errorKey;
|
|
2077
|
-
});
|
|
2078
|
-
throw normalizedError;
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
/**
|
|
2082
|
-
* Fetches additional KYC requirements (e.g., ID proof, address proof) for a quote.
|
|
2083
|
-
*
|
|
2084
|
-
* @param quoteId - The quote ID to check additional requirements for.
|
|
2085
|
-
* @returns The list of additional forms required.
|
|
2086
|
-
*/
|
|
2087
|
-
async transakGetAdditionalRequirements(quoteId) {
|
|
2088
|
-
try {
|
|
2089
|
-
return await this.messenger.call('TransakService:getAdditionalRequirements', quoteId);
|
|
2090
|
-
}
|
|
2091
|
-
catch (error) {
|
|
2092
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2093
|
-
.normalizedError;
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2096
|
-
/**
|
|
2097
|
-
* Creates a new order on Transak. If an existing order conflicts (HTTP 409),
|
|
2098
|
-
* active orders are cancelled and the creation is retried.
|
|
2099
|
-
*
|
|
2100
|
-
* @param quoteId - The quote ID to create an order from.
|
|
2101
|
-
* @param walletAddress - The destination wallet address.
|
|
2102
|
-
* @param paymentMethodId - The payment method to use.
|
|
2103
|
-
* @returns The created deposit order.
|
|
2104
|
-
*/
|
|
2105
|
-
async transakCreateOrder(quoteId, walletAddress, paymentMethodId) {
|
|
2106
|
-
try {
|
|
2107
|
-
return await this.messenger.call('TransakService:createOrder', quoteId, walletAddress, paymentMethodId);
|
|
2108
|
-
}
|
|
2109
|
-
catch (error) {
|
|
2110
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2111
|
-
.normalizedError;
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
/**
|
|
2115
|
-
* Fetches an existing order from Transak by order ID.
|
|
2116
|
-
*
|
|
2117
|
-
* @param orderId - The order ID (deposit format or raw Transak format).
|
|
2118
|
-
* @param wallet - The wallet address associated with the order.
|
|
2119
|
-
* @param paymentDetails - Optional payment details to attach to the order.
|
|
2120
|
-
* @returns The deposit order details.
|
|
2121
|
-
*/
|
|
2122
|
-
async transakGetOrder(orderId, wallet, paymentDetails) {
|
|
2123
|
-
try {
|
|
2124
|
-
return await this.messenger.call('TransakService:getOrder', orderId, wallet, paymentDetails);
|
|
2125
|
-
}
|
|
2126
|
-
catch (error) {
|
|
2127
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error).normalizedError;
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
/**
|
|
2131
|
-
* Fetches the user's spending limits for a given currency and payment method.
|
|
2132
|
-
*
|
|
2133
|
-
* @param fiatCurrency - The fiat currency code.
|
|
2134
|
-
* @param paymentMethod - The payment method identifier.
|
|
2135
|
-
* @param kycType - The KYC level type.
|
|
2136
|
-
* @returns The user's limits, spending, and remaining amounts.
|
|
2137
|
-
*/
|
|
2138
|
-
async transakGetUserLimits(fiatCurrency, paymentMethod, kycType) {
|
|
2139
|
-
try {
|
|
2140
|
-
return await this.messenger.call('TransakService:getUserLimits', fiatCurrency, paymentMethod, kycType);
|
|
2141
|
-
}
|
|
2142
|
-
catch (error) {
|
|
2143
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2144
|
-
.normalizedError;
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
/**
|
|
2148
|
-
* Requests a one-time token (OTT) for the Transak payment widget.
|
|
2149
|
-
*
|
|
2150
|
-
* @returns The OTT response containing the token.
|
|
2151
|
-
*/
|
|
2152
|
-
async transakRequestOtt() {
|
|
2153
|
-
try {
|
|
2154
|
-
return await this.messenger.call('TransakService:requestOtt');
|
|
2155
|
-
}
|
|
2156
|
-
catch (error) {
|
|
2157
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2158
|
-
.normalizedError;
|
|
2159
|
-
}
|
|
2160
|
-
}
|
|
2161
|
-
/**
|
|
2162
|
-
* Generates a URL for the Transak payment widget with pre-filled parameters.
|
|
2163
|
-
*
|
|
2164
|
-
* @param ottToken - The one-time token for widget authentication.
|
|
2165
|
-
* @param quote - The buy quote to pre-fill in the widget.
|
|
2166
|
-
* @param walletAddress - The destination wallet address.
|
|
2167
|
-
* @param extraParams - Optional additional URL parameters.
|
|
2168
|
-
* @returns The fully constructed widget URL string.
|
|
2169
|
-
*/
|
|
2170
|
-
transakGeneratePaymentWidgetUrl(ottToken, quote, walletAddress, extraParams) {
|
|
2171
|
-
return this.messenger.call('TransakService:generatePaymentWidgetUrl', ottToken, quote, walletAddress, extraParams);
|
|
2172
|
-
}
|
|
2173
|
-
/**
|
|
2174
|
-
* Creates a Transak payment widget URL via the ramps API proxy, which
|
|
2175
|
-
* injects the partner API key server-side. Replaces the OTT flow
|
|
2176
|
-
* ({@link transakRequestOtt} + {@link transakGeneratePaymentWidgetUrl}).
|
|
2177
|
-
*
|
|
2178
|
-
* @param quote - The buy quote to pre-fill in the widget.
|
|
2179
|
-
* @param walletAddress - The destination wallet address.
|
|
2180
|
-
* @param extraParams - Optional additional widget parameters (e.g. theming).
|
|
2181
|
-
* @returns The single-use widget URL.
|
|
2182
|
-
*/
|
|
2183
|
-
async transakCreateWidgetUrl(quote, walletAddress, extraParams) {
|
|
2184
|
-
try {
|
|
2185
|
-
return await this.messenger.call('TransakService:createWidgetUrl', quote, walletAddress, extraParams);
|
|
2186
|
-
}
|
|
2187
|
-
catch (error) {
|
|
2188
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2189
|
-
.normalizedError;
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
/**
|
|
2193
|
-
* Submits the user's purpose of usage form for KYC compliance.
|
|
2194
|
-
*
|
|
2195
|
-
* @param purpose - Array of purpose strings selected by the user.
|
|
2196
|
-
* @returns A promise that resolves when the form is submitted.
|
|
2197
|
-
*/
|
|
2198
|
-
async transakSubmitPurposeOfUsageForm(purpose) {
|
|
2199
|
-
try {
|
|
2200
|
-
return await this.messenger.call('TransakService:submitPurposeOfUsageForm', purpose);
|
|
2201
|
-
}
|
|
2202
|
-
catch (error) {
|
|
2203
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2204
|
-
.normalizedError;
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
/**
|
|
2208
|
-
* Updates the user's personal or address details on Transak.
|
|
2209
|
-
*
|
|
2210
|
-
* @param data - The user data fields to update.
|
|
2211
|
-
* @returns The API response data.
|
|
2212
|
-
*/
|
|
2213
|
-
async transakPatchUser(data) {
|
|
2214
|
-
try {
|
|
2215
|
-
return await this.messenger.call('TransakService:patchUser', data);
|
|
2216
|
-
}
|
|
2217
|
-
catch (error) {
|
|
2218
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2219
|
-
.normalizedError;
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
/**
|
|
2223
|
-
* Submits the user's SSN for identity verification.
|
|
2224
|
-
*
|
|
2225
|
-
* @param ssn - The Social Security Number.
|
|
2226
|
-
* @param quoteId - The quote ID associated with the order requiring SSN.
|
|
2227
|
-
* @returns The API response data.
|
|
2228
|
-
*/
|
|
2229
|
-
async transakSubmitSsnDetails(ssn, quoteId) {
|
|
2230
|
-
try {
|
|
2231
|
-
return await this.messenger.call('TransakService:submitSsnDetails', ssn, quoteId);
|
|
2232
|
-
}
|
|
2233
|
-
catch (error) {
|
|
2234
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2235
|
-
.normalizedError;
|
|
2236
|
-
}
|
|
2237
|
-
}
|
|
2238
|
-
/**
|
|
2239
|
-
* Confirms payment for an order after the user has completed payment.
|
|
2240
|
-
*
|
|
2241
|
-
* @param orderId - The order ID to confirm payment for.
|
|
2242
|
-
* @param paymentMethodId - The payment method used.
|
|
2243
|
-
* @returns Whether the payment confirmation was successful.
|
|
2244
|
-
*/
|
|
2245
|
-
async transakConfirmPayment(orderId, paymentMethodId) {
|
|
2246
|
-
try {
|
|
2247
|
-
return await this.messenger.call('TransakService:confirmPayment', orderId, paymentMethodId);
|
|
2248
|
-
}
|
|
2249
|
-
catch (error) {
|
|
2250
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2251
|
-
.normalizedError;
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
/**
|
|
2255
|
-
* Translates generic ramps identifiers to Transak-specific identifiers.
|
|
2256
|
-
*
|
|
2257
|
-
* @param request - The translation request with optional identifiers to translate.
|
|
2258
|
-
* @returns The translated Transak-specific identifiers.
|
|
2259
|
-
*/
|
|
2260
|
-
async transakGetTranslation(request) {
|
|
2261
|
-
try {
|
|
2262
|
-
return await this.messenger.call('TransakService:getTranslation', request);
|
|
2263
|
-
}
|
|
2264
|
-
catch (error) {
|
|
2265
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error).normalizedError;
|
|
2266
|
-
}
|
|
2267
|
-
}
|
|
2268
|
-
/**
|
|
2269
|
-
* Checks the status of an ID proof submission for KYC.
|
|
2270
|
-
*
|
|
2271
|
-
* @param workFlowRunId - The workflow run ID to check status for.
|
|
2272
|
-
* @returns The current ID proof status.
|
|
2273
|
-
*/
|
|
2274
|
-
async transakGetIdProofStatus(workFlowRunId) {
|
|
2275
|
-
try {
|
|
2276
|
-
return await this.messenger.call('TransakService:getIdProofStatus', workFlowRunId);
|
|
2277
|
-
}
|
|
2278
|
-
catch (error) {
|
|
2279
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2280
|
-
.normalizedError;
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
/**
|
|
2284
|
-
* Cancels a specific Transak order.
|
|
2285
|
-
*
|
|
2286
|
-
* @param depositOrderId - The deposit order ID to cancel.
|
|
2287
|
-
* @returns A promise that resolves when the order is cancelled.
|
|
2288
|
-
*/
|
|
2289
|
-
async transakCancelOrder(depositOrderId) {
|
|
2290
|
-
try {
|
|
2291
|
-
return await this.messenger.call('TransakService:cancelOrder', depositOrderId);
|
|
2292
|
-
}
|
|
2293
|
-
catch (error) {
|
|
2294
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2295
|
-
.normalizedError;
|
|
2296
|
-
}
|
|
2297
|
-
}
|
|
2298
|
-
/**
|
|
2299
|
-
* Cancels all active Transak orders. Individual cancellation failures
|
|
2300
|
-
* are collected and returned rather than thrown.
|
|
2301
|
-
*
|
|
2302
|
-
* @returns An array of errors from any failed cancellations (empty if all succeeded).
|
|
2303
|
-
*/
|
|
2304
|
-
async transakCancelAllActiveOrders() {
|
|
2305
|
-
try {
|
|
2306
|
-
return await this.messenger.call('TransakService:cancelAllActiveOrders');
|
|
2307
|
-
}
|
|
2308
|
-
catch (error) {
|
|
2309
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2310
|
-
.normalizedError;
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
/**
|
|
2314
|
-
* Fetches all active Transak orders for the authenticated user.
|
|
2315
|
-
*
|
|
2316
|
-
* @returns The list of active orders.
|
|
2317
|
-
*/
|
|
2318
|
-
async transakGetActiveOrders() {
|
|
2319
|
-
try {
|
|
2320
|
-
return await this.messenger.call('TransakService:getActiveOrders');
|
|
2321
|
-
}
|
|
2322
|
-
catch (error) {
|
|
2323
|
-
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
2324
|
-
.normalizedError;
|
|
2325
|
-
}
|
|
2326
|
-
}
|
|
2327
|
-
}
|
|
2328
|
-
exports.RampsController = RampsController;
|
|
2329
|
-
_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() {
|
|
2330
|
-
for (const resourceType of DEPENDENT_RESOURCE_KEYS) {
|
|
2331
|
-
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
2332
|
-
const generation = __classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").get(resourceType) ?? 0;
|
|
2333
|
-
__classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").set(resourceType, generation + 1);
|
|
2334
|
-
}
|
|
2335
|
-
}, _RampsController_abortDependentRequests = function _RampsController_abortDependentRequests() {
|
|
2336
|
-
for (const [cacheKey, pending] of __classPrivateFieldGet(this, _RampsController_pendingRequests, "f").entries()) {
|
|
2337
|
-
if (pending.resourceType &&
|
|
2338
|
-
DEPENDENT_RESOURCE_KEYS_SET.has(pending.resourceType)) {
|
|
2339
|
-
pending.abortController.abort();
|
|
2340
|
-
__classPrivateFieldGet(this, _RampsController_pendingRequests, "f").delete(cacheKey);
|
|
2341
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_removeRequestState).call(this, cacheKey);
|
|
2342
|
-
}
|
|
2343
|
-
}
|
|
2344
|
-
}, _RampsController_resolveAllProvidersFlag = function _RampsController_resolveAllProvidersFlag() {
|
|
2345
|
-
try {
|
|
2346
|
-
const remoteFeatureFlagState = this.messenger.call('RemoteFeatureFlagController:getState');
|
|
2347
|
-
return {
|
|
2348
|
-
enabled: (0, featureFlags_js_1.isHeadlessAllProvidersEnabled)(remoteFeatureFlagState),
|
|
2349
|
-
allowlist: (0, featureFlags_js_1.getHeadlessProviderAllowlist)(remoteFeatureFlagState),
|
|
2350
|
-
};
|
|
2351
|
-
}
|
|
2352
|
-
catch {
|
|
2353
|
-
return { enabled: false };
|
|
2354
|
-
}
|
|
2355
|
-
}, _RampsController_mutateRequests = function _RampsController_mutateRequests(fn) {
|
|
2356
|
-
this.update((state) => {
|
|
2357
|
-
const requests = state.requests;
|
|
2358
|
-
fn(requests);
|
|
2359
|
-
});
|
|
2360
|
-
}, _RampsController_removeRequestState = function _RampsController_removeRequestState(cacheKey) {
|
|
2361
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_mutateRequests).call(this, (requests) => {
|
|
2362
|
-
delete requests[cacheKey];
|
|
2363
|
-
});
|
|
2364
|
-
}, _RampsController_cleanupState = function _RampsController_cleanupState() {
|
|
2365
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_abortDependentRequests).call(this);
|
|
2366
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_clearPendingResourceCountForDependentResources).call(this);
|
|
2367
|
-
this.update((state) => resetDependentResources(state, { clearUserRegionData: true }));
|
|
2368
|
-
}, _RampsController_requireRegion = function _RampsController_requireRegion() {
|
|
2369
|
-
const regionCode = this.state.userRegion?.regionCode;
|
|
2370
|
-
if (!regionCode) {
|
|
2371
|
-
throw new Error('Region is required. Cannot proceed without valid region information.');
|
|
2372
|
-
}
|
|
2373
|
-
return regionCode;
|
|
2374
|
-
}, _RampsController_isRegionCurrent = function _RampsController_isRegionCurrent(normalizedRegion) {
|
|
2375
|
-
const current = this.state.userRegion?.regionCode;
|
|
2376
|
-
return current === undefined || current === normalizedRegion;
|
|
2377
|
-
}, _RampsController_isTokenCurrent = function _RampsController_isTokenCurrent(normalizedAssetId) {
|
|
2378
|
-
const current = this.state.tokens.selected?.assetId ?? '';
|
|
2379
|
-
return current === normalizedAssetId;
|
|
2380
|
-
}, _RampsController_isProviderCurrent = function _RampsController_isProviderCurrent(normalizedProviderId) {
|
|
2381
|
-
const current = this.state.providers.selected?.id ?? '';
|
|
2382
|
-
return current === normalizedProviderId;
|
|
2383
|
-
}, _RampsController_updateResourceField = function _RampsController_updateResourceField(resourceType, field, value) {
|
|
2384
|
-
this.update((state) => {
|
|
2385
|
-
const resource = getResourceState(state, resourceType);
|
|
2386
|
-
resource[field] = value;
|
|
2387
|
-
});
|
|
2388
|
-
}, _RampsController_setResourceLoading = function _RampsController_setResourceLoading(resourceType, loading) {
|
|
2389
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateResourceField).call(this, resourceType, 'isLoading', loading);
|
|
2390
|
-
}, _RampsController_setResourceError = function _RampsController_setResourceError(resourceType, errorInfo) {
|
|
2391
|
-
this.update((state) => {
|
|
2392
|
-
const resource = getResourceState(state, resourceType);
|
|
2393
|
-
resource.error = errorInfo?.message ?? null;
|
|
2394
|
-
resource.errorKey = errorInfo?.errorKey ?? null;
|
|
2395
|
-
});
|
|
2396
|
-
}, _RampsController_updateRequestState = function _RampsController_updateRequestState(cacheKey, requestState) {
|
|
2397
|
-
const maxSize = __classPrivateFieldGet(this, _RampsController_requestCacheMaxSize, "f");
|
|
2398
|
-
const ttl = __classPrivateFieldGet(this, _RampsController_requestCacheTTL, "f");
|
|
2399
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_mutateRequests).call(this, (requests) => {
|
|
2400
|
-
requests[cacheKey] = requestState;
|
|
2401
|
-
const keys = Object.keys(requests);
|
|
2402
|
-
for (const key of keys) {
|
|
2403
|
-
const entry = requests[key];
|
|
2404
|
-
if (entry?.status === RequestCache_js_1.RequestStatus.SUCCESS &&
|
|
2405
|
-
(0, RequestCache_js_1.isCacheExpired)(entry, ttl)) {
|
|
2406
|
-
delete requests[key];
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
const remainingKeys = Object.keys(requests);
|
|
2410
|
-
if (remainingKeys.length > maxSize) {
|
|
2411
|
-
const sortedKeys = remainingKeys.sort((a, b) => {
|
|
2412
|
-
const aTime = requests[a]?.timestamp ?? 0;
|
|
2413
|
-
const bTime = requests[b]?.timestamp ?? 0;
|
|
2414
|
-
return aTime - bTime;
|
|
2415
|
-
});
|
|
2416
|
-
const entriesToRemove = remainingKeys.length - maxSize;
|
|
2417
|
-
for (let i = 0; i < entriesToRemove; i++) {
|
|
2418
|
-
const keyToRemove = sortedKeys[i];
|
|
2419
|
-
if (keyToRemove) {
|
|
2420
|
-
delete requests[keyToRemove];
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
}
|
|
2424
|
-
});
|
|
2425
|
-
}, _RampsController_runInit = async function _RampsController_runInit(options) {
|
|
2426
|
-
// Force-refetch the catalog on startup so region preset amounts stay
|
|
2427
|
-
// current, bypassing the in-session request cache. The catalog is not
|
|
2428
|
-
// persisted, so a cold start always re-fetches it regardless.
|
|
2429
|
-
await this.getCountries({ ...options, forceRefresh: true });
|
|
2430
|
-
// Always prefer the user's persisted region. Geolocation is only used to
|
|
2431
|
-
// seed the initial value; once the user (or a prior init) has set a region
|
|
2432
|
-
// we must respect that choice — even on forceRefresh.
|
|
2433
|
-
const persistedRegionCode = this.state.userRegion?.regionCode;
|
|
2434
|
-
const regionCode = persistedRegionCode ??
|
|
2435
|
-
(await this.messenger.call('RampsService:getGeolocation'));
|
|
2436
|
-
if (!regionCode) {
|
|
2437
|
-
throw new Error('Failed to fetch geolocation. Cannot initialize controller without valid region information.');
|
|
2438
|
-
}
|
|
2439
|
-
// For an already-persisted region, getCountries() has already re-synced it
|
|
2440
|
-
// from the fresh catalog (see #syncUserRegionFromCountriesCatalog). Calling
|
|
2441
|
-
// setUserRegion here would re-validate against that catalog and, if it is
|
|
2442
|
-
// momentarily empty or no longer lists the region (e.g. a transient/partial
|
|
2443
|
-
// catalog response or a region with no current provider coverage), throw and
|
|
2444
|
-
// wipe the persisted region via #cleanupState. Preserve the existing region
|
|
2445
|
-
// instead; only resolve a brand-new region (from geolocation) strictly.
|
|
2446
|
-
if (persistedRegionCode) {
|
|
2447
|
-
return;
|
|
2448
|
-
}
|
|
2449
|
-
await this.setUserRegion(regionCode, options);
|
|
2450
|
-
}, _RampsController_syncUserRegionFromCountriesCatalog = function _RampsController_syncUserRegionFromCountriesCatalog() {
|
|
2451
|
-
const regionCode = this.state.userRegion?.regionCode;
|
|
2452
|
-
if (!regionCode) {
|
|
2453
|
-
return;
|
|
2454
|
-
}
|
|
2455
|
-
const countriesData = this.state.countries.data;
|
|
2456
|
-
if (!countriesData.length) {
|
|
2457
|
-
return;
|
|
2458
|
-
}
|
|
2459
|
-
const userRegion = findRegionFromCode(regionCode, countriesData);
|
|
2460
|
-
if (!userRegion) {
|
|
2461
|
-
return;
|
|
2462
|
-
}
|
|
2463
|
-
this.update((state) => {
|
|
2464
|
-
state.userRegion = userRegion;
|
|
2465
|
-
});
|
|
2466
|
-
}, _RampsController_pickWidenedQuote = function _RampsController_pickWidenedQuote(response, { amount, fiat, providers, allowlist, }) {
|
|
2467
|
-
const providerByCode = new Map(providers.map((provider) => [provider.id, provider]));
|
|
2468
|
-
const allowedProviderIds = allowlist && allowlist.length > 0
|
|
2469
|
-
? new Set(allowlist.map(featureFlags_js_1.normalizeHeadlessProviderId))
|
|
2470
|
-
: undefined;
|
|
2471
|
-
const isAllowedProvider = (quote) => !allowedProviderIds ||
|
|
2472
|
-
allowedProviderIds.has((0, featureFlags_js_1.normalizeHeadlessProviderId)(quote.provider));
|
|
2473
|
-
const fitsProviderLimits = (quote) => {
|
|
2474
|
-
const provider = providerByCode.get(quote.provider);
|
|
2475
|
-
const limit = provider?.limits?.fiat?.[fiat]?.[quote.quote.paymentMethod];
|
|
2476
|
-
if (!limit) {
|
|
2477
|
-
// No published limits for this provider/payment method: treat as
|
|
2478
|
-
// eligible and let the provider enforce limits at checkout.
|
|
2479
|
-
return true;
|
|
2480
|
-
}
|
|
2481
|
-
return amount >= limit.minAmount && amount <= limit.maxAmount;
|
|
2482
|
-
};
|
|
2483
|
-
const candidates = response.success.filter((quote) => isAllowedProvider(quote) && fitsProviderLimits(quote));
|
|
2484
|
-
if (candidates.length === 0) {
|
|
2485
|
-
return undefined;
|
|
2486
|
-
}
|
|
2487
|
-
const candidateByCode = new Map(candidates.map((quote) => [quote.provider, quote]));
|
|
2488
|
-
const pickBySortOrder = (sortBy) => {
|
|
2489
|
-
const order = response.sorted.find((entry) => entry.sortBy === sortBy)?.ids;
|
|
2490
|
-
if (!order) {
|
|
2491
|
-
return undefined;
|
|
2492
|
-
}
|
|
2493
|
-
for (const providerId of order) {
|
|
2494
|
-
const match = candidateByCode.get(providerId);
|
|
2495
|
-
if (match) {
|
|
2496
|
-
return match;
|
|
2497
|
-
}
|
|
2498
|
-
}
|
|
2499
|
-
return undefined;
|
|
2500
|
-
};
|
|
2501
|
-
// Reliability first, then price, then the first surviving candidate.
|
|
2502
|
-
return (pickBySortOrder('reliability') ??
|
|
2503
|
-
pickBySortOrder('price') ??
|
|
2504
|
-
candidates[0]);
|
|
2505
|
-
}, _RampsController_getSupportingProvidersForRegion =
|
|
2506
|
-
/**
|
|
2507
|
-
* Returns the region's providers that support the given asset, plus the full
|
|
2508
|
-
* region provider list. Uses cached providers only when the request targets
|
|
2509
|
-
* the current region; otherwise fetches for the requested region, since
|
|
2510
|
-
* `getProviders` does not persist results for a non-current region. Does not
|
|
2511
|
-
* mutate state.
|
|
2512
|
-
*
|
|
2513
|
-
* @param options - The options.
|
|
2514
|
-
* @param options.assetId - CAIP-19 asset type identifier to resolve for.
|
|
2515
|
-
* @param options.region - Region to resolve providers for.
|
|
2516
|
-
* @returns The supporting providers and the full region provider list.
|
|
2517
|
-
*/
|
|
2518
|
-
async function _RampsController_getSupportingProvidersForRegion({ assetId, region, }) {
|
|
2519
|
-
const normalizedRegion = region.toLowerCase().trim();
|
|
2520
|
-
let providers;
|
|
2521
|
-
if (__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isRegionCurrent).call(this, normalizedRegion) &&
|
|
2522
|
-
this.state.providers.data.length > 0) {
|
|
2523
|
-
providers = this.state.providers.data;
|
|
2524
|
-
}
|
|
2525
|
-
else {
|
|
2526
|
-
({ providers } = await this.getProviders(normalizedRegion));
|
|
2527
|
-
}
|
|
2528
|
-
// Case-insensitive CAIP-19 matching is shared with headless-buy consumers
|
|
2529
|
-
// via `getProvidersServingAsset`, so the controller and the UI region gate
|
|
2530
|
-
// cannot disagree about which providers serve the asset.
|
|
2531
|
-
const supporting = (0, providerAvailability_js_1.getProvidersServingAsset)(providers, assetId);
|
|
2532
|
-
return { supporting, all: providers };
|
|
2533
|
-
}, _RampsController_filterProviderIdsBySupport =
|
|
2534
|
-
/**
|
|
2535
|
-
* Filters an explicitly-requested provider ID list down to those that support
|
|
2536
|
-
* the asset in the region. Used for headless-buy gating so an explicitly
|
|
2537
|
-
* passed provider that cannot serve the region/asset yields no providers
|
|
2538
|
-
* rather than being trusted blindly.
|
|
2539
|
-
*
|
|
2540
|
-
* @param options - The options.
|
|
2541
|
-
* @param options.providerIds - Explicitly requested provider IDs.
|
|
2542
|
-
* @param options.assetId - CAIP-19 asset type identifier to resolve for.
|
|
2543
|
-
* @param options.region - Region to resolve providers for.
|
|
2544
|
-
* @returns The subset of `providerIds` supporting the asset in the region.
|
|
2545
|
-
*/
|
|
2546
|
-
async function _RampsController_filterProviderIdsBySupport({ providerIds, assetId, region, }) {
|
|
2547
|
-
const { supporting } = await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getSupportingProvidersForRegion).call(this, {
|
|
2548
|
-
assetId,
|
|
2549
|
-
region,
|
|
2550
|
-
});
|
|
2551
|
-
const supportingIds = new Set(supporting.map((provider) => provider.id));
|
|
2552
|
-
return providerIds.filter((id) => supportingIds.has(id));
|
|
2553
|
-
}, _RampsController_resolveProviderIdsForQuote =
|
|
2554
|
-
/**
|
|
2555
|
-
* Resolves the provider IDs to use for a single quote request, scoped to the
|
|
2556
|
-
* given asset and region. Does not mutate `providers.selected` or any other
|
|
2557
|
-
* state.
|
|
2558
|
-
*
|
|
2559
|
-
* Resolves against the region's supporting providers using this precedence:
|
|
2560
|
-
* 1. The currently selected provider, if it is in the supporting set.
|
|
2561
|
-
* 2. The first preferred provider that supports the asset, where the
|
|
2562
|
-
* preference is taken from `preferredProviderIds` when supplied, otherwise
|
|
2563
|
-
* derived from the user's completed-order history (most recent first).
|
|
2564
|
-
* This takes priority over Transak Native to preserve an existing KYC
|
|
2565
|
-
* relationship.
|
|
2566
|
-
* 3. A native provider (e.g. Transak Native).
|
|
2567
|
-
* 4. The first supporting provider — unless `restrictToKnownOrNative` is set, in
|
|
2568
|
-
* which case no further provider is introduced and nothing is returned.
|
|
2569
|
-
*
|
|
2570
|
-
* When `restrictToKnownOrNative` is unset and no provider supports the asset, falls
|
|
2571
|
-
* back to all known provider IDs so the request behaves as if no
|
|
2572
|
-
* auto-selection occurred.
|
|
2573
|
-
*
|
|
2574
|
-
* @param options - The options.
|
|
2575
|
-
* @param options.assetId - CAIP-19 asset type identifier to resolve for.
|
|
2576
|
-
* @param options.region - Region to resolve providers for.
|
|
2577
|
-
* @param options.preferredProviderIds - Provider IDs to prefer, in order.
|
|
2578
|
-
* @param options.restrictToKnownOrNative - When true, resolve only a native provider
|
|
2579
|
-
* (or no providers when none supports the asset).
|
|
2580
|
-
* @returns Provider IDs for this request only.
|
|
2581
|
-
*/
|
|
2582
|
-
async function _RampsController_resolveProviderIdsForQuote({ assetId, region, preferredProviderIds, restrictToKnownOrNative, }) {
|
|
2583
|
-
const { supporting, all } = await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getSupportingProvidersForRegion).call(this, {
|
|
2584
|
-
assetId,
|
|
2585
|
-
region,
|
|
2586
|
-
});
|
|
2587
|
-
// When not restricted and nothing supports the asset, behave as if no
|
|
2588
|
-
// auto-selection occurred (quote against all known providers).
|
|
2589
|
-
if (!restrictToKnownOrNative && supporting.length === 0) {
|
|
2590
|
-
return all.map((provider) => provider.id);
|
|
2591
|
-
}
|
|
2592
|
-
// 1. The currently selected provider, if it supports the asset.
|
|
2593
|
-
const { selected } = this.state.providers;
|
|
2594
|
-
if (selected &&
|
|
2595
|
-
supporting.some((provider) => provider.id === selected.id)) {
|
|
2596
|
-
return [selected.id];
|
|
2597
|
-
}
|
|
2598
|
-
// 2. A provider the user has transacted with before — from
|
|
2599
|
-
// `preferredProviderIds` when supplied, otherwise completed-order
|
|
2600
|
-
// history. Takes priority over Transak Native to preserve an existing
|
|
2601
|
-
// KYC relationship and avoid churn.
|
|
2602
|
-
const preferred = preferredProviderIds ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getPreferredProviderIdsFromOrders).call(this);
|
|
2603
|
-
for (const preferredId of preferred) {
|
|
2604
|
-
const match = supporting.find((provider) => provider.id === preferredId);
|
|
2605
|
-
if (match) {
|
|
2606
|
-
return [match.id];
|
|
2607
|
-
}
|
|
2608
|
-
}
|
|
2609
|
-
// 3. A native provider (e.g. Transak Native).
|
|
2610
|
-
const nativeProvider = supporting.find((provider) => provider.type === 'native');
|
|
2611
|
-
if (nativeProvider) {
|
|
2612
|
-
return [nativeProvider.id];
|
|
2613
|
-
}
|
|
2614
|
-
// 4. Fallback. Under headless gating, introduce no other provider — return
|
|
2615
|
-
// nothing so the caller surfaces an "unavailable" state. Otherwise the
|
|
2616
|
-
// aggregator and all other providers are treated equally: first wins.
|
|
2617
|
-
if (restrictToKnownOrNative) {
|
|
2618
|
-
return [];
|
|
2619
|
-
}
|
|
2620
|
-
return [supporting[0].id];
|
|
2621
|
-
}, _RampsController_resolveProviderIdsForPaymentMethods =
|
|
2622
|
-
/**
|
|
2623
|
-
* Resolves provider IDs that should contribute payment methods for a
|
|
2624
|
-
* quoting context. Mirrors {@link getQuotes} provider-set selection, with
|
|
2625
|
-
* one intentional difference on the widened path: when the all-providers
|
|
2626
|
-
* flag allowlist is non-empty, returns supporting providers intersected
|
|
2627
|
-
* with that allowlist (pick survivors for the picker). Does not mutate
|
|
2628
|
-
* state.
|
|
2629
|
-
*
|
|
2630
|
-
* @param options - Resolution inputs aligned with `getQuotes`.
|
|
2631
|
-
* @param options.assetId - CAIP-19 asset type identifier to resolve for.
|
|
2632
|
-
* @param options.region - Region to resolve providers for.
|
|
2633
|
-
* @param options.providers - Explicit provider IDs, when provided.
|
|
2634
|
-
* @param options.autoSelectProvider - Resolve providers like `getQuotes`.
|
|
2635
|
-
* @param options.preferredProviderIds - Preferred provider IDs in order.
|
|
2636
|
-
* @param options.restrictToKnownOrNativeProviders - Headless gating.
|
|
2637
|
-
* @returns Provider IDs for this request only.
|
|
2638
|
-
*/
|
|
2639
|
-
async function _RampsController_resolveProviderIdsForPaymentMethods({ assetId, region, providers, autoSelectProvider, preferredProviderIds, restrictToKnownOrNativeProviders, }) {
|
|
2640
|
-
const wantsAutoSelection = !providers &&
|
|
2641
|
-
(autoSelectProvider === true ||
|
|
2642
|
-
restrictToKnownOrNativeProviders === true);
|
|
2643
|
-
const { enabled: allProvidersEnabled, allowlist: providerAllowlist } = wantsAutoSelection
|
|
2644
|
-
? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_resolveAllProvidersFlag).call(this)
|
|
2645
|
-
: { enabled: false, allowlist: undefined };
|
|
2646
|
-
const widenToAllProviders = wantsAutoSelection && allProvidersEnabled;
|
|
2647
|
-
if (providers) {
|
|
2648
|
-
return restrictToKnownOrNativeProviders
|
|
2649
|
-
? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_filterProviderIdsBySupport).call(this, {
|
|
2650
|
-
providerIds: providers,
|
|
2651
|
-
assetId,
|
|
2652
|
-
region,
|
|
2653
|
-
})
|
|
2654
|
-
: providers;
|
|
2655
|
-
}
|
|
2656
|
-
if (widenToAllProviders) {
|
|
2657
|
-
const { supporting } = await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getSupportingProvidersForRegion).call(this, {
|
|
2658
|
-
assetId,
|
|
2659
|
-
region,
|
|
2660
|
-
});
|
|
2661
|
-
if (providerAllowlist && providerAllowlist.length > 0) {
|
|
2662
|
-
const allowedProviderIds = new Set(providerAllowlist.map(featureFlags_js_1.normalizeHeadlessProviderId));
|
|
2663
|
-
return supporting
|
|
2664
|
-
.filter((provider) => allowedProviderIds.has((0, featureFlags_js_1.normalizeHeadlessProviderId)(provider.id)))
|
|
2665
|
-
.map((provider) => provider.id);
|
|
2666
|
-
}
|
|
2667
|
-
return supporting.map((provider) => provider.id);
|
|
2668
|
-
}
|
|
2669
|
-
if (autoSelectProvider || restrictToKnownOrNativeProviders) {
|
|
2670
|
-
return __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_resolveProviderIdsForQuote).call(this, {
|
|
2671
|
-
assetId,
|
|
2672
|
-
region,
|
|
2673
|
-
preferredProviderIds,
|
|
2674
|
-
restrictToKnownOrNative: restrictToKnownOrNativeProviders,
|
|
2675
|
-
});
|
|
2676
|
-
}
|
|
2677
|
-
const selectedId = this.state.providers.selected?.id;
|
|
2678
|
-
return selectedId ? [selectedId] : [];
|
|
2679
|
-
}, _RampsController_getPreferredProviderIdsFromOrders = function _RampsController_getPreferredProviderIdsFromOrders() {
|
|
2680
|
-
const orderedIds = [];
|
|
2681
|
-
const completedOrders = this.state.orders
|
|
2682
|
-
.filter((order) => order.status === RampsService_js_1.RampsOrderStatus.Completed && order.provider?.id)
|
|
2683
|
-
.sort((orderA, orderB) => orderB.createdAt - orderA.createdAt);
|
|
2684
|
-
for (const order of completedOrders) {
|
|
2685
|
-
const id = order.provider?.id;
|
|
2686
|
-
if (id && !orderedIds.includes(id)) {
|
|
2687
|
-
orderedIds.push(id);
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
|
-
return orderedIds;
|
|
2691
|
-
}, _RampsController_applyAutorampRemoteSnapshot = function _RampsController_applyAutorampRemoteSnapshot(remote, { allowInsert = true } = {}) {
|
|
2692
|
-
const local = this.state.autoramps.find((autoramp) => autoramp.id === remote.id) ??
|
|
2693
|
-
null;
|
|
2694
|
-
if (local === null && !allowInsert) {
|
|
2695
|
-
return (0, autorampAccount_js_1.applyAutorampRemoteStatus)(null, remote).account;
|
|
2696
|
-
}
|
|
2697
|
-
const result = (0, autorampAccount_js_1.applyAutorampRemoteStatus)(local, remote);
|
|
2698
|
-
this.update((state) => {
|
|
2699
|
-
const idx = state.autoramps.findIndex((autoramp) => autoramp.id === result.account.id);
|
|
2700
|
-
if (idx === -1) {
|
|
2701
|
-
state.autoramps.push(result.account);
|
|
2702
|
-
}
|
|
2703
|
-
else {
|
|
2704
|
-
state.autoramps[idx] = result.account;
|
|
2705
|
-
}
|
|
2706
|
-
});
|
|
2707
|
-
if (result.statusChanged) {
|
|
2708
|
-
this.messenger.publish('RampsController:autorampStatusChanged', {
|
|
2709
|
-
autoramp: result.account,
|
|
2710
|
-
previousStatus: result.previousStatus,
|
|
2711
|
-
shouldNotify: result.shouldNotify,
|
|
2712
|
-
});
|
|
2713
|
-
}
|
|
2714
|
-
return (this.state.autoramps.find((autoramp) => autoramp.id === result.account.id) ?? result.account);
|
|
2715
|
-
}, _RampsController_refreshOrder =
|
|
2716
|
-
/**
|
|
2717
|
-
* Refreshes a single order via the V2 API and updates it in state.
|
|
2718
|
-
* Publishes orderStatusChanged if the status transitioned.
|
|
2719
|
-
*
|
|
2720
|
-
* @param order - The order to refresh (needs provider and providerOrderId).
|
|
2721
|
-
*/
|
|
2722
|
-
async function _RampsController_refreshOrder(order) {
|
|
2723
|
-
const providerCode = order.provider?.id ?? '';
|
|
2724
|
-
if (!providerCode || !order.providerOrderId || !order.walletAddress) {
|
|
2725
|
-
return;
|
|
2726
|
-
}
|
|
2727
|
-
const previousStatus = order.status;
|
|
2728
|
-
try {
|
|
2729
|
-
const updatedOrder = await this.getOrder(providerCode, order.providerOrderId, order.walletAddress);
|
|
2730
|
-
const meta = __classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").get(order.providerOrderId) ?? {
|
|
2731
|
-
lastTimeFetched: 0,
|
|
2732
|
-
errorCount: 0,
|
|
2733
|
-
};
|
|
2734
|
-
if (updatedOrder.status === RampsService_js_1.RampsOrderStatus.Unknown) {
|
|
2735
|
-
meta.errorCount = Math.min(meta.errorCount + 1, MAX_ERROR_COUNT);
|
|
2736
|
-
}
|
|
2737
|
-
else {
|
|
2738
|
-
meta.errorCount = 0;
|
|
2739
|
-
}
|
|
2740
|
-
meta.lastTimeFetched = Date.now();
|
|
2741
|
-
__classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").set(order.providerOrderId, meta);
|
|
2742
|
-
if (previousStatus !== updatedOrder.status &&
|
|
2743
|
-
previousStatus !== undefined) {
|
|
2744
|
-
this.messenger.publish('RampsController:orderStatusChanged', {
|
|
2745
|
-
order: updatedOrder,
|
|
2746
|
-
previousStatus,
|
|
2747
|
-
});
|
|
2748
|
-
}
|
|
2749
|
-
if (orderStatus_js_1.TERMINAL_ORDER_STATUSES.has(updatedOrder.status)) {
|
|
2750
|
-
__classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").delete(order.providerOrderId);
|
|
2751
|
-
}
|
|
2752
|
-
}
|
|
2753
|
-
catch {
|
|
2754
|
-
const meta = __classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").get(order.providerOrderId) ?? {
|
|
2755
|
-
lastTimeFetched: 0,
|
|
2756
|
-
errorCount: 0,
|
|
2757
|
-
};
|
|
2758
|
-
meta.errorCount = Math.min(meta.errorCount + 1, MAX_ERROR_COUNT);
|
|
2759
|
-
meta.lastTimeFetched = Date.now();
|
|
2760
|
-
__classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").set(order.providerOrderId, meta);
|
|
2761
|
-
}
|
|
2762
|
-
}, _RampsController_pollPendingOrders = async function _RampsController_pollPendingOrders() {
|
|
2763
|
-
if (__classPrivateFieldGet(this, _RampsController_isPolling, "f")) {
|
|
2764
|
-
return;
|
|
2765
|
-
}
|
|
2766
|
-
__classPrivateFieldSet(this, _RampsController_isPolling, true, "f");
|
|
2767
|
-
try {
|
|
2768
|
-
const pendingOrders = this.state.orders.filter((order) => orderStatus_js_1.PENDING_ORDER_STATUSES.has(order.status));
|
|
2769
|
-
const now = Date.now();
|
|
2770
|
-
await Promise.allSettled(pendingOrders.map(async (order) => {
|
|
2771
|
-
const meta = __classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").get(order.providerOrderId);
|
|
2772
|
-
if (meta) {
|
|
2773
|
-
const backoffMs = meta.errorCount > 0
|
|
2774
|
-
? Math.min(DEFAULT_POLLING_INTERVAL_MS *
|
|
2775
|
-
Math.pow(2, meta.errorCount - 1), 5 * 60 * 1000)
|
|
2776
|
-
: 0;
|
|
2777
|
-
const pollingMinMs = (order.pollingSecondsMinimum ?? 0) * 1000;
|
|
2778
|
-
const minWait = Math.max(backoffMs, pollingMinMs);
|
|
2779
|
-
if (now - meta.lastTimeFetched < minWait) {
|
|
2780
|
-
return;
|
|
2781
|
-
}
|
|
2782
|
-
}
|
|
2783
|
-
await __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_refreshOrder).call(this, order);
|
|
2784
|
-
}));
|
|
2785
|
-
}
|
|
2786
|
-
finally {
|
|
2787
|
-
__classPrivateFieldSet(this, _RampsController_isPolling, false, "f");
|
|
2788
|
-
}
|
|
2789
|
-
}, _RampsController_syncTransakAuthOnError = function _RampsController_syncTransakAuthOnError(error) {
|
|
2790
|
-
if (hasHttpStatus(error) && error.httpStatus === 401) {
|
|
2791
|
-
this.transakSetAuthenticated(false);
|
|
2792
|
-
}
|
|
2793
|
-
}, _RampsController_getNormalizedTransakError = function _RampsController_getNormalizedTransakError(error, options = {}) {
|
|
2794
|
-
if (options.syncAuth) {
|
|
2795
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
2796
|
-
}
|
|
2797
|
-
return getNormalizedRampsError(error);
|
|
2798
|
-
};
|
|
2799
|
-
//# sourceMappingURL=RampsController.cjs.map
|