@metamask-previews/ramps-controller 29.0.0-preview-e53b41ba2 → 29.0.0-preview-c62310f6e
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 +11 -0
- package/dist/RampsController-method-action-types.d.ts +12 -0
- package/dist/RampsController-method-action-types.d.ts.map +1 -1
- package/dist/RampsController-method-action-types.js.map +1 -1
- package/dist/RampsController.d.ts +23 -1
- package/dist/RampsController.d.ts.map +1 -1
- package/dist/RampsController.js +100 -7
- package/dist/RampsController.js.map +1 -1
- package/dist/TransakService.d.ts +18 -5
- package/dist/TransakService.d.ts.map +1 -1
- package/dist/TransakService.js +293 -114
- package/dist/TransakService.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/rampsErrorCodes.d.ts +1 -0
- package/dist/rampsErrorCodes.d.ts.map +1 -1
- package/dist/rampsErrorCodes.js +1 -0
- package/dist/rampsErrorCodes.js.map +1 -1
- package/package.json +4 -3
package/dist/TransakService.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseDataService } from '@metamask/base-data-service';
|
|
2
|
+
import { HttpError } from '@metamask/controller-utils';
|
|
3
|
+
import { any, array, boolean, nullable, number, optional, record, string, type as looseObject, } from '@metamask/superstruct';
|
|
2
4
|
import packageJson from '../package.json';
|
|
3
5
|
import { addRampsClientIdentityParams } from './client-identity.js';
|
|
4
6
|
import { RAMPS_SDK_VERSION } from './RampsService.js';
|
|
@@ -159,13 +161,131 @@ export class TransakApiError extends HttpError {
|
|
|
159
161
|
this.apiMessage = apiMessage;
|
|
160
162
|
}
|
|
161
163
|
}
|
|
164
|
+
// === RESPONSE STRUCTS ===
|
|
165
|
+
/**
|
|
166
|
+
* The structs below are intentionally lenient: they require only the fields
|
|
167
|
+
* the service itself depends on, check the type of any other field that is
|
|
168
|
+
* present, and ignore extra fields the APIs return. The APIs omit fields for
|
|
169
|
+
* incomplete profiles and sparse responses, and responses were not validated
|
|
170
|
+
* before, so a missing field must not fail a call.
|
|
171
|
+
*/
|
|
172
|
+
const TransakPaymentDetailsStruct = array(looseObject({
|
|
173
|
+
fiatCurrency: string(),
|
|
174
|
+
paymentMethod: string(),
|
|
175
|
+
fields: array(looseObject({ name: string(), id: string(), value: string() })),
|
|
176
|
+
}));
|
|
177
|
+
const SendUserOtpResponseStruct = looseObject({
|
|
178
|
+
isTncAccepted: boolean(),
|
|
179
|
+
stateToken: string(),
|
|
180
|
+
email: string(),
|
|
181
|
+
expiresIn: number(),
|
|
182
|
+
});
|
|
183
|
+
const VerifyUserOtpResponseStruct = looseObject({
|
|
184
|
+
accessToken: string(),
|
|
185
|
+
ttl: number(),
|
|
186
|
+
created: string(),
|
|
187
|
+
});
|
|
188
|
+
const UserDetailsStruct = looseObject({
|
|
189
|
+
id: optional(string()),
|
|
190
|
+
firstName: optional(string()),
|
|
191
|
+
lastName: optional(string()),
|
|
192
|
+
email: optional(string()),
|
|
193
|
+
mobileNumber: optional(string()),
|
|
194
|
+
status: optional(string()),
|
|
195
|
+
dob: optional(string()),
|
|
196
|
+
kyc: optional(looseObject({
|
|
197
|
+
status: optional(string()),
|
|
198
|
+
type: optional(string()),
|
|
199
|
+
userId: optional(string()),
|
|
200
|
+
workFlowRunId: optional(string()),
|
|
201
|
+
})),
|
|
202
|
+
address: optional(looseObject({
|
|
203
|
+
addressLine1: optional(string()),
|
|
204
|
+
addressLine2: optional(string()),
|
|
205
|
+
state: optional(string()),
|
|
206
|
+
city: optional(string()),
|
|
207
|
+
postCode: optional(string()),
|
|
208
|
+
country: optional(string()),
|
|
209
|
+
countryCode: optional(string()),
|
|
210
|
+
})),
|
|
211
|
+
createdAt: optional(string()),
|
|
212
|
+
});
|
|
213
|
+
const BuyQuoteStruct = looseObject({
|
|
214
|
+
quoteId: string(),
|
|
215
|
+
conversionPrice: optional(number()),
|
|
216
|
+
marketConversionPrice: optional(number()),
|
|
217
|
+
slippage: optional(number()),
|
|
218
|
+
fiatCurrency: optional(string()),
|
|
219
|
+
cryptoCurrency: optional(string()),
|
|
220
|
+
paymentMethod: optional(string()),
|
|
221
|
+
fiatAmount: optional(number()),
|
|
222
|
+
cryptoAmount: optional(number()),
|
|
223
|
+
isBuyOrSell: optional(string()),
|
|
224
|
+
network: optional(string()),
|
|
225
|
+
feeDecimal: optional(number()),
|
|
226
|
+
totalFee: optional(number()),
|
|
227
|
+
feeBreakdown: optional(array(record(string(), any()))),
|
|
228
|
+
nonce: optional(number()),
|
|
229
|
+
cryptoLiquidityProvider: optional(string()),
|
|
230
|
+
notes: optional(array(record(string(), any()))),
|
|
231
|
+
});
|
|
232
|
+
const KycRequirementStruct = looseObject({
|
|
233
|
+
status: string(),
|
|
234
|
+
kycType: string(),
|
|
235
|
+
isAllowedToPlaceOrder: boolean(),
|
|
236
|
+
});
|
|
237
|
+
const AdditionalRequirementsStruct = looseObject({
|
|
238
|
+
formsRequired: array(looseObject({ type: string(), metadata: optional(any()) })),
|
|
239
|
+
});
|
|
240
|
+
const TransakOrderStruct = looseObject({
|
|
241
|
+
orderId: string(),
|
|
242
|
+
walletAddress: string(),
|
|
243
|
+
paymentDetails: optional(nullable(TransakPaymentDetailsStruct)),
|
|
244
|
+
});
|
|
245
|
+
const TransakOrderPaymentDetailsStruct = looseObject({
|
|
246
|
+
paymentDetails: optional(nullable(TransakPaymentDetailsStruct)),
|
|
247
|
+
});
|
|
248
|
+
const ActiveOrdersStruct = array(looseObject({ orderId: string(), status: string() }));
|
|
249
|
+
const DepositOrderStruct = looseObject({
|
|
250
|
+
providerOrderId: string(),
|
|
251
|
+
status: string(),
|
|
252
|
+
});
|
|
253
|
+
const UserLimitsStruct = looseObject({
|
|
254
|
+
limits: looseObject({ '1': number(), '30': number(), '365': number() }),
|
|
255
|
+
spent: looseObject({ '1': number(), '30': number(), '365': number() }),
|
|
256
|
+
remaining: looseObject({ '1': number(), '30': number(), '365': number() }),
|
|
257
|
+
exceeded: looseObject({ '1': boolean(), '30': boolean(), '365': boolean() }),
|
|
258
|
+
shortage: optional(record(string(), number())),
|
|
259
|
+
});
|
|
260
|
+
const OttStruct = looseObject({ ott: string() });
|
|
261
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
262
|
+
const TranslationStruct = looseObject({
|
|
263
|
+
region: optional(string()),
|
|
264
|
+
paymentMethod: optional(string()),
|
|
265
|
+
cryptoCurrency: string(),
|
|
266
|
+
network: string(),
|
|
267
|
+
fiatCurrency: string(),
|
|
268
|
+
});
|
|
269
|
+
const IdProofStatusStruct = looseObject({
|
|
270
|
+
status: string(),
|
|
271
|
+
kycType: string(),
|
|
272
|
+
randomLogIdentifier: optional(string()),
|
|
273
|
+
});
|
|
274
|
+
const PaymentConfirmationStruct = looseObject({ success: boolean() });
|
|
275
|
+
const WidgetUrlResponseStruct = looseObject({ widgetUrl: string() });
|
|
276
|
+
/**
|
|
277
|
+
* Wraps a struct in the `{ data }` envelope the Transak API gateway uses.
|
|
278
|
+
*
|
|
279
|
+
* @param dataStruct - The struct for the `data` property.
|
|
280
|
+
* @returns The envelope struct.
|
|
281
|
+
*/
|
|
282
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
283
|
+
function envelope(dataStruct) {
|
|
284
|
+
return looseObject({ data: dataStruct });
|
|
285
|
+
}
|
|
162
286
|
// === SERVICE DEFINITION ===
|
|
163
|
-
export class TransakService {
|
|
164
|
-
name;
|
|
165
|
-
#messenger;
|
|
287
|
+
export class TransakService extends BaseDataService {
|
|
166
288
|
#fetch;
|
|
167
|
-
#policy;
|
|
168
|
-
#noRetryPolicy;
|
|
169
289
|
#environment;
|
|
170
290
|
#context;
|
|
171
291
|
#orderRetryDelayMs;
|
|
@@ -184,15 +304,9 @@ export class TransakService {
|
|
|
184
304
|
*/
|
|
185
305
|
#referrerDomain;
|
|
186
306
|
#clientIdentity;
|
|
187
|
-
constructor({ messenger, environment = TransakEnvironment.Staging, context, fetch: fetchFunction, apiKey, policyOptions
|
|
188
|
-
|
|
189
|
-
this.#messenger = messenger;
|
|
307
|
+
constructor({ messenger, environment = TransakEnvironment.Staging, context, fetch: fetchFunction, apiKey, policyOptions, orderRetryDelayMs = 2000, rampsApiBaseUrlOverride, referrerDomain = TRANSAK_REFERRER_DOMAIN, clientProduct, clientVersion, }) {
|
|
308
|
+
super({ name: serviceName, messenger, policyOptions });
|
|
190
309
|
this.#fetch = fetchFunction;
|
|
191
|
-
this.#policy = createServicePolicy(policyOptions);
|
|
192
|
-
this.#noRetryPolicy = createServicePolicy({
|
|
193
|
-
...policyOptions,
|
|
194
|
-
maxRetries: 0,
|
|
195
|
-
});
|
|
196
310
|
this.#environment = environment;
|
|
197
311
|
this.#context = context;
|
|
198
312
|
this.#apiKey = apiKey ?? null;
|
|
@@ -203,7 +317,7 @@ export class TransakService {
|
|
|
203
317
|
clientProduct,
|
|
204
318
|
clientVersion,
|
|
205
319
|
};
|
|
206
|
-
this
|
|
320
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
207
321
|
}
|
|
208
322
|
setApiKey(apiKey) {
|
|
209
323
|
this.#apiKey = apiKey;
|
|
@@ -270,7 +384,21 @@ export class TransakService {
|
|
|
270
384
|
}
|
|
271
385
|
throw new TransakApiError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'${errorBody ? `: ${errorBody}` : ''}`, errorCode, apiMessage);
|
|
272
386
|
}
|
|
273
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Identifies the current login session without exposing the access token,
|
|
389
|
+
* so reads made under different sessions never share a request.
|
|
390
|
+
*
|
|
391
|
+
* @returns The access token creation time in milliseconds, or `null` when
|
|
392
|
+
* logged out.
|
|
393
|
+
*/
|
|
394
|
+
#getSessionId() {
|
|
395
|
+
return this.#accessToken
|
|
396
|
+
? new Date(this.#accessToken.created).getTime()
|
|
397
|
+
: null;
|
|
398
|
+
}
|
|
399
|
+
async #transakGet(queryName, path,
|
|
400
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
401
|
+
dataStruct, params) {
|
|
274
402
|
const baseUrl = getTransakApiBaseUrl(this.#environment);
|
|
275
403
|
const url = new URL(path, baseUrl);
|
|
276
404
|
if (params) {
|
|
@@ -282,59 +410,98 @@ export class TransakService {
|
|
|
282
410
|
}
|
|
283
411
|
const apiKey = this.#ensureApiKey();
|
|
284
412
|
url.searchParams.set('apiKey', apiKey);
|
|
285
|
-
const response = await this
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
413
|
+
const response = (await this.fetchQuery({
|
|
414
|
+
// The API key is deliberately left out of the key, as keys appear in the
|
|
415
|
+
// names of published `cacheUpdated` events.
|
|
416
|
+
queryKey: [
|
|
417
|
+
`${this.name}:${queryName}`,
|
|
418
|
+
path,
|
|
419
|
+
params ?? {},
|
|
420
|
+
this.#getSessionId(),
|
|
421
|
+
],
|
|
422
|
+
staleTime: 0,
|
|
423
|
+
gcTime: 0,
|
|
424
|
+
responseStruct: envelope(dataStruct),
|
|
425
|
+
queryFn: async () => {
|
|
426
|
+
const fetchResponse = await this.#fetch(url.toString(), {
|
|
427
|
+
method: 'GET',
|
|
428
|
+
headers: this.#getHeaders(),
|
|
429
|
+
});
|
|
430
|
+
if (!fetchResponse.ok) {
|
|
431
|
+
await this.#throwTransakApiError(fetchResponse, url);
|
|
432
|
+
}
|
|
433
|
+
return (await fetchResponse.json());
|
|
434
|
+
},
|
|
435
|
+
}));
|
|
295
436
|
return response.data;
|
|
296
437
|
}
|
|
297
|
-
|
|
438
|
+
/**
|
|
439
|
+
* Sends a request that changes server side data. Mutations are never
|
|
440
|
+
* retried, and the mutation key holds only the method name, as keys appear
|
|
441
|
+
* in the names of published `cacheUpdated` events.
|
|
442
|
+
*
|
|
443
|
+
* @param options - The options.
|
|
444
|
+
* @param options.mutationName - The name of the public method.
|
|
445
|
+
* @param options.url - The request URL.
|
|
446
|
+
* @param options.init - The request method, headers and body.
|
|
447
|
+
* @param options.responseStruct - The struct for the response body. When
|
|
448
|
+
* omitted, the response body is ignored.
|
|
449
|
+
* @returns The validated response body, or `null` if it was ignored.
|
|
450
|
+
*/
|
|
451
|
+
async #sendMutation({ mutationName, url, init, responseStruct, }) {
|
|
452
|
+
return (await this.executeMutation({
|
|
453
|
+
mutationKey: [`${this.name}:${mutationName}`],
|
|
454
|
+
// Some responses carry credentials (`verifyUserOtp` returns the access
|
|
455
|
+
// token), so do not keep finished mutations in the cache.
|
|
456
|
+
gcTime: 0,
|
|
457
|
+
responseStruct,
|
|
458
|
+
mutationFn: async () => {
|
|
459
|
+
const fetchResponse = await this.#fetch(url.toString(), init);
|
|
460
|
+
if (!fetchResponse.ok) {
|
|
461
|
+
await this.#throwTransakApiError(fetchResponse, url);
|
|
462
|
+
}
|
|
463
|
+
return responseStruct ? (await fetchResponse.json()) : null;
|
|
464
|
+
},
|
|
465
|
+
}));
|
|
466
|
+
}
|
|
467
|
+
async #transakPost(mutationName, path,
|
|
468
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
469
|
+
dataStruct, body) {
|
|
298
470
|
const apiKey = this.#ensureApiKey();
|
|
299
471
|
const baseUrl = getTransakApiBaseUrl(this.#environment);
|
|
300
472
|
const url = new URL(path, baseUrl);
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const policy = options.policy ?? this.#policy;
|
|
306
|
-
const response = await policy.execute(async () => {
|
|
307
|
-
const fetchResponse = await this.#fetch(url.toString(), {
|
|
473
|
+
const response = (await this.#sendMutation({
|
|
474
|
+
mutationName,
|
|
475
|
+
url,
|
|
476
|
+
init: {
|
|
308
477
|
method: 'POST',
|
|
309
478
|
headers: this.#getHeaders(),
|
|
310
|
-
body: JSON.stringify(
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
return fetchResponse.json();
|
|
316
|
-
});
|
|
479
|
+
body: JSON.stringify({ ...(body ?? {}), apiKey }),
|
|
480
|
+
},
|
|
481
|
+
responseStruct: envelope(dataStruct),
|
|
482
|
+
}));
|
|
317
483
|
return response.data;
|
|
318
484
|
}
|
|
319
|
-
async #transakPatch(path,
|
|
485
|
+
async #transakPatch(mutationName, path,
|
|
486
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
487
|
+
dataStruct, body) {
|
|
320
488
|
const apiKey = this.#ensureApiKey();
|
|
321
489
|
const baseUrl = getTransakApiBaseUrl(this.#environment);
|
|
322
490
|
const url = new URL(path, baseUrl);
|
|
323
491
|
url.searchParams.set('apiKey', apiKey);
|
|
324
|
-
const response = await this.#
|
|
325
|
-
|
|
492
|
+
const response = (await this.#sendMutation({
|
|
493
|
+
mutationName,
|
|
494
|
+
url,
|
|
495
|
+
init: {
|
|
326
496
|
method: 'PATCH',
|
|
327
497
|
headers: this.#getHeaders(),
|
|
328
498
|
body: JSON.stringify(body),
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
return fetchResponse.json();
|
|
334
|
-
});
|
|
499
|
+
},
|
|
500
|
+
responseStruct: envelope(dataStruct),
|
|
501
|
+
}));
|
|
335
502
|
return response.data;
|
|
336
503
|
}
|
|
337
|
-
async #transakDelete(path, params) {
|
|
504
|
+
async #transakDelete(mutationName, path, params) {
|
|
338
505
|
const apiKey = this.#ensureApiKey();
|
|
339
506
|
const baseUrl = getTransakApiBaseUrl(this.#environment);
|
|
340
507
|
const url = new URL(path, baseUrl);
|
|
@@ -346,14 +513,10 @@ export class TransakService {
|
|
|
346
513
|
}
|
|
347
514
|
}
|
|
348
515
|
}
|
|
349
|
-
await this.#
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
});
|
|
354
|
-
if (!fetchResponse.ok) {
|
|
355
|
-
await this.#throwTransakApiError(fetchResponse, url);
|
|
356
|
-
}
|
|
516
|
+
await this.#sendMutation({
|
|
517
|
+
mutationName,
|
|
518
|
+
url,
|
|
519
|
+
init: { method: 'DELETE', headers: this.#getHeaders() },
|
|
357
520
|
});
|
|
358
521
|
}
|
|
359
522
|
/**
|
|
@@ -380,7 +543,9 @@ export class TransakService {
|
|
|
380
543
|
// client product / version.
|
|
381
544
|
addRampsClientIdentityParams(url, this.#clientIdentity);
|
|
382
545
|
}
|
|
383
|
-
async #ordersApiGet(path,
|
|
546
|
+
async #ordersApiGet(queryName, path,
|
|
547
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
548
|
+
dataStruct, params) {
|
|
384
549
|
const baseUrl = this.#getRampsApiBaseUrl();
|
|
385
550
|
const providerPath = getRampsProviderPath(this.#environment);
|
|
386
551
|
const url = new URL(`${providerPath}${path}`, baseUrl);
|
|
@@ -396,29 +561,36 @@ export class TransakService {
|
|
|
396
561
|
}
|
|
397
562
|
}
|
|
398
563
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
564
|
+
return (await this.fetchQuery({
|
|
565
|
+
queryKey: [`${this.name}:${queryName}`, path, params ?? {}],
|
|
566
|
+
staleTime: 0,
|
|
567
|
+
gcTime: 0,
|
|
568
|
+
responseStruct: dataStruct,
|
|
569
|
+
queryFn: async () => {
|
|
570
|
+
const fetchResponse = await this.#fetch(url.toString(), {
|
|
571
|
+
method: 'GET',
|
|
572
|
+
headers: { Accept: 'application/json' },
|
|
573
|
+
});
|
|
574
|
+
if (!fetchResponse.ok) {
|
|
575
|
+
throw new HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
|
|
576
|
+
}
|
|
577
|
+
return (await fetchResponse.json());
|
|
578
|
+
},
|
|
579
|
+
}));
|
|
410
580
|
}
|
|
411
581
|
// === PUBLIC API METHODS ===
|
|
412
582
|
async sendUserOtp(email) {
|
|
413
|
-
const result = await this.#transakPost('/api/v2/auth/login', {
|
|
583
|
+
const result = await this.#transakPost('sendUserOtp', '/api/v2/auth/login', SendUserOtpResponseStruct, {
|
|
584
|
+
email,
|
|
585
|
+
});
|
|
414
586
|
return result;
|
|
415
587
|
}
|
|
416
588
|
async verifyUserOtp(email, verificationCode, stateToken) {
|
|
417
|
-
const responseData = await this.#transakPost('/api/v2/auth/verify', {
|
|
589
|
+
const responseData = await this.#transakPost('verifyUserOtp', '/api/v2/auth/verify', VerifyUserOtpResponseStruct, {
|
|
418
590
|
email,
|
|
419
591
|
otp: verificationCode,
|
|
420
592
|
stateToken,
|
|
421
|
-
}
|
|
593
|
+
});
|
|
422
594
|
const accessToken = {
|
|
423
595
|
accessToken: responseData.accessToken,
|
|
424
596
|
ttl: responseData.ttl,
|
|
@@ -430,7 +602,7 @@ export class TransakService {
|
|
|
430
602
|
async logout() {
|
|
431
603
|
this.#ensureAccessToken();
|
|
432
604
|
try {
|
|
433
|
-
const result = await this.#transakPost('/api/v1/auth/logout');
|
|
605
|
+
const result = await this.#transakPost('logout', '/api/v1/auth/logout', string());
|
|
434
606
|
this.clearAccessToken();
|
|
435
607
|
return result;
|
|
436
608
|
}
|
|
@@ -444,7 +616,7 @@ export class TransakService {
|
|
|
444
616
|
}
|
|
445
617
|
async getUserDetails() {
|
|
446
618
|
this.#ensureAccessToken();
|
|
447
|
-
return this.#transakGet('/api/v2/user/');
|
|
619
|
+
return this.#transakGet('getUserDetails', '/api/v2/user/', UserDetailsStruct);
|
|
448
620
|
}
|
|
449
621
|
async getBuyQuote(genericFiatCurrency, genericCryptoCurrency, genericNetwork, genericPaymentMethod, fiatAmount, isFeeExcludedFromFiat = true) {
|
|
450
622
|
const normalizedPaymentMethod = normalizePaymentMethodForTranslation(genericPaymentMethod || undefined);
|
|
@@ -468,7 +640,7 @@ export class TransakService {
|
|
|
468
640
|
if (translation.paymentMethod) {
|
|
469
641
|
params.paymentMethod = translation.paymentMethod;
|
|
470
642
|
}
|
|
471
|
-
const quote = await this.#transakGet('/api/v2/lookup/quotes', params);
|
|
643
|
+
const quote = await this.#transakGet('getBuyQuote', '/api/v2/lookup/quotes', BuyQuoteStruct, params);
|
|
472
644
|
return {
|
|
473
645
|
...quote,
|
|
474
646
|
requestedAssetId: genericCryptoCurrency,
|
|
@@ -477,14 +649,14 @@ export class TransakService {
|
|
|
477
649
|
}
|
|
478
650
|
async getKycRequirement(quoteId) {
|
|
479
651
|
this.#ensureAccessToken();
|
|
480
|
-
const result = await this.#transakGet('/api/v2/kyc/requirement', {
|
|
652
|
+
const result = await this.#transakGet('getKycRequirement', '/api/v2/kyc/requirement', KycRequirementStruct, {
|
|
481
653
|
'metadata[quoteId]': quoteId,
|
|
482
654
|
});
|
|
483
655
|
return result;
|
|
484
656
|
}
|
|
485
657
|
async getAdditionalRequirements(quoteId) {
|
|
486
658
|
this.#ensureAccessToken();
|
|
487
|
-
return this.#transakGet('/api/v2/kyc/additional-requirements', { 'metadata[quoteId]': quoteId });
|
|
659
|
+
return this.#transakGet('getAdditionalRequirements', '/api/v2/kyc/additional-requirements', AdditionalRequirementsStruct, { 'metadata[quoteId]': quoteId });
|
|
488
660
|
}
|
|
489
661
|
async createOrder(quoteId, walletAddress, paymentMethodId) {
|
|
490
662
|
this.#ensureAccessToken();
|
|
@@ -494,7 +666,7 @@ export class TransakService {
|
|
|
494
666
|
});
|
|
495
667
|
const paymentInstrumentId = translation.paymentMethod ?? normalizedPaymentMethod;
|
|
496
668
|
try {
|
|
497
|
-
const transakOrder = await this.#transakPost('/api/v2/orders', {
|
|
669
|
+
const transakOrder = await this.#transakPost('createOrder', '/api/v2/orders', TransakOrderStruct, {
|
|
498
670
|
quoteId,
|
|
499
671
|
walletAddress,
|
|
500
672
|
paymentInstrumentId,
|
|
@@ -508,7 +680,7 @@ export class TransakService {
|
|
|
508
680
|
error.errorCode === TRANSAK_ERROR_CODES.ORDER_EXISTS) {
|
|
509
681
|
await this.cancelAllActiveOrders();
|
|
510
682
|
await new Promise((resolve) => setTimeout(resolve, this.#orderRetryDelayMs));
|
|
511
|
-
const retryOrder = await this.#transakPost('/api/v2/orders', {
|
|
683
|
+
const retryOrder = await this.#transakPost('createOrder', '/api/v2/orders', TransakOrderStruct, {
|
|
512
684
|
quoteId,
|
|
513
685
|
walletAddress,
|
|
514
686
|
paymentInstrumentId,
|
|
@@ -528,7 +700,7 @@ export class TransakService {
|
|
|
528
700
|
depositOrderId = TransakOrderIdTransformer.transakOrderIdToDepositOrderId(orderId, this.#environment);
|
|
529
701
|
}
|
|
530
702
|
const transakOrderId = TransakOrderIdTransformer.extractTransakOrderId(depositOrderId);
|
|
531
|
-
const order = await this.#ordersApiGet(`/orders/${transakOrderId}`, { wallet });
|
|
703
|
+
const order = await this.#ordersApiGet('getOrder', `/orders/${transakOrderId}`, DepositOrderStruct, { wallet });
|
|
532
704
|
const orderWithId = {
|
|
533
705
|
...order,
|
|
534
706
|
id: depositOrderId,
|
|
@@ -539,7 +711,7 @@ export class TransakService {
|
|
|
539
711
|
}
|
|
540
712
|
if (this.#accessToken?.accessToken) {
|
|
541
713
|
try {
|
|
542
|
-
const transakOrder = await this.#transakGet(`/api/v2/orders/${transakOrderId}
|
|
714
|
+
const transakOrder = await this.#transakGet('getOrderPaymentDetails', `/api/v2/orders/${transakOrderId}`, TransakOrderPaymentDetailsStruct);
|
|
543
715
|
return { ...orderWithId, paymentDetails: transakOrder.paymentDetails };
|
|
544
716
|
}
|
|
545
717
|
catch {
|
|
@@ -561,7 +733,7 @@ export class TransakService {
|
|
|
561
733
|
if (translation.paymentMethod) {
|
|
562
734
|
params.paymentCategory = translation.paymentMethod;
|
|
563
735
|
}
|
|
564
|
-
return this.#transakGet('/api/v2/orders/user-limit', params);
|
|
736
|
+
return this.#transakGet('getUserLimits', '/api/v2/orders/user-limit', UserLimitsStruct, params);
|
|
565
737
|
}
|
|
566
738
|
/**
|
|
567
739
|
* @deprecated Use {@link createWidgetUrl} instead. The OTT flow requires the
|
|
@@ -570,7 +742,7 @@ export class TransakService {
|
|
|
570
742
|
*/
|
|
571
743
|
async requestOtt() {
|
|
572
744
|
this.#ensureAccessToken();
|
|
573
|
-
const result = await this.#transakPost('/api/v2/auth/request-ott');
|
|
745
|
+
const result = await this.#transakPost('requestOtt', '/api/v2/auth/request-ott', OttStruct);
|
|
574
746
|
return result;
|
|
575
747
|
}
|
|
576
748
|
/**
|
|
@@ -626,7 +798,7 @@ export class TransakService {
|
|
|
626
798
|
*/
|
|
627
799
|
async createWidgetUrl(quote, walletAddress, extraParams) {
|
|
628
800
|
this.#ensureAccessToken();
|
|
629
|
-
const bearerToken = await this
|
|
801
|
+
const bearerToken = await this.messenger.call('AuthenticationController:getBearerToken');
|
|
630
802
|
const baseUrl = this.#getRampsApiBaseUrl();
|
|
631
803
|
const providerPath = getRampsProviderPath(this.#environment);
|
|
632
804
|
const url = new URL(`${providerPath}/widget-url`, baseUrl);
|
|
@@ -653,32 +825,32 @@ export class TransakService {
|
|
|
653
825
|
if (this.#accessToken?.accessToken) {
|
|
654
826
|
headers['x-transak-access-token'] = this.#accessToken.accessToken;
|
|
655
827
|
}
|
|
656
|
-
const response = await this.#
|
|
657
|
-
|
|
828
|
+
const response = (await this.#sendMutation({
|
|
829
|
+
mutationName: 'createWidgetUrl',
|
|
830
|
+
url,
|
|
831
|
+
init: {
|
|
658
832
|
method: 'POST',
|
|
659
833
|
headers,
|
|
660
834
|
body: JSON.stringify({ widgetParams }),
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
}
|
|
665
|
-
return fetchResponse.json();
|
|
666
|
-
});
|
|
835
|
+
},
|
|
836
|
+
responseStruct: WidgetUrlResponseStruct,
|
|
837
|
+
}));
|
|
667
838
|
return response.widgetUrl;
|
|
668
839
|
}
|
|
669
840
|
async submitPurposeOfUsageForm(purpose) {
|
|
670
841
|
this.#ensureAccessToken();
|
|
671
|
-
await this.#transakPost('/api/v2/kyc/purpose-of-usage', {
|
|
672
|
-
purposeList: purpose,
|
|
673
|
-
});
|
|
842
|
+
await this.#transakPost('submitPurposeOfUsageForm', '/api/v2/kyc/purpose-of-usage', any(), { purposeList: purpose });
|
|
674
843
|
}
|
|
675
844
|
async patchUser(data) {
|
|
676
845
|
this.#ensureAccessToken();
|
|
677
|
-
return this.#transakPatch('/api/v2/kyc/user', data);
|
|
846
|
+
return this.#transakPatch('patchUser', '/api/v2/kyc/user', any(), data);
|
|
678
847
|
}
|
|
679
848
|
async submitSsnDetails(ssn, quoteId) {
|
|
680
849
|
this.#ensureAccessToken();
|
|
681
|
-
return this.#transakPost('/api/v2/kyc/ssn',
|
|
850
|
+
return this.#transakPost('submitSsnDetails', '/api/v2/kyc/ssn', any(), {
|
|
851
|
+
ssn,
|
|
852
|
+
quoteId,
|
|
853
|
+
});
|
|
682
854
|
}
|
|
683
855
|
async confirmPayment(orderId, paymentMethodId) {
|
|
684
856
|
this.#ensureAccessToken();
|
|
@@ -687,7 +859,7 @@ export class TransakService {
|
|
|
687
859
|
paymentMethod: normalizedPaymentMethod,
|
|
688
860
|
});
|
|
689
861
|
const transakOrderId = TransakOrderIdTransformer.extractTransakOrderId(orderId);
|
|
690
|
-
return this.#transakPost('/api/v2/orders/payment-confirmation', {
|
|
862
|
+
return this.#transakPost('confirmPayment', '/api/v2/orders/payment-confirmation', PaymentConfirmationStruct, {
|
|
691
863
|
orderId: transakOrderId,
|
|
692
864
|
paymentMethod: translation.paymentMethod ?? normalizedPaymentMethod,
|
|
693
865
|
});
|
|
@@ -702,31 +874,38 @@ export class TransakService {
|
|
|
702
874
|
...translationRequest,
|
|
703
875
|
paymentMethod: normalizePaymentMethodForTranslation(translationRequest.paymentMethod),
|
|
704
876
|
};
|
|
877
|
+
const params = {};
|
|
705
878
|
for (const [key, value] of Object.entries(normalizedRequest)) {
|
|
706
879
|
if (value !== undefined) {
|
|
707
880
|
url.searchParams.set(key, value);
|
|
881
|
+
params[key] = value;
|
|
708
882
|
}
|
|
709
883
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
884
|
+
return (await this.fetchQuery({
|
|
885
|
+
queryKey: [`${this.name}:getTranslation`, params],
|
|
886
|
+
staleTime: 0,
|
|
887
|
+
gcTime: 0,
|
|
888
|
+
responseStruct: TranslationStruct,
|
|
889
|
+
queryFn: async () => {
|
|
890
|
+
const fetchResponse = await this.#fetch(url.toString(), {
|
|
891
|
+
method: 'GET',
|
|
892
|
+
headers: { Accept: 'application/json' },
|
|
893
|
+
});
|
|
894
|
+
if (!fetchResponse.ok) {
|
|
895
|
+
throw new HttpError(fetchResponse.status, `Fetching '${url.toString()}' failed with status '${fetchResponse.status}'`);
|
|
896
|
+
}
|
|
897
|
+
return (await fetchResponse.json());
|
|
898
|
+
},
|
|
899
|
+
}));
|
|
721
900
|
}
|
|
722
901
|
async getIdProofStatus(workFlowRunId) {
|
|
723
902
|
this.#ensureAccessToken();
|
|
724
|
-
return this.#transakGet('/api/v2/kyc/id-proof-status', { workFlowRunId });
|
|
903
|
+
return this.#transakGet('getIdProofStatus', '/api/v2/kyc/id-proof-status', IdProofStatusStruct, { workFlowRunId });
|
|
725
904
|
}
|
|
726
905
|
async cancelOrder(depositOrderId) {
|
|
727
906
|
this.#ensureAccessToken();
|
|
728
907
|
const transakOrderId = TransakOrderIdTransformer.extractTransakOrderId(depositOrderId);
|
|
729
|
-
await this.#transakDelete(`/api/v2/orders/${transakOrderId}`, {
|
|
908
|
+
await this.#transakDelete('cancelOrder', `/api/v2/orders/${transakOrderId}`, {
|
|
730
909
|
cancelReason: 'Creating new order',
|
|
731
910
|
});
|
|
732
911
|
}
|
|
@@ -747,7 +926,7 @@ export class TransakService {
|
|
|
747
926
|
}
|
|
748
927
|
async getActiveOrders() {
|
|
749
928
|
this.#ensureAccessToken();
|
|
750
|
-
return this.#transakGet('/api/v2/active-orders');
|
|
929
|
+
return this.#transakGet('getActiveOrders', '/api/v2/active-orders', ActiveOrdersStruct);
|
|
751
930
|
}
|
|
752
931
|
}
|
|
753
932
|
//# sourceMappingURL=TransakService.js.map
|