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

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,7 +3247,6 @@ 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
  }
@@ -3261,7 +3261,7 @@ class PublicSwapService {
3261
3261
  SwapUtils.safeHandleRequestsLimitExceeding();
3262
3262
  return {
3263
3263
  result: false,
3264
- reason: this.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3264
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3265
3265
  };
3266
3266
  }
3267
3267
  Logger.log(`Retrieved ${result == null || (_result$coins = result.coins) == null ? void 0 : _result$coins.length} supported currencies for swap`, loggerSource);
@@ -3304,13 +3304,13 @@ class PublicSwapService {
3304
3304
  SwapUtils.safeHandleRequestsLimitExceeding();
3305
3305
  return {
3306
3306
  result: false,
3307
- reason: this.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3307
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3308
3308
  };
3309
3309
  }
3310
3310
  if (result.reason === SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED) {
3311
3311
  return {
3312
3312
  result: false,
3313
- reason: this.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED
3313
+ reason: PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED
3314
3314
  };
3315
3315
  }
3316
3316
  }
@@ -3351,10 +3351,10 @@ class PublicSwapService {
3351
3351
  fiatMax = null;
3352
3352
  if (coinUsdtRate != null) {
3353
3353
  if (min != null) {
3354
- fiatMin = BigNumber(min).times(coinUsdtRate).toFixed(this._fiatDecimalsCount);
3354
+ fiatMin = BigNumber(min).times(coinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
3355
3355
  }
3356
3356
  if (max != null) {
3357
- fiatMax = BigNumber(max).times(coinUsdtRate).toFixed(this._fiatDecimalsCount);
3357
+ fiatMax = BigNumber(max).times(coinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
3358
3358
  }
3359
3359
  }
3360
3360
  const composeFailResult = reason => {
@@ -3370,16 +3370,16 @@ class PublicSwapService {
3370
3370
  };
3371
3371
  };
3372
3372
  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) {
3373
+ 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
3374
  SwapUtils.safeHandleRequestsLimitExceeding();
3375
- return composeFailResult(this.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
3375
+ return composeFailResult(PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
3376
3376
  }
3377
3377
  }
3378
3378
  const fromAmountBigNumber = BigNumber(fromAmountCoins);
3379
3379
  if (typeof min === "string" && fromAmountBigNumber.lt(min)) {
3380
- return composeFailResult(this.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_LESS_THAN_MIN_SWAPPABLE);
3380
+ return composeFailResult(PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_LESS_THAN_MIN_SWAPPABLE);
3381
3381
  } else if (typeof max === "string" && fromAmountBigNumber.gt(max)) {
3382
- return composeFailResult(this.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_HIGHER_THAN_MAX_SWAPPABLE);
3382
+ return composeFailResult(PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_HIGHER_THAN_MAX_SWAPPABLE);
3383
3383
  }
3384
3384
  const toAmountCoins = AmountUtils.trim(fromAmountBigNumber.times(details.rate), fromCoin.digits);
3385
3385
  const result = {
@@ -3408,6 +3408,7 @@ class PublicSwapService {
3408
3408
  * @param swapCreationInfo {BaseSwapCreationInfo}
3409
3409
  * @param toAddress {string}
3410
3410
  * @param refundAddress {string}
3411
+ * @param clientIp {string}
3411
3412
  * @return {Promise<{
3412
3413
  * result: true,
3413
3414
  * fiatCurrencyCode: string,
@@ -3448,14 +3449,14 @@ class PublicSwapService {
3448
3449
  SwapUtils.safeHandleRequestsLimitExceeding();
3449
3450
  return {
3450
3451
  result: false,
3451
- reason: this.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3452
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3452
3453
  };
3453
3454
  }
3454
3455
  if ((result == null ? void 0 : result.reason) === SwapProvider.CREATION_FAIL_REASONS.RETRIABLE_FAIL) {
3455
3456
  // TODO: [feature, high] implement retrying if one partner fail and we have another partners task_id=a07e367e488f4a4899613ac9056fa359
3456
3457
  // return {
3457
3458
  // result: false,
3458
- // reason: this.SWAP_CREATION_FAIL_REASONS.RETRIABLE_FAIL,
3459
+ // reason: PublicSwapService.SWAP_CREATION_FAIL_REASONS.RETRIABLE_FAIL,
3459
3460
  // };
3460
3461
  }
3461
3462
  }
@@ -3467,15 +3468,15 @@ class PublicSwapService {
3467
3468
  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
3469
  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
3470
  if (fromCoinUsdtRate != null && result.fromAmount != null) {
3470
- fromAmountFiat = BigNumber(result.fromAmount).times(fromCoinUsdtRate).toFixed(this._fiatDecimalsCount);
3471
+ fromAmountFiat = BigNumber(result.fromAmount).times(fromCoinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
3471
3472
  }
3472
3473
  if (toCoinUsdtRate != null && result.toAmount != null) {
3473
- toAmountFiat = BigNumber(result.toAmount).times(toCoinUsdtRate).toFixed(this._fiatDecimalsCount);
3474
+ toAmountFiat = BigNumber(result.toAmount).times(toCoinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
3474
3475
  }
3475
3476
  } catch (e) {
3476
3477
  Logger.logError(e, loggerSource, "Failed to calculate fiat amounts for result");
3477
3478
  }
3478
- EventBusInstance.dispatch(this.PUBLIC_SWAP_CREATED_EVENT, null, fromCoin.ticker, toCoin.ticker, fromAmountFiat);
3479
+ EventBusInstance.dispatch(PublicSwapService.PUBLIC_SWAP_CREATED_EVENT, null, fromCoin.ticker, toCoin.ticker, fromAmountFiat);
3479
3480
  const toReturn = {
3480
3481
  result: true,
3481
3482
  swapId: result.swapId,
@@ -3486,7 +3487,7 @@ class PublicSwapService {
3486
3487
  fromAmountFiat: fromAmountFiat,
3487
3488
  toAmountFiat: toAmountFiat,
3488
3489
  fiatCurrencyCode: "USD",
3489
- fiatCurrencyDecimals: this._fiatDecimalsCount,
3490
+ fiatCurrencyDecimals: PublicSwapService._fiatDecimalsCount,
3490
3491
  rate: result.rate,
3491
3492
  durationMinutesRange: swapCreationInfo.durationMinutesRange,
3492
3493
  address: result.fromAddress // CRITICAL: this is the address to send coins to swaps provider
@@ -3526,7 +3527,7 @@ class PublicSwapService {
3526
3527
  SwapUtils.safeHandleRequestsLimitExceeding();
3527
3528
  return {
3528
3529
  result: false,
3529
- reason: this.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3530
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3530
3531
  };
3531
3532
  }
3532
3533
  throw new Error("Unknown reason: " + (result == null ? void 0 : result.reason));