@rabbitio/ui-kit 1.0.0-beta.23 → 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,17 +3229,17 @@ 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
  });
@@ -3205,7 +3249,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3205
3249
  return !fromCoinSwapspaceDetails.deposit || !toCoinSwapspaceDetails.withdrawal ? {
3206
3250
  result: false,
3207
3251
  reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
3208
- } : 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) {
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) {
3209
3253
  var _response$data;
3210
3254
  Logger.log("Retrieved " + (response == null || (_response$data = response.data) == null ? void 0 : _response$data.length) + " options", loggerSource);
3211
3255
  var options = Array.isArray(response.data) ? response.data : [];
@@ -3284,7 +3328,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3284
3328
  max: max,
3285
3329
  smallestMin: smallestMin,
3286
3330
  greatestMax: greatestMax,
3287
- rate: rate != null ? AmountUtils.trim(rate, _this7._maxRateDigits) : null,
3331
+ rate: rate != null ? AmountUtils.trim(rate, _this8._maxRateDigits) : null,
3288
3332
  durationMinutesRange: (_bestOpt$duration = bestOpt.duration) != null ? _bestOpt$duration : null,
3289
3333
  rawSwapData: bestOpt
3290
3334
  };
@@ -3299,8 +3343,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3299
3343
  return result;
3300
3344
  });
3301
3345
  }, function (e) {
3302
- var _e$response3;
3303
- 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) {
3304
3348
  return {
3305
3349
  result: false,
3306
3350
  reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
@@ -3315,7 +3359,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3315
3359
  };
3316
3360
  _proto.createSwap = function createSwap(fromCoin, toCoin, amount, toAddress, refundAddress, rawSwapData, clientIpAddress) {
3317
3361
  try {
3318
- var _this8 = this;
3362
+ var _this9 = this;
3319
3363
  var loggerSource = "createSwap";
3320
3364
  var partner = rawSwapData == null ? void 0 : rawSwapData.partner;
3321
3365
  return Promise.resolve(_catch$2(function () {
@@ -3326,12 +3370,12 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3326
3370
  ) {
3327
3371
  throw new Error("Invalid raw swap data: " + safeStringify(rawSwapData));
3328
3372
  }
3329
- return Promise.resolve(_this8._fetchSupportedCurrenciesIfNeeded()).then(function () {
3330
- var _this8$_supportedCoin, _this8$_supportedCoin2;
3331
- 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) {
3332
3376
  var _item$coin4;
3333
3377
  return ((_item$coin4 = item.coin) == null ? void 0 : _item$coin4.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
3334
- })) == null ? void 0 : _this8$_supportedCoin2.extraId) != null ? _this8$_supportedCoin : "";
3378
+ })) == null ? void 0 : _this9$_supportedCoin2.extraId) != null ? _this9$_supportedCoin : "";
3335
3379
  var requestData = {
3336
3380
  partner: partner,
3337
3381
  fromCurrency: rawSwapData == null ? void 0 : rawSwapData.fromCurrency,
@@ -3347,7 +3391,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3347
3391
  refund: refundAddress
3348
3392
  };
3349
3393
  Logger.log("Sending create request: " + safeStringify(requestData), loggerSource);
3350
- 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) {
3351
3395
  var result = response.data;
3352
3396
  Logger.log("Creation result " + safeStringify(result), loggerSource);
3353
3397
  if (result != null && result.id) {
@@ -3371,7 +3415,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3371
3415
  toCoin: toCoin,
3372
3416
  toAmount: AmountUtils.trim(result == null || (_result$to4 = result.to) == null ? void 0 : _result$to4.amount, toCoin.digits),
3373
3417
  toAddress: result == null || (_result$to5 = result.to) == null ? void 0 : _result$to5.address,
3374
- rate: AmountUtils.trim(rate, _this8._maxRateDigits)
3418
+ rate: AmountUtils.trim(rate, _this9._maxRateDigits)
3375
3419
  };
3376
3420
  }
