@metamask/ramps-controller 7.1.0 → 8.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 +22 -1
- package/dist/RampsController.cjs +651 -131
- package/dist/RampsController.cjs.map +1 -1
- package/dist/RampsController.d.cts +271 -21
- package/dist/RampsController.d.cts.map +1 -1
- package/dist/RampsController.d.mts +271 -21
- package/dist/RampsController.d.mts.map +1 -1
- package/dist/RampsController.mjs +651 -131
- 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 +14 -2
- package/dist/RampsService-method-action-types.d.cts.map +1 -1
- package/dist/RampsService-method-action-types.d.mts +14 -2
- 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 +28 -4
- package/dist/RampsService.cjs.map +1 -1
- package/dist/RampsService.d.cts +42 -7
- package/dist/RampsService.d.cts.map +1 -1
- package/dist/RampsService.d.mts +42 -7
- package/dist/RampsService.d.mts.map +1 -1
- package/dist/RampsService.mjs +28 -4
- package/dist/RampsService.mjs.map +1 -1
- package/dist/RequestCache.cjs.map +1 -1
- package/dist/RequestCache.d.cts +2 -0
- package/dist/RequestCache.d.cts.map +1 -1
- package/dist/RequestCache.d.mts +2 -0
- package/dist/RequestCache.d.mts.map +1 -1
- package/dist/RequestCache.mjs.map +1 -1
- package/dist/TransakService-method-action-types.cjs +7 -0
- package/dist/TransakService-method-action-types.cjs.map +1 -0
- package/dist/TransakService-method-action-types.d.cts +106 -0
- package/dist/TransakService-method-action-types.d.cts.map +1 -0
- package/dist/TransakService-method-action-types.d.mts +106 -0
- package/dist/TransakService-method-action-types.d.mts.map +1 -0
- package/dist/TransakService-method-action-types.mjs +6 -0
- package/dist/TransakService-method-action-types.mjs.map +1 -0
- package/dist/TransakService.cjs +588 -0
- package/dist/TransakService.cjs.map +1 -0
- package/dist/TransakService.d.cts +329 -0
- package/dist/TransakService.d.cts.map +1 -0
- package/dist/TransakService.d.mts +329 -0
- package/dist/TransakService.d.mts.map +1 -0
- package/dist/TransakService.mjs +582 -0
- package/dist/TransakService.mjs.map +1 -0
- package/dist/index.cjs +6 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -6
package/dist/RampsController.mjs
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_quotePollingInterval, _RampsController_quotePollingOptions, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_fireAndForget, _RampsController_restartPollingIfActive, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState;
|
|
12
|
+
var _RampsController_instances, _RampsController_requestCacheTTL, _RampsController_requestCacheMaxSize, _RampsController_pendingRequests, _RampsController_pendingResourceCount, _RampsController_quotePollingInterval, _RampsController_quotePollingOptions, _RampsController_clearPendingResourceCountForDependentResources, _RampsController_abortDependentRequests, _RampsController_mutateRequests, _RampsController_removeRequestState, _RampsController_cleanupState, _RampsController_fireAndForget, _RampsController_restartPollingIfActive, _RampsController_requireRegion, _RampsController_isRegionCurrent, _RampsController_isTokenCurrent, _RampsController_isProviderCurrent, _RampsController_updateResourceField, _RampsController_setResourceLoading, _RampsController_setResourceError, _RampsController_updateRequestState, _RampsController_syncWidgetUrl, _RampsController_syncTransakAuthOnError;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
14
|
import { DEFAULT_REQUEST_CACHE_TTL, DEFAULT_REQUEST_CACHE_MAX_SIZE, createCacheKey, isCacheExpired, createLoadingState, createSuccessState, createErrorState, RequestStatus } from "./RequestCache.mjs";
|
|
15
15
|
// === GENERAL ===
|
|
@@ -31,6 +31,31 @@ export const RAMPS_CONTROLLER_REQUIRED_SERVICE_ACTIONS = [
|
|
|
31
31
|
'RampsService:getProviders',
|
|
32
32
|
'RampsService:getPaymentMethods',
|
|
33
33
|
'RampsService:getQuotes',
|
|
34
|
+
'RampsService:getBuyWidgetUrl',
|
|
35
|
+
'TransakService:setApiKey',
|
|
36
|
+
'TransakService:setAccessToken',
|
|
37
|
+
'TransakService:clearAccessToken',
|
|
38
|
+
'TransakService:sendUserOtp',
|
|
39
|
+
'TransakService:verifyUserOtp',
|
|
40
|
+
'TransakService:logout',
|
|
41
|
+
'TransakService:getUserDetails',
|
|
42
|
+
'TransakService:getBuyQuote',
|
|
43
|
+
'TransakService:getKycRequirement',
|
|
44
|
+
'TransakService:getAdditionalRequirements',
|
|
45
|
+
'TransakService:createOrder',
|
|
46
|
+
'TransakService:getOrder',
|
|
47
|
+
'TransakService:getUserLimits',
|
|
48
|
+
'TransakService:requestOtt',
|
|
49
|
+
'TransakService:generatePaymentWidgetUrl',
|
|
50
|
+
'TransakService:submitPurposeOfUsageForm',
|
|
51
|
+
'TransakService:patchUser',
|
|
52
|
+
'TransakService:submitSsnDetails',
|
|
53
|
+
'TransakService:confirmPayment',
|
|
54
|
+
'TransakService:getTranslation',
|
|
55
|
+
'TransakService:getIdProofStatus',
|
|
56
|
+
'TransakService:cancelOrder',
|
|
57
|
+
'TransakService:cancelAllActiveOrders',
|
|
58
|
+
'TransakService:getActiveOrders',
|
|
34
59
|
];
|
|
35
60
|
/**
|
|
36
61
|
* Default TTL for quotes requests (15 seconds).
|
|
@@ -77,12 +102,24 @@ const rampsControllerMetadata = {
|
|
|
77
102
|
includeInStateLogs: false,
|
|
78
103
|
usedInUi: true,
|
|
79
104
|
},
|
|
105
|
+
widgetUrl: {
|
|
106
|
+
persist: false,
|
|
107
|
+
includeInDebugSnapshot: true,
|
|
108
|
+
includeInStateLogs: false,
|
|
109
|
+
usedInUi: true,
|
|
110
|
+
},
|
|
80
111
|
requests: {
|
|
81
112
|
persist: false,
|
|
82
113
|
includeInDebugSnapshot: true,
|
|
83
114
|
includeInStateLogs: false,
|
|
84
115
|
usedInUi: true,
|
|
85
116
|
},
|
|
117
|
+
nativeProviders: {
|
|
118
|
+
persist: false,
|
|
119
|
+
includeInDebugSnapshot: true,
|
|
120
|
+
includeInStateLogs: false,
|
|
121
|
+
usedInUi: true,
|
|
122
|
+
},
|
|
86
123
|
};
|
|
87
124
|
/**
|
|
88
125
|
* Creates a default resource state object.
|
|
@@ -117,9 +154,46 @@ export function getDefaultRampsControllerState() {
|
|
|
117
154
|
tokens: createDefaultResourceState(null, null),
|
|
118
155
|
paymentMethods: createDefaultResourceState([], null),
|
|
119
156
|
quotes: createDefaultResourceState(null, null),
|
|
157
|
+
widgetUrl: createDefaultResourceState(null),
|
|
120
158
|
requests: {},
|
|
159
|
+
nativeProviders: {
|
|
160
|
+
transak: {
|
|
161
|
+
isAuthenticated: false,
|
|
162
|
+
userDetails: createDefaultResourceState(null),
|
|
163
|
+
buyQuote: createDefaultResourceState(null),
|
|
164
|
+
kycRequirement: createDefaultResourceState(null),
|
|
165
|
+
},
|
|
166
|
+
},
|
|
121
167
|
};
|
|
122
168
|
}
|
|
169
|
+
const DEPENDENT_RESOURCE_KEYS = [
|
|
170
|
+
'providers',
|
|
171
|
+
'tokens',
|
|
172
|
+
'paymentMethods',
|
|
173
|
+
'quotes',
|
|
174
|
+
];
|
|
175
|
+
const DEPENDENT_RESOURCE_KEYS_SET = new Set(DEPENDENT_RESOURCE_KEYS);
|
|
176
|
+
function resetResource(state, resourceType, defaultResource) {
|
|
177
|
+
const def = defaultResource ?? getDefaultRampsControllerState()[resourceType];
|
|
178
|
+
const resource = state[resourceType];
|
|
179
|
+
resource.data = def.data;
|
|
180
|
+
resource.selected = def.selected;
|
|
181
|
+
resource.isLoading = def.isLoading;
|
|
182
|
+
resource.error = def.error;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Resets the widgetUrl resource to its default state.
|
|
186
|
+
* Mutates state in place; use from within controller update() for atomic updates.
|
|
187
|
+
*
|
|
188
|
+
* @param state - The state object to mutate.
|
|
189
|
+
*/
|
|
190
|
+
function resetWidgetUrl(state) {
|
|
191
|
+
const def = getDefaultRampsControllerState().widgetUrl;
|
|
192
|
+
state.widgetUrl.data = def.data;
|
|
193
|
+
state.widgetUrl.selected = def.selected;
|
|
194
|
+
state.widgetUrl.isLoading = def.isLoading;
|
|
195
|
+
state.widgetUrl.error = def.error;
|
|
196
|
+
}
|
|
123
197
|
/**
|
|
124
198
|
* Resets region-dependent resources (userRegion, providers, tokens, paymentMethods, quotes).
|
|
125
199
|
* Mutates state in place; use from within controller update() for atomic updates.
|
|
@@ -132,22 +206,11 @@ function resetDependentResources(state, options) {
|
|
|
132
206
|
if (options?.clearUserRegionData) {
|
|
133
207
|
state.userRegion = null;
|
|
134
208
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
state
|
|
140
|
-
state.tokens.data = null;
|
|
141
|
-
state.tokens.isLoading = false;
|
|
142
|
-
state.tokens.error = null;
|
|
143
|
-
state.paymentMethods.data = [];
|
|
144
|
-
state.paymentMethods.selected = null;
|
|
145
|
-
state.paymentMethods.isLoading = false;
|
|
146
|
-
state.paymentMethods.error = null;
|
|
147
|
-
state.quotes.data = null;
|
|
148
|
-
state.quotes.selected = null;
|
|
149
|
-
state.quotes.isLoading = false;
|
|
150
|
-
state.quotes.error = null;
|
|
209
|
+
const defaultState = getDefaultRampsControllerState();
|
|
210
|
+
for (const key of DEPENDENT_RESOURCE_KEYS) {
|
|
211
|
+
resetResource(state, key, defaultState[key]);
|
|
212
|
+
}
|
|
213
|
+
resetWidgetUrl(state);
|
|
151
214
|
}
|
|
152
215
|
// === HELPER FUNCTIONS ===
|
|
153
216
|
/**
|
|
@@ -271,31 +334,49 @@ export class RampsController extends BaseController {
|
|
|
271
334
|
__classPrivateFieldSet(this, _RampsController_requestCacheMaxSize, requestCacheMaxSize, "f");
|
|
272
335
|
}
|
|
273
336
|
/**
|
|
274
|
-
* Executes a request with caching and
|
|
337
|
+
* Executes a request with caching, deduplication, and at most one in-flight
|
|
338
|
+
* request per resource type.
|
|
275
339
|
*
|
|
276
|
-
* If a request with
|
|
277
|
-
*
|
|
278
|
-
* a new request.
|
|
340
|
+
* 1. **Same cache key in flight** – If a request with this cache key is
|
|
341
|
+
* already pending, returns that promise (deduplication; no second request).
|
|
279
342
|
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
343
|
+
* 2. **Cache hit** – If valid, non-expired data exists in state.requests for
|
|
344
|
+
* this key and forceRefresh is not set, returns that data without fetching.
|
|
345
|
+
*
|
|
346
|
+
* 3. **New request** – Creates an AbortController and fires the fetcher.
|
|
347
|
+
* If options.resourceType is set, tags the pending request with that
|
|
348
|
+
* resource type (so #abortDependentRequests can cancel it on region
|
|
349
|
+
* change or cleanup) and ref-counts resource-level loading state.
|
|
350
|
+
* On success or error, updates request state and resource error;
|
|
351
|
+
* in finally, clears resource loading only if this request was not
|
|
352
|
+
* aborted.
|
|
353
|
+
*
|
|
354
|
+
* @param cacheKey - Unique identifier for this request (e.g. from createCacheKey).
|
|
355
|
+
* @param fetcher - Async function that performs the fetch. Receives an AbortSignal
|
|
356
|
+
* that is aborted when this request is superseded by another for the same resource.
|
|
357
|
+
* @param options - Optional forceRefresh, ttl, and resourceType for loading/error state.
|
|
358
|
+
* @returns The result of the request (from cache, joined promise, or fetcher).
|
|
284
359
|
*/
|
|
285
360
|
async executeRequest(cacheKey, fetcher, options) {
|
|
361
|
+
// Get TTL for verifying cache expiration
|
|
286
362
|
const ttl = options?.ttl ?? __classPrivateFieldGet(this, _RampsController_requestCacheTTL, "f");
|
|
287
|
-
//
|
|
363
|
+
// DEDUPLICATION:
|
|
364
|
+
// Check if a request is already in flight for this cache key
|
|
365
|
+
// If so, return the original promise for that request
|
|
288
366
|
const pending = __classPrivateFieldGet(this, _RampsController_pendingRequests, "f").get(cacheKey);
|
|
289
367
|
if (pending) {
|
|
290
368
|
return pending.promise;
|
|
291
369
|
}
|
|
370
|
+
// CACHE HIT:
|
|
371
|
+
// If cache is not expired, return the cached data
|
|
292
372
|
if (!options?.forceRefresh) {
|
|
293
373
|
const cached = this.state.requests[cacheKey];
|
|
294
374
|
if (cached && !isCacheExpired(cached, ttl)) {
|
|
295
375
|
return cached.data;
|
|
296
376
|
}
|
|
297
377
|
}
|
|
298
|
-
// Create abort controller for this request
|
|
378
|
+
// Create a new abort controller for this request
|
|
379
|
+
// Record the time the request was started
|
|
299
380
|
const abortController = new AbortController();
|
|
300
381
|
const lastFetchedAt = Date.now();
|
|
301
382
|
const { resourceType } = options ?? {};
|
|
@@ -314,15 +395,11 @@ export class RampsController extends BaseController {
|
|
|
314
395
|
const promise = (async () => {
|
|
315
396
|
try {
|
|
316
397
|
const data = await fetcher(abortController.signal);
|
|
317
|
-
// Don't update state if aborted
|
|
318
398
|
if (abortController.signal.aborted) {
|
|
319
399
|
throw new Error('Request was aborted');
|
|
320
400
|
}
|
|
321
401
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_updateRequestState).call(this, cacheKey, createSuccessState(data, lastFetchedAt));
|
|
322
402
|
if (resourceType) {
|
|
323
|
-
// We need the extra logic because there are two situations where we’re allowed to clear the error:
|
|
324
|
-
// No callback → always clear
|
|
325
|
-
// Callback present → clear only when isResultCurrent() returns true.
|
|
326
403
|
const isCurrent = !options?.isResultCurrent || options.isResultCurrent();
|
|
327
404
|
if (isCurrent) {
|
|
328
405
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_setResourceError).call(this, resourceType, null);
|
|
@@ -331,7 +408,6 @@ export class RampsController extends BaseController {
|
|
|
331
408
|
return data;
|
|
332
409
|
}
|
|
333
410
|
catch (error) {
|
|
334
|
-
// Don't update state if aborted
|
|
335
411
|
if (abortController.signal.aborted) {
|
|
336
412
|
throw error;
|
|
337
413
|
}
|
|
@@ -346,13 +422,12 @@ export class RampsController extends BaseController {
|
|
|
346
422
|
throw error;
|
|
347
423
|
}
|
|
348
424
|
finally {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if (currentPending?.abortController === abortController) {
|
|
425
|
+
if (__classPrivateFieldGet(this, _RampsController_pendingRequests, "f").get(cacheKey)?.abortController ===
|
|
426
|
+
abortController) {
|
|
352
427
|
__classPrivateFieldGet(this, _RampsController_pendingRequests, "f").delete(cacheKey);
|
|
353
428
|
}
|
|
354
429
|
// Clear resource-level loading state only when no requests for this resource remain
|
|
355
|
-
if (resourceType) {
|
|
430
|
+
if (resourceType && !abortController.signal.aborted) {
|
|
356
431
|
const count = __classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").get(resourceType) ?? 0;
|
|
357
432
|
const next = Math.max(0, count - 1);
|
|
358
433
|
if (next === 0) {
|
|
@@ -365,8 +440,11 @@ export class RampsController extends BaseController {
|
|
|
365
440
|
}
|
|
366
441
|
}
|
|
367
442
|
})();
|
|
368
|
-
|
|
369
|
-
|
|
443
|
+
__classPrivateFieldGet(this, _RampsController_pendingRequests, "f").set(cacheKey, {
|
|
444
|
+
promise,
|
|
445
|
+
abortController,
|
|
446
|
+
resourceType,
|
|
447
|
+
});
|
|
370
448
|
return promise;
|
|
371
449
|
}
|
|
372
450
|
/**
|
|
@@ -420,9 +498,8 @@ export class RampsController extends BaseController {
|
|
|
420
498
|
!this.state.tokens.data ||
|
|
421
499
|
this.state.providers.data.length === 0;
|
|
422
500
|
if (regionChanged) {
|
|
501
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_abortDependentRequests).call(this);
|
|
423
502
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_clearPendingResourceCountForDependentResources).call(this);
|
|
424
|
-
}
|
|
425
|
-
if (regionChanged) {
|
|
426
503
|
this.stopQuotePolling();
|
|
427
504
|
}
|
|
428
505
|
this.update((state) => {
|
|
@@ -463,15 +540,11 @@ export class RampsController extends BaseController {
|
|
|
463
540
|
this.stopQuotePolling();
|
|
464
541
|
this.update((state) => {
|
|
465
542
|
state.providers.selected = null;
|
|
466
|
-
state
|
|
467
|
-
state.paymentMethods.selected = null;
|
|
543
|
+
resetResource(state, 'paymentMethods');
|
|
468
544
|
});
|
|
469
545
|
return;
|
|
470
546
|
}
|
|
471
|
-
const regionCode = this.
|
|
472
|
-
if (!regionCode) {
|
|
473
|
-
throw new Error('Region is required. Cannot set selected provider without valid region information.');
|
|
474
|
-
}
|
|
547
|
+
const regionCode = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
475
548
|
const providers = this.state.providers.data;
|
|
476
549
|
if (!providers || providers.length === 0) {
|
|
477
550
|
throw new Error('Providers not loaded. Cannot set selected provider before providers are fetched.');
|
|
@@ -482,9 +555,9 @@ export class RampsController extends BaseController {
|
|
|
482
555
|
}
|
|
483
556
|
this.update((state) => {
|
|
484
557
|
state.providers.selected = provider;
|
|
485
|
-
state
|
|
486
|
-
state.paymentMethods.selected = null;
|
|
558
|
+
resetResource(state, 'paymentMethods');
|
|
487
559
|
state.quotes.selected = null;
|
|
560
|
+
resetWidgetUrl(state);
|
|
488
561
|
});
|
|
489
562
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { provider: provider.id }).then(() => {
|
|
490
563
|
// Restart quote polling after payment methods are fetched
|
|
@@ -512,10 +585,7 @@ export class RampsController extends BaseController {
|
|
|
512
585
|
await this.setUserRegion(regionCode, options);
|
|
513
586
|
}
|
|
514
587
|
hydrateState(options) {
|
|
515
|
-
const regionCode = this.
|
|
516
|
-
if (!regionCode) {
|
|
517
|
-
throw new Error('Region code is required. Cannot hydrate state without valid region information.');
|
|
518
|
-
}
|
|
588
|
+
const regionCode = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
519
589
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getTokens(regionCode, 'buy', options));
|
|
520
590
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getProviders(regionCode, options));
|
|
521
591
|
}
|
|
@@ -533,7 +603,7 @@ export class RampsController extends BaseController {
|
|
|
533
603
|
return this.messenger.call('RampsService:getCountries');
|
|
534
604
|
}, { ...options, resourceType: 'countries' });
|
|
535
605
|
this.update((state) => {
|
|
536
|
-
state.countries.data = countries;
|
|
606
|
+
state.countries.data = Array.isArray(countries) ? [...countries] : [];
|
|
537
607
|
});
|
|
538
608
|
return countries;
|
|
539
609
|
}
|
|
@@ -548,10 +618,7 @@ export class RampsController extends BaseController {
|
|
|
548
618
|
* @returns The tokens response containing topTokens and allTokens.
|
|
549
619
|
*/
|
|
550
620
|
async getTokens(region, action = 'buy', options) {
|
|
551
|
-
const regionToUse = region ?? this.
|
|
552
|
-
if (!regionToUse) {
|
|
553
|
-
throw new Error('Region is required. Either provide a region parameter or ensure userRegion is set in controller state.');
|
|
554
|
-
}
|
|
621
|
+
const regionToUse = region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
555
622
|
const normalizedRegion = regionToUse.toLowerCase().trim();
|
|
556
623
|
const cacheKey = createCacheKey('getTokens', [
|
|
557
624
|
normalizedRegion,
|
|
@@ -565,8 +632,7 @@ export class RampsController extends BaseController {
|
|
|
565
632
|
}, {
|
|
566
633
|
...options,
|
|
567
634
|
resourceType: 'tokens',
|
|
568
|
-
isResultCurrent: () => this
|
|
569
|
-
this.state.userRegion?.regionCode === normalizedRegion,
|
|
635
|
+
isResultCurrent: () => __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isRegionCurrent).call(this, normalizedRegion),
|
|
570
636
|
});
|
|
571
637
|
this.update((state) => {
|
|
572
638
|
const userRegionCode = state.userRegion?.regionCode;
|
|
@@ -589,15 +655,11 @@ export class RampsController extends BaseController {
|
|
|
589
655
|
this.stopQuotePolling();
|
|
590
656
|
this.update((state) => {
|
|
591
657
|
state.tokens.selected = null;
|
|
592
|
-
state
|
|
593
|
-
state.paymentMethods.selected = null;
|
|
658
|
+
resetResource(state, 'paymentMethods');
|
|
594
659
|
});
|
|
595
660
|
return;
|
|
596
661
|
}
|
|
597
|
-
const regionCode = this.
|
|
598
|
-
if (!regionCode) {
|
|
599
|
-
throw new Error('Region is required. Cannot set selected token without valid region information.');
|
|
600
|
-
}
|
|
662
|
+
const regionCode = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
601
663
|
const tokens = this.state.tokens.data;
|
|
602
664
|
if (!tokens) {
|
|
603
665
|
throw new Error('Tokens not loaded. Cannot set selected token before tokens are fetched.');
|
|
@@ -609,9 +671,9 @@ export class RampsController extends BaseController {
|
|
|
609
671
|
}
|
|
610
672
|
this.update((state) => {
|
|
611
673
|
state.tokens.selected = token;
|
|
612
|
-
state
|
|
613
|
-
state.paymentMethods.selected = null;
|
|
674
|
+
resetResource(state, 'paymentMethods');
|
|
614
675
|
state.quotes.selected = null;
|
|
676
|
+
resetWidgetUrl(state);
|
|
615
677
|
});
|
|
616
678
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.getPaymentMethods(regionCode, { assetId: token.assetId }).then(() => {
|
|
617
679
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_restartPollingIfActive).call(this);
|
|
@@ -631,10 +693,7 @@ export class RampsController extends BaseController {
|
|
|
631
693
|
* @returns The providers response containing providers array.
|
|
632
694
|
*/
|
|
633
695
|
async getProviders(region, options) {
|
|
634
|
-
const regionToUse = region ?? this.
|
|
635
|
-
if (!regionToUse) {
|
|
636
|
-
throw new Error('Region is required. Either provide a region parameter or ensure userRegion is set in controller state.');
|
|
637
|
-
}
|
|
696
|
+
const regionToUse = region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
638
697
|
const normalizedRegion = regionToUse.toLowerCase().trim();
|
|
639
698
|
const cacheKey = createCacheKey('getProviders', [
|
|
640
699
|
normalizedRegion,
|
|
@@ -653,8 +712,7 @@ export class RampsController extends BaseController {
|
|
|
653
712
|
}, {
|
|
654
713
|
...options,
|
|
655
714
|
resourceType: 'providers',
|
|
656
|
-
isResultCurrent: () => this
|
|
657
|
-
this.state.userRegion?.regionCode === normalizedRegion,
|
|
715
|
+
isResultCurrent: () => __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isRegionCurrent).call(this, normalizedRegion),
|
|
658
716
|
});
|
|
659
717
|
this.update((state) => {
|
|
660
718
|
const userRegionCode = state.userRegion?.regionCode;
|
|
@@ -676,13 +734,10 @@ export class RampsController extends BaseController {
|
|
|
676
734
|
* @returns The payment methods response containing payments array.
|
|
677
735
|
*/
|
|
678
736
|
async getPaymentMethods(region, options) {
|
|
679
|
-
const regionCode = region ?? this
|
|
737
|
+
const regionCode = region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
680
738
|
const fiatToUse = options?.fiat ?? this.state.userRegion?.country?.currency ?? null;
|
|
681
739
|
const assetIdToUse = options?.assetId ?? this.state.tokens.selected?.assetId ?? '';
|
|
682
740
|
const providerToUse = options?.provider ?? this.state.providers.selected?.id ?? '';
|
|
683
|
-
if (!regionCode) {
|
|
684
|
-
throw new Error('Region is required. Either provide a region parameter or ensure userRegion is set in controller state.');
|
|
685
|
-
}
|
|
686
741
|
if (!fiatToUse) {
|
|
687
742
|
throw new Error('Fiat currency is required. Either provide a fiat parameter or ensure userRegion is set in controller state.');
|
|
688
743
|
}
|
|
@@ -705,10 +760,9 @@ export class RampsController extends BaseController {
|
|
|
705
760
|
...options,
|
|
706
761
|
resourceType: 'paymentMethods',
|
|
707
762
|
isResultCurrent: () => {
|
|
708
|
-
const regionMatch = this
|
|
709
|
-
|
|
710
|
-
const
|
|
711
|
-
const providerMatch = (this.state.providers.selected?.id ?? '') === providerToUse;
|
|
763
|
+
const regionMatch = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isRegionCurrent).call(this, normalizedRegion);
|
|
764
|
+
const tokenMatch = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isTokenCurrent).call(this, assetIdToUse);
|
|
765
|
+
const providerMatch = __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isProviderCurrent).call(this, providerToUse);
|
|
712
766
|
return regionMatch && tokenMatch && providerMatch;
|
|
713
767
|
},
|
|
714
768
|
});
|
|
@@ -770,7 +824,7 @@ export class RampsController extends BaseController {
|
|
|
770
824
|
* @param options.amount - The amount (in fiat for buy, crypto for sell).
|
|
771
825
|
* @param options.walletAddress - The destination wallet address.
|
|
772
826
|
* @param options.paymentMethods - Array of payment method IDs. If not provided, uses paymentMethods from state.
|
|
773
|
-
* @param options.
|
|
827
|
+
* @param options.providers - Optional provider IDs to filter quotes.
|
|
774
828
|
* @param options.redirectUrl - Optional redirect URL after order completion.
|
|
775
829
|
* @param options.action - The ramp action type. Defaults to 'buy'.
|
|
776
830
|
* @param options.forceRefresh - Whether to bypass cache.
|
|
@@ -778,32 +832,35 @@ export class RampsController extends BaseController {
|
|
|
778
832
|
* @returns The quotes response containing success, sorted, error, and customActions.
|
|
779
833
|
*/
|
|
780
834
|
async getQuotes(options) {
|
|
781
|
-
const regionToUse = options.region ?? this.
|
|
835
|
+
const regionToUse = options.region ?? __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
782
836
|
const fiatToUse = options.fiat ?? this.state.userRegion?.country?.currency;
|
|
783
837
|
const paymentMethodsToUse = options.paymentMethods ??
|
|
784
838
|
this.state.paymentMethods.data.map((pm) => pm.id);
|
|
839
|
+
const providersToUse = options.providers ??
|
|
840
|
+
this.state.providers.data.map((provider) => provider.id);
|
|
785
841
|
const action = options.action ?? 'buy';
|
|
786
|
-
|
|
787
|
-
throw new Error('Region is required. Either provide a region parameter or ensure userRegion is set in controller state.');
|
|
788
|
-
}
|
|
842
|
+
const assetIdToUse = options.assetId ?? this.state.tokens.selected?.assetId;
|
|
789
843
|
if (!fiatToUse) {
|
|
790
844
|
throw new Error('Fiat currency is required. Either provide a fiat parameter or ensure userRegion is set in controller state.');
|
|
791
845
|
}
|
|
792
|
-
|
|
846
|
+
const normalizedAssetIdForValidation = (assetIdToUse ?? '').trim();
|
|
847
|
+
if (normalizedAssetIdForValidation === '') {
|
|
848
|
+
throw new Error('assetId is required.');
|
|
849
|
+
}
|
|
850
|
+
if (!paymentMethodsToUse ||
|
|
851
|
+
paymentMethodsToUse.length === 0 ||
|
|
852
|
+
paymentMethodsToUse.some((pm) => pm.trim() === '')) {
|
|
793
853
|
throw new Error('Payment methods are required. Either provide paymentMethods parameter or ensure paymentMethods are set in controller state.');
|
|
794
854
|
}
|
|
795
855
|
if (options.amount <= 0 || !Number.isFinite(options.amount)) {
|
|
796
856
|
throw new Error('Amount must be a positive finite number.');
|
|
797
857
|
}
|
|
798
|
-
if (!options.assetId || options.assetId.trim() === '') {
|
|
799
|
-
throw new Error('assetId is required.');
|
|
800
|
-
}
|
|
801
858
|
if (!options.walletAddress || options.walletAddress.trim() === '') {
|
|
802
859
|
throw new Error('walletAddress is required.');
|
|
803
860
|
}
|
|
804
861
|
const normalizedRegion = regionToUse.toLowerCase().trim();
|
|
805
862
|
const normalizedFiat = fiatToUse.toLowerCase().trim();
|
|
806
|
-
const normalizedAssetId =
|
|
863
|
+
const normalizedAssetId = normalizedAssetIdForValidation;
|
|
807
864
|
const normalizedWalletAddress = options.walletAddress.trim();
|
|
808
865
|
const cacheKey = createCacheKey('getQuotes', [
|
|
809
866
|
normalizedRegion,
|
|
@@ -812,7 +869,7 @@ export class RampsController extends BaseController {
|
|
|
812
869
|
options.amount,
|
|
813
870
|
normalizedWalletAddress,
|
|
814
871
|
[...paymentMethodsToUse].sort().join(','),
|
|
815
|
-
|
|
872
|
+
[...providersToUse].sort().join(','),
|
|
816
873
|
options.redirectUrl,
|
|
817
874
|
action,
|
|
818
875
|
]);
|
|
@@ -823,7 +880,7 @@ export class RampsController extends BaseController {
|
|
|
823
880
|
amount: options.amount,
|
|
824
881
|
walletAddress: normalizedWalletAddress,
|
|
825
882
|
paymentMethods: paymentMethodsToUse,
|
|
826
|
-
|
|
883
|
+
providers: providersToUse,
|
|
827
884
|
redirectUrl: options.redirectUrl,
|
|
828
885
|
action,
|
|
829
886
|
};
|
|
@@ -833,8 +890,7 @@ export class RampsController extends BaseController {
|
|
|
833
890
|
forceRefresh: options.forceRefresh,
|
|
834
891
|
ttl: options.ttl ?? DEFAULT_QUOTES_TTL,
|
|
835
892
|
resourceType: 'quotes',
|
|
836
|
-
isResultCurrent: () => this
|
|
837
|
-
this.state.userRegion?.regionCode === normalizedRegion,
|
|
893
|
+
isResultCurrent: () => __classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_isRegionCurrent).call(this, normalizedRegion),
|
|
838
894
|
});
|
|
839
895
|
this.update((state) => {
|
|
840
896
|
const userRegionCode = state.userRegion?.regionCode;
|
|
@@ -850,21 +906,20 @@ export class RampsController extends BaseController {
|
|
|
850
906
|
* If the response contains exactly one quote, it is auto-selected.
|
|
851
907
|
* If multiple quotes are returned, the existing selection is preserved if still valid.
|
|
852
908
|
*
|
|
909
|
+
* Returns early (no-op) if the selected payment method is not yet set,
|
|
910
|
+
* allowing callers to invoke this before payment-method selection is finalized.
|
|
911
|
+
*
|
|
853
912
|
* @param options - Parameters for fetching quotes.
|
|
854
913
|
* @param options.walletAddress - The destination wallet address.
|
|
855
914
|
* @param options.amount - The amount (in fiat for buy, crypto for sell).
|
|
856
915
|
* @param options.redirectUrl - Optional redirect URL after order completion.
|
|
857
|
-
* @throws If required dependencies (region, token, provider
|
|
916
|
+
* @throws If required dependencies (region, token, provider) are not set.
|
|
858
917
|
*/
|
|
859
918
|
startQuotePolling(options) {
|
|
860
|
-
|
|
861
|
-
const regionCode = this.state.userRegion?.regionCode;
|
|
919
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_requireRegion).call(this);
|
|
862
920
|
const token = this.state.tokens.selected;
|
|
863
921
|
const provider = this.state.providers.selected;
|
|
864
922
|
const paymentMethod = this.state.paymentMethods.selected;
|
|
865
|
-
if (!regionCode) {
|
|
866
|
-
throw new Error('Region is required. Cannot start quote polling without valid region information.');
|
|
867
|
-
}
|
|
868
923
|
if (!token) {
|
|
869
924
|
throw new Error('Token is required. Cannot start quote polling without a selected token.');
|
|
870
925
|
}
|
|
@@ -886,13 +941,15 @@ export class RampsController extends BaseController {
|
|
|
886
941
|
walletAddress: options.walletAddress,
|
|
887
942
|
redirectUrl: options.redirectUrl,
|
|
888
943
|
paymentMethods: [paymentMethod.id],
|
|
889
|
-
|
|
944
|
+
providers: [provider.id],
|
|
890
945
|
forceRefresh: true,
|
|
891
946
|
}).then((response) => {
|
|
947
|
+
let newSelectedQuote = null;
|
|
892
948
|
// Auto-select logic: only when exactly one quote is returned
|
|
893
949
|
this.update((state) => {
|
|
894
950
|
if (response.success.length === 1) {
|
|
895
|
-
|
|
951
|
+
newSelectedQuote = response.success[0];
|
|
952
|
+
state.quotes.selected = newSelectedQuote;
|
|
896
953
|
}
|
|
897
954
|
else {
|
|
898
955
|
// Keep existing selection if still valid, but update with fresh data
|
|
@@ -901,11 +958,12 @@ export class RampsController extends BaseController {
|
|
|
901
958
|
const freshQuote = response.success.find((quote) => quote.provider === currentSelection.provider &&
|
|
902
959
|
quote.quote.paymentMethod ===
|
|
903
960
|
currentSelection.quote.paymentMethod);
|
|
904
|
-
|
|
905
|
-
state.quotes.selected =
|
|
961
|
+
newSelectedQuote = freshQuote ?? null;
|
|
962
|
+
state.quotes.selected = newSelectedQuote;
|
|
906
963
|
}
|
|
907
964
|
}
|
|
908
965
|
});
|
|
966
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncWidgetUrl).call(this, newSelectedQuote);
|
|
909
967
|
return undefined;
|
|
910
968
|
}));
|
|
911
969
|
};
|
|
@@ -927,6 +985,7 @@ export class RampsController extends BaseController {
|
|
|
927
985
|
}
|
|
928
986
|
/**
|
|
929
987
|
* Manually sets the selected quote.
|
|
988
|
+
* Automatically triggers a widget URL fetch for the new quote.
|
|
930
989
|
*
|
|
931
990
|
* @param quote - The quote to select, or null to clear the selection.
|
|
932
991
|
*/
|
|
@@ -934,6 +993,7 @@ export class RampsController extends BaseController {
|
|
|
934
993
|
this.update((state) => {
|
|
935
994
|
state.quotes.selected = quote;
|
|
936
995
|
});
|
|
996
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncWidgetUrl).call(this, quote);
|
|
937
997
|
}
|
|
938
998
|
/**
|
|
939
999
|
* Cleans up controller resources.
|
|
@@ -945,37 +1005,450 @@ export class RampsController extends BaseController {
|
|
|
945
1005
|
super.destroy();
|
|
946
1006
|
}
|
|
947
1007
|
/**
|
|
948
|
-
*
|
|
949
|
-
*
|
|
1008
|
+
* Fetches the widget URL from a quote for redirect providers.
|
|
1009
|
+
* Makes a request to the buyURL endpoint via the RampsService to get the
|
|
1010
|
+
* actual provider widget URL, using the injected fetch and retry policy.
|
|
1011
|
+
*
|
|
1012
|
+
* @param quote - The quote to fetch the widget URL from.
|
|
1013
|
+
* @returns Promise resolving to the widget URL string, or null if not available.
|
|
1014
|
+
* @deprecated Read `state.widgetUrl` instead. The widget URL is now automatically
|
|
1015
|
+
* fetched and stored in state whenever the selected quote changes.
|
|
1016
|
+
*/
|
|
1017
|
+
async getWidgetUrl(quote) {
|
|
1018
|
+
const buyUrl = quote.quote?.buyURL;
|
|
1019
|
+
if (!buyUrl) {
|
|
1020
|
+
return null;
|
|
1021
|
+
}
|
|
1022
|
+
try {
|
|
1023
|
+
const buyWidget = await this.messenger.call('RampsService:getBuyWidgetUrl', buyUrl);
|
|
1024
|
+
return buyWidget.url ?? null;
|
|
1025
|
+
}
|
|
1026
|
+
catch {
|
|
1027
|
+
return null;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Sets the Transak API key used for all Transak API requests.
|
|
1032
|
+
*
|
|
1033
|
+
* @param apiKey - The Transak API key.
|
|
1034
|
+
*/
|
|
1035
|
+
transakSetApiKey(apiKey) {
|
|
1036
|
+
this.messenger.call('TransakService:setApiKey', apiKey);
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Sets the Transak access token and marks the user as authenticated.
|
|
1040
|
+
*
|
|
1041
|
+
* @param token - The access token received from Transak auth.
|
|
1042
|
+
*/
|
|
1043
|
+
transakSetAccessToken(token) {
|
|
1044
|
+
this.messenger.call('TransakService:setAccessToken', token);
|
|
1045
|
+
this.transakSetAuthenticated(true);
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Clears the Transak access token and marks the user as unauthenticated.
|
|
1049
|
+
*/
|
|
1050
|
+
transakClearAccessToken() {
|
|
1051
|
+
this.messenger.call('TransakService:clearAccessToken');
|
|
1052
|
+
this.transakSetAuthenticated(false);
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Updates the Transak authentication flag in controller state.
|
|
1056
|
+
*
|
|
1057
|
+
* @param isAuthenticated - Whether the user is authenticated with Transak.
|
|
1058
|
+
*/
|
|
1059
|
+
transakSetAuthenticated(isAuthenticated) {
|
|
1060
|
+
this.update((state) => {
|
|
1061
|
+
state.nativeProviders.transak.isAuthenticated = isAuthenticated;
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Resets all Transak state back to defaults (unauthenticated, no data).
|
|
1066
|
+
*/
|
|
1067
|
+
transakResetState() {
|
|
1068
|
+
this.messenger.call('TransakService:clearAccessToken');
|
|
1069
|
+
this.update((state) => {
|
|
1070
|
+
state.nativeProviders.transak =
|
|
1071
|
+
getDefaultRampsControllerState().nativeProviders.transak;
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Sends a one-time password to the user's email for Transak authentication.
|
|
1076
|
+
*
|
|
1077
|
+
* @param email - The user's email address.
|
|
1078
|
+
* @returns The OTP response containing a state token for verification.
|
|
1079
|
+
*/
|
|
1080
|
+
async transakSendUserOtp(email) {
|
|
1081
|
+
return this.messenger.call('TransakService:sendUserOtp', email);
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Verifies a one-time password and authenticates the user with Transak.
|
|
1085
|
+
* Updates the controller's authentication state on success.
|
|
1086
|
+
*
|
|
1087
|
+
* @param email - The user's email address.
|
|
1088
|
+
* @param verificationCode - The OTP code entered by the user.
|
|
1089
|
+
* @param stateToken - The state token from the sendUserOtp response.
|
|
1090
|
+
* @returns The access token for subsequent authenticated requests.
|
|
1091
|
+
*/
|
|
1092
|
+
async transakVerifyUserOtp(email, verificationCode, stateToken) {
|
|
1093
|
+
const token = await this.messenger.call('TransakService:verifyUserOtp', email, verificationCode, stateToken);
|
|
1094
|
+
this.transakSetAuthenticated(true);
|
|
1095
|
+
return token;
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Logs the user out of Transak. Clears authentication state and user details
|
|
1099
|
+
* regardless of whether the API call succeeds or fails.
|
|
1100
|
+
*
|
|
1101
|
+
* @returns A message indicating the logout result.
|
|
1102
|
+
*/
|
|
1103
|
+
async transakLogout() {
|
|
1104
|
+
try {
|
|
1105
|
+
const result = await this.messenger.call('TransakService:logout');
|
|
1106
|
+
return result;
|
|
1107
|
+
}
|
|
1108
|
+
finally {
|
|
1109
|
+
this.transakClearAccessToken();
|
|
1110
|
+
this.update((state) => {
|
|
1111
|
+
state.nativeProviders.transak.userDetails.data = null;
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Fetches the authenticated user's details from Transak.
|
|
1117
|
+
* Updates the userDetails resource state with loading/success/error states.
|
|
1118
|
+
*
|
|
1119
|
+
* @returns The user's profile and KYC details.
|
|
1120
|
+
*/
|
|
1121
|
+
async transakGetUserDetails() {
|
|
1122
|
+
this.update((state) => {
|
|
1123
|
+
state.nativeProviders.transak.userDetails.isLoading = true;
|
|
1124
|
+
state.nativeProviders.transak.userDetails.error = null;
|
|
1125
|
+
});
|
|
1126
|
+
try {
|
|
1127
|
+
const details = await this.messenger.call('TransakService:getUserDetails');
|
|
1128
|
+
this.update((state) => {
|
|
1129
|
+
state.nativeProviders.transak.userDetails.data = details;
|
|
1130
|
+
state.nativeProviders.transak.userDetails.isLoading = false;
|
|
1131
|
+
});
|
|
1132
|
+
return details;
|
|
1133
|
+
}
|
|
1134
|
+
catch (error) {
|
|
1135
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1136
|
+
const errorMessage = error?.message ?? 'Unknown error';
|
|
1137
|
+
this.update((state) => {
|
|
1138
|
+
state.nativeProviders.transak.userDetails.isLoading = false;
|
|
1139
|
+
state.nativeProviders.transak.userDetails.error = errorMessage;
|
|
1140
|
+
});
|
|
1141
|
+
throw error;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Fetches a buy quote from Transak for the given parameters.
|
|
1146
|
+
* Updates the buyQuote resource state with loading/success/error states.
|
|
1147
|
+
*
|
|
1148
|
+
* @param fiatCurrency - The fiat currency code (e.g., "USD").
|
|
1149
|
+
* @param cryptoCurrency - The cryptocurrency identifier.
|
|
1150
|
+
* @param network - The blockchain network identifier.
|
|
1151
|
+
* @param paymentMethod - The payment method identifier.
|
|
1152
|
+
* @param fiatAmount - The fiat amount as a string.
|
|
1153
|
+
* @returns The buy quote with pricing and fee details.
|
|
1154
|
+
*/
|
|
1155
|
+
async transakGetBuyQuote(fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount) {
|
|
1156
|
+
this.update((state) => {
|
|
1157
|
+
state.nativeProviders.transak.buyQuote.isLoading = true;
|
|
1158
|
+
state.nativeProviders.transak.buyQuote.error = null;
|
|
1159
|
+
});
|
|
1160
|
+
try {
|
|
1161
|
+
const quote = await this.messenger.call('TransakService:getBuyQuote', fiatCurrency, cryptoCurrency, network, paymentMethod, fiatAmount);
|
|
1162
|
+
this.update((state) => {
|
|
1163
|
+
state.nativeProviders.transak.buyQuote.data = quote;
|
|
1164
|
+
state.nativeProviders.transak.buyQuote.isLoading = false;
|
|
1165
|
+
});
|
|
1166
|
+
return quote;
|
|
1167
|
+
}
|
|
1168
|
+
catch (error) {
|
|
1169
|
+
const errorMessage = error?.message ?? 'Unknown error';
|
|
1170
|
+
this.update((state) => {
|
|
1171
|
+
state.nativeProviders.transak.buyQuote.isLoading = false;
|
|
1172
|
+
state.nativeProviders.transak.buyQuote.error = errorMessage;
|
|
1173
|
+
});
|
|
1174
|
+
throw error;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Fetches the KYC requirement for a given quote.
|
|
1179
|
+
* Updates the kycRequirement resource state with loading/success/error states.
|
|
1180
|
+
*
|
|
1181
|
+
* @param quoteId - The quote ID to check KYC requirements for.
|
|
1182
|
+
* @returns The KYC requirement status and whether the user can place an order.
|
|
1183
|
+
*/
|
|
1184
|
+
async transakGetKycRequirement(quoteId) {
|
|
1185
|
+
this.update((state) => {
|
|
1186
|
+
state.nativeProviders.transak.kycRequirement.isLoading = true;
|
|
1187
|
+
state.nativeProviders.transak.kycRequirement.error = null;
|
|
1188
|
+
});
|
|
1189
|
+
try {
|
|
1190
|
+
const requirement = await this.messenger.call('TransakService:getKycRequirement', quoteId);
|
|
1191
|
+
this.update((state) => {
|
|
1192
|
+
state.nativeProviders.transak.kycRequirement.data = requirement;
|
|
1193
|
+
state.nativeProviders.transak.kycRequirement.isLoading = false;
|
|
1194
|
+
});
|
|
1195
|
+
return requirement;
|
|
1196
|
+
}
|
|
1197
|
+
catch (error) {
|
|
1198
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1199
|
+
const errorMessage = error?.message ?? 'Unknown error';
|
|
1200
|
+
this.update((state) => {
|
|
1201
|
+
state.nativeProviders.transak.kycRequirement.isLoading = false;
|
|
1202
|
+
state.nativeProviders.transak.kycRequirement.error = errorMessage;
|
|
1203
|
+
});
|
|
1204
|
+
throw error;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Fetches additional KYC requirements (e.g., ID proof, address proof) for a quote.
|
|
950
1209
|
*
|
|
951
|
-
* @param
|
|
952
|
-
* @returns The
|
|
1210
|
+
* @param quoteId - The quote ID to check additional requirements for.
|
|
1211
|
+
* @returns The list of additional forms required.
|
|
953
1212
|
*/
|
|
954
|
-
|
|
955
|
-
|
|
1213
|
+
async transakGetAdditionalRequirements(quoteId) {
|
|
1214
|
+
try {
|
|
1215
|
+
return await this.messenger.call('TransakService:getAdditionalRequirements', quoteId);
|
|
1216
|
+
}
|
|
1217
|
+
catch (error) {
|
|
1218
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1219
|
+
throw error;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Creates a new order on Transak. If an existing order conflicts (HTTP 409),
|
|
1224
|
+
* active orders are cancelled and the creation is retried.
|
|
1225
|
+
*
|
|
1226
|
+
* @param quoteId - The quote ID to create an order from.
|
|
1227
|
+
* @param walletAddress - The destination wallet address.
|
|
1228
|
+
* @param paymentMethodId - The payment method to use.
|
|
1229
|
+
* @returns The created deposit order.
|
|
1230
|
+
*/
|
|
1231
|
+
async transakCreateOrder(quoteId, walletAddress, paymentMethodId) {
|
|
1232
|
+
try {
|
|
1233
|
+
return await this.messenger.call('TransakService:createOrder', quoteId, walletAddress, paymentMethodId);
|
|
1234
|
+
}
|
|
1235
|
+
catch (error) {
|
|
1236
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1237
|
+
throw error;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Fetches an existing order from Transak by order ID.
|
|
1242
|
+
*
|
|
1243
|
+
* @param orderId - The order ID (deposit format or raw Transak format).
|
|
1244
|
+
* @param wallet - The wallet address associated with the order.
|
|
1245
|
+
* @param paymentDetails - Optional payment details to attach to the order.
|
|
1246
|
+
* @returns The deposit order details.
|
|
1247
|
+
*/
|
|
1248
|
+
async transakGetOrder(orderId, wallet, paymentDetails) {
|
|
1249
|
+
return this.messenger.call('TransakService:getOrder', orderId, wallet, paymentDetails);
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Fetches the user's spending limits for a given currency and payment method.
|
|
1253
|
+
*
|
|
1254
|
+
* @param fiatCurrency - The fiat currency code.
|
|
1255
|
+
* @param paymentMethod - The payment method identifier.
|
|
1256
|
+
* @param kycType - The KYC level type.
|
|
1257
|
+
* @returns The user's limits, spending, and remaining amounts.
|
|
1258
|
+
*/
|
|
1259
|
+
async transakGetUserLimits(fiatCurrency, paymentMethod, kycType) {
|
|
1260
|
+
try {
|
|
1261
|
+
return await this.messenger.call('TransakService:getUserLimits', fiatCurrency, paymentMethod, kycType);
|
|
1262
|
+
}
|
|
1263
|
+
catch (error) {
|
|
1264
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1265
|
+
throw error;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Requests a one-time token (OTT) for the Transak payment widget.
|
|
1270
|
+
*
|
|
1271
|
+
* @returns The OTT response containing the token.
|
|
1272
|
+
*/
|
|
1273
|
+
async transakRequestOtt() {
|
|
1274
|
+
try {
|
|
1275
|
+
return await this.messenger.call('TransakService:requestOtt');
|
|
1276
|
+
}
|
|
1277
|
+
catch (error) {
|
|
1278
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1279
|
+
throw error;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Generates a URL for the Transak payment widget with pre-filled parameters.
|
|
1284
|
+
*
|
|
1285
|
+
* @param ottToken - The one-time token for widget authentication.
|
|
1286
|
+
* @param quote - The buy quote to pre-fill in the widget.
|
|
1287
|
+
* @param walletAddress - The destination wallet address.
|
|
1288
|
+
* @param extraParams - Optional additional URL parameters.
|
|
1289
|
+
* @returns The fully constructed widget URL string.
|
|
1290
|
+
*/
|
|
1291
|
+
transakGeneratePaymentWidgetUrl(ottToken, quote, walletAddress, extraParams) {
|
|
1292
|
+
return this.messenger.call('TransakService:generatePaymentWidgetUrl', ottToken, quote, walletAddress, extraParams);
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Submits the user's purpose of usage form for KYC compliance.
|
|
1296
|
+
*
|
|
1297
|
+
* @param purpose - Array of purpose strings selected by the user.
|
|
1298
|
+
* @returns A promise that resolves when the form is submitted.
|
|
1299
|
+
*/
|
|
1300
|
+
async transakSubmitPurposeOfUsageForm(purpose) {
|
|
1301
|
+
try {
|
|
1302
|
+
return await this.messenger.call('TransakService:submitPurposeOfUsageForm', purpose);
|
|
1303
|
+
}
|
|
1304
|
+
catch (error) {
|
|
1305
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1306
|
+
throw error;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Updates the user's personal or address details on Transak.
|
|
1311
|
+
*
|
|
1312
|
+
* @param data - The user data fields to update.
|
|
1313
|
+
* @returns The API response data.
|
|
1314
|
+
*/
|
|
1315
|
+
async transakPatchUser(data) {
|
|
1316
|
+
try {
|
|
1317
|
+
return await this.messenger.call('TransakService:patchUser', data);
|
|
1318
|
+
}
|
|
1319
|
+
catch (error) {
|
|
1320
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1321
|
+
throw error;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Submits the user's SSN for identity verification.
|
|
1326
|
+
*
|
|
1327
|
+
* @param ssn - The Social Security Number.
|
|
1328
|
+
* @param quoteId - The quote ID associated with the order requiring SSN.
|
|
1329
|
+
* @returns The API response data.
|
|
1330
|
+
*/
|
|
1331
|
+
async transakSubmitSsnDetails(ssn, quoteId) {
|
|
1332
|
+
try {
|
|
1333
|
+
return await this.messenger.call('TransakService:submitSsnDetails', ssn, quoteId);
|
|
1334
|
+
}
|
|
1335
|
+
catch (error) {
|
|
1336
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1337
|
+
throw error;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Confirms payment for an order after the user has completed payment.
|
|
1342
|
+
*
|
|
1343
|
+
* @param orderId - The order ID to confirm payment for.
|
|
1344
|
+
* @param paymentMethodId - The payment method used.
|
|
1345
|
+
* @returns Whether the payment confirmation was successful.
|
|
1346
|
+
*/
|
|
1347
|
+
async transakConfirmPayment(orderId, paymentMethodId) {
|
|
1348
|
+
try {
|
|
1349
|
+
return await this.messenger.call('TransakService:confirmPayment', orderId, paymentMethodId);
|
|
1350
|
+
}
|
|
1351
|
+
catch (error) {
|
|
1352
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1353
|
+
throw error;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Translates generic ramps identifiers to Transak-specific identifiers.
|
|
1358
|
+
*
|
|
1359
|
+
* @param request - The translation request with optional identifiers to translate.
|
|
1360
|
+
* @returns The translated Transak-specific identifiers.
|
|
1361
|
+
*/
|
|
1362
|
+
async transakGetTranslation(request) {
|
|
1363
|
+
return this.messenger.call('TransakService:getTranslation', request);
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Checks the status of an ID proof submission for KYC.
|
|
1367
|
+
*
|
|
1368
|
+
* @param workFlowRunId - The workflow run ID to check status for.
|
|
1369
|
+
* @returns The current ID proof status.
|
|
1370
|
+
*/
|
|
1371
|
+
async transakGetIdProofStatus(workFlowRunId) {
|
|
1372
|
+
try {
|
|
1373
|
+
return await this.messenger.call('TransakService:getIdProofStatus', workFlowRunId);
|
|
1374
|
+
}
|
|
1375
|
+
catch (error) {
|
|
1376
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1377
|
+
throw error;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Cancels a specific Transak order.
|
|
1382
|
+
*
|
|
1383
|
+
* @param depositOrderId - The deposit order ID to cancel.
|
|
1384
|
+
* @returns A promise that resolves when the order is cancelled.
|
|
1385
|
+
*/
|
|
1386
|
+
async transakCancelOrder(depositOrderId) {
|
|
1387
|
+
try {
|
|
1388
|
+
return await this.messenger.call('TransakService:cancelOrder', depositOrderId);
|
|
1389
|
+
}
|
|
1390
|
+
catch (error) {
|
|
1391
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1392
|
+
throw error;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Cancels all active Transak orders. Individual cancellation failures
|
|
1397
|
+
* are collected and returned rather than thrown.
|
|
1398
|
+
*
|
|
1399
|
+
* @returns An array of errors from any failed cancellations (empty if all succeeded).
|
|
1400
|
+
*/
|
|
1401
|
+
async transakCancelAllActiveOrders() {
|
|
1402
|
+
try {
|
|
1403
|
+
return await this.messenger.call('TransakService:cancelAllActiveOrders');
|
|
1404
|
+
}
|
|
1405
|
+
catch (error) {
|
|
1406
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1407
|
+
throw error;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Fetches all active Transak orders for the authenticated user.
|
|
1412
|
+
*
|
|
1413
|
+
* @returns The list of active orders.
|
|
1414
|
+
*/
|
|
1415
|
+
async transakGetActiveOrders() {
|
|
1416
|
+
try {
|
|
1417
|
+
return await this.messenger.call('TransakService:getActiveOrders');
|
|
1418
|
+
}
|
|
1419
|
+
catch (error) {
|
|
1420
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_syncTransakAuthOnError).call(this, error);
|
|
1421
|
+
throw error;
|
|
1422
|
+
}
|
|
956
1423
|
}
|
|
957
1424
|
}
|
|
958
1425
|
_RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheMaxSize = new WeakMap(), _RampsController_pendingRequests = new WeakMap(), _RampsController_pendingResourceCount = new WeakMap(), _RampsController_quotePollingInterval = new WeakMap(), _RampsController_quotePollingOptions = new WeakMap(), _RampsController_instances = new WeakSet(), _RampsController_clearPendingResourceCountForDependentResources = function _RampsController_clearPendingResourceCountForDependentResources() {
|
|
959
|
-
const
|
|
960
|
-
'providers',
|
|
961
|
-
'tokens',
|
|
962
|
-
'paymentMethods',
|
|
963
|
-
'quotes',
|
|
964
|
-
];
|
|
965
|
-
for (const resourceType of types) {
|
|
1426
|
+
for (const resourceType of DEPENDENT_RESOURCE_KEYS) {
|
|
966
1427
|
__classPrivateFieldGet(this, _RampsController_pendingResourceCount, "f").delete(resourceType);
|
|
967
1428
|
}
|
|
968
|
-
},
|
|
1429
|
+
}, _RampsController_abortDependentRequests = function _RampsController_abortDependentRequests() {
|
|
1430
|
+
for (const [cacheKey, pending] of __classPrivateFieldGet(this, _RampsController_pendingRequests, "f").entries()) {
|
|
1431
|
+
if (pending.resourceType &&
|
|
1432
|
+
DEPENDENT_RESOURCE_KEYS_SET.has(pending.resourceType)) {
|
|
1433
|
+
pending.abortController.abort();
|
|
1434
|
+
__classPrivateFieldGet(this, _RampsController_pendingRequests, "f").delete(cacheKey);
|
|
1435
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_removeRequestState).call(this, cacheKey);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
}, _RampsController_mutateRequests = function _RampsController_mutateRequests(fn) {
|
|
969
1439
|
this.update((state) => {
|
|
970
1440
|
const requests = state.requests;
|
|
1441
|
+
fn(requests);
|
|
1442
|
+
});
|
|
1443
|
+
}, _RampsController_removeRequestState = function _RampsController_removeRequestState(cacheKey) {
|
|
1444
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_mutateRequests).call(this, (requests) => {
|
|
971
1445
|
delete requests[cacheKey];
|
|
972
1446
|
});
|
|
973
1447
|
}, _RampsController_cleanupState = function _RampsController_cleanupState() {
|
|
974
1448
|
this.stopQuotePolling();
|
|
1449
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_abortDependentRequests).call(this);
|
|
975
1450
|
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_clearPendingResourceCountForDependentResources).call(this);
|
|
976
|
-
this.update((state) => resetDependentResources(state, {
|
|
977
|
-
clearUserRegionData: true,
|
|
978
|
-
}));
|
|
1451
|
+
this.update((state) => resetDependentResources(state, { clearUserRegionData: true }));
|
|
979
1452
|
}, _RampsController_fireAndForget = function _RampsController_fireAndForget(promise) {
|
|
980
1453
|
promise.catch((_error) => undefined);
|
|
981
1454
|
}, _RampsController_restartPollingIfActive = function _RampsController_restartPollingIfActive() {
|
|
@@ -990,6 +1463,21 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
990
1463
|
// when dependencies are available
|
|
991
1464
|
}
|
|
992
1465
|
}
|
|
1466
|
+
}, _RampsController_requireRegion = function _RampsController_requireRegion() {
|
|
1467
|
+
const regionCode = this.state.userRegion?.regionCode;
|
|
1468
|
+
if (!regionCode) {
|
|
1469
|
+
throw new Error('Region is required. Cannot proceed without valid region information.');
|
|
1470
|
+
}
|
|
1471
|
+
return regionCode;
|
|
1472
|
+
}, _RampsController_isRegionCurrent = function _RampsController_isRegionCurrent(normalizedRegion) {
|
|
1473
|
+
const current = this.state.userRegion?.regionCode;
|
|
1474
|
+
return current === undefined || current === normalizedRegion;
|
|
1475
|
+
}, _RampsController_isTokenCurrent = function _RampsController_isTokenCurrent(normalizedAssetId) {
|
|
1476
|
+
const current = this.state.tokens.selected?.assetId ?? '';
|
|
1477
|
+
return current === normalizedAssetId;
|
|
1478
|
+
}, _RampsController_isProviderCurrent = function _RampsController_isProviderCurrent(normalizedProviderId) {
|
|
1479
|
+
const current = this.state.providers.selected?.id ?? '';
|
|
1480
|
+
return current === normalizedProviderId;
|
|
993
1481
|
}, _RampsController_updateResourceField = function _RampsController_updateResourceField(resourceType, field, value) {
|
|
994
1482
|
this.update((state) => {
|
|
995
1483
|
const resource = state[resourceType];
|
|
@@ -1004,30 +1492,23 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1004
1492
|
}, _RampsController_updateRequestState = function _RampsController_updateRequestState(cacheKey, requestState) {
|
|
1005
1493
|
const maxSize = __classPrivateFieldGet(this, _RampsController_requestCacheMaxSize, "f");
|
|
1006
1494
|
const ttl = __classPrivateFieldGet(this, _RampsController_requestCacheTTL, "f");
|
|
1007
|
-
this.
|
|
1008
|
-
const requests = state.requests;
|
|
1495
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_mutateRequests).call(this, (requests) => {
|
|
1009
1496
|
requests[cacheKey] = requestState;
|
|
1010
|
-
// Evict expired entries based on TTL
|
|
1011
|
-
// Only evict SUCCESS states that have exceeded their TTL
|
|
1012
1497
|
const keys = Object.keys(requests);
|
|
1013
1498
|
for (const key of keys) {
|
|
1014
1499
|
const entry = requests[key];
|
|
1015
|
-
if (entry &&
|
|
1016
|
-
entry.status === RequestStatus.SUCCESS &&
|
|
1500
|
+
if (entry?.status === RequestStatus.SUCCESS &&
|
|
1017
1501
|
isCacheExpired(entry, ttl)) {
|
|
1018
1502
|
delete requests[key];
|
|
1019
1503
|
}
|
|
1020
1504
|
}
|
|
1021
|
-
// Evict oldest entries if cache still exceeds max size
|
|
1022
1505
|
const remainingKeys = Object.keys(requests);
|
|
1023
1506
|
if (remainingKeys.length > maxSize) {
|
|
1024
|
-
// Sort by timestamp (oldest first)
|
|
1025
1507
|
const sortedKeys = remainingKeys.sort((a, b) => {
|
|
1026
1508
|
const aTime = requests[a]?.timestamp ?? 0;
|
|
1027
1509
|
const bTime = requests[b]?.timestamp ?? 0;
|
|
1028
1510
|
return aTime - bTime;
|
|
1029
1511
|
});
|
|
1030
|
-
// Remove oldest entries until we're under the limit
|
|
1031
1512
|
const entriesToRemove = remainingKeys.length - maxSize;
|
|
1032
1513
|
for (let i = 0; i < entriesToRemove; i++) {
|
|
1033
1514
|
const keyToRemove = sortedKeys[i];
|
|
@@ -1037,5 +1518,44 @@ _RampsController_requestCacheTTL = new WeakMap(), _RampsController_requestCacheM
|
|
|
1037
1518
|
}
|
|
1038
1519
|
}
|
|
1039
1520
|
});
|
|
1521
|
+
}, _RampsController_syncWidgetUrl = function _RampsController_syncWidgetUrl(quote) {
|
|
1522
|
+
const buyUrl = quote?.quote?.buyURL;
|
|
1523
|
+
if (!buyUrl) {
|
|
1524
|
+
this.update((state) => {
|
|
1525
|
+
resetWidgetUrl(state);
|
|
1526
|
+
});
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
if (this.state.widgetUrl.data === null) {
|
|
1530
|
+
this.update((state) => {
|
|
1531
|
+
state.widgetUrl.isLoading = true;
|
|
1532
|
+
state.widgetUrl.error = null;
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
__classPrivateFieldGet(this, _RampsController_instances, "m", _RampsController_fireAndForget).call(this, this.messenger
|
|
1536
|
+
.call('RampsService:getBuyWidgetUrl', buyUrl)
|
|
1537
|
+
.then((buyWidget) => {
|
|
1538
|
+
this.update((state) => {
|
|
1539
|
+
state.widgetUrl.data = buyWidget;
|
|
1540
|
+
state.widgetUrl.isLoading = false;
|
|
1541
|
+
state.widgetUrl.error = null;
|
|
1542
|
+
});
|
|
1543
|
+
return undefined;
|
|
1544
|
+
})
|
|
1545
|
+
.catch((error) => {
|
|
1546
|
+
this.update((state) => {
|
|
1547
|
+
state.widgetUrl.isLoading = false;
|
|
1548
|
+
state.widgetUrl.error =
|
|
1549
|
+
error instanceof Error
|
|
1550
|
+
? error.message
|
|
1551
|
+
: 'Failed to fetch widget URL';
|
|
1552
|
+
});
|
|
1553
|
+
}));
|
|
1554
|
+
}, _RampsController_syncTransakAuthOnError = function _RampsController_syncTransakAuthOnError(error) {
|
|
1555
|
+
if (error instanceof Error &&
|
|
1556
|
+
'httpStatus' in error &&
|
|
1557
|
+
error.httpStatus === 401) {
|
|
1558
|
+
this.transakSetAuthenticated(false);
|
|
1559
|
+
}
|
|
1040
1560
|
};
|
|
1041
1561
|
//# sourceMappingURL=RampsController.mjs.map
|