@rabbitio/ui-kit 1.0.0-beta.19 → 1.0.0-beta.20

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.
@@ -2695,7 +2695,10 @@ class SwapspaceSwapProvider extends SwapProvider {
2695
2695
  Logger.log(`We have ${(_this$_supportedCoins2 = this._supportedCoins) == null ? void 0 : _this$_supportedCoins2.length} supported coins, getting withdrawable`, loggerSource);
2696
2696
  return {
2697
2697
  result: true,
2698
- coins: this._supportedCoins.filter(item => item.withdrawal && (!exceptCurrency || item.coin !== exceptCurrency)).map(item => item.coin)
2698
+ coins: this._supportedCoins.filter(item => {
2699
+ var _item$coin;
2700
+ return item.withdrawal && (!exceptCurrency || ((_item$coin = item.coin) == null ? void 0 : _item$coin.ticker) !== (exceptCurrency == null ? void 0 : exceptCurrency.ticker));
2701
+ }).map(item => item.coin)
2699
2702
  };
2700
2703
  } catch (e) {
2701
2704
  var _e$response2;
@@ -2751,7 +2754,7 @@ class SwapspaceSwapProvider extends SwapProvider {
2751
2754
  const defaultMinConfirmationsForCoinNotSupportedOOB = 1;
2752
2755
  coin = new Coin(item.name, ticker, code, defaultDecimalPlacesForCoinNotSupportedOOB, null, "", null, null, defaultMinConfirmationsForCoinNotSupportedOOB, null, [], 60000, null,
2753
2756
  // We cannot recognize blockchain from swapspace data
2754
- new Protocol(network),
2757
+ code !== network ? new Protocol(network) : null,
2755
2758
  // TODO: [dev] maybe we should recognize standard protocols?
2756
2759
  item.contractAddress || null, false);
2757
2760
  }
@@ -2794,10 +2797,11 @@ class SwapspaceSwapProvider extends SwapProvider {
2794
2797
  const loggerSource = "getCoinToUSDTRate";
2795
2798
  try {
2796
2799
  var _this$_supportedCoins7;
2800
+ if (!coin) return null;
2797
2801
  await this._fetchSupportedCurrenciesIfNeeded();
2798
2802
 
2799
2803
  // Using USDT TRC20 as usually fee in this network is smaller than ERC20 and this network is widely used for USDT
2800
- const usdtTrc20 = (_this$_supportedCoins7 = this._supportedCoins.find(i => i.code === "usdt" && i.network === "trc20")) == null ? void 0 : _this$_supportedCoins7.coin;
2804
+ const usdtTrc20 = (_this$_supportedCoins7 = this._supportedCoins.find(i => i.coin.ticker === "USDTTRC20")) == null ? void 0 : _this$_supportedCoins7.coin;
2801
2805
  if (!usdtTrc20) {
2802
2806
  return {
2803
2807
  result: false
@@ -2810,7 +2814,7 @@ class SwapspaceSwapProvider extends SwapProvider {
2810
2814
  rate: cached
2811
2815
  };
2812
2816
  }
2813
- Logger.log("Loading USDT -> coin rate as not found in cache:", coin == null ? void 0 : coin.ticker);
2817
+ Logger.log("Loading USDT->coin rate as not found in cache:", coin == null ? void 0 : coin.ticker);
2814
2818
  const result = await this.getSwapInfo(usdtTrc20, coin, "5000");
2815
2819
  if (!result.result) {
2816
2820
  return {
@@ -2821,7 +2825,8 @@ class SwapspaceSwapProvider extends SwapProvider {
2821
2825
  // This calculation is not precise as we cannot recognize the actual fee and network fee. Just approximate.
2822
2826
  const standardSwapspaceFeeMultiplier = 1.002; // usually 0.2%
2823
2827
  const rate = BigNumber(1).div(BigNumber(result.rate).times(standardSwapspaceFeeMultiplier)).toString();
2824
- this._cache.put("swapspace_usdt_rate_" + coin.ticker, rate, 15 * 60000);
2828
+ this._cache.put("swapspace_usdt_rate_" + coin.ticker, rate, 15 * 60000 // 15 minutes
2829
+ );
2825
2830
  return {
2826
2831
  result: true,
2827
2832
  rate: rate
@@ -2832,9 +2837,9 @@ class SwapspaceSwapProvider extends SwapProvider {
2832
2837
  }
2833
2838
  getCoinByTickerIfPresent(ticker) {
2834
2839
  try {
2835
- var _item$coin;
2840
+ var _item$coin2;
2836
2841
  const item = this._supportedCoins.find(i => i.coin.ticker === ticker);
2837
- return (_item$coin = item == null ? void 0 : item.coin) != null ? _item$coin : null;
2842
+ return (_item$coin2 = item == null ? void 0 : item.coin) != null ? _item$coin2 : null;
2838
2843
  } catch (e) {
2839
2844
  improveAndRethrow(e, "getCoinByTickerIfPresent");
2840
2845
  }
@@ -2846,8 +2851,14 @@ class SwapspaceSwapProvider extends SwapProvider {
2846
2851
  if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amountCoins !== "string" || BigNumber(amountCoins).lt("0")) {
2847
2852
  throw new Error(`Wrong input params: ${amountCoins} ${fromCoin.ticker} -> ${toCoin.ticker}` + (fromCoin instanceof Coin) + (toCoin instanceof Coin));
2848
2853
  }
2849
- const fromCoinSwapspaceDetails = this._supportedCoins.find(i => i.coin === fromCoin);
2850
- const toCoinSwapspaceDetails = this._supportedCoins.find(i => i.coin === toCoin);
2854
+ const fromCoinSwapspaceDetails = this._supportedCoins.find(i => {
2855
+ var _i$coin;
2856
+ return ((_i$coin = i.coin) == null ? void 0 : _i$coin.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
2857
+ });
2858
+ const toCoinSwapspaceDetails = this._supportedCoins.find(i => {
2859
+ var _i$coin2;
2860
+ return ((_i$coin2 = i.coin) == null ? void 0 : _i$coin2.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
2861
+ });
2851
2862
  if (!fromCoinSwapspaceDetails || !toCoinSwapspaceDetails) {
2852
2863
  throw new Error("Failed to find swapspace coin details for: " + fromCoin.ticker + " -> " + toCoin.ticker);
2853
2864
  }
@@ -2959,7 +2970,10 @@ class SwapspaceSwapProvider extends SwapProvider {
2959
2970
  throw new Error(`Invalid raw swap data: ${safeStringify(rawSwapData)}`);
2960
2971
  }
2961
2972
  await this._fetchSupportedCurrenciesIfNeeded();
2962
- const toCurrencyExtraId = (_this$_supportedCoins8 = (_this$_supportedCoins9 = this._supportedCoins.find(item => item.coin === toCoin)) == null ? void 0 : _this$_supportedCoins9.extraId) != null ? _this$_supportedCoins8 : "";
2973
+ const toCurrencyExtraId = (_this$_supportedCoins8 = (_this$_supportedCoins9 = this._supportedCoins.find(item => {
2974
+ var _item$coin3;
2975
+ return ((_item$coin3 = item.coin) == null ? void 0 : _item$coin3.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
2976
+ })) == null ? void 0 : _this$_supportedCoins9.extraId) != null ? _this$_supportedCoins8 : "";
2963
2977
  const requestData = {
2964
2978
  partner: partner,
2965
2979
  fromCurrency: rawSwapData == null ? void 0 : rawSwapData.fromCurrency,
@@ -3029,9 +3043,12 @@ class SwapspaceSwapProvider extends SwapProvider {
3029
3043
  improveAndRethrow(e, loggerSource);
3030
3044
  }
3031
3045
  }
3032
- _mapSwapspaceStatusToRabbitStatus(status) {
3046
+ _mapSwapspaceStatusToRabbitStatus(status, isExpiredByTime) {
3033
3047
  switch (status) {
3034
3048
  case "waiting":
3049
+ if (isExpiredByTime) {
3050
+ return SwapProvider.SWAP_STATUSES.EXPIRED;
3051
+ }
3035
3052
  return SwapProvider.SWAP_STATUSES.WAITING_FOR_PAYMENT;
3036
3053
  case "confirming":
3037
3054
  return SwapProvider.SWAP_STATUSES.CONFIRMING;
@@ -3078,11 +3095,13 @@ class SwapspaceSwapProvider extends SwapProvider {
3078
3095
  if (!fromCoin || !toCoin) {
3079
3096
  return []; // We skip swaps with not supported coins for now
3080
3097
  }
3081
- const status = this._mapSwapspaceStatusToRabbitStatus(swap.status);
3098
+ const toUtcTimestamp = timeStr => Date.parse(timeStr.match(/.+[Zz]$/) ? timeStr : `${timeStr}Z`);
3099
+ const expiresAt = toUtcTimestamp(swap.timestamps.expiresAt);
3100
+ const isExpiredByTime = expiresAt > Date.now();
3101
+ const status = this._mapSwapspaceStatusToRabbitStatus(swap.status, isExpiredByTime);
3082
3102
  const toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
3083
3103
  const addressToSendCoinsToSwapspace = swap.from.address;
3084
- const toUtcTimestamp = timeStr => Date.parse(timeStr.match(/.+[Zz]$/) ? timeStr : `${timeStr}Z`);
3085
- return new ExistingSwap(swapIds[index], status, toUtcTimestamp(swap.timestamps.createdAt), toUtcTimestamp(swap.timestamps.expiresAt), swap.confirmations, AmountUtils.trim(swap.rate, this._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);
3104
+ return new ExistingSwap(swapIds[index], status, toUtcTimestamp(swap.timestamps.createdAt), expiresAt, swap.confirmations, AmountUtils.trim(swap.rate, this._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);
3086
3105
  }).flat();
3087
3106
  Logger.log(`Swap details result ${safeStringify(swaps)}`, loggerSource);
3088
3107
  return {
@@ -3107,7 +3126,10 @@ class SwapspaceSwapProvider extends SwapProvider {
3107
3126
  }
3108
3127
  isAddressValidForAsset(asset, address) {
3109
3128
  try {
3110
- const assetData = this._supportedCoins.find(i => i.coin === asset);
3129
+ const assetData = this._supportedCoins.find(i => {
3130
+ var _i$coin3;
3131
+ return ((_i$coin3 = i.coin) == null ? void 0 : _i$coin3.ticker) === (asset == null ? void 0 : asset.ticker);
3132
+ });
3111
3133
  if (assetData) {
3112
3134
  let corrected = assetData.validationRegexp.trim();
3113
3135
  corrected = corrected[0] === "/" ? corrected.slice(1) : corrected;