@metamask-previews/ramps-controller 8.1.0-preview-8a5acbf75 → 8.1.0-preview-25c8c1fad
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 +6 -0
- package/dist/RampsController.cjs +35 -97
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +2 -9
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +2 -9
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +35 -97
- package/dist/RampsController.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -13,8 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
13
13
|
|
|
14
14
|
### Changed
|
|
15
15
|
|
|
16
|
+
- **BREAKING:** Replace `startQuotePolling()`/`stopQuotePolling()` with `fetchQuotesForSelection()` — quotes are now fetched once per call instead of polling on a 15-second interval ([#7999](https://github.com/MetaMask/core/pull/7999))
|
|
16
17
|
- Bump `@metamask/controller-utils` from `^11.18.0` to `^11.19.0` ([#7995](https://github.com/MetaMask/core/pull/7995))
|
|
17
18
|
|
|
19
|
+
### Removed
|
|
20
|
+
|
|
21
|
+
- Remove `stopQuotePolling()` method (no interval to stop)
|
|
22
|
+
- Remove internal polling restart logic (`#restartPollingIfActive`) from `setSelectedProvider`, `setSelectedToken`, and `setSelectedPaymentMethod`
|
|
23
|
+
|
|
18
24
|
## [8.1.0]
|
|
19
25
|
|
|
20
26
|
### Added
|
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,
|
|
13
|
+
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _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_syncWidgetUrl, _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");
|
|
@@ -326,16 +326,6 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
326
326
|
* Used so isLoading is only cleared when the last request for that resource finishes.
|
|
327
327
|
*/
|
|
328
328
|
_RampsController_pendingResourceCount.set(this, new Map());
|
|
329
|
-
/**
|
|
330
|
-
* Interval ID for automatic quote polling.
|
|
331
|
-
* Set when startQuotePolling() is called, cleared when stopQuotePolling() is called.
|
|
332
|
-
*/
|
|
333
|
-
_RampsController_quotePollingInterval.set(this, null);
|
|
334
|
-
/**
|
|
335
|
-
* Options used for quote polling (walletAddress, amount, redirectUrl).
|
|
336
|
-
* Stored so polling can be restarted when dependencies change.
|
|
337
|
-
*/
|
|
338
|
-
_RampsController_quotePollingOptions.set(this, null);
|
|
339
329
|
__classPrivateFieldSet(this, _RampsController_requestCacheTTL, requestCacheTTL, "f");
|
|
340
330
|
__classPrivateFieldSet(this, _RampsController_requestCacheMaxSize, requestCacheMaxSize, "f");
|
|
341
331
|
}
|
|
@@ -506,7 +496,6 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
506
496
|
if (regionChanged) {
|
|
507
497
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_abortDependentRequests).call(this);
|
|
508
498
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_clearPendingResourceCountForDependentResources).call(this);
|
|
509
|
-
this.stopQuotePolling();
|
|
510
499
|
}
|
|
511
500
|
this.update((state) => {
|
|
512
501
|
if (regionChanged) {
|
|
@@ -543,7 +532,6 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
543
532
|
*/
|
|
544
533
|
setSelectedProvider(providerId) {
|
|
545
534
|
if (providerId === null) {
|
|
546
|
-
this.stopQuotePolling();
|
|
547
535
|
this.update((state) => {
|
|
548
536
|
state.providers.selected = null;
|
|
549
537
|
resetResource(state, 'paymentMethods');
|
|
@@ -565,11 +553,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
565
553
|
state.quotes.selected = null;
|
|
566
554
|
resetWidgetUrl(state);
|
|
567
555
|
});
|
|
568
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { provider: provider.id })
|
|
569
|
-
// Restart quote polling after payment methods are fetched
|
|
570
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_restartPollingIfActive).call(this);
|
|
571
|
-
return undefined;
|
|
572
|
-
}));
|
|
556
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { provider: provider.id }));
|
|
573
557
|
}
|
|
574
558
|
/**
|
|
575
559
|
* Initializes the controller by fetching the user's region from geolocation.
|
|
@@ -658,7 +642,6 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
658
642
|
*/
|
|
659
643
|
setSelectedToken(assetId) {
|
|
660
644
|
if (!assetId) {
|
|
661
|
-
this.stopQuotePolling();
|
|
662
645
|
this.update((state) => {
|
|
663
646
|
state.tokens.selected = null;
|
|
664
647
|
resetResource(state, 'paymentMethods');
|
|
@@ -681,10 +664,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
681
664
|
state.quotes.selected = null;
|
|
682
665
|
resetWidgetUrl(state);
|
|
683
666
|
});
|
|
684
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { assetId: token.assetId })
|
|
685
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_restartPollingIfActive).call(this);
|
|
686
|
-
return undefined;
|
|
687
|
-
}));
|
|
667
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { assetId: token.assetId }));
|
|
688
668
|
}
|
|
689
669
|
/**
|
|
690
670
|
* Fetches the list of providers for a given region.
|
|
@@ -816,8 +796,6 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
816
796
|
this.update((state) => {
|
|
817
797
|
state.paymentMethods.selected = paymentMethod;
|
|
818
798
|
});
|
|
819
|
-
// Restart quote polling if active
|
|
820
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_restartPollingIfActive).call(this);
|
|
821
799
|
}
|
|
822
800
|
/**
|
|
823
801
|
* Fetches quotes from all providers for a given set of parameters.
|
|
@@ -907,8 +885,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
907
885
|
return response;
|
|
908
886
|
}
|
|
909
887
|
/**
|
|
910
|
-
*
|
|
911
|
-
* Fetches quotes immediately and then every 15 seconds.
|
|
888
|
+
* Fetches quotes for the currently selected token, provider, and payment method.
|
|
912
889
|
* If the response contains exactly one quote, it is auto-selected.
|
|
913
890
|
* If multiple quotes are returned, the existing selection is preserved if still valid.
|
|
914
891
|
*
|
|
@@ -921,73 +898,49 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
921
898
|
* @param options.redirectUrl - Optional redirect URL after order completion.
|
|
922
899
|
* @throws If required dependencies (region, token, provider) are not set.
|
|
923
900
|
*/
|
|
924
|
-
|
|
901
|
+
fetchQuotesForSelection(options) {
|
|
925
902
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
926
903
|
const token = this.state.tokens.selected;
|
|
927
904
|
const provider = this.state.providers.selected;
|
|
928
905
|
const paymentMethod = this.state.paymentMethods.selected;
|
|
929
906
|
if (!token) {
|
|
930
|
-
throw new Error('Token is required. Cannot
|
|
907
|
+
throw new Error('Token is required. Cannot fetch quotes without a selected token.');
|
|
931
908
|
}
|
|
932
909
|
if (!provider) {
|
|
933
|
-
throw new Error('Provider is required. Cannot
|
|
910
|
+
throw new Error('Provider is required. Cannot fetch quotes without a selected provider.');
|
|
934
911
|
}
|
|
935
912
|
if (!paymentMethod) {
|
|
936
913
|
return;
|
|
937
914
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
915
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getQuotes({
|
|
916
|
+
assetId: token.assetId,
|
|
917
|
+
amount: options.amount,
|
|
918
|
+
walletAddress: options.walletAddress,
|
|
919
|
+
redirectUrl: options.redirectUrl,
|
|
920
|
+
paymentMethods: [paymentMethod.id],
|
|
921
|
+
providers: [provider.id],
|
|
922
|
+
forceRefresh: true,
|
|
923
|
+
}).then((response) => {
|
|
924
|
+
let newSelectedQuote = null;
|
|
925
|
+
this.update((state) => {
|
|
926
|
+
if (response.success.length === 1) {
|
|
927
|
+
newSelectedQuote = response.success[0];
|
|
928
|
+
state.quotes.selected = newSelectedQuote;
|
|
929
|
+
}
|
|
930
|
+
else {
|
|
931
|
+
const currentSelection = state.quotes.selected;
|
|
932
|
+
if (currentSelection) {
|
|
933
|
+
const freshQuote = response.success.find((quote) => quote.provider === currentSelection.provider &&
|
|
934
|
+
quote.quote.paymentMethod ===
|
|
935
|
+
currentSelection.quote.paymentMethod);
|
|
936
|
+
newSelectedQuote = freshQuote ?? null;
|
|
958
937
|
state.quotes.selected = newSelectedQuote;
|
|
959
938
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
quote.quote.paymentMethod ===
|
|
966
|
-
currentSelection.quote.paymentMethod);
|
|
967
|
-
newSelectedQuote = freshQuote ?? null;
|
|
968
|
-
state.quotes.selected = newSelectedQuote;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
});
|
|
972
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncWidgetUrl).call(this, newSelectedQuote);
|
|
973
|
-
return undefined;
|
|
974
|
-
}));
|
|
975
|
-
};
|
|
976
|
-
// Fetch immediately
|
|
977
|
-
fetchQuotes();
|
|
978
|
-
// Set up 15-second polling
|
|
979
|
-
__classPrivateFieldSet(this, _RampsController_quotePollingInterval, setInterval(fetchQuotes, 15000), "f");
|
|
980
|
-
}
|
|
981
|
-
/**
|
|
982
|
-
* Stops automatic quote polling.
|
|
983
|
-
* Does not clear quotes data or selection, only stops the interval.
|
|
984
|
-
*/
|
|
985
|
-
stopQuotePolling() {
|
|
986
|
-
if (__classPrivateFieldGet(this, _RampsController_quotePollingInterval, "f") !== null) {
|
|
987
|
-
clearInterval(__classPrivateFieldGet(this, _RampsController_quotePollingInterval, "f"));
|
|
988
|
-
__classPrivateFieldSet(this, _RampsController_quotePollingInterval, null, "f");
|
|
989
|
-
}
|
|
990
|
-
__classPrivateFieldSet(this, _RampsController_quotePollingOptions, null, "f");
|
|
939
|
+
}
|
|
940
|
+
});
|
|
941
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncWidgetUrl).call(this, newSelectedQuote);
|
|
942
|
+
return undefined;
|
|
943
|
+
}));
|
|
991
944
|
}
|
|
992
945
|
/**
|
|
993
946
|
* Manually sets the selected quote.
|
|
@@ -1003,11 +956,9 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1003
956
|
}
|
|
1004
957
|
/**
|
|
1005
958
|
* Cleans up controller resources.
|
|
1006
|
-
* Stops any active quote polling to prevent memory leaks.
|
|
1007
959
|
* Should be called when the controller is no longer needed.
|
|
1008
960
|
*/
|
|
1009
961
|
destroy() {
|
|
1010
|
-
this.stopQuotePolling();
|
|
1011
962
|
super.destroy();
|
|
1012
963
|
}
|
|
1013
964
|
/**
|
|
@@ -1455,7 +1406,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1455
1406
|
}
|
|
1456
1407
|
}
|
|
1457
1408
|
exports.RampsController = RampsController;
|
|
1458
|
-
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_pendingResourceCount = new WeakMap(),
|
|
1409
|
+
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_pendingResourceCount = new WeakMap(), _RampsController_instances = new WeakSet(), _RampsController_clearPendingResourceCountForDependentResources = function _RampsController_clearPendingResourceCountForDependentResources() {
|
|
1459
1410
|
for (const resourceType of DEPENDENT_RESOURCE_KEYS) {
|
|
1460
1411
|
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
1461
1412
|
}
|
|
@@ -1478,24 +1429,11 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1478
1429
|
delete requests[cacheKey];
|
|
1479
1430
|
});
|
|
1480
1431
|
}, _RampsController_cleanupState = function _RampsController_cleanupState() {
|
|
1481
|
-
this.stopQuotePolling();
|
|
1482
1432
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_abortDependentRequests).call(this);
|
|
1483
1433
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_clearPendingResourceCountForDependentResources).call(this);
|
|
1484
1434
|
this.update((state) => resetDependentResources(state, { clearUserRegionData: true }));
|
|
1485
1435
|
}, _RampsController_fireAndForget = function _RampsController_fireAndForget(promise) {
|
|
1486
1436
|
promise.catch((_error) => undefined);
|
|
1487
|
-
}, _RampsController_restartPollingIfActive = function _RampsController_restartPollingIfActive() {
|
|
1488
|
-
if (__classPrivateFieldGet(this, _RampsController_quotePollingInterval, "f") !== null && __classPrivateFieldGet(this, _RampsController_quotePollingOptions, "f")) {
|
|
1489
|
-
const options = __classPrivateFieldGet(this, _RampsController_quotePollingOptions, "f");
|
|
1490
|
-
this.stopQuotePolling();
|
|
1491
|
-
try {
|
|
1492
|
-
this.startQuotePolling(options);
|
|
1493
|
-
}
|
|
1494
|
-
catch {
|
|
1495
|
-
// Dependencies not met yet, polling will need to be manually restarted
|
|
1496
|
-
// when dependencies are available
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
1437
|
}, _RampsController_requireRegion = function _RampsController_requireRegion() {
|
|
1500
1438
|
const regionCode = this.state.userRegion?.regionCode;
|
|
1501
1439
|
if (!regionCode) {
|