@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.
package/dist/index.cjs CHANGED
@@ -2999,7 +2999,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
2999
2999
  return {
3000
3000
  result: true,
3001
3001
  coins: _this3._supportedCoins.filter(function (item) {
3002
- return item.withdrawal && (!exceptCurrency || item.coin !== exceptCurrency);
3002
+ var _item$coin, _exceptCurrency;
3003
+ return item.withdrawal && (!exceptCurrency || ((_item$coin = item.coin) == null ? void 0 : _item$coin.ticker) !== ((_exceptCurrency = exceptCurrency) == null ? void 0 : _exceptCurrency.ticker));
3003
3004
  }).map(function (item) {
3004
3005
  return item.coin;
3005
3006
  })
@@ -3073,7 +3074,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3073
3074
  var defaultMinConfirmationsForCoinNotSupportedOOB = 1;
3074
3075
  coin = new Coin(item.name, ticker, code, defaultDecimalPlacesForCoinNotSupportedOOB, null, "", null, null, defaultMinConfirmationsForCoinNotSupportedOOB, null, [], 60000, null,
3075
3076
  // We cannot recognize blockchain from swapspace data
3076
- new Protocol(network),
3077
+ code !== network ? new Protocol(network) : null,
3077
3078
  // TODO: [dev] maybe we should recognize standard protocols?
3078
3079
  item.contractAddress || null, false);
3079
3080
  }
@@ -3123,11 +3124,11 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3123
3124
  var _this6 = this;
3124
3125
  var loggerSource = "getCoinToUSDTRate";
