@metamask-previews/ramps-controller 10.2.0-preview-d8831108d → 12.0.0-preview-b2ccba4
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 +19 -5
- package/dist/RampsController.cjs +38 -16
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +4 -4
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +4 -4
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +38 -16
- package/dist/RampsController.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [12.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** Update state hydration to make `init()` idempotent and remove `hydrateState()` ([#8157](https://github.com/MetaMask/core/pull/8157))
|
|
15
|
+
|
|
16
|
+
### Removed
|
|
17
|
+
|
|
18
|
+
- Remove `hydrateState()` — use `init()` as the single entry point for controller hydration
|
|
19
|
+
|
|
20
|
+
## [11.0.0]
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- **BREAKING:** Replace `getWidgetUrl` with `getBuyWidgetData` (returns `BuyWidget | null`); add `addPrecreatedOrder` for custom-action ramp flows (e.g., PayPal, Robinhood, Coinbase) ([#8100](https://github.com/MetaMask/core/pull/8100))
|
|
25
|
+
|
|
10
26
|
## [10.2.0]
|
|
11
27
|
|
|
12
28
|
### Fixed
|
|
@@ -22,10 +38,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
22
38
|
- Added `RampsController:orderStatusChanged` event, published when a polled order's status transitions ([#8045](https://github.com/MetaMask/core/pull/8045))
|
|
23
39
|
- Add messenger actions for `RampsController:setSelectedToken`, `RampsController:getQuotes`, and `RampsController:getOrder`, register their handlers in `RampsController`, and export the action types from the package index ([#8081](https://github.com/MetaMask/core/pull/8081))
|
|
24
40
|
|
|
25
|
-
### Changed
|
|
26
|
-
|
|
27
|
-
- **BREAKING:** Replace `getWidgetUrl` with `getBuyWidgetData` (returns `BuyWidget | null`); add `addPrecreatedOrder` for custom-action ramp flows (e.g., PayPal) ([#8100](https://github.com/MetaMask/core/pull/8100))
|
|
28
|
-
|
|
29
41
|
## [10.0.0]
|
|
30
42
|
|
|
31
43
|
### Changed
|
|
@@ -202,7 +214,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
202
214
|
- Add `OnRampService` for interacting with the OnRamp API
|
|
203
215
|
- Add geolocation detection via IP address lookup
|
|
204
216
|
|
|
205
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@
|
|
217
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@12.0.0...HEAD
|
|
218
|
+
[12.0.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@11.0.0...@metamask/ramps-controller@12.0.0
|
|
219
|
+
[11.0.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@10.2.0...@metamask/ramps-controller@11.0.0
|
|
206
220
|
[10.2.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@10.1.0...@metamask/ramps-controller@10.2.0
|
|
207
221
|
[10.1.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@10.0.0...@metamask/ramps-controller@10.1.0
|
|
208
222
|
[10.0.0]: https://github.com/MetaMask/core/compare/@metamask/ramps-controller@9.0.0...@metamask/ramps-controller@10.0.0
|
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, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError;
|
|
13
|
+
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_orderPollingMeta, _RampsController_orderPollingTimer, _RampsController_isPolling, _RampsController_initPromise, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_registerActionHandlers, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_fireAndForget, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_runInit, _RampsController_refreshOrder, _RampsController_pollPendingOrders, _RampsController_syncTransakAuthOnError;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.RampsController = exports.normalizeProviderCode = exports.getDefaultRampsControllerState = exports.RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = exports.controllerName = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -327,6 +327,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
327
327
|
_RampsController_orderPollingMeta.set(this, new Map());
|
|
328
328
|
_RampsController_orderPollingTimer.set(this, null);
|
|
329
329
|
_RampsController_isPolling.set(this, false);
|
|
330
|
+
_RampsController_initPromise.set(this, null);
|
|
330
331
|
__classPrivateFieldSet(this, _RampsController_requestCacheTTL, requestCacheTTL, "f");
|
|
331
332
|
__classPrivateFieldSet(this, _RampsController_requestCacheMaxSize, requestCacheMaxSize, "f");
|
|
332
333
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_registerActionHandlers).call(this);
|
|
@@ -569,25 +570,28 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
569
570
|
* Initializes the controller by fetching the user's region from geolocation.
|
|
570
571
|
* This should be called once at app startup to set up the initial region.
|
|
571
572
|
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
573
|
+
* Idempotent: subsequent calls return the same promise unless forceRefresh is set.
|
|
574
|
+
* Skips getCountries when countries are already loaded; skips geolocation when
|
|
575
|
+
* userRegion already exists.
|
|
574
576
|
*
|
|
575
|
-
* @param options - Options for cache behavior.
|
|
577
|
+
* @param options - Options for cache behavior. forceRefresh bypasses idempotency and re-runs the full flow.
|
|
576
578
|
* @returns Promise that resolves when initialization is complete.
|
|
577
579
|
*/
|
|
578
580
|
async init(options) {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
regionCode ?? (regionCode = await this.messenger.call('RampsService:getGeolocation'));
|
|
582
|
-
if (!regionCode) {
|
|
583
|
-
throw new Error('Failed to fetch geolocation. Cannot initialize controller without valid region information.');
|
|
581
|
+
if (!options?.forceRefresh && __classPrivateFieldGet(this, _RampsController_initPromise, "f") !== null) {
|
|
582
|
+
return __classPrivateFieldGet(this, _RampsController_initPromise, "f");
|
|
584
583
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
|
|
584
|
+
if (options?.forceRefresh) {
|
|
585
|
+
__classPrivateFieldSet(this, _RampsController_initPromise, null, "f");
|
|
586
|
+
}
|
|
587
|
+
const initPromise = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_runInit).call(this, options).then(() => undefined, (error) => {
|
|
588
|
+
if (__classPrivateFieldGet(this, _RampsController_initPromise, "f") === initPromise) {
|
|
589
|
+
__classPrivateFieldSet(this, _RampsController_initPromise, null, "f");
|
|
590
|
+
}
|
|
591
|
+
throw error;
|
|
592
|
+
});
|
|
593
|
+
__classPrivateFieldSet(this, _RampsController_initPromise, initPromise, "f");
|
|
594
|
+
return initPromise;
|
|
591
595
|
}
|
|
592
596
|
/**
|
|
593
597
|
* Fetches the list of supported countries.
|
|
@@ -1457,7 +1461,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1457
1461
|
}
|
|
1458
1462
|
}
|
|
1459
1463
|
exports.RampsController = RampsController;
|
|
1460
|
-
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_pendingResourceCount = new WeakMap(), _RampsController_orderPollingMeta = new WeakMap(), _RampsController_orderPollingTimer = new WeakMap(), _RampsController_isPolling = new WeakMap(), _RampsController_instances = new WeakSet(), _RampsController_clearPendingResourceCountForDependentResources = function _RampsController_clearPendingResourceCountForDependentResources() {
|
|
1464
|
+
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_pendingResourceCount = 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() {
|
|
1461
1465
|
for (const resourceType of DEPENDENT_RESOURCE_KEYS) {
|
|
1462
1466
|
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
1463
1467
|
}
|
|
@@ -1544,6 +1548,24 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1544
1548
|
}
|
|
1545
1549
|
}
|
|
1546
1550
|
});
|
|
1551
|
+
}, _RampsController_runInit = async function _RampsController_runInit(options) {
|
|
1552
|
+
const forceRefresh = options?.forceRefresh === true;
|
|
1553
|
+
const hasCountries = this.state.countries.data.length > 0;
|
|
1554
|
+
if (forceRefresh || !hasCountries) {
|
|
1555
|
+
await this.getCountries(options);
|
|
1556
|
+
}
|
|
1557
|
+
let regionCode;
|
|
1558
|
+
if (forceRefresh) {
|
|
1559
|
+
regionCode = await this.messenger.call('RampsService:getGeolocation');
|
|
1560
|
+
}
|
|
1561
|
+
else {
|
|
1562
|
+
regionCode = this.state.userRegion?.regionCode;
|
|
1563
|
+
regionCode ?? (regionCode = await this.messenger.call('RampsService:getGeolocation'));
|
|
1564
|
+
}
|
|
1565
|
+
if (!regionCode) {
|
|
1566
|
+
throw new Error('Failed to fetch geolocation. Cannot initialize controller without valid region information.');
|
|
1567
|
+
}
|
|
1568
|
+
await this.setUserRegion(regionCode, options);
|
|
1547
1569
|
}, _RampsController_refreshOrder =
|
|
1548
1570
|
/**
|
|
1549
1571
|
* Refreshes a single order via the V2 API and updates it in state.
|