3377
3421
  var errorMessage = "Swap creation succeeded but the response is wrong: " + safeStringify(response);
@@ -3380,7 +3424,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3380
3424
  });
3381
3425
  });
3382
3426
  }, function (e) {
3383
- var _e$response4, _e$response5;
3427
+ var _e$response5, _e$response6;
3384
3428
  Logger.logError(e, loggerSource, "Failed to create swap. Error is: " + safeStringify(e));
3385
3429
  var composeFailResult = function composeFailResult(reason) {
3386
3430
  return {
@@ -3389,8 +3433,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3389
3433
  partner: partner
3390
3434
  };
3391
3435
  };
3392
- var status = e == null || (_e$response4 = e.response) == null ? void 0 : _e$response4.status;
3393
- 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;
3394
3438
  if (status === 429) {
3395
3439
  Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
3396
3440
  return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
@@ -3439,7 +3483,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3439
3483
  };
3440
3484
  _proto.getExistingSwapsDetailsAndStatus = function getExistingSwapsDetailsAndStatus(swapIds) {
3441
3485
  try {
3442
- var _this9 = this;
3486
+ var _this10 = this;
3443
3487
  var loggerSource = "getExistingSwapsDetailsAndStatus";
3444
3488
  return Promise.resolve(_catch$2(function () {
3445
3489
  if (swapIds.find(function (id) {
@@ -3450,7 +3494,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3450
3494
  var getNotFailingOn404 = function getNotFailingOn404(swapId) {
3451
3495
  try {
3452
3496
  return Promise.resolve(_catch$2(function () {
3453
- 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));
3454
3498
  }, function (error) {
3455
3499
  var _error$response;
3456
3500
  if ((error == null || (_error$response = error.response) == null ? void 0 : _error$response.status) === 404) return [];
@@ -3467,13 +3511,13 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3467
3511
  var swaps = wo404.map(function (r) {
3468
3512
  return r.data;
3469
3513
  }).map(function (swap, index) {
3470
- var _this9$_supportedCoin, _this9$_supportedCoin2;
3471
- 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) {
3472
3516
  return i.code === swap.from.code && i.network === swap.from.network;
3473
- })) == null ? void 0 : _this9$_supportedCoin.coin;
3474
- 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) {
3475
3519
  return i.code === swap.to.code && i.network === swap.to.network;
3476
- })) == null ? void 0 : _this9$_supportedCoin2.coin;
3520
+ })) == null ? void 0 : _this10$_supportedCoi2.coin;
3477
3521
  if (!fromCoin || !toCoin) {
3478
3522
  return []; // We skip swaps with not supported coins for now
3479
3523
  }
@@ -3482,10 +3526,10 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3482
3526
  };
3483
3527
  var expiresAt = toUtcTimestamp(swap.timestamps.expiresAt);
3484
3528
  var isExpiredByTime = expiresAt < Date.now();
3485
- var status = _this9._mapSwapspaceStatusToRabbitStatus(swap.status, isExpiredByTime);
3529
+ var status = _this10._mapSwapspaceStatusToRabbitStatus(swap.status, isExpiredByTime);
3486
3530
  var toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
3487
3531
  var addressToSendCoinsToSwapspace = swap.from.address;
3488
- 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);
3489
3533
  }).flat();
3490
3534
  Logger.log("Swap details result " + safeStringify(swaps), loggerSource);
3491
3535
  return {
@@ -3494,7 +3538,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3494
3538
  };
3495
3539
  });
