@rabbitio/ui-kit 1.0.0-beta.16 → 1.0.0-beta.18

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.
@@ -1,6 +1,7 @@
1
1
  import React, { useState, useRef, useEffect, useCallback } from 'react';
2
2
  import { BigNumber } from 'bignumber.js';
3
3
  import axios from 'axios';
4
+ import EventBusInstance from 'eventbusjs';
4
5
 
5
6
  function createCommonjsModule(fn) {
6
7
  var module = { exports: {} };
@@ -1549,7 +1550,7 @@ class Logger {
1549
1550
  }
1550
1551
  const finalErrorText = message + ". " + safeStringify(e);
1551
1552
  // eslint-disable-next-line no-console
1552
- console.error(finalErrorText);
1553
+ console.error(finalErrorText, e);
1553
1554
  if (!onlyToConsole) {
1554
1555
  this.log(finalErrorText, "logError");
1555
1556
  }
@@ -3006,7 +3007,7 @@ class SwapspaceSwapProvider extends SwapProvider {
3006
3007
  throw new Error(errorMessage);
3007
3008
  } catch (e) {
3008
3009
  var _e$response4, _e$response5;
3009
- Logger.log(`Failed to create swap. Error is: ${safeStringify(e)}`, loggerSource);
3010
+ Logger.logError(e, loggerSource, `Failed to create swap. Error is: ${safeStringify(e)}`);
3010
3011
  const composeFailResult = reason => ({
3011
3012
  result: false,
3012
3013
  reason: reason,
@@ -3090,7 +3091,7 @@ class SwapspaceSwapProvider extends SwapProvider {
3090
3091
  };
3091
3092
  } catch (e) {
3092
3093
  var _e$response6, _e$response7;
3093
- Logger.log(`Failed to get swap details. Error is: ${safeStringify(e)}`, loggerSource);
3094
+ Logger.logError(e, loggerSource, `Failed to get swap details. Error is: ${safeStringify(e)}`);
3094
3095
  const composeFailResult = reason => ({
3095
3096
  result: false,
3096
3097
  reason: reason
@@ -3189,7 +3190,7 @@ class SwapUtils {
3189
3190
  Logger.log(`Returning: ${safeStringify(result)}`, loggerSource);
3190
3191
  return result;
3191
3192
  } catch (e) {
3192
- Logger.log(`Failed to init swap: ${safeStringify(e)}`, loggerSource);
3193
+ Logger.logError(e, loggerSource, `Failed to init swap: ${safeStringify(e)}`);
3193
3194
  improveAndRethrow(e, loggerSource);
3194
3195
  }
3195
3196
  }
@@ -3246,22 +3247,34 @@ class PublicSwapService {
3246
3247
  async initialize() {
3247
3248
  try {
3248
3249
  await this._swapProvider.initialize();
3249
- SwapUtils.safeHandleRequestsLimitExceeding();
3250
3250
  } catch (e) {
3251
3251
  Logger.logError(e, "PublicSwapService.initialize");
3252
3252
  }
3253
3253
  }
3254
- async getCurrenciesListForPublicSwap(currencyThatShouldNotBeFirst = null) {
3254
+ async getDepositCurrenciesListForPublicSwap() {
3255
+ try {
3256
+ return await this._getCurrenciesListForPublicSwap(false);
3257
+ } catch (e) {
3258
+ improveAndRethrow(e, "getDepositCurrenciesListForPublicSwap");
3259
+ }
3260
+ }
3261
+ async getWithdrawCurrenciesListForPublicSwap() {
3262
+ try {
3263
+ return await this._getCurrenciesListForPublicSwap(true);
3264
+ } catch (e) {
3265
+ improveAndRethrow(e, "getWithdrawCurrenciesListForPublicSwap");
3266
+ }
3267
+ }
3268
+ async _getCurrenciesListForPublicSwap(withdraw = false) {
3255
3269
  const loggerSource = "getCurrenciesListForPublicSwap";
3256
3270
  try {
3257
3271
  var _result$coins;
3258
- // TODO: [dev] this is temporary hack, change it to use dedicated lists inside UI and also here
3259
- const result = currencyThatShouldNotBeFirst ? await this._swapProvider.getWithdrawalCurrencies(currencyThatShouldNotBeFirst) : await this._swapProvider.getDepositCurrencies();
3272
+ const result = withdraw ? await this._swapProvider.getWithdrawalCurrencies() : await this._swapProvider.getDepositCurrencies();
3260
3273
  if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3261
3274
  SwapUtils.safeHandleRequestsLimitExceeding();
3262
3275
  return {
3263
3276
  result: false,
3264
- reason: this.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3277
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3265
3278
  };
3266
3279
  }
3267
3280
  Logger.log(`Retrieved ${result == null || (_result$coins = result.coins) == null ? void 0 : _result$coins.length} supported currencies for swap`, loggerSource);
@@ -3304,13 +3317,13 @@ class PublicSwapService {
3304
3317
  SwapUtils.safeHandleRequestsLimitExceeding();
3305
3318
  return {
3306
3319
  result: false,
3307
- reason: this.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3320
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3308
3321
  };
3309
3322
  }
3310
3323
  if (result.reason === SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED) {
3311
3324
  return {
3312
3325
  result: false,
3313
- reason: this.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED
3326
+ reason: PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED
3314
3327
  };
3315
3328
  }
3316
3329
  }
@@ -3351,10 +3364,10 @@ class PublicSwapService {
3351
3364
  fiatMax = null;
3352
3365
  if (coinUsdtRate != null) {
3353
3366
  if (min != null) {
3354
- fiatMin = BigNumber(min).times(coinUsdtRate).toFixed(this._fiatDecimalsCount);
3367
+ fiatMin = BigNumber(min).times(coinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
3355
3368
  }
3356
3369
  if (max != null) {
3357
- fiatMax = BigNumber(max).times(coinUsdtRate).toFixed(this._fiatDecimalsCount);
3370
+ fiatMax = BigNumber(max).times(coinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
3358
3371
  }
3359
3372
  }
3360
3373
  const composeFailResult = reason => {
@@ -3370,16 +3383,16 @@ class PublicSwapService {
3370
3383
  };
3371
3384
  };
3372
3385
  if (!details.result) {
3373
- if ((details == null ? void 0 : details.reason) === SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED) return composeFailResult(this.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED);else if ((details == null ? void 0 : details.reason) === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3386
+ if ((details == null ? void 0 : details.reason) === SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED) return composeFailResult(PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED);else if ((details == null ? void 0 : details.reason) === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3374
3387
  SwapUtils.safeHandleRequestsLimitExceeding();
3375
- return composeFailResult(this.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
3388
+ return composeFailResult(PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
3376
3389
  }
3377
3390
  }
3378
3391
  const fromAmountBigNumber = BigNumber(fromAmountCoins);
3379
3392
  if (typeof min === "string" && fromAmountBigNumber.lt(min)) {
3380
- return composeFailResult(this.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_LESS_THAN_MIN_SWAPPABLE);
3393
+ return composeFailResult(PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_LESS_THAN_MIN_SWAPPABLE);
3381
3394
  } else if (typeof max === "string" && fromAmountBigNumber.gt(max)) {
3382
- return composeFailResult(this.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_HIGHER_THAN_MAX_SWAPPABLE);
3395
+ return composeFailResult(PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_HIGHER_THAN_MAX_SWAPPABLE);
3383
3396
  }
3384
3397
  const toAmountCoins = AmountUtils.trim(fromAmountBigNumber.times(details.rate), fromCoin.digits);
3385
3398
  const result = {
@@ -3408,6 +3421,7 @@ class PublicSwapService {
3408
3421
  * @param swapCreationInfo {BaseSwapCreationInfo}
3409
3422
  * @param toAddress {string}
3410
3423
  * @param refundAddress {string}
3424
+ * @param clientIp {string}
3411
3425
  * @return {Promise<{
3412
3426
  * result: true,
3413
3427
  * fiatCurrencyCode: string,
@@ -3448,14 +3462,14 @@ class PublicSwapService {
3448
3462
  SwapUtils.safeHandleRequestsLimitExceeding();
3449
3463
  return {
3450
3464
  result: false,
3451
- reason: this.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3465
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3452
3466
  };
3453
3467
  }
3454
3468
  if ((result == null ? void 0 : result.reason) === SwapProvider.CREATION_FAIL_REASONS.RETRIABLE_FAIL) {
3455
3469
  // TODO: [feature, high] implement retrying if one partner fail and we have another partners task_id=a07e367e488f4a4899613ac9056fa359
3456
3470
  // return {
3457
3471
  // result: false,
3458
- // reason: this.SWAP_CREATION_FAIL_REASONS.RETRIABLE_FAIL,
3472
+ // reason: PublicSwapService.SWAP_CREATION_FAIL_REASONS.RETRIABLE_FAIL,
3459
3473
  // };
3460
3474
  }
3461
3475
  }
@@ -3467,15 +3481,15 @@ class PublicSwapService {
3467
3481
  const fromCoinUsdtRate = (_await$this$_swapProv3 = (_await$this$_swapProv4 = await this._swapProvider.getCoinToUSDTRate(fromCoin)) == null ? void 0 : _await$this$_swapProv4.rate) != null ? _await$this$_swapProv3 : null;
3468
3482
  const toCoinUsdtRate = (_await$this$_swapProv5 = (_await$this$_swapProv6 = await this._swapProvider.getCoinToUSDTRate(fromCoin)) == null ? void 0 : _await$this$_swapProv6.rate) != null ? _await$this$_swapProv5 : null;
3469
3483
  if (fromCoinUsdtRate != null && result.fromAmount != null) {
3470
- fromAmountFiat = BigNumber(result.fromAmount).times(fromCoinUsdtRate).toFixed(this._fiatDecimalsCount);
3484
+ fromAmountFiat = BigNumber(result.fromAmount).times(fromCoinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
3471
3485
  }
3472
3486
  if (toCoinUsdtRate != null && result.toAmount != null) {
3473
- toAmountFiat = BigNumber(result.toAmount).times(toCoinUsdtRate).toFixed(this._fiatDecimalsCount);
3487
+ toAmountFiat = BigNumber(result.toAmount).times(toCoinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
3474
3488
  }
3475
3489
  } catch (e) {
3476
3490
  Logger.logError(e, loggerSource, "Failed to calculate fiat amounts for result");
3477
3491
  }
3478
- EventBusInstance.dispatch(this.PUBLIC_SWAP_CREATED_EVENT, null, fromCoin.ticker, toCoin.ticker, fromAmountFiat);
3492
+ EventBusInstance.dispatch(PublicSwapService.PUBLIC_SWAP_CREATED_EVENT, null, fromCoin.ticker, toCoin.ticker, fromAmountFiat);
3479
3493
  const toReturn = {
3480
3494
  result: true,
3481
3495
  swapId: result.swapId,
@@ -3486,7 +3500,7 @@ class PublicSwapService {
3486
3500
  fromAmountFiat: fromAmountFiat,
3487
3501
  toAmountFiat: toAmountFiat,
3488
3502
  fiatCurrencyCode: "USD",
3489
- fiatCurrencyDecimals: this._fiatDecimalsCount,
3503
+ fiatCurrencyDecimals: PublicSwapService._fiatDecimalsCount,
3490
3504
  rate: result.rate,
3491
3505
  durationMinutesRange: swapCreationInfo.durationMinutesRange,
3492
3506
  address: result.fromAddress // CRITICAL: this is the address to send coins to swaps provider
@@ -3526,7 +3540,7 @@ class PublicSwapService {
3526
3540
  SwapUtils.safeHandleRequestsLimitExceeding();
3527
3541
  return {
3528
3542
  result: false,
3529
- reason: this.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3543
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3530
3544
  };
3531
3545
  }
3532
3546
  throw new Error("Unknown reason: " + (result == null ? void 0 : result.reason));