@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.
@@ -2492,6 +2492,16 @@ class SwapProvider {
2492
2492
  throw new Error("Not implemented in base");
2493
2493
  }
2494
2494
 
2495
+ /**
2496
+ * Retrieves all currencies supported by this swap provider.
2497
+ * Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
2498
+ *
2499
+ * @return {Promise<({ result: true, coins: Coin[] }|{ result: false, reason: string })>}
2500
+ */
2501
+ async getAllSupportedCurrencies() {
2502
+ throw new Error("Not implemented in base");
2503
+ }
2504
+
2495
2505
  /**
2496
2506
  * Retrieves all deposit currencies supported by this swap provider.
2497
2507
  * Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
@@ -2538,6 +2548,7 @@ class SwapProvider {
2538
2548
  * null min or max signals there is no corresponding limitation. undefined means that the limits were not retrieved.
2539
2549
  * For fail result on of SwapProvider.NO_SWAPS_REASONS or SwapProvider.COMMON_ERRORS reasons will be returned.
2540
2550
  *
2551
+ * WARNING: MUST return NOT_SUPPORTED error code for any case when pair is not available/supported (Should not throw random errors for this case)
2541
2552
  * @param fromCoin {Coin}
2542
2553
  * @param toCoin {Coin}
2543
2554
  * @param amountCoins {string}
@@ -2687,12 +2698,33 @@ class SwapspaceSwapProvider extends SwapProvider {
2687
2698
  improveAndRethrow(e, loggerSource);
2688
2699
  }
2689
2700
  }
2701
+ async getAllSupportedCurrencies() {
2702
+ const loggerSource = "getAllSupportedCurrencies";
2703
+ try {
2704
+ var _this$_supportedCoins2;
2705
+ await this._fetchSupportedCurrenciesIfNeeded();
2706
+ Logger.log(`We have ${(_this$_supportedCoins2 = this._supportedCoins) == null ? void 0 : _this$_supportedCoins2.length} supported coins returning`, loggerSource);
2707
+ return {
2708
+ result: true,
2709
+ coins: this._supportedCoins.map(item => item.coin)
2710
+ };
2711
+ } catch (e) {
2712
+ var _e$response2;
2713
+ if ((e == null || (_e$response2 = e.response) == null ? void 0 : _e$response2.status) === 429) {
2714
+ return {
2715
+ result: false,
2716
+ reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
2717
+ };
2718
+ }
2719
+ improveAndRethrow(e, loggerSource);
2720
+ }
2721
+ }
2690
2722
  async getWithdrawalCurrencies(exceptCurrency = null) {
2691
2723
  const loggerSource = "getWithdrawalCurrencies";
2692
2724
  try {
2693
- var _this$_supportedCoins2;
2725
+ var _this$_supportedCoins3;
2694
2726
  await this._fetchSupportedCurrenciesIfNeeded();
2695
- Logger.log(`We have ${(_this$_supportedCoins2 = this._supportedCoins) == null ? void 0 : _this$_supportedCoins2.length} supported coins, getting withdrawable`, loggerSource);
2727
+ Logger.log(`We have ${(_this$_supportedCoins3 = this._supportedCoins) == null ? void 0 : _this$_supportedCoins3.length} supported coins, getting withdrawable`, loggerSource);
2696
2728
  return {
2697
2729
  result: true,
2698
2730
  coins: this._supportedCoins.filter(item => {
@@ -2701,8 +2733,8 @@ class SwapspaceSwapProvider extends SwapProvider {
2701
2733
  }).map(item => item.coin)
2702
2734
  };
2703
2735
  } catch (e) {
2704
- var _e$response2;
2705
- if ((e == null || (_e$response2 = e.response) == null ? void 0 : _e$response2.status) === 429) {
2736
+ var _e$response3;
2737
+ if ((e == null || (_e$response3 = e.response) == null ? void 0 : _e$response3.status) === 429) {
2706
2738
  return {
2707
2739
  result: false,
2708
2740
  reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
@@ -2717,16 +2749,16 @@ class SwapspaceSwapProvider extends SwapProvider {
2717
2749
  getIconUrl(coinOrTicker) {
2718
2750
  const loggerSource = "getIconUrl";
2719
2751
  try {
2720
- var _this$_supportedCoins4, _this$_supportedCoins5;
2752
+ var _this$_supportedCoins5, _this$_supportedCoins6;
2721
2753
  let coin = coinOrTicker;
2722
2754
  if (!(coinOrTicker instanceof Coin)) {
2723
- var _this$_supportedCoins3;
2724
- coin = (_this$_supportedCoins3 = this._supportedCoins.find(i => i.coin.ticker === coinOrTicker)) == null ? void 0 : _this$_supportedCoins3.coin;
2755
+ var _this$_supportedCoins4;
2756
+ coin = (_this$_supportedCoins4 = this._supportedCoins.find(i => i.coin.ticker === coinOrTicker)) == null ? void 0 : _this$_supportedCoins4.coin;
2725
2757
  }
2726
- return (_this$_supportedCoins4 = (_this$_supportedCoins5 = this._supportedCoins.find(item => {
2758
+ return (_this$_supportedCoins5 = (_this$_supportedCoins6 = this._supportedCoins.find(item => {
2727
2759
  var _item$coin2, _coin;
2728
2760
  return ((_item$coin2 = item.coin) == null ? void 0 : _item$coin2.ticker) === ((_coin = coin) == null ? void 0 : _coin.ticker);
2729
- })) == null ? void 0 : _this$_supportedCoins5.iconURL) != null ? _this$_supportedCoins4 : FALLBACK_ICON_URL;
2761
+ })) == null ? void 0 : _this$_supportedCoins6.iconURL) != null ? _this$_supportedCoins5 : FALLBACK_ICON_URL;
2730
2762
  } catch (e) {
2731
2763
  improveAndRethrow(e, loggerSource);
2732
2764
  }
@@ -2734,8 +2766,8 @@ class SwapspaceSwapProvider extends SwapProvider {
2734
2766
  async _fetchSupportedCurrenciesIfNeeded() {
2735
2767
  const loggerSource = "_fetchSupportedCurrenciesIfNeeded";
2736
2768
  try {
2737
- var _this$_supportedCoins6;
2738
- if (!((_this$_supportedCoins6 = this._supportedCoins) != null && _this$_supportedCoins6.length)) {
2769
+ var _this$_supportedCoins7;
2770
+ if (!((_this$_supportedCoins7 = this._supportedCoins) != null && _this$_supportedCoins7.length)) {
2739
2771
  var _rawResponse$data, _rawResponse$data2;
2740
2772
  const rawResponse = await axios.get(`${this._URL}/api/v2/currencies`);
2741
2773
  Logger.log(`Retrieved ${rawResponse == null || (_rawResponse$data = rawResponse.data) == null ? void 0 : _rawResponse$data.length} currencies`, loggerSource);
@@ -2799,12 +2831,12 @@ class SwapspaceSwapProvider extends SwapProvider {
2799
2831
  async getCoinToUSDTRate(coin) {
2800
2832
  const loggerSource = "getCoinToUSDTRate";
2801
2833
  try {
2802
- var _this$_supportedCoins7;
2834
+ var _this$_supportedCoins8;
2803
2835
  if (!coin) return null;
2804
2836
  await this._fetchSupportedCurrenciesIfNeeded();
2805
2837
 
2806
2838
  // Using USDT TRC20 as usually fee in this network is smaller than ERC20 and this network is widely used for USDT
2807
- const usdtTrc20 = (_this$_supportedCoins7 = this._supportedCoins.find(i => i.coin.ticker === "USDTTRC20")) == null ? void 0 : _this$_supportedCoins7.coin;
2839
+ const usdtTrc20 = (_this$_supportedCoins8 = this._supportedCoins.find(i => i.coin.ticker === "USDTTRC20")) == null ? void 0 : _this$_supportedCoins8.coin;
2808
2840
  if (!usdtTrc20) {
2809
2841
  return {
2810
2842
  result: false
@@ -2955,8 +2987,8 @@ class SwapspaceSwapProvider extends SwapProvider {
2955
2987
  Logger.log(`Returning result ${safeStringify(result)}`, loggerSource);
2956
2988
  return result;
2957
2989
  } catch (e) {
2958
- var _e$response3;
2959
- if ((e == null || (_e$response3 = e.response) == null ? void 0 : _e$response3.status) === 429) {
2990
+ var _e$response4;
2991
+ if ((e == null || (_e$response4 = e.response) == null ? void 0 : _e$response4.status) === 429) {
2960
2992
  return {
2961
2993
  result: false,
2962
2994
  reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
@@ -2970,7 +3002,7 @@ class SwapspaceSwapProvider extends SwapProvider {
2970
3002
  const loggerSource = "createSwap";
2971
3003
  const partner = rawSwapData == null ? void 0 : rawSwapData.partner;
2972
3004
  try {
2973
- var _this$_supportedCoins8, _this$_supportedCoins9;
3005
+ var _this$_supportedCoins9, _this$_supportedCoins10;
2974
3006
  if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amount !== "string" || typeof toAddress !== "string" || typeof refundAddress !== "string") {
2975
3007
  throw new Error(`Invalid input: ${fromCoin} ${toCoin} ${amount} ${toAddress} ${refundAddress}`);
2976
3008
  }
@@ -2979,10 +3011,10 @@ class SwapspaceSwapProvider extends SwapProvider {
2979
3011
  throw new Error(`Invalid raw swap data: ${safeStringify(rawSwapData)}`);
2980
3012
  }
2981
3013
  await this._fetchSupportedCurrenciesIfNeeded();
2982
- const toCurrencyExtraId = (_this$_supportedCoins8 = (_this$_supportedCoins9 = this._supportedCoins.find(item => {
3014
+ const toCurrencyExtraId = (_this$_supportedCoins9 = (_this$_supportedCoins10 = this._supportedCoins.find(item => {
2983
3015
  var _item$coin4;
2984
3016
  return ((_item$coin4 = item.coin) == null ? void 0 : _item$coin4.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
2985
- })) == null ? void 0 : _this$_supportedCoins9.extraId) != null ? _this$_supportedCoins8 : "";
3017
+ })) == null ? void 0 : _this$_supportedCoins10.extraId) != null ? _this$_supportedCoins9 : "";
2986
3018
  const requestData = {
2987
3019
  partner: partner,
2988
3020
  fromCurrency: rawSwapData == null ? void 0 : rawSwapData.fromCurrency,
@@ -3029,15 +3061,15 @@ class SwapspaceSwapProvider extends SwapProvider {
3029
3061
  Logger.log(errorMessage, loggerSource);
3030
3062
  throw new Error(errorMessage);
3031
3063
  } catch (e) {
3032
- var _e$response4, _e$response5;
3064
+ var _e$response5, _e$response6;
3033
3065
  Logger.logError(e, loggerSource, `Failed to create swap. Error is: ${safeStringify(e)}`);
3034
3066
  const composeFailResult = reason => ({
3035
3067
  result: false,
3036
3068
  reason: reason,
3037
3069
  partner: partner
3038
3070
  });
3039
- const status = e == null || (_e$response4 = e.response) == null ? void 0 : _e$response4.status;
3040
- const data = e == null || (_e$response5 = e.response) == null ? void 0 : _e$response5.data;
3071
+ const status = e == null || (_e$response5 = e.response) == null ? void 0 : _e$response5.status;
3072
+ const data = e == null || (_e$response6 = e.response) == null ? void 0 : _e$response6.data;
3041
3073
  if (status === 429) {
3042
3074
  Logger.log(`Returning fail - RPS limit exceeded ${data}`, loggerSource);
3043
3075
  return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
@@ -3098,9 +3130,9 @@ class SwapspaceSwapProvider extends SwapProvider {
3098
3130
  const responses = await Promise.all(swapIds.map(swapId => getNotFailingOn404(swapId)));
3099
3131
  const wo404 = responses.flat();
3100
3132
  const swaps = wo404.map(r => r.data).map((swap, index) => {
3101
- var _this$_supportedCoins10, _this$_supportedCoins11;
3102
- const fromCoin = (_this$_supportedCoins10 = this._supportedCoins.find(i => i.code === swap.from.code && i.network === swap.from.network)) == null ? void 0 : _this$_supportedCoins10.coin;
3103
- const toCoin = (_this$_supportedCoins11 = this._supportedCoins.find(i => i.code === swap.to.code && i.network === swap.to.network)) == null ? void 0 : _this$_supportedCoins11.coin;
3133
+ var _this$_supportedCoins11, _this$_supportedCoins12;
3134
+ const fromCoin = (_this$_supportedCoins11 = this._supportedCoins.find(i => i.code === swap.from.code && i.network === swap.from.network)) == null ? void 0 : _this$_supportedCoins11.coin;
3135
+ const toCoin = (_this$_supportedCoins12 = this._supportedCoins.find(i => i.code === swap.to.code && i.network === swap.to.network)) == null ? void 0 : _this$_supportedCoins12.coin;
3104
3136
  if (!fromCoin || !toCoin) {
3105
3137
  return []; // We skip swaps with not supported coins for now
3106
3138
  }
@@ -3118,14 +3150,14 @@ class SwapspaceSwapProvider extends SwapProvider {
3118
3150
  swaps: swaps
3119
3151
  };
3120
3152
  } catch (e) {
3121
- var _e$response6, _e$response7;
3153
+ var _e$response7, _e$response8;
3122
3154
  Logger.logError(e, loggerSource, `Failed to get swap details. Error is: ${safeStringify(e)}`);
3123
3155
  const composeFailResult = reason => ({
3124
3156
  result: false,
3125
3157
  reason: reason
3126
3158
  });
3127
- const status = e == null || (_e$response6 = e.response) == null ? void 0 : _e$response6.status;
3128
- const data = e == null || (_e$response7 = e.response) == null ? void 0 : _e$response7.data;
3159
+ const status = e == null || (_e$response7 = e.response) == null ? void 0 : _e$response7.status;
3160
+ const data = e == null || (_e$response8 = e.response) == null ? void 0 : _e$response8.data;
3129
3161
  if (status === 429) {
3130
3162
  Logger.log(`Returning fail - RPS limit exceeded ${data}`, loggerSource);
3131
3163
  return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
@@ -3282,6 +3314,27 @@ class PublicSwapService {
3282
3314
  Logger.logError(e, "PublicSwapService.initialize");
3283
3315
  }
3284
3316
  }
3317
+ async getAllSupportedCurrenciesListForPublicSwap() {
3318
+ const loggerSource = "getAllSupportedCurrenciesListForPublicSwap";
3319
+ try {
3320
+ var _result$coins;
3321
+ const result = await this._swapProvider.getAllSupportedCurrencies();
3322
+ if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3323
+ SwapUtils.safeHandleRequestsLimitExceeding();
3324
+ return {
3325
+ result: false,
3326
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3327
+ };
3328
+ }
3329
+ Logger.log(`Retrieved ${result == null || (_result$coins = result.coins) == null ? void 0 : _result$coins.length} supported currencies for swap`, loggerSource);
3330
+ return {
3331
+ result: true,
3332
+ coins: result.coins
3333
+ };
3334
+ } catch (e) {
3335
+ improveAndRethrow(e, "getDepositCurrenciesListForPublicSwap");
3336
+ }
3337
+ }
3285
3338
  async getDepositCurrenciesListForPublicSwap() {
3286
3339
  try {
3287
3340
  return await this._getCurrenciesListForPublicSwap(false);
@@ -3299,7 +3352,7 @@ class PublicSwapService {
3299
3352
  async _getCurrenciesListForPublicSwap(withdraw = false) {
3300
3353
  const loggerSource = "getCurrenciesListForPublicSwap";
3301
3354
  try {
3302
- var _result$coins;
3355
+ var _result$coins2;
3303
3356
  const result = withdraw ? await this._swapProvider.getWithdrawalCurrencies() : await this._swapProvider.getDepositCurrencies();
3304
3357
  if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3305
3358
  SwapUtils.safeHandleRequestsLimitExceeding();
@@ -3308,12 +3361,7 @@ class PublicSwapService {
3308
3361
  reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3309
3362
  };
3310
3363
  }
3311
- Logger.log(`Retrieved ${result == null || (_result$coins = result.coins) == null ? void 0 : _result$coins.length} supported currencies for swap`, loggerSource);
3312
- if (result.coins.length > 1) {
3313
- let temp = result.coins[0];
3314
- result.coins[0] = result.coins[1];
3315
- result.coins[1] = temp;
3316
- }
3364
+ Logger.log(`Retrieved ${result == null || (_result$coins2 = result.coins) == null ? void 0 : _result$coins2.length} supported currencies for swap`, loggerSource);
3317
3365
  return {
3318
3366
  result: true,
3319
3367
  coins: result.coins