3496
3540
  }, function (e) {
3497
- var _e$response6, _e$response7;
3541
+ var _e$response7, _e$response8;
3498
3542
  Logger.logError(e, loggerSource, "Failed to get swap details. Error is: " + safeStringify(e));
3499
3543
  var composeFailResult = function composeFailResult(reason) {
3500
3544
  return {
@@ -3502,8 +3546,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3502
3546
  reason: reason
3503
3547
  };
3504
3548
  };
3505
- var status = e == null || (_e$response6 = e.response) == null ? void 0 : _e$response6.status;
3506
- 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;
3507
3551
  if (status === 429) {
3508
3552
  Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
3509
3553
  return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
@@ -3881,11 +3925,26 @@ var PublicSwapService = /*#__PURE__*/function () {
3881
3925
  return Promise.reject(e);
3882
3926
  }
3883
3927
  };
3884
- _proto.getDepositCurrenciesListForPublicSwap = function getDepositCurrenciesListForPublicSwap() {
3928
+ _proto.getAllSupportedCurrenciesListForPublicSwap = function getAllSupportedCurrenciesListForPublicSwap() {
3885
3929
  try {
3886
3930
  var _this2 = this;
3931
+ var loggerSource = "getAllSupportedCurrenciesListForPublicSwap";
3887
3932
  return Promise.resolve(_catch(function () {
3888
- 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
+ });
3889
3948
  }, function (e) {
3890
3949
  improveAndRethrow(e, "getDepositCurrenciesListForPublicSwap");
3891
3950
  }));
@@ -3893,11 +3952,23 @@ var PublicSwapService = /*#__PURE__*/function () {
3893
3952
  return Promise.reject(e);
3894
3953
  }
3895
3954
  };
3896
- _proto.getWithdrawCurrenciesListForPublicSwap = function getWithdrawCurrenciesListForPublicSwap() {
3955
+ _proto.getDepositCurrenciesListForPublicSwap = function getDepositCurrenciesListForPublicSwap() {
3897
3956
  try {
3898
3957
  var _this3 = this;
3899
3958
  return Promise.resolve(_catch(function () {
3900
- 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));
3901
3972
  }, function (e) {
3902
3973
  improveAndRethrow(e, "getWithdrawCurrenciesListForPublicSwap");
3903
3974
  }));
@@ -3910,11 +3981,11 @@ var PublicSwapService = /*#__PURE__*/function () {
3910
3981
  withdraw = false;
3911
3982
  }
3912
3983
  try {
3913
- var _this4 = this;
3984
+ var _this5 = this;
3914
3985
  var loggerSource = "getCurrenciesListForPublicSwap";
3915
3986
  return Promise.resolve(_catch(function () {
3916
- return Promise.resolve(withdraw ? _this4._swapProvider.getWithdrawalCurrencies() : _this4._swapProvider.getDepositCurrencies()).then(function (result) {
3917
- var _result$coins;
3987
+ return Promise.resolve(withdraw ? _this5._swapProvider.getWithdrawalCurrencies() : _this5._swapProvider.getDepositCurrencies()).then(function (result) {
3988
+ var _result$coins2;
3918
3989
  if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3919
3990
  SwapUtils.safeHandleRequestsLimitExceeding();
3920
3991
  return {
@@ -3922,12 +3993,7 @@ var PublicSwapService = /*#__PURE__*/function () {
3922
3993
  reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3923
3994
  };
3924
3995
  }
3925
- Logger.log("Retrieved " + (result == null || (_result$coins = result.coins) == null ? void 0 : _result$coins.length) + " supported currencies for swap", loggerSource);
3926
- if (result.coins.length > 1) {
3927
- var temp = result.coins[0];
3928
- result.coins[0] = result.coins[1];
3929
- result.coins[1] = temp;
3930
- }
3996
+ Logger.log("Retrieved " + (result == null || (_result$coins2 = result.coins) == null ? void 0 : _result$coins2.length) + " supported currencies for swap", loggerSource);
3931
3997
  return {
3932
3998
  result: true,
3933
3999
  coins: result.coins
@@ -3960,9 +4026,9 @@ var PublicSwapService = /*#__PURE__*/function () {
3960
4026
  ;
3961
4027
  _proto.getInitialPublicSwapData = function getInitialPublicSwapData(fromCoin, toCoin) {
3962
4028
  try {
3963
- var _this5 = this;
4029
+ var _this6 = this;
3964
4030
  return Promise.resolve(_catch(function () {
3965
- 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) {
3966
4032
  if (!result.result) {
3967
4033
  if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3968
4034
  SwapUtils.safeHandleRequestsLimitExceeding();
@@ -4009,13 +4075,13 @@ var PublicSwapService = /*#__PURE__*/function () {
4009
4075
  ;
4010
4076
  _proto.getPublicSwapDetails = function getPublicSwapDetails(fromCoin, toCoin, fromAmountCoins) {
4011
4077
  try {
4012
- var _this6 = this;
4078
+ var _this7 = this;
4013
4079
  var loggerSource = "getPublicSwapDetails";
4014
4080
  return Promise.resolve(_catch(function () {
4015
- return Promise.resolve(_this6._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this6$_swapProvider$) {
4016
- var _this6$_swapProvider$2;
4017
- var coinUsdtRate = (_this6$_swapProvider$2 = _this6$_swapProvider$ == null ? void 0 : _this6$_swapProvider$.rate) != null ? _this6$_swapProvider$2 : null;
4018
- 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) {
4019
4085
  var _result$swapCreationI, _result$swapCreationI2;
4020
4086
  var min = details.result ? details.min : details.smallestMin;
4021
4087
  var max = details.result ? details.max : details.greatestMax;
@@ -4107,7 +4173,7 @@ var PublicSwapService = /*#__PURE__*/function () {
4107
4173
  ;
4108
4174
  _proto.createPublicSwap = function createPublicSwap(fromCoin, toCoin, fromAmount, swapCreationInfo, toAddress, refundAddress, clientIp) {
4109
4175
  try {
4110
- var _this7 = this;
4176
+ var _this8 = this;
4111
4177
  var loggerSource = "createPublicSwap";
4112
4178
  return Promise.resolve(_catch(function () {
4113
4179
  var _swapCreationInfo$fro, _swapCreationInfo$toC;
@@ -4118,10 +4184,10 @@ var PublicSwapService = /*#__PURE__*/function () {
4118
4184
  fromCoin: swapCreationInfo == null || (_swapCreationInfo$fro = swapCreationInfo.fromCoin) == null ? void 0 : _swapCreationInfo$fro.ticker,
4119
4185
  toCoin: swapCreationInfo == null || (_swapCreationInfo$toC = swapCreationInfo.toCoin) == null ? void 0 : _swapCreationInfo$toC.ticker
4120
4186
  })), loggerSource);
4121
- 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) {
4122
4188
  var _exit;
4123
- function _temp5(_result7) {
4124
- if (_exit) return _result7;
4189
+ function _temp5(_result8) {
4190
+ if (_exit) return _result8;
4125
4191
  throw new Error("Unexpected result from provider " + safeStringify(result));
4126
4192
  }
4127
4193
  Logger.log("Created:" + safeStringify(_extends({}, result, {
@@ -4163,7 +4229,7 @@ var PublicSwapService = /*#__PURE__*/function () {
4163
4229
  durationMinutesRange: swapCreationInfo.durationMinutesRange,
4164
4230
  address: result.fromAddress // CRITICAL: this is the address to send coins to swaps provider
4165
4231
  };
4166
- _this7._savePublicSwapIdLocally(result.swapId);
4232
+ _this8._savePublicSwapIdLocally(result.swapId);
4167
4233
  Logger.log("Returning: " + safeStringify(_extends({}, toReturn, {
4168
4234
  fromCoin: fromCoin == null ? void 0 : fromCoin.ticker,
4169
4235
  toCoin: toCoin == null ? void 0 : toCoin.ticker
@@ -4174,12 +4240,12 @@ var PublicSwapService = /*#__PURE__*/function () {
4174
4240
  var _fromAmountFiat = null,
4175
4241
  _toAmountFiat = null;
4176
4242
  var _temp2 = _catch(function () {
4177
- return Promise.resolve(_this7._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this7$_swapProvider$) {
4178
- var _this7$_swapProvider$3;
4179
- var fromCoinUsdtRate = (_this7$_swapProvider$3 = _this7$_swapProvider$ == null ? void 0 : _this7$_swapProvider$.rate) != null ? _this7$_swapProvider$3 : null;
4180
- return Promise.resolve(_this7._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this7$_swapProvider$2) {
4181
- var _this7$_swapProvider$4;
4182
- 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;
4183
4249
  if (fromCoinUsdtRate != null && result.fromAmount != null) {
4184
4250
  _fromAmountFiat = bignumber_js.BigNumber(result.fromAmount).times(fromCoinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
4185
4251
  }
@@ -4219,10 +4285,10 @@ var PublicSwapService = /*#__PURE__*/function () {
4219
4285
  ;
4220
4286
  _proto.getPublicExistingSwapDetailsAndStatus = function getPublicExistingSwapDetailsAndStatus(swapIds) {
4221
4287
  try {
4222
- var _this8 = this;
4288
+ var _this9 = this;
4223
4289
  var loggerSource = "getPublicExistingSwapDetailsAndStatus";
4224
4290
  return Promise.resolve(_catch(function () {
4225
- return Promise.resolve(SwapUtils.getExistingSwapsDetailsWithFiatAmounts(_this8._swapProvider, swapIds)).then(function (result) {
4291
+ return Promise.resolve(SwapUtils.getExistingSwapsDetailsWithFiatAmounts(_this9._swapProvider, swapIds)).then(function (result) {
4226
4292
  if (!(result != null && result.result)) {
4227
4293
  if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
4228
4294
  SwapUtils.safeHandleRequestsLimitExceeding();
@@ -4257,20 +4323,20 @@ var PublicSwapService = /*#__PURE__*/function () {
4257
4323
  _proto.getPublicSwapsHistory = function getPublicSwapsHistory() {
4258
4324
  try {
4259
4325
  var _exit2;
4260
- var _this9 = this;
4326
+ var _this10 = this;
4261
4327
  return Promise.resolve(_catch(function () {
4262
- function _temp7(_result9) {
4263
- return _exit2 ? _result9 : {
4328
+ function _temp7(_result10) {
4329
+ return _exit2 ? _result10 : {
4264
4330
  result: true,
4265
4331
  swaps: []
4266
4332
  };
4267
4333
  }
4268
- var swapIds = _this9._getPublicSwapIdsSavedLocally();
4334
+ var swapIds = _this10._getPublicSwapIdsSavedLocally();
4269
4335
  var _temp6 = function () {
4270
4336
  if (swapIds.length) {
4271
- return Promise.resolve(_this9.getPublicExistingSwapDetailsAndStatus(swapIds)).then(function (_await$_this9$getPubl) {
4337
+ return Promise.resolve(_this10.getPublicExistingSwapDetailsAndStatus(swapIds)).then(function (_await$_this10$getPub) {
4272
4338
  _exit2 = 1;
4273
- return _await$_this9$getPubl;
4339
+ return _await$_this10$getPub;
4274
4340
  });
4275
4341
  }
4276
4342
  }();
@@ -4338,9 +4404,9 @@ var PublicSwapService = /*#__PURE__*/function () {
4338
4404
  */;
4339
4405
  _proto.getAssetToUsdtRate = function getAssetToUsdtRate(asset) {
4340
4406
  try {
4341
- var _this10 = this;
4407
+ var _this11 = this;
4342
4408
  return Promise.resolve(_catch(function () {
4343
- return Promise.resolve(_this10._swapProvider.getCoinToUSDTRate(asset)).then(function (result) {
4409
+ return Promise.resolve(_this11._swapProvider.getCoinToUSDTRate(asset)).then(function (result) {
4344
4410
  var _result$rate;
4345
4411
  return (_result$rate = result == null ? void 0 : result.rate) != null ? _result$rate : null;
4346
4412
  });