@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabbitio/ui-kit",
3
- "version": "1.0.0-beta.19",
3
+ "version": "1.0.0-beta.20",
4
4
  "description": "Rabbit.io react.js components kit",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -69,6 +69,7 @@
69
69
  "prettier": {
70
70
  "trailingComma": "es5",
71
71
  "tabWidth": 4,
72
- "singleQuote": false
72
+ "singleQuote": false,
73
+ "printWidth": 80
73
74
  }
74
75
  }
@@ -74,7 +74,8 @@ export class SwapspaceSwapProvider extends SwapProvider {
74
74
  .filter(
75
75
  (item) =>
76
76
  item.withdrawal &&
77
- (!exceptCurrency || item.coin !== exceptCurrency)
77
+ (!exceptCurrency ||
78
+ item.coin?.ticker !== exceptCurrency?.ticker)
78
79
  )
79
80
  .map((item) => item.coin),
80
81
  };
@@ -158,7 +159,7 @@ export class SwapspaceSwapProvider extends SwapProvider {
158
159
  [],
159
160
  60000,
160
161
  null, // We cannot recognize blockchain from swapspace data
161
- new Protocol(network), // TODO: [dev] maybe we should recognize standard protocols?
162
+ code !== network ? new Protocol(network) : null, // TODO: [dev] maybe we should recognize standard protocols?
162
163
  item.contractAddress || null,
163
164
  false
164
165
  );
@@ -209,11 +210,13 @@ export class SwapspaceSwapProvider extends SwapProvider {
209
210
  async getCoinToUSDTRate(coin) {
210
211
  const loggerSource = "getCoinToUSDTRate";
211
212
  try {
213
+ if (!coin) return null;
214
+
212
215
  await this._fetchSupportedCurrenciesIfNeeded();
213
216
 
214
217
  // Using USDT TRC20 as usually fee in this network is smaller than ERC20 and this network is widely used for USDT
215
218
  const usdtTrc20 = this._supportedCoins.find(
216
- (i) => i.code === "usdt" && i.network === "trc20"
219
+ (i) => i.coin.ticker === "USDTTRC20"
217
220
  )?.coin;
218
221
  if (!usdtTrc20) {
219
222
  return { result: false };
@@ -227,8 +230,9 @@ export class SwapspaceSwapProvider extends SwapProvider {
227
230
  rate: cached,
228
231
  };
229
232
  }
233
+
230
234
  Logger.log(
231
- "Loading USDT -> coin rate as not found in cache:",
235
+ "Loading USDT->coin rate as not found in cache:",
232
236
  coin?.ticker
233
237
  );
234
238
  const result = await this.getSwapInfo(usdtTrc20, coin, "5000");
@@ -246,7 +250,7 @@ export class SwapspaceSwapProvider extends SwapProvider {
246
250
  this._cache.put(
247
251
  "swapspace_usdt_rate_" + coin.ticker,
248
252
  rate,
249
- 15 * 60000
253
+ 15 * 60000 // 15 minutes
250
254
  );
251
255
  return {
252
256
  result: true,
@@ -284,10 +288,10 @@ export class SwapspaceSwapProvider extends SwapProvider {
284
288
  );
285
289
  }
286
290
  const fromCoinSwapspaceDetails = this._supportedCoins.find(
287
- (i) => i.coin === fromCoin
291
+ (i) => i.coin?.ticker === fromCoin?.ticker
288
292
  );
289
293
  const toCoinSwapspaceDetails = this._supportedCoins.find(
290
- (i) => i.coin === toCoin
294
+ (i) => i.coin?.ticker === toCoin?.ticker
291
295
  );
292
296
  if (!fromCoinSwapspaceDetails || !toCoinSwapspaceDetails) {
293
297
  throw new Error(
@@ -523,8 +527,9 @@ export class SwapspaceSwapProvider extends SwapProvider {
523
527
 
524
528
  await this._fetchSupportedCurrenciesIfNeeded();
525
529
  const toCurrencyExtraId =
526
- this._supportedCoins.find((item) => item.coin === toCoin)
527
- ?.extraId ?? "";
530
+ this._supportedCoins.find(
531
+ (item) => item.coin?.ticker === toCoin?.ticker
532
+ )?.extraId ?? "";
528
533
  const requestData = {
529
534
  partner: partner,
530
535
  fromCurrency: rawSwapData?.fromCurrency,
@@ -649,9 +654,12 @@ export class SwapspaceSwapProvider extends SwapProvider {
649
654
  }
650
655
  }
651
656
 
652
- _mapSwapspaceStatusToRabbitStatus(status) {
657
+ _mapSwapspaceStatusToRabbitStatus(status, isExpiredByTime) {
653
658
  switch (status) {
654
659
  case "waiting":
660
+ if (isExpiredByTime) {
661
+ return SwapProvider.SWAP_STATUSES.EXPIRED;
662
+ }
655
663
  return SwapProvider.SWAP_STATUSES.WAITING_FOR_PAYMENT;
656
664
  case "confirming":
657
665
  return SwapProvider.SWAP_STATUSES.CONFIRMING;
@@ -713,23 +721,26 @@ export class SwapspaceSwapProvider extends SwapProvider {
713
721
  return []; // We skip swaps with not supported coins for now
714
722
  }
715
723
 
724
+ const toUtcTimestamp = (timeStr) =>
725
+ Date.parse(
726
+ timeStr.match(/.+[Zz]$/) ? timeStr : `${timeStr}Z`
727
+ );
728
+ const expiresAt = toUtcTimestamp(swap.timestamps.expiresAt);
729
+ const isExpiredByTime = expiresAt > Date.now();
716
730
  const status = this._mapSwapspaceStatusToRabbitStatus(
717
- swap.status
731
+ swap.status,
732
+ isExpiredByTime
718
733
  );
719
734
  const toDigits =
720
735
  status === SwapProvider.SWAP_STATUSES.REFUNDED
721
736
  ? fromCoin.digits
722
737
  : toCoin.digits;
723
738
  const addressToSendCoinsToSwapspace = swap.from.address;
724
- const toUtcTimestamp = (timeStr) =>
725
- Date.parse(
726
- timeStr.match(/.+[Zz]$/) ? timeStr : `${timeStr}Z`
727
- );
728
739
  return new ExistingSwap(
729
740
  swapIds[index],
730
741
  status,
731
742
  toUtcTimestamp(swap.timestamps.createdAt),
732
- toUtcTimestamp(swap.timestamps.expiresAt),
743
+ expiresAt,
733
744
  swap.confirmations,
734
745
  AmountUtils.trim(swap.rate, this._maxRateDigits),
735
746
  swap.refundAddress,
@@ -780,7 +791,7 @@ export class SwapspaceSwapProvider extends SwapProvider {
780
791
  isAddressValidForAsset(asset, address) {
781
792
  try {
782
793
  const assetData = this._supportedCoins.find(
783
- (i) => i.coin === asset
794
+ (i) => i.coin?.ticker === asset?.ticker
784
795
  );
785
796
  if (assetData) {
786
797
  let corrected = assetData.validationRegexp.trim();