@metamask-previews/ramps-controller 10.2.0-preview-bc00f2c → 10.2.0-preview-93519965c
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 +4 -0
- package/dist/RampsController.cjs +16 -9
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +6 -0
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +6 -0
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +16 -9
- package/dist/RampsController.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add `status` field to `ResourceState` to distinguish between uninitialized and empty-fetched states ([#8116](https://github.com/MetaMask/core/pull/8116))
|
|
13
|
+
|
|
10
14
|
## [10.2.0]
|
|
11
15
|
|
|
12
16
|
### Fixed
|
package/dist/RampsController.cjs
CHANGED
|
@@ -10,7 +10,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
10
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
11
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
12
|
};
|
|
13
|
-
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_registerActionHandlers, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_fireAndForget, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent,
|
|
13
|
+
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_registerActionHandlers, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_fireAndForget, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceFields, _RampsController_setResourceError, _RampsController_setResourceLoadingAndStatus, _RampsController_updateRequestState, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.RampsController = exports.getDefaultRampsControllerState = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.controllerName = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -136,6 +136,7 @@ function createDefaultResourceState(data, selected = null) {
|
|
|
136
136
|
selected,
|
|
137
137
|
isLoading: false,
|
|
138
138
|
error: null,
|
|
139
|
+
status: RequestCache_1.RequestStatus.IDLE,
|
|
139
140
|
};
|
|
140
141
|
}
|
|
141
142
|
/**
|
|
@@ -179,6 +180,7 @@ function resetResource(state, resourceType, defaultResource) {
|
|
|
179
180
|
resource.selected = def.selected;
|
|
180
181
|
resource.isLoading = def.isLoading;
|
|
181
182
|
resource.error = def.error;
|
|
183
|
+
resource.status = def.status;
|
|
182
184
|
}
|
|
183
185
|
/**
|
|
184
186
|
* Resets region-dependent resources (userRegion, providers, tokens, paymentMethods).
|
|
@@ -382,11 +384,12 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
382
384
|
const count = __classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").get(resourceType) ?? 0;
|
|
383
385
|
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").set(resourceType, count + 1);
|
|
384
386
|
if (count === 0) {
|
|
385
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m",
|
|
387
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_setResourceLoadingAndStatus).call(this, resourceType, true, RequestCache_1.RequestStatus.LOADING);
|
|
386
388
|
}
|
|
387
389
|
}
|
|
388
390
|
// Create the fetch promise
|
|
389
391
|
const promise = (async () => {
|
|
392
|
+
let terminalStatus;
|
|
390
393
|
try {
|
|
391
394
|
const data = await fetcher(abortController.signal);
|
|
392
395
|
if (abortController.signal.aborted) {
|
|
@@ -397,6 +400,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
397
400
|
const isCurrent = !options?.isResultCurrent || options.isResultCurrent();
|
|
398
401
|
if (isCurrent) {
|
|
399
402
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_setResourceError).call(this, resourceType, null);
|
|
403
|
+
terminalStatus = RequestCache_1.RequestStatus.SUCCESS;
|
|
400
404
|
}
|
|
401
405
|
}
|
|
402
406
|
return data;
|
|
@@ -411,6 +415,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
411
415
|
const isCurrent = !options?.isResultCurrent || options.isResultCurrent();
|
|
412
416
|
if (isCurrent) {
|
|
413
417
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_setResourceError).call(this, resourceType, errorMessage);
|
|
418
|
+
terminalStatus = RequestCache_1.RequestStatus.ERROR;
|
|
414
419
|
}
|
|
415
420
|
}
|
|
416
421
|
throw error;
|
|
@@ -426,7 +431,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
426
431
|
const next = Math.max(0, count - 1);
|
|
427
432
|
if (next === 0) {
|
|
428
433
|
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
429
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m",
|
|
434
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_setResourceLoadingAndStatus).call(this, resourceType, false, terminalStatus ?? RequestCache_1.RequestStatus.IDLE);
|
|
430
435
|
}
|
|
431
436
|
else {
|
|
432
437
|
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").set(resourceType, next);
|
|
@@ -959,7 +964,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
959
964
|
}
|
|
960
965
|
try {
|
|
961
966
|
const buyWidget = await this.messenger.call('RampsService:getBuyWidgetUrl', buyUrl);
|
|
962
|
-
return buyWidget.url
|
|
967
|
+
return buyWidget.url;
|
|
963
968
|
}
|
|
964
969
|
catch {
|
|
965
970
|
return null;
|
|
@@ -1444,17 +1449,19 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1444
1449
|
}, _RampsController_isProviderCurrent = function _RampsController_isProviderCurrent(normalizedProviderId) {
|
|
1445
1450
|
const current = this.state.providers.selected?.id ?? '';
|
|
1446
1451
|
return current === normalizedProviderId;
|
|
1447
|
-
},
|
|
1452
|
+
}, _RampsController_updateResourceFields = function _RampsController_updateResourceFields(resourceType, fields) {
|
|
1448
1453
|
this.update((state) => {
|
|
1449
1454
|
const resource = state[resourceType];
|
|
1450
1455
|
if (resource) {
|
|
1451
|
-
|
|
1456
|
+
for (const [field, value] of Object.entries(fields)) {
|
|
1457
|
+
resource[field] = value;
|
|
1458
|
+
}
|
|
1452
1459
|
}
|
|
1453
1460
|
});
|
|
1454
|
-
}, _RampsController_setResourceLoading = function _RampsController_setResourceLoading(resourceType, loading) {
|
|
1455
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateResourceField).call(this, resourceType, 'isLoading', loading);
|
|
1456
1461
|
}, _RampsController_setResourceError = function _RampsController_setResourceError(resourceType, error) {
|
|
1457
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m",
|
|
1462
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateResourceFields).call(this, resourceType, { error });
|
|
1463
|
+
}, _RampsController_setResourceLoadingAndStatus = function _RampsController_setResourceLoadingAndStatus(resourceType, loading, status) {
|
|
1464
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateResourceFields).call(this, resourceType, { isLoading: loading, status });
|
|
1458
1465
|
}, _RampsController_updateRequestState = function _RampsController_updateRequestState(cacheKey, requestState) {
|
|
1459
1466
|
const maxSize = __classPrivateFieldGet(this, _RampsController_requestCacheMaxSize, "f");
|
|
1460
1467
|
const ttl = __classPrivateFieldGet(this, _RampsController_requestCacheTTL, "f");
|