@metamask/ramps-controller 17.0.0 → 17.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -1
- package/dist/RampsController-method-action-types.cjs.map +1 -1
- package/dist/RampsController-method-action-types.d.cts +15 -1
- package/dist/RampsController-method-action-types.d.cts.map +1 -1
- package/dist/RampsController-method-action-types.d.mts +15 -1
- package/dist/RampsController-method-action-types.d.mts.map +1 -1
- package/dist/RampsController-method-action-types.mjs.map +1 -1
- package/dist/RampsController.cjs +53 -32
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +14 -3
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +14 -3
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +21 -0
- package/dist/RampsController.mjs.map +1 -1
- package/dist/RampsService-method-action-types.cjs.map +1 -1
- package/dist/RampsService-method-action-types.d.cts.map +1 -1
- package/dist/RampsService-method-action-types.d.mts.map +1 -1
- package/dist/RampsService-method-action-types.mjs.map +1 -1
- package/dist/RampsService.cjs.map +1 -1
- package/dist/RampsService.d.cts.map +1 -1
- package/dist/RampsService.d.mts.map +1 -1
- package/dist/RampsService.mjs.map +1 -1
- package/dist/RequestCache.cjs.map +1 -1
- package/dist/RequestCache.d.cts.map +1 -1
- package/dist/RequestCache.d.mts.map +1 -1
- package/dist/RequestCache.mjs.map +1 -1
- package/dist/TransakService-method-action-types.cjs.map +1 -1
- package/dist/TransakService-method-action-types.d.cts +35 -1
- package/dist/TransakService-method-action-types.d.cts.map +1 -1
- package/dist/TransakService-method-action-types.d.mts +35 -1
- package/dist/TransakService-method-action-types.d.mts.map +1 -1
- package/dist/TransakService-method-action-types.mjs.map +1 -1
- package/dist/TransakService.cjs +128 -12
- package/dist/TransakService.cjs.map +1 -1
- package/dist/TransakService.d.cts +41 -3
- package/dist/TransakService.d.cts.map +1 -1
- package/dist/TransakService.d.mts +41 -3
- package/dist/TransakService.d.mts.map +1 -1
- package/dist/TransakService.mjs +123 -10
- package/dist/TransakService.mjs.map +1 -1
- package/dist/index.cjs +48 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providerAvailability.cjs.map +1 -1
- package/dist/providerAvailability.d.cts.map +1 -1
- package/dist/providerAvailability.d.mts.map +1 -1
- package/dist/providerAvailability.mjs.map +1 -1
- package/dist/quoteClassification.cjs.map +1 -1
- package/dist/quoteClassification.d.cts.map +1 -1
- package/dist/quoteClassification.d.mts.map +1 -1
- package/dist/quoteClassification.mjs.map +1 -1
- package/dist/selectors.cjs +3 -3
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs.map +1 -1
- package/dist/transakApiErrorUtils.cjs +5 -5
- package/dist/transakApiErrorUtils.cjs.map +1 -1
- package/dist/transakApiErrorUtils.mjs.map +1 -1
- package/package.json +8 -6
package/dist/RampsController.cjs
CHANGED
|
@@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.RampsController = exports.getInternalOrderCode = exports.getDefaultRampsControllerState = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.controllerName = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
17
17
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
18
|
+
const featureFlags_js_1 = require("./featureFlags.cjs");
|
|
19
|
+
const providerAvailability_js_1 = require("./providerAvailability.cjs");
|
|
20
|
+
const rampsErrorCodes_js_1 = require("./rampsErrorCodes.cjs");
|
|
21
|
+
const RampsService_js_1 = require("./RampsService.cjs");
|
|
22
|
+
const RequestCache_js_1 = require("./RequestCache.cjs");
|
|
23
23
|
// === GENERAL ===
|
|
24
24
|
/**
|
|
25
25
|
* The name of the {@link RampsController}, used to namespace the
|
|
@@ -57,6 +57,7 @@ exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = [
|
|
|
57
57
|
'TransakService:getUserLimits',
|
|
58
58
|
'TransakService:requestOtt',
|
|
59
59
|
'TransakService:generatePaymentWidgetUrl',
|
|
60
|
+
'TransakService:createWidgetUrl',
|
|
60
61
|
'TransakService:submitPurposeOfUsageForm',
|
|
61
62
|
'TransakService:patchUser',
|
|
62
63
|
'TransakService:submitSsnDetails',
|
|
@@ -85,7 +86,7 @@ function hasHttpStatus(error) {
|
|
|
85
86
|
function getRampsErrorInfo(error) {
|
|
86
87
|
if (error instanceof controller_utils_1.BrokenCircuitError && hasStringMessage(error)) {
|
|
87
88
|
return {
|
|
88
|
-
errorKey:
|
|
89
|
+
errorKey: rampsErrorCodes_js_1.RAMPS_ERROR_CODES.CIRCUIT_BREAKER_OPEN,
|
|
89
90
|
message: error.message,
|
|
90
91
|
};
|
|
91
92
|
}
|
|
@@ -98,7 +99,7 @@ function getRampsErrorInfo(error) {
|
|
|
98
99
|
}
|
|
99
100
|
if (rawMessage?.includes(CIRCUIT_BREAKER_OPEN_ERROR)) {
|
|
100
101
|
return {
|
|
101
|
-
errorKey:
|
|
102
|
+
errorKey: rampsErrorCodes_js_1.RAMPS_ERROR_CODES.CIRCUIT_BREAKER_OPEN,
|
|
102
103
|
message: rawMessage,
|
|
103
104
|
};
|
|
104
105
|
}
|
|
@@ -354,16 +355,16 @@ function getInternalOrderCode(orderOrId) {
|
|
|
354
355
|
exports.getInternalOrderCode = getInternalOrderCode;
|
|
355
356
|
// === ORDER POLLING CONSTANTS ===
|
|
356
357
|
const TERMINAL_ORDER_STATUSES = new Set([
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
358
|
+
RampsService_js_1.RampsOrderStatus.Completed,
|
|
359
|
+
RampsService_js_1.RampsOrderStatus.Failed,
|
|
360
|
+
RampsService_js_1.RampsOrderStatus.Cancelled,
|
|
361
|
+
RampsService_js_1.RampsOrderStatus.IdExpired,
|
|
361
362
|
]);
|
|
362
363
|
const PENDING_ORDER_STATUSES = new Set([
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
364
|
+
RampsService_js_1.RampsOrderStatus.Pending,
|
|
365
|
+
RampsService_js_1.RampsOrderStatus.Created,
|
|
366
|
+
RampsService_js_1.RampsOrderStatus.Unknown,
|
|
367
|
+
RampsService_js_1.RampsOrderStatus.Precreated,
|
|
367
368
|
]);
|
|
368
369
|
const DEFAULT_POLLING_INTERVAL_MS = 30000;
|
|
369
370
|
const MAX_ERROR_COUNT = 5;
|
|
@@ -407,6 +408,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
407
408
|
'transakGetUserLimits',
|
|
408
409
|
'transakRequestOtt',
|
|
409
410
|
'transakGeneratePaymentWidgetUrl',
|
|
411
|
+
'transakCreateWidgetUrl',
|
|
410
412
|
'transakSubmitPurposeOfUsageForm',
|
|
411
413
|
'transakPatchUser',
|
|
412
414
|
'transakSubmitSsnDetails',
|
|
@@ -443,7 +445,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
443
445
|
* redirect URL used for the widened quote fetch when the caller omits
|
|
444
446
|
* `redirectUrl`. Defaults to a callback returning `undefined`.
|
|
445
447
|
*/
|
|
446
|
-
constructor({ messenger, state = {}, requestCacheTTL =
|
|
448
|
+
constructor({ messenger, state = {}, requestCacheTTL = RequestCache_js_1.DEFAULT_REQUEST_CACHE_TTL, requestCacheMaxSize = RequestCache_js_1.DEFAULT_REQUEST_CACHE_MAX_SIZE, getDefaultRedirectUrl, }) {
|
|
447
449
|
super({
|
|
448
450
|
messenger,
|
|
449
451
|
metadata: rampsControllerMetadata,
|
|
@@ -532,7 +534,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
532
534
|
// If cache is not expired, return the cached data
|
|
533
535
|
if (!options?.forceRefresh) {
|
|
534
536
|
const cached = this.state.requests[cacheKey];
|
|
535
|
-
if (cached && !(0,
|
|
537
|
+
if (cached && !(0, RequestCache_js_1.isCacheExpired)(cached, ttl)) {
|
|
536
538
|
return cached.data;
|
|
537
539
|
}
|
|
538
540
|
}
|
|
@@ -545,7 +547,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
545
547
|
? (__classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").get(resourceType) ?? 0)
|
|
546
548
|
: undefined;
|
|
547
549
|
// Update state to loading
|
|
548
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, (0,
|
|
550
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, (0, RequestCache_js_1.createLoadingState)());
|
|
549
551
|
// Set resource-level loading state (only on cache miss). Ref-count so concurrent
|
|
550
552
|
// requests for the same resource type (different cache keys) keep isLoading true.
|
|
551
553
|
if (resourceType) {
|
|
@@ -562,7 +564,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
562
564
|
if (abortController.signal.aborted) {
|
|
563
565
|
throw new Error('Request was aborted');
|
|
564
566
|
}
|
|
565
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, (0,
|
|
567
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, (0, RequestCache_js_1.createSuccessState)(data, lastFetchedAt));
|
|
566
568
|
if (resourceType) {
|
|
567
569
|
const isCurrent = !options?.isResultCurrent || options.isResultCurrent();
|
|
568
570
|
if (isCurrent) {
|
|
@@ -576,7 +578,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
576
578
|
throw error;
|
|
577
579
|
}
|
|
578
580
|
const { errorInfo, normalizedError } = getNormalizedRampsError(error);
|
|
579
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, (0,
|
|
581
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, (0, RequestCache_js_1.createErrorState)(errorInfo.message, lastFetchedAt, errorInfo.errorKey));
|
|
580
582
|
if (resourceType) {
|
|
581
583
|
const isCurrent = !options?.isResultCurrent || options.isResultCurrent();
|
|
582
584
|
if (isCurrent) {
|
|
@@ -762,7 +764,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
762
764
|
* @returns An array of countries.
|
|
763
765
|
*/
|
|
764
766
|
async getCountries(options) {
|
|
765
|
-
const cacheKey = (0,
|
|
767
|
+
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getCountries', []);
|
|
766
768
|
const countries = await this.executeRequest(cacheKey, async () => {
|
|
767
769
|
return this.messenger.call('RampsService:getCountries');
|
|
768
770
|
}, { ...options, resourceType: 'countries' });
|
|
@@ -785,7 +787,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
785
787
|
async getTokens(region, action = 'buy', options) {
|
|
786
788
|
const regionToUse = region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
787
789
|
const normalizedRegion = regionToUse.toLowerCase().trim();
|
|
788
|
-
const cacheKey = (0,
|
|
790
|
+
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getTokens', [
|
|
789
791
|
normalizedRegion,
|
|
790
792
|
action,
|
|
791
793
|
options?.provider,
|
|
@@ -850,7 +852,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
850
852
|
async getProviders(region, options) {
|
|
851
853
|
const regionToUse = region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
852
854
|
const normalizedRegion = regionToUse.toLowerCase().trim();
|
|
853
|
-
const cacheKey = (0,
|
|
855
|
+
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getProviders', [
|
|
854
856
|
normalizedRegion,
|
|
855
857
|
options?.provider,
|
|
856
858
|
options?.crypto,
|
|
@@ -890,7 +892,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
890
892
|
const assetIdToUse = options?.assetId ?? this.state.tokens.selected?.assetId ?? '';
|
|
891
893
|
const providerToUse = options?.provider ?? this.state.providers.selected?.id ?? '';
|
|
892
894
|
const normalizedRegion = regionCode.toLowerCase().trim();
|
|
893
|
-
const cacheKey = (0,
|
|
895
|
+
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getPaymentMethods', [
|
|
894
896
|
normalizedRegion,
|
|
895
897
|
assetIdToUse,
|
|
896
898
|
providerToUse,
|
|
@@ -1086,7 +1088,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1086
1088
|
// (flag off) never injects.
|
|
1087
1089
|
const effectiveRedirectUrl = options.redirectUrl ??
|
|
1088
1090
|
(widenToAllProviders ? __classPrivateFieldGet(this, _RampsController_getDefaultRedirectUrl, "f").call(this) : undefined);
|
|
1089
|
-
const cacheKey = (0,
|
|
1091
|
+
const cacheKey = (0, RequestCache_js_1.createCacheKey)('getQuotes', [
|
|
1090
1092
|
normalizedRegion,
|
|
1091
1093
|
normalizedFiat,
|
|
1092
1094
|
normalizedAssetId,
|
|
@@ -1263,7 +1265,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1263
1265
|
logos: { light: '', dark: '', height: 0, width: 0 },
|
|
1264
1266
|
},
|
|
1265
1267
|
walletAddress,
|
|
1266
|
-
status:
|
|
1268
|
+
status: RampsService_js_1.RampsOrderStatus.Precreated,
|
|
1267
1269
|
orderType: 'buy',
|
|
1268
1270
|
createdAt: Date.now(),
|
|
1269
1271
|
isOnlyLink: false,
|
|
@@ -1621,6 +1623,25 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1621
1623
|
transakGeneratePaymentWidgetUrl(ottToken, quote, walletAddress, extraParams) {
|
|
1622
1624
|
return this.messenger.call('TransakService:generatePaymentWidgetUrl', ottToken, quote, walletAddress, extraParams);
|
|
1623
1625
|
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Creates a Transak payment widget URL via the ramps API proxy, which
|
|
1628
|
+
* injects the partner API key server-side. Replaces the OTT flow
|
|
1629
|
+
* ({@link transakRequestOtt} + {@link transakGeneratePaymentWidgetUrl}).
|
|
1630
|
+
*
|
|
1631
|
+
* @param quote - The buy quote to pre-fill in the widget.
|
|
1632
|
+
* @param walletAddress - The destination wallet address.
|
|
1633
|
+
* @param extraParams - Optional additional widget parameters (e.g. theming).
|
|
1634
|
+
* @returns The single-use widget URL.
|
|
1635
|
+
*/
|
|
1636
|
+
async transakCreateWidgetUrl(quote, walletAddress, extraParams) {
|
|
1637
|
+
try {
|
|
1638
|
+
return await this.messenger.call('TransakService:createWidgetUrl', quote, walletAddress, extraParams);
|
|
1639
|
+
}
|
|
1640
|
+
catch (error) {
|
|
1641
|
+
throw __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_getNormalizedTransakError).call(this, error, { syncAuth: true })
|
|
1642
|
+
.normalizedError;
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1624
1645
|
/**
|
|
1625
1646
|
* Submits the user's purpose of usage form for KYC compliance.
|
|
1626
1647
|
*
|
|
@@ -1776,7 +1797,7 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1776
1797
|
}, _RampsController_isAllProvidersEnabled = function _RampsController_isAllProvidersEnabled() {
|
|
1777
1798
|
try {
|
|
1778
1799
|
const remoteFeatureFlagState = this.messenger.call('RemoteFeatureFlagController:getState');
|
|
1779
|
-
return (0,
|
|
1800
|
+
return (0, featureFlags_js_1.isHeadlessAllProvidersEnabled)(remoteFeatureFlagState);
|
|
1780
1801
|
}
|
|
1781
1802
|
catch {
|
|
1782
1803
|
return false;
|
|
@@ -1830,8 +1851,8 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1830
1851
|
const keys = Object.keys(requests);
|
|
1831
1852
|
for (const key of keys) {
|
|
1832
1853
|
const entry = requests[key];
|
|
1833
|
-
if (entry?.status ===
|
|
1834
|
-
(0,
|
|
1854
|
+
if (entry?.status === RequestCache_js_1.RequestStatus.SUCCESS &&
|
|
1855
|
+
(0, RequestCache_js_1.isCacheExpired)(entry, ttl)) {
|
|
1835
1856
|
delete requests[key];
|
|
1836
1857
|
}
|
|
1837
1858
|
}
|
|
@@ -1952,7 +1973,7 @@ async function _RampsController_getSupportingProvidersForRegion({ assetId, regio
|
|
|
1952
1973
|
// Case-insensitive CAIP-19 matching is shared with headless-buy consumers
|
|
1953
1974
|
// via `getProvidersServingAsset`, so the controller and the UI region gate
|
|
1954
1975
|
// cannot disagree about which providers serve the asset.
|
|
1955
|
-
const supporting = (0,
|
|
1976
|
+
const supporting = (0, providerAvailability_js_1.getProvidersServingAsset)(providers, assetId);
|
|
1956
1977
|
return { supporting, all: providers };
|
|
1957
1978
|
}, _RampsController_filterProviderIdsBySupport =
|
|
1958
1979
|
/**
|
|
@@ -2045,7 +2066,7 @@ async function _RampsController_resolveProviderIdsForQuote({ assetId, region, pr
|
|
|
2045
2066
|
}, _RampsController_getPreferredProviderIdsFromOrders = function _RampsController_getPreferredProviderIdsFromOrders() {
|
|
2046
2067
|
const orderedIds = [];
|
|
2047
2068
|
const completedOrders = this.state.orders
|
|
2048
|
-
.filter((order) => order.status ===
|
|
2069
|
+
.filter((order) => order.status === RampsService_js_1.RampsOrderStatus.Completed && order.provider?.id)
|
|
2049
2070
|
.sort((orderA, orderB) => orderB.createdAt - orderA.createdAt);
|
|
2050
2071
|
for (const order of completedOrders) {
|
|
2051
2072
|
const id = order.provider?.id;
|
|
@@ -2073,7 +2094,7 @@ async function _RampsController_refreshOrder(order) {
|
|
|
2073
2094
|
lastTimeFetched: 0,
|
|
2074
2095
|
errorCount: 0,
|
|
2075
2096
|
};
|
|
2076
|
-
if (updatedOrder.status ===
|
|
2097
|
+
if (updatedOrder.status === RampsService_js_1.RampsOrderStatus.Unknown) {
|
|
2077
2098
|
meta.errorCount = Math.min(meta.errorCount + 1, MAX_ERROR_COUNT);
|
|
2078
2099
|
}
|
|
2079
2100
|
else {
|