@rabbitio/ui-kit 1.0.0-beta.22 → 1.0.0-beta.24

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/dist/index.cjs CHANGED
@@ -2733,11 +2733,25 @@ var SwapProvider = /*#__PURE__*/function () {
2733
2733
  }
2734
2734
 
2735
2735
  /**
2736
- * Retrieves all deposit currencies supported by this swap provider.
2736
+ * Retrieves all currencies supported by this swap provider.
2737
2737
  * Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
2738
2738
  *
2739
2739
  * @return {Promise<({ result: true, coins: Coin[] }|{ result: false, reason: string })>}
2740
2740
  */;
2741
+ _proto.getAllSupportedCurrencies = function getAllSupportedCurrencies() {
2742
+ try {
2743
+ throw new Error("Not implemented in base");
2744
+ } catch (e) {
2745
+ return Promise.reject(e);
2746
+ }
2747
+ }
2748
+ /**
2749
+ * Retrieves all deposit currencies supported by this swap provider.
2750
+ * Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
2751
+ *
2752
+ * @return {Promise<({ result: true, coins: Coin[] }|{ result: false, reason: string })>}
2753
+ */
2754
+ ;
2741
2755
  _proto.getDepositCurrencies = function getDepositCurrencies() {
2742
2756
  try {
2743
2757
  throw new Error("Not implemented in base");
@@ -2789,6 +2803,7 @@ var SwapProvider = /*#__PURE__*/function () {
2789
2803
  * null min or max signals there is no corresponding limitation. undefined means that the limits were not retrieved.
2790
2804
  * For fail result on of SwapProvider.NO_SWAPS_REASONS or SwapProvider.COMMON_ERRORS reasons will be returned.
2791
2805
  *
2806
+ * WARNING: MUST return NOT_SUPPORTED error code for any case when pair is not available/supported (Should not throw random errors for this case)
2792
2807
  * @param fromCoin {Coin}
2793
2808
  * @param toCoin {Coin}
2794
2809
  * @param amountCoins {string}
@@ -2985,20 +3000,49 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
2985
3000
  return Promise.reject(e);
2986
3001
  }
2987
3002
  };
3003
+ _proto.getAllSupportedCurrencies = function getAllSupportedCurrencies() {
3004
+ try {
3005
+ var _this3 = this;
3006
+ var loggerSource = "getAllSupportedCurrencies";
3007
+ return Promise.resolve(_catch$2(function () {
3008
+ return Promise.resolve(_this3._fetchSupportedCurrenciesIfNeeded()).then(function () {
3009
+ var _this3$_supportedCoin;
3010
+ Logger.log("We have " + ((_this3$_supportedCoin = _this3._supportedCoins) == null ? void 0 : _this3$_supportedCoin.length) + " supported coins returning", loggerSource);
3011
+ return {
3012
+ result: true,
3013
+ coins: _this3._supportedCoins.map(function (item) {
3014
+ return item.coin;
3015
+ })
3016
+ };
3017
+ });
3018
+ }, function (e) {
3019
+ var _e$response2;
3020
+ if ((e == null || (_e$response2 = e.response) == null ? void 0 : _e$response2.status) === 429) {
3021
+ return {
3022
+ result: false,
3023
+ reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3024
+ };
3025
+ }
3026
+ improveAndRethrow(e, loggerSource);
3027
+ }));
3028
+ } catch (e) {
3029
+ return Promise.reject(e);
3030
+ }
3031
+ };
2988
3032
  _proto.getWithdrawalCurrencies = function getWithdrawalCurrencies(exceptCurrency) {
2989
3033
  if (exceptCurrency === void 0) {
2990
3034
  exceptCurrency = null;
2991
3035
  }
2992
3036
  try {
2993
- var _this3 = this;
3037
+ var _this4 = this;
2994
3038
  var loggerSource = "getWithdrawalCurrencies";
2995
3039
  return Promise.resolve(_catch$2(function () {
2996
- return Promise.resolve(_this3._fetchSupportedCurrenciesIfNeeded()).then(function () {
2997
- var _this3$_supportedCoin;
2998
- Logger.log("We have " + ((_this3$_supportedCoin = _this3._supportedCoins) == null ? void 0 : _this3$_supportedCoin.length) + " supported coins, getting withdrawable", loggerSource);
3040
+ return Promise.resolve(_this4._fetchSupportedCurrenciesIfNeeded()).then(function () {
3041
+ var _this4$_supportedCoin;
3042
+ Logger.log("We have " + ((_this4$_supportedCoin = _this4._supportedCoins) == null ? void 0 : _this4$_supportedCoin.length) + " supported coins, getting withdrawable", loggerSource);
2999
3043
  return {
3000
3044
  result: true,
3001
- coins: _this3._supportedCoins.filter(function (item) {
3045
+ coins: _this4._supportedCoins.filter(function (item) {
3002
3046
  var _item$coin, _exceptCurrency;
3003
3047
  return item.withdrawal && (!exceptCurrency || ((_item$coin = item.coin) == null ? void 0 : _item$coin.ticker) !== ((_exceptCurrency = exceptCurrency) == null ? void 0 : _exceptCurrency.ticker));
3004
3048
  }).map(function (item) {
@@ -3007,8 +3051,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3007
3051
  };
3008
3052
  });
3009
3053
  }, function (e) {
3010
- var _e$response2;
3011
- if ((e == null || (_e$response2 = e.response) == null ? void 0 : _e$response2.status) === 429) {
3054
+ var _e$response3;
3055
+ if ((e == null || (_e$response3 = e.response) == null ? void 0 : _e$response3.status) === 429) {
3012
3056
  return {
3013
3057
  result: false,
3014
3058
  reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
@@ -3022,8 +3066,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3022
3066
  };
3023
3067
  _proto.initialize = function initialize() {
3024
3068
  try {
3025
- var _this4 = this;
3026
- return Promise.resolve(_this4._fetchSupportedCurrenciesIfNeeded()).then(function () {});
3069
+ var _this5 = this;
3070
+ return Promise.resolve(_this5._fetchSupportedCurrenciesIfNeeded()).then(function () {});
3027
3071
  } catch (e) {
3028
3072
  return Promise.reject(e);
3029
3073
  }
@@ -3049,17 +3093,17 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3049
3093
  };
3050
3094
  _proto._fetchSupportedCurrenciesIfNeeded = function _fetchSupportedCurrenciesIfNeeded() {
3051
3095
  try {
3052
- var _this5 = this;
3096
+ var _this6 = this;
3053
3097
  var loggerSource = "_fetchSupportedCurrenciesIfNeeded";
3054
3098
  return Promise.resolve(_catch$2(function () {
3055
- var _temp = function (_this5$_supportedCoin) {
3056
- if (!((_this5$_supportedCoin = _this5._supportedCoins) != null && _this5$_supportedCoin.length)) {
3057
- return Promise.resolve(axios__default["default"].get(_this5._URL + "/api/v2/currencies")).then(function (rawResponse) {
3099
+ var _temp = function (_this6$_supportedCoin) {
3100
+ if (!((_this6$_supportedCoin = _this6._supportedCoins) != null && _this6$_supportedCoin.length)) {
3101
+ return Promise.resolve(axios__default["default"].get(_this6._URL + "/api/v2/currencies")).then(function (rawResponse) {
3058
3102
  var _rawResponse$data, _rawResponse$data2;
3059
3103
  Logger.log("Retrieved " + (rawResponse == null || (_rawResponse$data = rawResponse.data) == null ? void 0 : _rawResponse$data.length) + " currencies", loggerSource);
3060
- _this5._supportedCoins = ((_rawResponse$data2 = rawResponse == null ? void 0 : rawResponse.data) != null ? _rawResponse$data2 : []).map(function (item) {
3061
- var coin = _this5._customCoinBuilder(item.code, item.network);
3062
- if (!coin && !_this5.useRestrictedCoinsSet) {
3104
+ _this6._supportedCoins = ((_rawResponse$data2 = rawResponse == null ? void 0 : rawResponse.data) != null ? _rawResponse$data2 : []).map(function (item) {
3105
+ var coin = _this6._customCoinBuilder(item.code, item.network);
3106
+ if (!coin && !_this6.useRestrictedCoinsSet) {
3063
3107
  /** Building coin object for coin that isn't supported OOB in Rabbit.
3064
3108
  * We are doing this way to be able to use extended coins set for swaps.
3065
3109
  * These temporary built coins are only for in-swap use, and we omit some usual
@@ -3095,7 +3139,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3095
3139
  }
3096
3140
  return [];
3097
3141
  }).flat();
3098
- _this5._putPopularCoinsFirst();
3142
+ _this6._putPopularCoinsFirst();
3099
3143
  });
3100
3144
  }
3101
3145
  }();
@@ -3122,21 +3166,21 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3122
3166
  };
3123
3167
  _proto.getCoinToUSDTRate = function getCoinToUSDTRate(coin) {
3124
3168
  try {
3125
- var _this6 = this;
3169
+ var _this7 = this;
3126
3170
  var loggerSource = "getCoinToUSDTRate";
3127
3171
  return Promise.resolve(_catch$2(function () {
3128
- return coin ? Promise.resolve(_this6._fetchSupportedCurrenciesIfNeeded()).then(function () {
3129
- var _this6$_supportedCoin;
3172
+ return coin ? Promise.resolve(_this7._fetchSupportedCurrenciesIfNeeded()).then(function () {
3173
+ var _this7$_supportedCoin;
3130
3174
  // Using USDT TRC20 as usually fee in this network is smaller than ERC20 and this network is widely used for USDT
3131
- var usdtTrc20 = (_this6$_supportedCoin = _this6._supportedCoins.find(function (i) {
3175
+ var usdtTrc20 = (_this7$_supportedCoin = _this7._supportedCoins.find(function (i) {
3132
3176
  return i.coin.ticker === "USDTTRC20";
3133
- })) == null ? void 0 : _this6$_supportedCoin.coin;
3177
+ })) == null ? void 0 : _this7$_supportedCoin.coin;
3134
3178
  if (!usdtTrc20) {
3135
3179
  return {
3136
3180
  result: false
3137
3181
  };
3138
3182
  }
3139
- var cached = _this6._cache.get("swapspace_usdt_rate_" + coin.ticker);
3183
+ var cached = _this7._cache.get("swapspace_usdt_rate_" + coin.ticker);
3140
3184
  if (cached != null) {
3141
3185
  return {
3142
3186
  result: true,
@@ -3144,7 +3188,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3144
3188
  };
3145
3189
  }
3146
3190
  Logger.log("Loading USDT->coin rate as not found in cache:", coin == null ? void 0 : coin.ticker);
3147
- return Promise.resolve(_this6.getSwapInfo(usdtTrc20, coin, "5000")).then(function (result) {
3191
+ return Promise.resolve(_this7.getSwapInfo(usdtTrc20, coin, "5000")).then(function (result) {
3148
3192
  if (!result.result) {
3149
3193
  return {
3150
3194
  result: false
@@ -3154,7 +3198,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3154
3198
  // This calculation is not precise as we cannot recognize the actual fee and network fee. Just approximate.
3155
3199
  var standardSwapspaceFeeMultiplier = 1.002; // usually 0.2%
3156
3200
  var rate = bignumber_js.BigNumber(1).div(bignumber_js.BigNumber(result.rate).times(standardSwapspaceFeeMultiplier)).toString();
3157
- _this6._cache.put("swapspace_usdt_rate_" + coin.ticker, rate, 15 * 60000 // 15 minutes
3201
+ _this7._cache.put("swapspace_usdt_rate_" + coin.ticker, rate, 15 * 60000 // 15 minutes
3158
3202
  );
3159
3203
  return {
3160
3204
  result: true,
@@ -3185,28 +3229,27 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3185
3229
  fromCoinToUsdRate = null;
3186
3230
  }
3187
3231
  try {
3188
- var _this7 = this;
3232
+ var _this8 = this;
3189
3233
  var loggerSource = "getSwapInfo";
3190
3234
  return Promise.resolve(_catch$2(function () {
3191
3235
  if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amountCoins !== "string" || bignumber_js.BigNumber(amountCoins).lt("0")) {
3192
3236
  throw new Error("Wrong input params: " + amountCoins + " " + fromCoin.ticker + " -> " + toCoin.ticker + (fromCoin instanceof Coin) + (toCoin instanceof Coin));
3193
3237
  }
3194
- var fromCoinSwapspaceDetails = _this7._supportedCoins.find(function (i) {
3238
+ var fromCoinSwapspaceDetails = _this8._supportedCoins.find(function (i) {
3195
3239
  var _i$coin;
3196
3240
  return ((_i$coin = i.coin) == null ? void 0 : _i$coin.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
3197
3241
  });
3198
- var toCoinSwapspaceDetails = _this7._supportedCoins.find(function (i) {
3242
+ var toCoinSwapspaceDetails = _this8._supportedCoins.find(function (i) {
3199
3243
  var _i$coin2;
3200
3244
  return ((_i$coin2 = i.coin) == null ? void 0 : _i$coin2.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
3201
3245
  });
3202
3246
  if (!fromCoinSwapspaceDetails || !toCoinSwapspaceDetails) {
3203
3247
  throw new Error("Failed to find swapspace coin details for: " + fromCoin.ticker + " -> " + toCoin.ticker);
3204
3248
  }
3205
- /* Here we use not documented parameter 'estimated=false'. This parameter controls whether we want to use
3206
- * cached rate values stored in swapspace cache. Their support says they store at most for 30 sec.
3207
- * But we are better off using the most actual rates.
3208
- */
3209
- return Promise.resolve(axios__default["default"].get(_this7._URL + "/api/v2/amounts?fromCurrency=" + fromCoinSwapspaceDetails.code + "&fromNetwork=" + fromCoinSwapspaceDetails.network + "&toNetwork=" + toCoinSwapspaceDetails.network + "&toCurrency=" + toCoinSwapspaceDetails.code + "&amount=" + amountCoins + "&float=true&estimated=false")).then(function (response) {
3249
+ return !fromCoinSwapspaceDetails.deposit || !toCoinSwapspaceDetails.withdrawal ? {
3250
+ result: false,
3251
+ reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
3252
+ } : Promise.resolve(axios__default["default"].get(_this8._URL + "/api/v2/amounts?fromCurrency=" + fromCoinSwapspaceDetails.code + "&fromNetwork=" + fromCoinSwapspaceDetails.network + "&toNetwork=" + toCoinSwapspaceDetails.network + "&toCurrency=" + toCoinSwapspaceDetails.code + "&amount=" + amountCoins + "&float=true&estimated=false")).then(function (response) {
3210
3253
  var _response$data;
3211
3254
  Logger.log("Retrieved " + (response == null || (_response$data = response.data) == null ? void 0 : _response$data.length) + " options", loggerSource);
3212
3255
  var options = Array.isArray(response.data) ? response.data : [];
@@ -3285,7 +3328,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3285
3328
  max: max,
3286
3329
  smallestMin: smallestMin,
3287
3330
  greatestMax: greatestMax,
3288
- rate: rate != null ? AmountUtils.trim(rate, _this7._maxRateDigits) : null,
3331
+ rate: rate != null ? AmountUtils.trim(rate, _this8._maxRateDigits) : null,
3289
3332
  durationMinutesRange: (_bestOpt$duration = bestOpt.duration) != null ? _bestOpt$duration : null,
3290
3333
  rawSwapData: bestOpt
3291
3334
  };
@@ -3300,8 +3343,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3300
3343
  return result;
3301
3344
  });
3302
3345
  }, function (e) {
3303
- var _e$response3;
3304
- if ((e == null || (_e$response3 = e.response) == null ? void 0 : _e$response3.status) === 429) {
3346
+ var _e$response4;
3347
+ if ((e == null || (_e$response4 = e.response) == null ? void 0 : _e$response4.status) === 429) {
3305
3348
  return {
3306
3349
  result: false,
3307
3350
  reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
@@ -3316,7 +3359,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3316
3359
  };
3317
3360
  _proto.createSwap = function createSwap(fromCoin, toCoin, amount, toAddress, refundAddress, rawSwapData, clientIpAddress) {
3318
3361
  try {
3319
- var _this8 = this;
3362
+ var _this9 = this;
3320
3363
  var loggerSource = "createSwap";
3321
3364
  var partner = rawSwapData == null ? void 0 : rawSwapData.partner;
3322
3365
  return Promise.resolve(_catch$2(function () {
@@ -3327,12 +3370,12 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3327
3370
  ) {
3328
3371
  throw new Error("Invalid raw swap data: " + safeStringify(rawSwapData));
3329
3372
  }
3330
- return Promise.resolve(_this8._fetchSupportedCurrenciesIfNeeded()).then(function () {
3331
- var _this8$_supportedCoin, _this8$_supportedCoin2;
3332
- var toCurrencyExtraId = (_this8$_supportedCoin = (_this8$_supportedCoin2 = _this8._supportedCoins.find(function (item) {
3373
+ return Promise.resolve(_this9._fetchSupportedCurrenciesIfNeeded()).then(function () {
3374
+ var _this9$_supportedCoin, _this9$_supportedCoin2;
3375
+ var toCurrencyExtraId = (_this9$_supportedCoin = (_this9$_supportedCoin2 = _this9._supportedCoins.find(function (item) {
3333
3376
  var _item$coin4;
3334
3377
  return ((_item$coin4 = item.coin) == null ? void 0 : _item$coin4.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
3335
- })) == null ? void 0 : _this8$_supportedCoin2.extraId) != null ? _this8$_supportedCoin : "";
3378
+ })) == null ? void 0 : _this9$_supportedCoin2.extraId) != null ? _this9$_supportedCoin : "";
3336
3379
  var requestData = {
3337
3380
  partner: partner,
3338
3381
  fromCurrency: rawSwapData == null ? void 0 : rawSwapData.fromCurrency,
@@ -3348,7 +3391,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3348
3391
  refund: refundAddress
3349
3392
  };
3350
3393
  Logger.log("Sending create request: " + safeStringify(requestData), loggerSource);
3351
- return Promise.resolve(axios__default["default"].post(_this8._URL + "/api/v2/exchange", requestData)).then(function (response) {
3394
+ return Promise.resolve(axios__default["default"].post(_this9._URL + "/api/v2/exchange", requestData)).then(function (response) {
3352
3395
  var result = response.data;
3353
3396
  Logger.log("Creation result " + safeStringify(result), loggerSource);
3354
3397
  if (result != null && result.id) {
@@ -3372,7 +3415,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3372
3415
  toCoin: toCoin,
3373
3416
  toAmount: AmountUtils.trim(result == null || (_result$to4 = result.to) == null ? void 0 : _result$to4.amount, toCoin.digits),
3374
3417
  toAddress: result == null || (_result$to5 = result.to) == null ? void 0 : _result$to5.address,
3375
- rate: AmountUtils.trim(rate, _this8._maxRateDigits)
3418
+ rate: AmountUtils.trim(rate, _this9._maxRateDigits)
3376
3419
  };
3377
3420
  }
3378
3421
  var errorMessage = "Swap creation succeeded but the response is wrong: " + safeStringify(response);
@@ -3381,7 +3424,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3381
3424
  });
3382
3425
  });
3383
3426
  }, function (e) {
3384
- var _e$response4, _e$response5;
3427
+ var _e$response5, _e$response6;
3385
3428
  Logger.logError(e, loggerSource, "Failed to create swap. Error is: " + safeStringify(e));
3386
3429
  var composeFailResult = function composeFailResult(reason) {
3387
3430
  return {
@@ -3390,8 +3433,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3390
3433
  partner: partner
3391
3434
  };
3392
3435
  };
3393
- var status = e == null || (_e$response4 = e.response) == null ? void 0 : _e$response4.status;
3394
- var data = e == null || (_e$response5 = e.response) == null ? void 0 : _e$response5.data;
3436
+ var status = e == null || (_e$response5 = e.response) == null ? void 0 : _e$response5.status;
3437
+ var data = e == null || (_e$response6 = e.response) == null ? void 0 : _e$response6.data;
3395
3438
  if (status === 429) {
3396
3439
  Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
3397
3440
  return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
@@ -3440,7 +3483,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3440
3483
  };
3441
3484
  _proto.getExistingSwapsDetailsAndStatus = function getExistingSwapsDetailsAndStatus(swapIds) {
3442
3485
  try {
3443
- var _this9 = this;
3486
+ var _this10 = this;
3444
3487
  var loggerSource = "getExistingSwapsDetailsAndStatus";
3445
3488
  return Promise.resolve(_catch$2(function () {
3446
3489
  if (swapIds.find(function (id) {
@@ -3451,7 +3494,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3451
3494
  var getNotFailingOn404 = function getNotFailingOn404(swapId) {
3452
3495
  try {
3453
3496
  return Promise.resolve(_catch$2(function () {
3454
- return Promise.resolve(axios__default["default"].get(_this9._URL + "/api/v2/exchange/" + swapId));
3497
+ return Promise.resolve(axios__default["default"].get(_this10._URL + "/api/v2/exchange/" + swapId));
3455
3498
  }, function (error) {
3456
3499
  var _error$response;
3457
3500
  if ((error == null || (_error$response = error.response) == null ? void 0 : _error$response.status) === 404) return [];
@@ -3468,13 +3511,13 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3468
3511
  var swaps = wo404.map(function (r) {
3469
3512
  return r.data;
3470
3513
  }).map(function (swap, index) {
3471
- var _this9$_supportedCoin, _this9$_supportedCoin2;
3472
- var fromCoin = (_this9$_supportedCoin = _this9._supportedCoins.find(function (i) {
3514
+ var _this10$_supportedCoi, _this10$_supportedCoi2;
3515
+ var fromCoin = (_this10$_supportedCoi = _this10._supportedCoins.find(function (i) {
3473
3516
  return i.code === swap.from.code && i.network === swap.from.network;
3474
- })) == null ? void 0 : _this9$_supportedCoin.coin;
3475
- var toCoin = (_this9$_supportedCoin2 = _this9._supportedCoins.find(function (i) {
3517
+ })) == null ? void 0 : _this10$_supportedCoi.coin;
3518
+ var toCoin = (_this10$_supportedCoi2 = _this10._supportedCoins.find(function (i) {
3476
3519
  return i.code === swap.to.code && i.network === swap.to.network;
3477
- })) == null ? void 0 : _this9$_supportedCoin2.coin;
3520
+ })) == null ? void 0 : _this10$_supportedCoi2.coin;
3478
3521
  if (!fromCoin || !toCoin) {
3479
3522
  return []; // We skip swaps with not supported coins for now
3480
3523
  }
@@ -3483,10 +3526,10 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3483
3526
  };
3484
3527
  var expiresAt = toUtcTimestamp(swap.timestamps.expiresAt);
3485
3528
  var isExpiredByTime = expiresAt < Date.now();
3486
- var status = _this9._mapSwapspaceStatusToRabbitStatus(swap.status, isExpiredByTime);
3529
+ var status = _this10._mapSwapspaceStatusToRabbitStatus(swap.status, isExpiredByTime);
3487
3530
  var toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
3488
3531
  var addressToSendCoinsToSwapspace = swap.from.address;
3489
- return new ExistingSwap(swapIds[index], status, toUtcTimestamp(swap.timestamps.createdAt), expiresAt, swap.confirmations, AmountUtils.trim(swap.rate, _this9._maxRateDigits), swap.refundAddress, addressToSendCoinsToSwapspace, fromCoin, AmountUtils.trim(swap.from.amount, fromCoin.digits), swap.from.transactionHash, swap.blockExplorerTransactionUrl.from, toCoin, AmountUtils.trim(swap.to.amount, toDigits), swap.to.transactionHash, swap.blockExplorerTransactionUrl.to, swap.to.address, swap.partner);
3532
+ return new ExistingSwap(swapIds[index], status, toUtcTimestamp(swap.timestamps.createdAt), expiresAt, swap.confirmations, AmountUtils.trim(swap.rate, _this10._maxRateDigits), swap.refundAddress, addressToSendCoinsToSwapspace, fromCoin, AmountUtils.trim(swap.from.amount, fromCoin.digits), swap.from.transactionHash, swap.blockExplorerTransactionUrl.from, toCoin, AmountUtils.trim(swap.to.amount, toDigits), swap.to.transactionHash, swap.blockExplorerTransactionUrl.to, swap.to.address, swap.partner);
3490
3533
  }).flat();
3491
3534
  Logger.log("Swap details result " + safeStringify(swaps), loggerSource);
3492
3535
  return {
@@ -3495,7 +3538,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3495
3538
  };
3496
3539
  });
3497
3540
  }, function (e) {
3498
- var _e$response6, _e$response7;
3541
+ var _e$response7, _e$response8;
3499
3542
  Logger.logError(e, loggerSource, "Failed to get swap details. Error is: " + safeStringify(e));
3500
3543
  var composeFailResult = function composeFailResult(reason) {
3501
3544
  return {
@@ -3503,8 +3546,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3503
3546
  reason: reason
3504
3547
  };
3505
3548
  };
3506
- var status = e == null || (_e$response6 = e.response) == null ? void 0 : _e$response6.status;
3507
- var data = e == null || (_e$response7 = e.response) == null ? void 0 : _e$response7.data;
3549
+ var status = e == null || (_e$response7 = e.response) == null ? void 0 : _e$response7.status;
3550
+ var data = e == null || (_e$response8 = e.response) == null ? void 0 : _e$response8.data;
3508
3551
  if (status === 429) {
3509
3552
  Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
3510
3553
  return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
@@ -3882,11 +3925,26 @@ var PublicSwapService = /*#__PURE__*/function () {
3882
3925
  return Promise.reject(e);
3883
3926
  }
3884
3927
  };
3885
- _proto.getDepositCurrenciesListForPublicSwap = function getDepositCurrenciesListForPublicSwap() {
3928
+ _proto.getAllSupportedCurrenciesListForPublicSwap = function getAllSupportedCurrenciesListForPublicSwap() {
3886
3929
  try {
3887
3930
  var _this2 = this;
3931
+ var loggerSource = "getAllSupportedCurrenciesListForPublicSwap";
3888
3932
  return Promise.resolve(_catch(function () {
3889
- return Promise.resolve(_this2._getCurrenciesListForPublicSwap(false));
3933
+ return Promise.resolve(_this2._swapProvider.getAllSupportedCurrencies()).then(function (result) {
3934
+ var _result$coins;
3935
+ if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3936
+ SwapUtils.safeHandleRequestsLimitExceeding();
3937
+ return {
3938
+ result: false,
3939
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3940
+ };
3941
+ }
3942
+ Logger.log("Retrieved " + (result == null || (_result$coins = result.coins) == null ? void 0 : _result$coins.length) + " supported currencies for swap", loggerSource);
3943
+ return {
3944
+ result: true,
3945
+ coins: result.coins
3946
+ };
3947
+ });
3890
3948
  }, function (e) {
3891
3949
  improveAndRethrow(e, "getDepositCurrenciesListForPublicSwap");
3892
3950
  }));
@@ -3894,11 +3952,23 @@ var PublicSwapService = /*#__PURE__*/function () {
3894
3952
  return Promise.reject(e);
3895
3953
  }
3896
3954
  };
3897
- _proto.getWithdrawCurrenciesListForPublicSwap = function getWithdrawCurrenciesListForPublicSwap() {
3955
+ _proto.getDepositCurrenciesListForPublicSwap = function getDepositCurrenciesListForPublicSwap() {
3898
3956
  try {
3899
3957
  var _this3 = this;
3900
3958
  return Promise.resolve(_catch(function () {
3901
- return Promise.resolve(_this3._getCurrenciesListForPublicSwap(true));
3959
+ return Promise.resolve(_this3._getCurrenciesListForPublicSwap(false));
3960
+ }, function (e) {
3961
+ improveAndRethrow(e, "getDepositCurrenciesListForPublicSwap");
3962
+ }));
3963
+ } catch (e) {
3964
+ return Promise.reject(e);
3965
+ }
3966
+ };
3967
+ _proto.getWithdrawCurrenciesListForPublicSwap = function getWithdrawCurrenciesListForPublicSwap() {
3968
+ try {
3969
+ var _this4 = this;
3970
+ return Promise.resolve(_catch(function () {
3971
+ return Promise.resolve(_this4._getCurrenciesListForPublicSwap(true));
3902
3972
  }, function (e) {
3903
3973
  improveAndRethrow(e, "getWithdrawCurrenciesListForPublicSwap");
3904
3974
  }));
@@ -3911,11 +3981,11 @@ var PublicSwapService = /*#__PURE__*/function () {
3911
3981
  withdraw = false;
3912
3982
  }
3913
3983
  try {
3914
- var _this4 = this;
3984
+ var _this5 = this;
3915
3985
  var loggerSource = "getCurrenciesListForPublicSwap";
3916
3986
  return Promise.resolve(_catch(function () {
3917
- return Promise.resolve(withdraw ? _this4._swapProvider.getWithdrawalCurrencies() : _this4._swapProvider.getDepositCurrencies()).then(function (result) {
3918
- var _result$coins;
3987
+ return Promise.resolve(withdraw ? _this5._swapProvider.getWithdrawalCurrencies() : _this5._swapProvider.getDepositCurrencies()).then(function (result) {
3988
+ var _result$coins2;
3919
3989
  if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3920
3990
  SwapUtils.safeHandleRequestsLimitExceeding();
3921
3991
  return {
@@ -3923,12 +3993,7 @@ var PublicSwapService = /*#__PURE__*/function () {
3923
3993
  reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3924
3994
  };
3925
3995
  }
3926
- Logger.log("Retrieved " + (result == null || (_result$coins = result.coins) == null ? void 0 : _result$coins.length) + " supported currencies for swap", loggerSource);
3927
- if (result.coins.length > 1) {
3928
- var temp = result.coins[0];
3929
- result.coins[0] = result.coins[1];
3930
- result.coins[1] = temp;
3931
- }
3996
+ Logger.log("Retrieved " + (result == null || (_result$coins2 = result.coins) == null ? void 0 : _result$coins2.length) + " supported currencies for swap", loggerSource);
3932
3997
  return {
3933
3998
  result: true,
3934
3999
  coins: result.coins
@@ -3961,9 +4026,9 @@ var PublicSwapService = /*#__PURE__*/function () {
3961
4026
  ;
3962
4027
  _proto.getInitialPublicSwapData = function getInitialPublicSwapData(fromCoin, toCoin) {
3963
4028
  try {
3964
- var _this5 = this;
4029
+ var _this6 = this;
3965
4030
  return Promise.resolve(_catch(function () {
3966
- return Promise.resolve(SwapUtils.getInitialSwapData(_this5._swapProvider, fromCoin, toCoin)).then(function (result) {
4031
+ return Promise.resolve(SwapUtils.getInitialSwapData(_this6._swapProvider, fromCoin, toCoin)).then(function (result) {
3967
4032
  if (!result.result) {
3968
4033
  if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3969
4034
  SwapUtils.safeHandleRequestsLimitExceeding();
@@ -4010,13 +4075,13 @@ var PublicSwapService = /*#__PURE__*/function () {
4010
4075
  ;
4011
4076
  _proto.getPublicSwapDetails = function getPublicSwapDetails(fromCoin, toCoin, fromAmountCoins) {
4012
4077
  try {
4013
- var _this6 = this;
4078
+ var _this7 = this;
4014
4079
  var loggerSource = "getPublicSwapDetails";
4015
4080
  return Promise.resolve(_catch(function () {
4016
- return Promise.resolve(_this6._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this6$_swapProvider$) {
4017
- var _this6$_swapProvider$2;
4018
- var coinUsdtRate = (_this6$_swapProvider$2 = _this6$_swapProvider$ == null ? void 0 : _this6$_swapProvider$.rate) != null ? _this6$_swapProvider$2 : null;
4019
- return Promise.resolve(_this6._swapProvider.getSwapInfo(fromCoin, toCoin, fromAmountCoins, coinUsdtRate)).then(function (details) {
4081
+ return Promise.resolve(_this7._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this7$_swapProvider$) {
4082
+ var _this7$_swapProvider$2;
4083
+ var coinUsdtRate = (_this7$_swapProvider$2 = _this7$_swapProvider$ == null ? void 0 : _this7$_swapProvider$.rate) != null ? _this7$_swapProvider$2 : null;
4084
+ return Promise.resolve(_this7._swapProvider.getSwapInfo(fromCoin, toCoin, fromAmountCoins, coinUsdtRate)).then(function (details) {
4020
4085
  var _result$swapCreationI, _result$swapCreationI2;
4021
4086
  var min = details.result ? details.min : details.smallestMin;
4022
4087
  var max = details.result ? details.max : details.greatestMax;
@@ -4108,7 +4173,7 @@ var PublicSwapService = /*#__PURE__*/function () {
4108
4173
  ;
4109
4174
  _proto.createPublicSwap = function createPublicSwap(fromCoin, toCoin, fromAmount, swapCreationInfo, toAddress, refundAddress, clientIp) {
4110
4175
  try {
4111
- var _this7 = this;
4176
+ var _this8 = this;
4112
4177
  var loggerSource = "createPublicSwap";
4113
4178
  return Promise.resolve(_catch(function () {
4114
4179
  var _swapCreationInfo$fro, _swapCreationInfo$toC;
@@ -4119,10 +4184,10 @@ var PublicSwapService = /*#__PURE__*/function () {
4119
4184
  fromCoin: swapCreationInfo == null || (_swapCreationInfo$fro = swapCreationInfo.fromCoin) == null ? void 0 : _swapCreationInfo$fro.ticker,
4120
4185
  toCoin: swapCreationInfo == null || (_swapCreationInfo$toC = swapCreationInfo.toCoin) == null ? void 0 : _swapCreationInfo$toC.ticker
4121
4186
  })), loggerSource);
4122
- return Promise.resolve(_this7._swapProvider.createSwap(fromCoin, toCoin, fromAmount, toAddress, refundAddress, swapCreationInfo.rawSwapData, clientIp)).then(function (result) {
4187
+ return Promise.resolve(_this8._swapProvider.createSwap(fromCoin, toCoin, fromAmount, toAddress, refundAddress, swapCreationInfo.rawSwapData, clientIp)).then(function (result) {
4123
4188
  var _exit;
4124
- function _temp5(_result7) {
4125
- if (_exit) return _result7;
4189
+ function _temp5(_result8) {
4190
+ if (_exit) return _result8;
4126
4191
  throw new Error("Unexpected result from provider " + safeStringify(result));
4127
4192
  }
4128
4193
  Logger.log("Created:" + safeStringify(_extends({}, result, {
@@ -4164,7 +4229,7 @@ var PublicSwapService = /*#__PURE__*/function () {
4164
4229
  durationMinutesRange: swapCreationInfo.durationMinutesRange,
4165
4230
  address: result.fromAddress // CRITICAL: this is the address to send coins to swaps provider
4166
4231
  };
4167
- _this7._savePublicSwapIdLocally(result.swapId);
4232
+ _this8._savePublicSwapIdLocally(result.swapId);
4168
4233
  Logger.log("Returning: " + safeStringify(_extends({}, toReturn, {
4169
4234
  fromCoin: fromCoin == null ? void 0 : fromCoin.ticker,
4170
4235
  toCoin: toCoin == null ? void 0 : toCoin.ticker
@@ -4175,12 +4240,12 @@ var PublicSwapService = /*#__PURE__*/function () {
4175
4240
  var _fromAmountFiat = null,
4176
4241
  _toAmountFiat = null;
4177
4242
  var _temp2 = _catch(function () {
4178
- return Promise.resolve(_this7._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this7$_swapProvider$) {
4179
- var _this7$_swapProvider$3;
4180
- var fromCoinUsdtRate = (_this7$_swapProvider$3 = _this7$_swapProvider$ == null ? void 0 : _this7$_swapProvider$.rate) != null ? _this7$_swapProvider$3 : null;
4181
- return Promise.resolve(_this7._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this7$_swapProvider$2) {
4182
- var _this7$_swapProvider$4;
4183
- var toCoinUsdtRate = (_this7$_swapProvider$4 = _this7$_swapProvider$2 == null ? void 0 : _this7$_swapProvider$2.rate) != null ? _this7$_swapProvider$4 : null;
4243
+ return Promise.resolve(_this8._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this8$_swapProvider$) {
4244
+ var _this8$_swapProvider$3;
4245
+ var fromCoinUsdtRate = (_this8$_swapProvider$3 = _this8$_swapProvider$ == null ? void 0 : _this8$_swapProvider$.rate) != null ? _this8$_swapProvider$3 : null;
4246
+ return Promise.resolve(_this8._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this8$_swapProvider$2) {
4247
+ var _this8$_swapProvider$4;
4248
+ var toCoinUsdtRate = (_this8$_swapProvider$4 = _this8$_swapProvider$2 == null ? void 0 : _this8$_swapProvider$2.rate) != null ? _this8$_swapProvider$4 : null;
4184
4249
  if (fromCoinUsdtRate != null && result.fromAmount != null) {
4185
4250
  _fromAmountFiat = bignumber_js.BigNumber(result.fromAmount).times(fromCoinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
4186
4251
  }
@@ -4220,10 +4285,10 @@ var PublicSwapService = /*#__PURE__*/function () {
4220
4285
  ;
4221
4286
  _proto.getPublicExistingSwapDetailsAndStatus = function getPublicExistingSwapDetailsAndStatus(swapIds) {
4222
4287
  try {
4223
- var _this8 = this;
4288
+ var _this9 = this;
4224
4289
  var loggerSource = "getPublicExistingSwapDetailsAndStatus";
4225
4290
  return Promise.resolve(_catch(function () {
4226
- return Promise.resolve(SwapUtils.getExistingSwapsDetailsWithFiatAmounts(_this8._swapProvider, swapIds)).then(function (result) {
4291
+ return Promise.resolve(SwapUtils.getExistingSwapsDetailsWithFiatAmounts(_this9._swapProvider, swapIds)).then(function (result) {
4227
4292
  if (!(result != null && result.result)) {
4228
4293
  if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
4229
4294
  SwapUtils.safeHandleRequestsLimitExceeding();
@@ -4258,20 +4323,20 @@ var PublicSwapService = /*#__PURE__*/function () {
4258
4323
  _proto.getPublicSwapsHistory = function getPublicSwapsHistory() {
4259
4324
  try {
4260
4325
  var _exit2;
4261
- var _this9 = this;
4326
+ var _this10 = this;
4262
4327
  return Promise.resolve(_catch(function () {
4263
- function _temp7(_result9) {
4264
- return _exit2 ? _result9 : {
4328
+ function _temp7(_result10) {
4329
+ return _exit2 ? _result10 : {
4265
4330
  result: true,
4266
4331
  swaps: []
4267
4332
  };
4268
4333
  }
4269
- var swapIds = _this9._getPublicSwapIdsSavedLocally();
4334
+ var swapIds = _this10._getPublicSwapIdsSavedLocally();
4270
4335
  var _temp6 = function () {
4271
4336
  if (swapIds.length) {
4272
- return Promise.resolve(_this9.getPublicExistingSwapDetailsAndStatus(swapIds)).then(function (_await$_this9$getPubl) {
4337
+ return Promise.resolve(_this10.getPublicExistingSwapDetailsAndStatus(swapIds)).then(function (_await$_this10$getPub) {
4273
4338
  _exit2 = 1;
4274
- return _await$_this9$getPubl;
4339
+ return _await$_this10$getPub;
4275
4340
  });
4276
4341
  }
4277
4342
  }();
@@ -4339,9 +4404,9 @@ var PublicSwapService = /*#__PURE__*/function () {
4339
4404
  */;
4340
4405
  _proto.getAssetToUsdtRate = function getAssetToUsdtRate(asset) {
4341
4406
  try {
4342
- var _this10 = this;
4407
+ var _this11 = this;
4343
4408
  return Promise.resolve(_catch(function () {
4344
- return Promise.resolve(_this10._swapProvider.getCoinToUSDTRate(asset)).then(function (result) {
4409
+ return Promise.resolve(_this11._swapProvider.getCoinToUSDTRate(asset)).then(function (result) {
4345
4410
  var _result$rate;
4346
4411
  return (_result$rate = result == null ? void 0 : result.rate) != null ? _result$rate : null;
4347
4412
  });