@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 +29 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +37 -15
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +29 -18
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +29 -18
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -2
- package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +28 -17
package/dist/index.module.js
CHANGED
|
@@ -2993,7 +2993,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
2993
2993
|
return {
|
|
2994
2994
|
result: true,
|
|
2995
2995
|
coins: _this3._supportedCoins.filter(function (item) {
|
|
2996
|
-
|
|
2996
|
+
var _item$coin, _exceptCurrency;
|
|
2997
|
+
return item.withdrawal && (!exceptCurrency || ((_item$coin = item.coin) == null ? void 0 : _item$coin.ticker) !== ((_exceptCurrency = exceptCurrency) == null ? void 0 : _exceptCurrency.ticker));
|
|
2997
2998
|
}).map(function (item) {
|
|
2998
2999
|
return item.coin;
|
|
2999
3000
|
})
|
|
@@ -3067,7 +3068,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3067
3068
|
var defaultMinConfirmationsForCoinNotSupportedOOB = 1;
|
|
3068
3069
|
coin = new Coin(item.name, ticker, code, defaultDecimalPlacesForCoinNotSupportedOOB, null, "", null, null, defaultMinConfirmationsForCoinNotSupportedOOB, null, [], 60000, null,
|
|
3069
3070
|
// We cannot recognize blockchain from swapspace data
|
|
3070
|
-
new Protocol(network),
|
|
3071
|
+
code !== network ? new Protocol(network) : null,
|
|
3071
3072
|
// TODO: [dev] maybe we should recognize standard protocols?
|
|
3072
3073
|
item.contractAddress || null, false);
|
|
3073
3074
|
}
|
|
@@ -3117,11 +3118,11 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3117
3118
|
var _this6 = this;
|
|
3118
3119
|
var loggerSource = "getCoinToUSDTRate";
|
|
3119
3120
|
return Promise.resolve(_catch$2(function () {
|
|
3120
|
-
return Promise.resolve(_this6._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
3121
|
+
return coin ? Promise.resolve(_this6._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
3121
3122
|
var _this6$_supportedCoin;
|
|
3122
3123
|
// Using USDT TRC20 as usually fee in this network is smaller than ERC20 and this network is widely used for USDT
|
|
3123
3124
|
var usdtTrc20 = (_this6$_supportedCoin = _this6._supportedCoins.find(function (i) {
|
|
3124
|
-
return i.
|
|
3125
|
+
return i.coin.ticker === "USDTTRC20";
|
|
3125
3126
|
})) == null ? void 0 : _this6$_supportedCoin.coin;
|
|
3126
3127
|
if (!usdtTrc20) {
|
|
3127
3128
|
return {
|
|
@@ -3135,7 +3136,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3135
3136
|
rate: cached
|
|
3136
3137
|
};
|
|
3137
3138
|
}
|
|
3138
|
-
Logger.log("Loading USDT
|
|
3139
|
+
Logger.log("Loading USDT->coin rate as not found in cache:", coin == null ? void 0 : coin.ticker);
|
|
3139
3140
|
return Promise.resolve(_this6.getSwapInfo(usdtTrc20, coin, "5000")).then(function (result) {
|
|
3140
3141
|
if (!result.result) {
|
|
3141
3142
|
return {
|
|
@@ -3146,13 +3147,14 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3146
3147
|
// This calculation is not precise as we cannot recognize the actual fee and network fee. Just approximate.
|
|
3147
3148
|
var standardSwapspaceFeeMultiplier = 1.002; // usually 0.2%
|
|
3148
3149
|
var rate = BigNumber(1).div(BigNumber(result.rate).times(standardSwapspaceFeeMultiplier)).toString();
|
|
3149
|
-
_this6._cache.put("swapspace_usdt_rate_" + coin.ticker, rate, 15 * 60000
|
|
3150
|
+
_this6._cache.put("swapspace_usdt_rate_" + coin.ticker, rate, 15 * 60000 // 15 minutes
|
|
3151
|
+
);
|
|
3150
3152
|
return {
|
|
3151
3153
|
result: true,
|
|
3152
3154
|
rate: rate
|
|
3153
3155
|
};
|
|
3154
3156
|
});
|
|
3155
|
-
});
|
|
3157
|
+
}) : null;
|
|
3156
3158
|
}, function (e) {
|
|
3157
3159
|
improveAndRethrow(e, loggerSource);
|
|
3158
3160
|
}));
|
|
@@ -3162,11 +3164,11 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3162
3164
|
};
|
|
3163
3165
|
_proto.getCoinByTickerIfPresent = function getCoinByTickerIfPresent(ticker) {
|
|
3164
3166
|
try {
|
|
3165
|
-
var _item$
|
|
3167
|
+
var _item$coin2;
|
|
3166
3168
|
var item = this._supportedCoins.find(function (i) {
|
|
3167
3169
|
return i.coin.ticker === ticker;
|
|
3168
3170
|
});
|
|
3169
|
-
return (_item$
|
|
3171
|
+
return (_item$coin2 = item == null ? void 0 : item.coin) != null ? _item$coin2 : null;
|
|
3170
3172
|
} catch (e) {
|
|
3171
3173
|
improveAndRethrow(e, "getCoinByTickerIfPresent");
|
|
3172
3174
|
}
|
|
@@ -3183,10 +3185,12 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3183
3185
|
throw new Error("Wrong input params: " + amountCoins + " " + fromCoin.ticker + " -> " + toCoin.ticker + (fromCoin instanceof Coin) + (toCoin instanceof Coin));
|
|
3184
3186
|
}
|
|
3185
3187
|
var fromCoinSwapspaceDetails = _this7._supportedCoins.find(function (i) {
|
|
3186
|
-
|
|
3188
|
+
var _i$coin;
|
|
3189
|
+
return ((_i$coin = i.coin) == null ? void 0 : _i$coin.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
|
|
3187
3190
|
});
|
|
3188
3191
|
var toCoinSwapspaceDetails = _this7._supportedCoins.find(function (i) {
|
|
3189
|
-
|
|
3192
|
+
var _i$coin2;
|
|
3193
|
+
return ((_i$coin2 = i.coin) == null ? void 0 : _i$coin2.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
|
|
3190
3194
|
});
|
|
3191
3195
|
if (!fromCoinSwapspaceDetails || !toCoinSwapspaceDetails) {
|
|
3192
3196
|
throw new Error("Failed to find swapspace coin details for: " + fromCoin.ticker + " -> " + toCoin.ticker);
|
|
@@ -3319,7 +3323,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3319
3323
|
return Promise.resolve(_this8._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
3320
3324
|
var _this8$_supportedCoin, _this8$_supportedCoin2;
|
|
3321
3325
|
var toCurrencyExtraId = (_this8$_supportedCoin = (_this8$_supportedCoin2 = _this8._supportedCoins.find(function (item) {
|
|
3322
|
-
|
|
3326
|
+
var _item$coin3;
|
|
3327
|
+
return ((_item$coin3 = item.coin) == null ? void 0 : _item$coin3.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
|
|
3323
3328
|
})) == null ? void 0 : _this8$_supportedCoin2.extraId) != null ? _this8$_supportedCoin : "";
|
|
3324
3329
|
var requestData = {
|
|
3325
3330
|
partner: partner,
|
|
@@ -3399,9 +3404,12 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3399
3404
|
return Promise.reject(e);
|
|
3400
3405
|
}
|
|
3401
3406
|
};
|
|
3402
|
-
_proto._mapSwapspaceStatusToRabbitStatus = function _mapSwapspaceStatusToRabbitStatus(status) {
|
|
3407
|
+
_proto._mapSwapspaceStatusToRabbitStatus = function _mapSwapspaceStatusToRabbitStatus(status, isExpiredByTime) {
|
|
3403
3408
|
switch (status) {
|
|
3404
3409
|
case "waiting":
|
|
3410
|
+
if (isExpiredByTime) {
|
|
3411
|
+
return SwapProvider.SWAP_STATUSES.EXPIRED;
|
|
3412
|
+
}
|
|
3405
3413
|
return SwapProvider.SWAP_STATUSES.WAITING_FOR_PAYMENT;
|
|
3406
3414
|
case "confirming":
|
|
3407
3415
|
return SwapProvider.SWAP_STATUSES.CONFIRMING;
|
|
@@ -3463,13 +3471,15 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3463
3471
|
if (!fromCoin || !toCoin) {
|
|
3464
3472
|
return []; // We skip swaps with not supported coins for now
|
|
3465
3473
|
}
|
|
3466
|
-
var status = _this9._mapSwapspaceStatusToRabbitStatus(swap.status);
|
|
3467
|
-
var toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
|
|
3468
|
-
var addressToSendCoinsToSwapspace = swap.from.address;
|
|
3469
3474
|
var toUtcTimestamp = function toUtcTimestamp(timeStr) {
|
|
3470
3475
|
return Date.parse(timeStr.match(/.+[Zz]$/) ? timeStr : timeStr + "Z");
|
|
3471
3476
|
};
|
|
3472
|
-
|
|
3477
|
+
var expiresAt = toUtcTimestamp(swap.timestamps.expiresAt);
|
|
3478
|
+
var isExpiredByTime = expiresAt > Date.now();
|
|
3479
|
+
var status = _this9._mapSwapspaceStatusToRabbitStatus(swap.status, isExpiredByTime);
|
|
3480
|
+
var toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
|
|
3481
|
+
var addressToSendCoinsToSwapspace = swap.from.address;
|
|
3482
|
+
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);
|
|
3473
3483
|
}).flat();
|
|
3474
3484
|
Logger.log("Swap details result " + safeStringify(swaps), loggerSource);
|
|
3475
3485
|
return {
|
|
@@ -3501,7 +3511,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3501
3511
|
_proto.isAddressValidForAsset = function isAddressValidForAsset(asset, address) {
|
|
3502
3512
|
try {
|
|
3503
3513
|
var assetData = this._supportedCoins.find(function (i) {
|
|
3504
|
-
|
|
3514
|
+
var _i$coin3;
|
|
3515
|
+
return ((_i$coin3 = i.coin) == null ? void 0 : _i$coin3.ticker) === (asset == null ? void 0 : asset.ticker);
|
|
3505
3516
|
});
|
|
3506
3517
|
if (assetData) {
|
|
3507
3518
|
var corrected = assetData.validationRegexp.trim();
|