@metamask/ramps-controller 12.0.1 → 13.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 +36 -1
- package/dist/RampsController-method-action-types.cjs +1 -1
- package/dist/RampsController-method-action-types.cjs.map +1 -1
- package/dist/RampsController-method-action-types.d.cts +18 -10
- package/dist/RampsController-method-action-types.d.cts.map +1 -1
- package/dist/RampsController-method-action-types.d.mts +18 -10
- package/dist/RampsController-method-action-types.d.mts.map +1 -1
- package/dist/RampsController-method-action-types.mjs +1 -1
- package/dist/RampsController-method-action-types.mjs.map +1 -1
- package/dist/RampsController.cjs +103 -95
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +28 -11
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +28 -11
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +103 -95
- package/dist/RampsController.mjs.map +1 -1
- package/dist/RampsService-method-action-types.cjs +1 -1
- package/dist/RampsService-method-action-types.cjs.map +1 -1
- package/dist/RampsService-method-action-types.d.cts +5 -3
- package/dist/RampsService-method-action-types.d.cts.map +1 -1
- package/dist/RampsService-method-action-types.d.mts +5 -3
- package/dist/RampsService-method-action-types.d.mts.map +1 -1
- package/dist/RampsService-method-action-types.mjs +1 -1
- package/dist/RampsService-method-action-types.mjs.map +1 -1
- package/dist/RampsService.cjs +11 -5
- package/dist/RampsService.cjs.map +1 -1
- package/dist/RampsService.d.cts +4 -2
- package/dist/RampsService.d.cts.map +1 -1
- package/dist/RampsService.d.mts +4 -2
- package/dist/RampsService.d.mts.map +1 -1
- package/dist/RampsService.mjs +11 -5
- package/dist/RampsService.mjs.map +1 -1
- package/dist/TransakService-method-action-types.cjs +1 -1
- package/dist/TransakService-method-action-types.cjs.map +1 -1
- package/dist/TransakService-method-action-types.d.cts +1 -1
- package/dist/TransakService-method-action-types.d.mts +1 -1
- package/dist/TransakService-method-action-types.mjs +1 -1
- package/dist/TransakService-method-action-types.mjs.map +1 -1
- package/package.json +5 -5
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_initPromise, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState,
|
|
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_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _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");
|
|
@@ -85,13 +85,13 @@ const rampsControllerMetadata = {
|
|
|
85
85
|
usedInUi: true,
|
|
86
86
|
},
|
|
87
87
|
providers: {
|
|
88
|
-
persist:
|
|
88
|
+
persist: false,
|
|
89
89
|
includeInDebugSnapshot: true,
|
|
90
90
|
includeInStateLogs: true,
|
|
91
91
|
usedInUi: true,
|
|
92
92
|
},
|
|
93
93
|
tokens: {
|
|
94
|
-
persist:
|
|
94
|
+
persist: false,
|
|
95
95
|
includeInDebugSnapshot: true,
|
|
96
96
|
includeInStateLogs: true,
|
|
97
97
|
usedInUi: true,
|
|
@@ -120,6 +120,12 @@ const rampsControllerMetadata = {
|
|
|
120
120
|
includeInStateLogs: true,
|
|
121
121
|
usedInUi: true,
|
|
122
122
|
},
|
|
123
|
+
providerAutoSelected: {
|
|
124
|
+
persist: true,
|
|
125
|
+
includeInDebugSnapshot: true,
|
|
126
|
+
includeInStateLogs: true,
|
|
127
|
+
usedInUi: true,
|
|
128
|
+
},
|
|
123
129
|
};
|
|
124
130
|
/**
|
|
125
131
|
* Creates a default resource state object.
|
|
@@ -163,6 +169,7 @@ function getDefaultRampsControllerState() {
|
|
|
163
169
|
},
|
|
164
170
|
},
|
|
165
171
|
orders: [],
|
|
172
|
+
providerAutoSelected: false,
|
|
166
173
|
};
|
|
167
174
|
}
|
|
168
175
|
exports.getDefaultRampsControllerState = getDefaultRampsControllerState;
|
|
@@ -173,12 +180,11 @@ const DEPENDENT_RESOURCE_KEYS = [
|
|
|
173
180
|
];
|
|
174
181
|
const DEPENDENT_RESOURCE_KEYS_SET = new Set(DEPENDENT_RESOURCE_KEYS);
|
|
175
182
|
function resetResource(state, resourceType, defaultResource) {
|
|
176
|
-
const def = defaultResource ?? getDefaultRampsControllerState()[resourceType];
|
|
177
183
|
const resource = state[resourceType];
|
|
178
|
-
resource.data =
|
|
179
|
-
resource.selected =
|
|
180
|
-
resource.isLoading =
|
|
181
|
-
resource.error =
|
|
184
|
+
resource.data = defaultResource.data;
|
|
185
|
+
resource.selected = defaultResource.selected;
|
|
186
|
+
resource.isLoading = defaultResource.isLoading;
|
|
187
|
+
resource.error = defaultResource.error;
|
|
182
188
|
}
|
|
183
189
|
/**
|
|
184
190
|
* Resets region-dependent resources (userRegion, providers, tokens, paymentMethods).
|
|
@@ -196,6 +202,7 @@ function resetDependentResources(state, options) {
|
|
|
196
202
|
for (const key of DEPENDENT_RESOURCE_KEYS) {
|
|
197
203
|
resetResource(state, key, defaultState[key]);
|
|
198
204
|
}
|
|
205
|
+
state.providerAutoSelected = false;
|
|
199
206
|
}
|
|
200
207
|
// === HELPER FUNCTIONS ===
|
|
201
208
|
/**
|
|
@@ -373,6 +380,11 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
373
380
|
* Used so isLoading is only cleared when the last request for that resource finishes.
|
|
374
381
|
*/
|
|
375
382
|
_RampsController_pendingResourceCount.set(this, new Map());
|
|
383
|
+
/**
|
|
384
|
+
* Monotonic generation per resource type used to invalidate stale in-flight
|
|
385
|
+
* requests after region/token/provider dependent-resource resets.
|
|
386
|
+
*/
|
|
387
|
+
_RampsController_pendingResourceGeneration.set(this, new Map());
|
|
376
388
|
_RampsController_orderPollingMeta.set(this, new Map());
|
|
377
389
|
_RampsController_orderPollingTimer.set(this, null);
|
|
378
390
|
_RampsController_isPolling.set(this, false);
|
|
@@ -428,6 +440,9 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
428
440
|
const abortController = new AbortController();
|
|
429
441
|
const lastFetchedAt = Date.now();
|
|
430
442
|
const { resourceType } = options ?? {};
|
|
443
|
+
const resourceGeneration = resourceType
|
|
444
|
+
? (__classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").get(resourceType) ?? 0)
|
|
445
|
+
: undefined;
|
|
431
446
|
// Update state to loading
|
|
432
447
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, (0, RequestCache_1.createLoadingState)());
|
|
433
448
|
// Set resource-level loading state (only on cache miss). Ref-count so concurrent
|
|
@@ -476,14 +491,17 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
476
491
|
}
|
|
477
492
|
// Clear resource-level loading state only when no requests for this resource remain
|
|
478
493
|
if (resourceType && !abortController.signal.aborted) {
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
494
|
+
const currentGeneration = __classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").get(resourceType) ?? 0;
|
|
495
|
+
if (currentGeneration === resourceGeneration) {
|
|
496
|
+
const count = __classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").get(resourceType) ?? 0;
|
|
497
|
+
const next = Math.max(0, count - 1);
|
|
498
|
+
if (next === 0) {
|
|
499
|
+
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
500
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_setResourceLoading).call(this, resourceType, false);
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").set(resourceType, next);
|
|
504
|
+
}
|
|
487
505
|
}
|
|
488
506
|
}
|
|
489
507
|
}
|
|
@@ -541,12 +559,14 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
541
559
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_cleanupState).call(this);
|
|
542
560
|
throw new Error(`Region "${normalizedRegion}" not found in countries data. Cannot set user region without valid country information.`);
|
|
543
561
|
}
|
|
544
|
-
const regionChanged =
|
|
545
|
-
|
|
546
|
-
!this.state.tokens.data ||
|
|
547
|
-
this.state.providers.data.length === 0;
|
|
562
|
+
const regionChanged = Boolean(options?.forceRefresh) ||
|
|
563
|
+
normalizedRegion !== this.state.userRegion?.regionCode;
|
|
548
564
|
if (regionChanged) {
|
|
549
|
-
|
|
565
|
+
// Note: we intentionally do NOT abort in-flight requests here.
|
|
566
|
+
// Aborting causes data loss during rapid region switching (e.g.
|
|
567
|
+
// user taps France → Finland → France quickly). Instead we let
|
|
568
|
+
// old requests complete naturally; isResultCurrent guards in
|
|
569
|
+
// getProviders/getPaymentMethods discard stale results.
|
|
550
570
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_clearPendingResourceCountForDependentResources).call(this);
|
|
551
571
|
}
|
|
552
572
|
this.update((state) => {
|
|
@@ -555,18 +575,6 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
555
575
|
}
|
|
556
576
|
state.userRegion = userRegion;
|
|
557
577
|
});
|
|
558
|
-
if (needsRefetch) {
|
|
559
|
-
const refetchPromises = [];
|
|
560
|
-
if (regionChanged || !this.state.tokens.data) {
|
|
561
|
-
refetchPromises.push(this.getTokens(userRegion.regionCode, 'buy', options));
|
|
562
|
-
}
|
|
563
|
-
if (regionChanged || this.state.providers.data.length === 0) {
|
|
564
|
-
refetchPromises.push(this.getProviders(userRegion.regionCode, options));
|
|
565
|
-
}
|
|
566
|
-
if (refetchPromises.length > 0) {
|
|
567
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, Promise.all(refetchPromises));
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
578
|
return userRegion;
|
|
571
579
|
}
|
|
572
580
|
catch (error) {
|
|
@@ -575,44 +583,44 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
575
583
|
}
|
|
576
584
|
}
|
|
577
585
|
/**
|
|
578
|
-
* Sets the user's selected provider
|
|
579
|
-
*
|
|
580
|
-
*
|
|
586
|
+
* Sets the user's selected provider.
|
|
587
|
+
*
|
|
588
|
+
* Accepts either a Provider object (stored directly) or a provider ID
|
|
589
|
+
* string (looked up from state). The object form is preferred when the
|
|
590
|
+
* caller already has the full data (e.g. from React Query cache).
|
|
581
591
|
*
|
|
582
|
-
* @param
|
|
583
|
-
* @
|
|
592
|
+
* @param providerOrId - A Provider object, a provider ID string (e.g., "/providers/moonpay"), or null to clear.
|
|
593
|
+
* @param options - Optional settings for the selection.
|
|
594
|
+
* @param options.autoSelected - When true, marks the provider as system-guessed
|
|
595
|
+
* (soft selection). The UI will silently auto-switch on token conflict instead
|
|
596
|
+
* of showing the "Token Not Available" modal. Defaults to false.
|
|
584
597
|
*/
|
|
585
|
-
setSelectedProvider(
|
|
586
|
-
if (
|
|
598
|
+
setSelectedProvider(providerOrId, options) {
|
|
599
|
+
if (providerOrId === null) {
|
|
587
600
|
this.update((state) => {
|
|
588
601
|
state.providers.selected = null;
|
|
589
|
-
|
|
602
|
+
state.providerAutoSelected = false;
|
|
590
603
|
});
|
|
591
604
|
return;
|
|
592
605
|
}
|
|
593
|
-
|
|
606
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
607
|
+
// If a full Provider object is passed, store it directly (avoids
|
|
608
|
+
// depending on state.providers.data being populated).
|
|
609
|
+
if (typeof providerOrId !== 'string') {
|
|
610
|
+
this.update((state) => {
|
|
611
|
+
state.providers.selected = providerOrId;
|
|
612
|
+
state.providerAutoSelected = options?.autoSelected ?? false;
|
|
613
|
+
});
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
// ID string: look up from state
|
|
594
617
|
const providers = this.state.providers.data;
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}
|
|
602
|
-
const selectedToken = this.state.tokens.selected;
|
|
603
|
-
const supportedCryptos = provider.supportedCryptoCurrencies;
|
|
604
|
-
// Only fetch payment methods if the selected token is supported by the new
|
|
605
|
-
// provider. If it isn't, the payment methods request would fail or return
|
|
606
|
-
// empty for the wrong reason; the UI will show the Token Not Available modal
|
|
607
|
-
// so the user can change token or pick a different provider.
|
|
608
|
-
const assetId = selectedToken?.assetId;
|
|
609
|
-
const tokenSupportedByProvider = !(assetId && supportedCryptos?.[assetId] === false);
|
|
610
|
-
this.update((state) => {
|
|
611
|
-
state.providers.selected = provider;
|
|
612
|
-
resetResource(state, 'paymentMethods');
|
|
613
|
-
});
|
|
614
|
-
if (tokenSupportedByProvider) {
|
|
615
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { provider: provider.id }));
|
|
618
|
+
const provider = providers?.find((prov) => prov.id === providerOrId);
|
|
619
|
+
if (provider) {
|
|
620
|
+
this.update((state) => {
|
|
621
|
+
state.providers.selected = provider;
|
|
622
|
+
state.providerAutoSelected = options?.autoSelected ?? false;
|
|
623
|
+
});
|
|
616
624
|
}
|
|
617
625
|
}
|
|
618
626
|
/**
|
|
@@ -707,11 +715,10 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
707
715
|
if (!assetId) {
|
|
708
716
|
this.update((state) => {
|
|
709
717
|
state.tokens.selected = null;
|
|
710
|
-
resetResource(state, 'paymentMethods');
|
|
711
718
|
});
|
|
712
719
|
return;
|
|
713
720
|
}
|
|
714
|
-
|
|
721
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
715
722
|
const tokens = this.state.tokens.data;
|
|
716
723
|
if (!tokens) {
|
|
717
724
|
throw new Error('Tokens not loaded. Cannot set selected token before tokens are fetched.');
|
|
@@ -723,9 +730,7 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
723
730
|
}
|
|
724
731
|
this.update((state) => {
|
|
725
732
|
state.tokens.selected = token;
|
|
726
|
-
resetResource(state, 'paymentMethods');
|
|
727
733
|
});
|
|
728
|
-
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { assetId: token.assetId }));
|
|
729
734
|
}
|
|
730
735
|
/**
|
|
731
736
|
* Fetches the list of providers for a given region.
|
|
@@ -833,29 +838,35 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
833
838
|
return response;
|
|
834
839
|
}
|
|
835
840
|
/**
|
|
836
|
-
* Sets the user's selected payment method
|
|
837
|
-
*
|
|
841
|
+
* Sets the user's selected payment method.
|
|
842
|
+
*
|
|
843
|
+
* Accepts either a payment method ID (looked up from state) or a full
|
|
844
|
+
* PaymentMethod object (stored directly). The object form is preferred
|
|
845
|
+
* when the caller already has the full data (e.g. from React Query cache),
|
|
846
|
+
* as it avoids depending on controller state being populated.
|
|
838
847
|
*
|
|
839
|
-
* @param
|
|
840
|
-
* @throws If payment methods are not loaded or payment method is not found.
|
|
848
|
+
* @param paymentMethodOrId - A PaymentMethod object, a payment method ID string, or undefined/null to clear.
|
|
841
849
|
*/
|
|
842
|
-
setSelectedPaymentMethod(
|
|
843
|
-
if (!
|
|
850
|
+
setSelectedPaymentMethod(paymentMethodOrId) {
|
|
851
|
+
if (!paymentMethodOrId) {
|
|
844
852
|
this.update((state) => {
|
|
845
853
|
state.paymentMethods.selected = null;
|
|
846
854
|
});
|
|
847
855
|
return;
|
|
848
856
|
}
|
|
849
|
-
|
|
850
|
-
if (
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
throw new Error(`Payment method with ID "${paymentMethodId}" not found in available payment methods.`);
|
|
857
|
+
// If a full object is passed, store it directly
|
|
858
|
+
if (typeof paymentMethodOrId !== 'string') {
|
|
859
|
+
this.update((state) => {
|
|
860
|
+
state.paymentMethods.selected = paymentMethodOrId;
|
|
861
|
+
});
|
|
862
|
+
return;
|
|
856
863
|
}
|
|
864
|
+
// ID string: look up from state
|
|
865
|
+
const paymentMethodId = paymentMethodOrId;
|
|
866
|
+
const paymentMethods = this.state.paymentMethods.data;
|
|
867
|
+
const paymentMethod = paymentMethods?.find((pm) => pm.id === paymentMethodId);
|
|
857
868
|
this.update((state) => {
|
|
858
|
-
state.paymentMethods.selected = paymentMethod;
|
|
869
|
+
state.paymentMethods.selected = paymentMethod ?? null;
|
|
859
870
|
});
|
|
860
871
|
}
|
|
861
872
|
/**
|
|
@@ -1114,7 +1125,8 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1114
1125
|
* @returns The unified order data.
|
|
1115
1126
|
*/
|
|
1116
1127
|
async getOrderFromCallback(providerCode, callbackUrl, wallet) {
|
|
1117
|
-
|
|
1128
|
+
const order = await this.messenger.call('RampsService:getOrderFromCallback', providerCode, callbackUrl, wallet);
|
|
1129
|
+
return order;
|
|
1118
1130
|
}
|
|
1119
1131
|
/**
|
|
1120
1132
|
* Sets the Transak API key used for all Transak API requests.
|
|
@@ -1512,9 +1524,11 @@ class RampsController extends base_controller_1.BaseController {
|
|
|
1512
1524
|
}
|
|
1513
1525
|
}
|
|
1514
1526
|
exports.RampsController = RampsController;
|
|
1515
|
-
_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() {
|
|
1527
|
+
_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() {
|
|
1516
1528
|
for (const resourceType of DEPENDENT_RESOURCE_KEYS) {
|
|
1517
1529
|
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
1530
|
+
const generation = __classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").get(resourceType) ?? 0;
|
|
1531
|
+
__classPrivateFieldGet(this, _RampsController_pendingResourceGeneration, "f").set(resourceType, generation + 1);
|
|
1518
1532
|
}
|
|
1519
1533
|
}, _RampsController_abortDependentRequests = function _RampsController_abortDependentRequests() {
|
|
1520
1534
|
for (const [cacheKey, pending] of __classPrivateFieldGet(this, _RampsController_pendingRequests, "f").entries()) {
|
|
@@ -1538,8 +1552,6 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1538
1552
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_abortDependentRequests).call(this);
|
|
1539
1553
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_clearPendingResourceCountForDependentResources).call(this);
|
|
1540
1554
|
this.update((state) => resetDependentResources(state, { clearUserRegionData: true }));
|
|
1541
|
-
}, _RampsController_fireAndForget = function _RampsController_fireAndForget(promise) {
|
|
1542
|
-
promise.catch((_error) => undefined);
|
|
1543
1555
|
}, _RampsController_requireRegion = function _RampsController_requireRegion() {
|
|
1544
1556
|
const regionCode = this.state.userRegion?.regionCode;
|
|
1545
1557
|
if (!regionCode) {
|
|
@@ -1601,14 +1613,11 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1601
1613
|
if (forceRefresh || !hasCountries) {
|
|
1602
1614
|
await this.getCountries(options);
|
|
1603
1615
|
}
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
regionCode = this.state.userRegion?.regionCode;
|
|
1610
|
-
regionCode ?? (regionCode = await this.messenger.call('RampsService:getGeolocation'));
|
|
1611
|
-
}
|
|
1616
|
+
// Always prefer the user's persisted region. Geolocation is only used to
|
|
1617
|
+
// seed the initial value; once the user (or a prior init) has set a region
|
|
1618
|
+
// we must respect that choice — even on forceRefresh.
|
|
1619
|
+
let regionCode = this.state.userRegion?.regionCode;
|
|
1620
|
+
regionCode ?? (regionCode = await this.messenger.call('RampsService:getGeolocation'));
|
|
1612
1621
|
if (!regionCode) {
|
|
1613
1622
|
throw new Error('Failed to fetch geolocation. Cannot initialize controller without valid region information.');
|
|
1614
1623
|
}
|
|
@@ -1625,10 +1634,9 @@ async function _RampsController_refreshOrder(order) {
|
|
|
1625
1634
|
if (!providerCode || !order.providerOrderId || !order.walletAddress) {
|
|
1626
1635
|
return;
|
|
1627
1636
|
}
|
|
1628
|
-
const providerCodeSegment = normalizeProviderCode(providerCode);
|
|
1629
1637
|
const previousStatus = order.status;
|
|
1630
1638
|
try {
|
|
1631
|
-
const updatedOrder = await this.getOrder(
|
|
1639
|
+
const updatedOrder = await this.getOrder(providerCode, order.providerOrderId, order.walletAddress);
|
|
1632
1640
|
const meta = __classPrivateFieldGet(this, _RampsController_orderPollingMeta, "f").get(order.providerOrderId) ?? {
|
|
1633
1641
|
lastTimeFetched: 0,
|
|
1634
1642
|
errorCount: 0,
|