3125
3126
  return Promise.resolve(_catch$2(function () {
3126
- return Promise.resolve(_this6._fetchSupportedCurrenciesIfNeeded()).then(function () {
3127
+ return coin ? Promise.resolve(_this6._fetchSupportedCurrenciesIfNeeded()).then(function () {
3127
3128
  var _this6$_supportedCoin;
3128
3129
  // Using USDT TRC20 as usually fee in this network is smaller than ERC20 and this network is widely used for USDT
3129
3130
  var usdtTrc20 = (_this6$_supportedCoin = _this6._supportedCoins.find(function (i) {
3130
- return i.code === "usdt" && i.network === "trc20";
3131
+ return i.coin.ticker === "USDTTRC20";
3131
3132
  })) == null ? void 0 : _this6$_supportedCoin.coin;
3132
3133
  if (!usdtTrc20) {
3133
3134
  return {
@@ -3141,7 +3142,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3141
3142
  rate: cached
3142
3143
  };
3143
3144
  }
3144
- Logger.log("Loading USDT -> coin rate as not found in cache:", coin == null ? void 0 : coin.ticker);
3145
+ Logger.log("Loading USDT->coin rate as not found in cache:", coin == null ? void 0 : coin.ticker);
3145
3146
  return Promise.resolve(_this6.getSwapInfo(usdtTrc20, coin, "5000")).then(function (result) {
3146
3147
  if (!result.result) {
3147
3148
  return {
@@ -3152,13 +3153,14 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3152
3153
  // This calculation is not precise as we cannot recognize the actual fee and network fee. Just approximate.
3153
3154
  var standardSwapspaceFeeMultiplier = 1.002; // usually 0.2%
3154
3155
  var rate = bignumber_js.BigNumber(1).div(bignumber_js.BigNumber(result.rate).times(standardSwapspaceFeeMultiplier)).toString();
3155
- _this6._cache.put("swapspace_usdt_rate_" + coin.ticker, rate, 15 * 60000);
3156
+ _this6._cache.put("swapspace_usdt_rate_" + coin.ticker, rate, 15 * 60000 // 15 minutes
3157
+ );
3156
3158
  return {
3157
3159
  result: true,
3158
3160
  rate: rate
3159
3161
  };
3160
3162
  });
3161
- });
3163
+ }) : null;
3162
3164
  }, function (e) {
3163
3165
  improveAndRethrow(e, loggerSource);
3164
3166
  }));
@@ -3168,11 +3170,11 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3168
3170
  };
3169
3171
  _proto.getCoinByTickerIfPresent = function getCoinByTickerIfPresent(ticker) {
3170
3172
  try {
3171
- var _item$coin;
3173
+ var _item$coin2;
3172
3174
  var item = this._supportedCoins.find(function (i) {
3173
3175
  return i.coin.ticker === ticker;
3174
3176
  });
3175
- return (_item$coin = item == null ? void 0 : item.coin) != null ? _item$coin : null;
3177
+ return (_item$coin2 = item == null ? void 0 : item.coin) != null ? _item$coin2 : null;
3176
3178
  } catch (e) {
3177
3179
  improveAndRethrow(e, "getCoinByTickerIfPresent");
3178
3180
  }
@@ -3189,10 +3191,12 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3189
3191
  throw new Error("Wrong input params: " + amountCoins + " " + fromCoin.ticker + " -> " + toCoin.ticker + (fromCoin instanceof Coin) + (toCoin instanceof Coin));
3190
3192
  }
3191
3193
  var fromCoinSwapspaceDetails = _this7._supportedCoins.find(function (i) {
3192
- return i.coin === fromCoin;
3194
+ var _i$coin;
3195
+ return ((_i$coin = i.coin) == null ? void 0 : _i$coin.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
3193
3196
  });
3194
3197
  var toCoinSwapspaceDetails = _this7._supportedCoins.find(function (i) {
3195
- return i.coin === toCoin;
3198
+ var _i$coin2;
3199
+ return ((_i$coin2 = i.coin) == null ? void 0 : _i$coin2.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
3196
3200
  });
3197
3201
  if (!fromCoinSwapspaceDetails || !toCoinSwapspaceDetails) {
3198
3202
  throw new Error("Failed to find swapspace coin details for: " + fromCoin.ticker + " -> " + toCoin.ticker);
@@ -3325,7 +3329,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3325
3329
  return Promise.resolve(_this8._fetchSupportedCurrenciesIfNeeded()).then(function () {
3326
3330
  var _this8$_supportedCoin, _this8$_supportedCoin2;
3327
3331
  var toCurrencyExtraId = (_this8$_supportedCoin = (_this8$_supportedCoin2 = _this8._supportedCoins.find(function (item) {
3328
- return item.coin === toCoin;
3332
+ var _item$coin3;
3333
+ return ((_item$coin3 = item.coin) == null ? void 0 : _item$coin3.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
3329
3334
  })) == null ? void 0 : _this8$_supportedCoin2.extraId) != null ? _this8$_supportedCoin : "";
3330
3335
  var requestData = {
3331
3336
  partner: partner,
@@ -3405,9 +3410,12 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3405
3410
  return Promise.reject(e);
3406
3411
  }
3407
3412
  };
3408
- _proto._mapSwapspaceStatusToRabbitStatus = function _mapSwapspaceStatusToRabbitStatus(status) {
3413
+ _proto._mapSwapspaceStatusToRabbitStatus = function _mapSwapspaceStatusToRabbitStatus(status, isExpiredByTime) {
3409
3414
  switch (status) {
3410
3415
  case "waiting":
3416
+ if (isExpiredByTime) {
3417
+ return SwapProvider.SWAP_STATUSES.EXPIRED;
3418
+ }
3411
3419
  return SwapProvider.SWAP_STATUSES.WAITING_FOR_PAYMENT;
3412
3420
  case "confirming":
3413
3421
  return SwapProvider.SWAP_STATUSES.CONFIRMING;
@@ -3469,13 +3477,15 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3469
3477
  if (!fromCoin || !toCoin) {
3470
3478
  return []; // We skip swaps with not supported coins for now
3471
3479
  }
3472
- var status = _this9._mapSwapspaceStatusToRabbitStatus(swap.status);
3473
- var toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
3474
- var addressToSendCoinsToSwapspace = swap.from.address;
3475
3480
  var toUtcTimestamp = function toUtcTimestamp(timeStr) {
3476
3481
  return Date.parse(timeStr.match(/.+[Zz]$/) ? timeStr : timeStr + "Z");
3477
3482
  };
3478
- return new ExistingSwap(swapIds[index], status, toUtcTimestamp(swap.timestamps.createdAt), toUtcTimestamp(swap.timestamps.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);
3483
+ var expiresAt = toUtcTimestamp(swap.timestamps.expiresAt);
3484
+ var isExpiredByTime = expiresAt > Date.now();
3485
+ var status = _this9._mapSwapspaceStatusToRabbitStatus(swap.status, isExpiredByTime);
3486
+ var toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
3487
+ 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);
3479
3489
  }).flat();
3480
3490
  Logger.log("Swap details result " + safeStringify(swaps), loggerSource);
3481
3491
  return {
@@ -3507,7 +3517,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3507
3517
  _proto.isAddressValidForAsset = function isAddressValidForAsset(asset, address) {
3508
3518
  try {
3509
3519
  var assetData = this._supportedCoins.find(function (i) {
3510
- return i.coin === asset;
3520
+ var _i$coin3;
3521
+ return ((_i$coin3 = i.coin) == null ? void 0 : _i$coin3.ticker) === (asset == null ? void 0 : asset.ticker);
3511
3522
  });
3512
3523
  if (assetData) {
3513
3524
  var corrected = assetData.validationRegexp.trim();