@rabbitio/ui-kit 1.0.0-beta.22 → 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.
- package/dist/index.cjs +165 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +88 -34
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +165 -100
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +165 -100
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/swaps-lib/external-apis/swapProvider.js +20 -1
- package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +32 -0
- package/src/swaps-lib/services/publicSwapService.js +25 -5
package/dist/index.module.js
CHANGED
|
@@ -2727,11 +2727,25 @@ var SwapProvider = /*#__PURE__*/function () {
|
|
|
2727
2727
|
}
|
|
2728
2728
|
|
|
2729
2729
|
/**
|
|
2730
|
-
* Retrieves all
|
|
2730
|
+
* Retrieves all currencies supported by this swap provider.
|
|
2731
2731
|
* Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
|
|
2732
2732
|
*
|
|
2733
2733
|
* @return {Promise<({ result: true, coins: Coin[] }|{ result: false, reason: string })>}
|
|
2734
2734
|
*/;
|
|
2735
|
+
_proto.getAllSupportedCurrencies = function getAllSupportedCurrencies() {
|
|
2736
|
+
try {
|
|
2737
|
+
throw new Error("Not implemented in base");
|
|
2738
|
+
} catch (e) {
|
|
2739
|
+
return Promise.reject(e);
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
/**
|
|
2743
|
+
* Retrieves all deposit currencies supported by this swap provider.
|
|
2744
|
+
* Returns one of SwapProvider.COMMON_ERRORS in case of processable fail.
|
|
2745
|
+
*
|
|
2746
|
+
* @return {Promise<({ result: true, coins: Coin[] }|{ result: false, reason: string })>}
|
|
2747
|
+
*/
|
|
2748
|
+
;
|
|
2735
2749
|
_proto.getDepositCurrencies = function getDepositCurrencies() {
|
|
2736
2750
|
try {
|
|
2737
2751
|
throw new Error("Not implemented in base");
|
|
@@ -2783,6 +2797,7 @@ var SwapProvider = /*#__PURE__*/function () {
|
|
|
2783
2797
|
* null min or max signals there is no corresponding limitation. undefined means that the limits were not retrieved.
|
|
2784
2798
|
* For fail result on of SwapProvider.NO_SWAPS_REASONS or SwapProvider.COMMON_ERRORS reasons will be returned.
|
|
2785
2799
|
*
|
|
2800
|
+
* WARNING: MUST return NOT_SUPPORTED error code for any case when pair is not available/supported (Should not throw random errors for this case)
|
|
2786
2801
|
* @param fromCoin {Coin}
|
|
2787
2802
|
* @param toCoin {Coin}
|
|
2788
2803
|
* @param amountCoins {string}
|
|
@@ -2979,20 +2994,49 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
2979
2994
|
return Promise.reject(e);
|
|
2980
2995
|
}
|
|
2981
2996
|
};
|
|
2997
|
+
_proto.getAllSupportedCurrencies = function getAllSupportedCurrencies() {
|
|
2998
|
+
try {
|
|
2999
|
+
var _this3 = this;
|
|
3000
|
+
var loggerSource = "getAllSupportedCurrencies";
|
|
3001
|
+
return Promise.resolve(_catch$2(function () {
|
|
3002
|
+
return Promise.resolve(_this3._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
3003
|
+
var _this3$_supportedCoin;
|
|
3004
|
+
Logger.log("We have " + ((_this3$_supportedCoin = _this3._supportedCoins) == null ? void 0 : _this3$_supportedCoin.length) + " supported coins returning", loggerSource);
|
|
3005
|
+
return {
|
|
3006
|
+
result: true,
|
|
3007
|
+
coins: _this3._supportedCoins.map(function (item) {
|
|
3008
|
+
return item.coin;
|
|
3009
|
+
})
|
|
3010
|
+
};
|
|
3011
|
+
});
|
|
3012
|
+
}, function (e) {
|
|
3013
|
+
var _e$response2;
|
|
3014
|
+
if ((e == null || (_e$response2 = e.response) == null ? void 0 : _e$response2.status) === 429) {
|
|
3015
|
+
return {
|
|
3016
|
+
result: false,
|
|
3017
|
+
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
|
|
3018
|
+
};
|
|
3019
|
+
}
|
|
3020
|
+
improveAndRethrow(e, loggerSource);
|
|
3021
|
+
}));
|
|
3022
|
+
} catch (e) {
|
|
3023
|
+
return Promise.reject(e);
|
|
3024
|
+
}
|
|
3025
|
+
};
|
|
2982
3026
|
_proto.getWithdrawalCurrencies = function getWithdrawalCurrencies(exceptCurrency) {
|
|
2983
3027
|
if (exceptCurrency === void 0) {
|
|
2984
3028
|
exceptCurrency = null;
|
|
2985
3029
|
}
|
|
2986
3030
|
try {
|
|
2987
|
-
var
|
|
3031
|
+
var _this4 = this;
|
|
2988
3032
|
var loggerSource = "getWithdrawalCurrencies";
|
|
2989
3033
|
return Promise.resolve(_catch$2(function () {
|
|
2990
|
-
return Promise.resolve(
|
|
2991
|
-
var
|
|
2992
|
-
Logger.log("We have " + ((
|
|
3034
|
+
return Promise.resolve(_this4._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
3035
|
+
var _this4$_supportedCoin;
|
|
3036
|
+
Logger.log("We have " + ((_this4$_supportedCoin = _this4._supportedCoins) == null ? void 0 : _this4$_supportedCoin.length) + " supported coins, getting withdrawable", loggerSource);
|
|
2993
3037
|
return {
|
|
2994
3038
|
result: true,
|
|
2995
|
-
coins:
|
|
3039
|
+
coins: _this4._supportedCoins.filter(function (item) {
|
|
2996
3040
|
var _item$coin, _exceptCurrency;
|
|
2997
3041
|
return item.withdrawal && (!exceptCurrency || ((_item$coin = item.coin) == null ? void 0 : _item$coin.ticker) !== ((_exceptCurrency = exceptCurrency) == null ? void 0 : _exceptCurrency.ticker));
|
|
2998
3042
|
}).map(function (item) {
|
|
@@ -3001,8 +3045,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3001
3045
|
};
|
|
3002
3046
|
});
|
|
3003
3047
|
}, function (e) {
|
|
3004
|
-
var _e$
|
|
3005
|
-
if ((e == null || (_e$
|
|
3048
|
+
var _e$response3;
|
|
3049
|
+
if ((e == null || (_e$response3 = e.response) == null ? void 0 : _e$response3.status) === 429) {
|
|
3006
3050
|
return {
|
|
3007
3051
|
result: false,
|
|
3008
3052
|
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
|
|
@@ -3016,8 +3060,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3016
3060
|
};
|
|
3017
3061
|
_proto.initialize = function initialize() {
|
|
3018
3062
|
try {
|
|
3019
|
-
var
|
|
3020
|
-
return Promise.resolve(
|
|
3063
|
+
var _this5 = this;
|
|
3064
|
+
return Promise.resolve(_this5._fetchSupportedCurrenciesIfNeeded()).then(function () {});
|
|
3021
3065
|
} catch (e) {
|
|
3022
3066
|
return Promise.reject(e);
|
|
3023
3067
|
}
|
|
@@ -3043,17 +3087,17 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3043
3087
|
};
|
|
3044
3088
|
_proto._fetchSupportedCurrenciesIfNeeded = function _fetchSupportedCurrenciesIfNeeded() {
|
|
3045
3089
|
try {
|
|
3046
|
-
var
|
|
3090
|
+
var _this6 = this;
|
|
3047
3091
|
var loggerSource = "_fetchSupportedCurrenciesIfNeeded";
|
|
3048
3092
|
return Promise.resolve(_catch$2(function () {
|
|
3049
|
-
var _temp = function (
|
|
3050
|
-
if (!((
|
|
3051
|
-
return Promise.resolve(axios.get(
|
|
3093
|
+
var _temp = function (_this6$_supportedCoin) {
|
|
3094
|
+
if (!((_this6$_supportedCoin = _this6._supportedCoins) != null && _this6$_supportedCoin.length)) {
|
|
3095
|
+
return Promise.resolve(axios.get(_this6._URL + "/api/v2/currencies")).then(function (rawResponse) {
|
|
3052
3096
|
var _rawResponse$data, _rawResponse$data2;
|
|
3053
3097
|
Logger.log("Retrieved " + (rawResponse == null || (_rawResponse$data = rawResponse.data) == null ? void 0 : _rawResponse$data.length) + " currencies", loggerSource);
|
|
3054
|
-
|
|
3055
|
-
var coin =
|
|
3056
|
-
if (!coin && !
|
|
3098
|
+
_this6._supportedCoins = ((_rawResponse$data2 = rawResponse == null ? void 0 : rawResponse.data) != null ? _rawResponse$data2 : []).map(function (item) {
|
|
3099
|
+
var coin = _this6._customCoinBuilder(item.code, item.network);
|
|
3100
|
+
if (!coin && !_this6.useRestrictedCoinsSet) {
|
|
3057
3101
|
/** Building coin object for coin that isn't supported OOB in Rabbit.
|
|
3058
3102
|
* We are doing this way to be able to use extended coins set for swaps.
|
|
3059
3103
|
* These temporary built coins are only for in-swap use, and we omit some usual
|
|
@@ -3089,7 +3133,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3089
3133
|
}
|
|
3090
3134
|
return [];
|
|
3091
3135
|
}).flat();
|
|
3092
|
-
|
|
3136
|
+
_this6._putPopularCoinsFirst();
|
|
3093
3137
|
});
|
|
3094
3138
|
}
|
|
3095
3139
|
}();
|
|
@@ -3116,21 +3160,21 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3116
3160
|
};
|
|
3117
3161
|
_proto.getCoinToUSDTRate = function getCoinToUSDTRate(coin) {
|
|
3118
3162
|
try {
|
|
3119
|
-
var
|
|
3163
|
+
var _this7 = this;
|
|
3120
3164
|
var loggerSource = "getCoinToUSDTRate";
|
|
3121
3165
|
return Promise.resolve(_catch$2(function () {
|
|
3122
|
-
return coin ? Promise.resolve(
|
|
3123
|
-
var
|
|
3166
|
+
return coin ? Promise.resolve(_this7._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
3167
|
+
var _this7$_supportedCoin;
|
|
3124
3168
|
// Using USDT TRC20 as usually fee in this network is smaller than ERC20 and this network is widely used for USDT
|
|
3125
|
-
var usdtTrc20 = (
|
|
3169
|
+
var usdtTrc20 = (_this7$_supportedCoin = _this7._supportedCoins.find(function (i) {
|
|
3126
3170
|
return i.coin.ticker === "USDTTRC20";
|
|
3127
|
-
})) == null ? void 0 :
|
|
3171
|
+
})) == null ? void 0 : _this7$_supportedCoin.coin;
|
|
3128
3172
|
if (!usdtTrc20) {
|
|
3129
3173
|
return {
|
|
3130
3174
|
result: false
|
|
3131
3175
|
};
|
|
3132
3176
|
}
|
|
3133
|
-
var cached =
|
|
3177
|
+
var cached = _this7._cache.get("swapspace_usdt_rate_" + coin.ticker);
|
|
3134
3178
|
if (cached != null) {
|
|
3135
3179
|
return {
|
|
3136
3180
|
result: true,
|
|
@@ -3138,7 +3182,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3138
3182
|
};
|
|
3139
3183
|
}
|
|
3140
3184
|
Logger.log("Loading USDT->coin rate as not found in cache:", coin == null ? void 0 : coin.ticker);
|
|
3141
|
-
return Promise.resolve(
|
|
3185
|
+
return Promise.resolve(_this7.getSwapInfo(usdtTrc20, coin, "5000")).then(function (result) {
|
|
3142
3186
|
if (!result.result) {
|
|
3143
3187
|
return {
|
|
3144
3188
|
result: false
|
|
@@ -3148,7 +3192,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3148
3192
|
// This calculation is not precise as we cannot recognize the actual fee and network fee. Just approximate.
|
|
3149
3193
|
var standardSwapspaceFeeMultiplier = 1.002; // usually 0.2%
|
|
3150
3194
|
var rate = BigNumber(1).div(BigNumber(result.rate).times(standardSwapspaceFeeMultiplier)).toString();
|
|
3151
|
-
|
|
3195
|
+
_this7._cache.put("swapspace_usdt_rate_" + coin.ticker, rate, 15 * 60000 // 15 minutes
|
|
3152
3196
|
);
|
|
3153
3197
|
return {
|
|
3154
3198
|
result: true,
|
|
@@ -3179,28 +3223,27 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3179
3223
|
fromCoinToUsdRate = null;
|
|
3180
3224
|
}
|
|
3181
3225
|
try {
|
|
3182
|
-
var
|
|
3226
|
+
var _this8 = this;
|
|
3183
3227
|
var loggerSource = "getSwapInfo";
|
|
3184
3228
|
return Promise.resolve(_catch$2(function () {
|
|
3185
3229
|
if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amountCoins !== "string" || BigNumber(amountCoins).lt("0")) {
|
|
3186
3230
|
throw new Error("Wrong input params: " + amountCoins + " " + fromCoin.ticker + " -> " + toCoin.ticker + (fromCoin instanceof Coin) + (toCoin instanceof Coin));
|
|
3187
3231
|
}
|
|
3188
|
-
var fromCoinSwapspaceDetails =
|
|
3232
|
+
var fromCoinSwapspaceDetails = _this8._supportedCoins.find(function (i) {
|
|
3189
3233
|
var _i$coin;
|
|
3190
3234
|
return ((_i$coin = i.coin) == null ? void 0 : _i$coin.ticker) === (fromCoin == null ? void 0 : fromCoin.ticker);
|
|
3191
3235
|
});
|
|
3192
|
-
var toCoinSwapspaceDetails =
|
|
3236
|
+
var toCoinSwapspaceDetails = _this8._supportedCoins.find(function (i) {
|
|
3193
3237
|
var _i$coin2;
|
|
3194
3238
|
return ((_i$coin2 = i.coin) == null ? void 0 : _i$coin2.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
|
|
3195
3239
|
});
|
|
3196
3240
|
if (!fromCoinSwapspaceDetails || !toCoinSwapspaceDetails) {
|
|
3197
3241
|
throw new Error("Failed to find swapspace coin details for: " + fromCoin.ticker + " -> " + toCoin.ticker);
|
|
3198
3242
|
}
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
return Promise.resolve(axios.get(_this7._URL + "/api/v2/amounts?fromCurrency=" + fromCoinSwapspaceDetails.code + "&fromNetwork=" + fromCoinSwapspaceDetails.network + "&toNetwork=" + toCoinSwapspaceDetails.network + "&toCurrency=" + toCoinSwapspaceDetails.code + "&amount=" + amountCoins + "&float=true&estimated=false")).then(function (response) {
|
|
3243
|
+
return !fromCoinSwapspaceDetails.deposit || !toCoinSwapspaceDetails.withdrawal ? {
|
|
3244
|
+
result: false,
|
|
3245
|
+
reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
|
|
3246
|
+
} : Promise.resolve(axios.get(_this8._URL + "/api/v2/amounts?fromCurrency=" + fromCoinSwapspaceDetails.code + "&fromNetwork=" + fromCoinSwapspaceDetails.network + "&toNetwork=" + toCoinSwapspaceDetails.network + "&toCurrency=" + toCoinSwapspaceDetails.code + "&amount=" + amountCoins + "&float=true&estimated=false")).then(function (response) {
|
|
3204
3247
|
var _response$data;
|
|
3205
3248
|
Logger.log("Retrieved " + (response == null || (_response$data = response.data) == null ? void 0 : _response$data.length) + " options", loggerSource);
|
|
3206
3249
|
var options = Array.isArray(response.data) ? response.data : [];
|
|
@@ -3279,7 +3322,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3279
3322
|
max: max,
|
|
3280
3323
|
smallestMin: smallestMin,
|
|
3281
3324
|
greatestMax: greatestMax,
|
|
3282
|
-
rate: rate != null ? AmountUtils.trim(rate,
|
|
3325
|
+
rate: rate != null ? AmountUtils.trim(rate, _this8._maxRateDigits) : null,
|
|
3283
3326
|
durationMinutesRange: (_bestOpt$duration = bestOpt.duration) != null ? _bestOpt$duration : null,
|
|
3284
3327
|
rawSwapData: bestOpt
|
|
3285
3328
|
};
|
|
@@ -3294,8 +3337,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3294
3337
|
return result;
|
|
3295
3338
|
});
|
|
3296
3339
|
}, function (e) {
|
|
3297
|
-
var _e$
|
|
3298
|
-
if ((e == null || (_e$
|
|
3340
|
+
var _e$response4;
|
|
3341
|
+
if ((e == null || (_e$response4 = e.response) == null ? void 0 : _e$response4.status) === 429) {
|
|
3299
3342
|
return {
|
|
3300
3343
|
result: false,
|
|
3301
3344
|
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
|
|
@@ -3310,7 +3353,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3310
3353
|
};
|
|
3311
3354
|
_proto.createSwap = function createSwap(fromCoin, toCoin, amount, toAddress, refundAddress, rawSwapData, clientIpAddress) {
|
|
3312
3355
|
try {
|
|
3313
|
-
var
|
|
3356
|
+
var _this9 = this;
|
|
3314
3357
|
var loggerSource = "createSwap";
|
|
3315
3358
|
var partner = rawSwapData == null ? void 0 : rawSwapData.partner;
|
|
3316
3359
|
return Promise.resolve(_catch$2(function () {
|
|
@@ -3321,12 +3364,12 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3321
3364
|
) {
|
|
3322
3365
|
throw new Error("Invalid raw swap data: " + safeStringify(rawSwapData));
|
|
3323
3366
|
}
|
|
3324
|
-
return Promise.resolve(
|
|
3325
|
-
var
|
|
3326
|
-
var toCurrencyExtraId = (
|
|
3367
|
+
return Promise.resolve(_this9._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
3368
|
+
var _this9$_supportedCoin, _this9$_supportedCoin2;
|
|
3369
|
+
var toCurrencyExtraId = (_this9$_supportedCoin = (_this9$_supportedCoin2 = _this9._supportedCoins.find(function (item) {
|
|
3327
3370
|
var _item$coin4;
|
|
3328
3371
|
return ((_item$coin4 = item.coin) == null ? void 0 : _item$coin4.ticker) === (toCoin == null ? void 0 : toCoin.ticker);
|
|
3329
|
-
})) == null ? void 0 :
|
|
3372
|
+
})) == null ? void 0 : _this9$_supportedCoin2.extraId) != null ? _this9$_supportedCoin : "";
|
|
3330
3373
|
var requestData = {
|
|
3331
3374
|
partner: partner,
|
|
3332
3375
|
fromCurrency: rawSwapData == null ? void 0 : rawSwapData.fromCurrency,
|
|
@@ -3342,7 +3385,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3342
3385
|
refund: refundAddress
|
|
3343
3386
|
};
|
|
3344
3387
|
Logger.log("Sending create request: " + safeStringify(requestData), loggerSource);
|
|
3345
|
-
return Promise.resolve(axios.post(
|
|
3388
|
+
return Promise.resolve(axios.post(_this9._URL + "/api/v2/exchange", requestData)).then(function (response) {
|
|
3346
3389
|
var result = response.data;
|
|
3347
3390
|
Logger.log("Creation result " + safeStringify(result), loggerSource);
|
|
3348
3391
|
if (result != null && result.id) {
|
|
@@ -3366,7 +3409,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3366
3409
|
toCoin: toCoin,
|
|
3367
3410
|
toAmount: AmountUtils.trim(result == null || (_result$to4 = result.to) == null ? void 0 : _result$to4.amount, toCoin.digits),
|
|
3368
3411
|
toAddress: result == null || (_result$to5 = result.to) == null ? void 0 : _result$to5.address,
|
|
3369
|
-
rate: AmountUtils.trim(rate,
|
|
3412
|
+
rate: AmountUtils.trim(rate, _this9._maxRateDigits)
|
|
3370
3413
|
};
|
|
3371
3414
|
}
|
|
3372
3415
|
var errorMessage = "Swap creation succeeded but the response is wrong: " + safeStringify(response);
|
|
@@ -3375,7 +3418,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3375
3418
|
});
|
|
3376
3419
|
});
|
|
3377
3420
|
}, function (e) {
|
|
3378
|
-
var _e$
|
|
3421
|
+
var _e$response5, _e$response6;
|
|
3379
3422
|
Logger.logError(e, loggerSource, "Failed to create swap. Error is: " + safeStringify(e));
|
|
3380
3423
|
var composeFailResult = function composeFailResult(reason) {
|
|
3381
3424
|
return {
|
|
@@ -3384,8 +3427,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3384
3427
|
partner: partner
|
|
3385
3428
|
};
|
|
3386
3429
|
};
|
|
3387
|
-
var status = e == null || (_e$
|
|
3388
|
-
var data = e == null || (_e$
|
|
3430
|
+
var status = e == null || (_e$response5 = e.response) == null ? void 0 : _e$response5.status;
|
|
3431
|
+
var data = e == null || (_e$response6 = e.response) == null ? void 0 : _e$response6.data;
|
|
3389
3432
|
if (status === 429) {
|
|
3390
3433
|
Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
|
|
3391
3434
|
return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
|
|
@@ -3434,7 +3477,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3434
3477
|
};
|
|
3435
3478
|
_proto.getExistingSwapsDetailsAndStatus = function getExistingSwapsDetailsAndStatus(swapIds) {
|
|
3436
3479
|
try {
|
|
3437
|
-
var
|
|
3480
|
+
var _this10 = this;
|
|
3438
3481
|
var loggerSource = "getExistingSwapsDetailsAndStatus";
|
|
3439
3482
|
return Promise.resolve(_catch$2(function () {
|
|
3440
3483
|
if (swapIds.find(function (id) {
|
|
@@ -3445,7 +3488,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3445
3488
|
var getNotFailingOn404 = function getNotFailingOn404(swapId) {
|
|
3446
3489
|
try {
|
|
3447
3490
|
return Promise.resolve(_catch$2(function () {
|
|
3448
|
-
return Promise.resolve(axios.get(
|
|
3491
|
+
return Promise.resolve(axios.get(_this10._URL + "/api/v2/exchange/" + swapId));
|
|
3449
3492
|
}, function (error) {
|
|
3450
3493
|
var _error$response;
|
|
3451
3494
|
if ((error == null || (_error$response = error.response) == null ? void 0 : _error$response.status) === 404) return [];
|
|
@@ -3462,13 +3505,13 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3462
3505
|
var swaps = wo404.map(function (r) {
|
|
3463
3506
|
return r.data;
|
|
3464
3507
|
}).map(function (swap, index) {
|
|
3465
|
-
var
|
|
3466
|
-
var fromCoin = (
|
|
3508
|
+
var _this10$_supportedCoi, _this10$_supportedCoi2;
|
|
3509
|
+
var fromCoin = (_this10$_supportedCoi = _this10._supportedCoins.find(function (i) {
|
|
3467
3510
|
return i.code === swap.from.code && i.network === swap.from.network;
|
|
3468
|
-
})) == null ? void 0 :
|
|
3469
|
-
var toCoin = (
|
|
3511
|
+
})) == null ? void 0 : _this10$_supportedCoi.coin;
|
|
3512
|
+
var toCoin = (_this10$_supportedCoi2 = _this10._supportedCoins.find(function (i) {
|
|
3470
3513
|
return i.code === swap.to.code && i.network === swap.to.network;
|
|
3471
|
-
})) == null ? void 0 :
|
|
3514
|
+
})) == null ? void 0 : _this10$_supportedCoi2.coin;
|
|
3472
3515
|
if (!fromCoin || !toCoin) {
|
|
3473
3516
|
return []; // We skip swaps with not supported coins for now
|
|
3474
3517
|
}
|
|
@@ -3477,10 +3520,10 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3477
3520
|
};
|
|
3478
3521
|
var expiresAt = toUtcTimestamp(swap.timestamps.expiresAt);
|
|
3479
3522
|
var isExpiredByTime = expiresAt < Date.now();
|
|
3480
|
-
var status =
|
|
3523
|
+
var status = _this10._mapSwapspaceStatusToRabbitStatus(swap.status, isExpiredByTime);
|
|
3481
3524
|
var toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
|
|
3482
3525
|
var addressToSendCoinsToSwapspace = swap.from.address;
|
|
3483
|
-
return new ExistingSwap(swapIds[index], status, toUtcTimestamp(swap.timestamps.createdAt), expiresAt, swap.confirmations, AmountUtils.trim(swap.rate,
|
|
3526
|
+
return new ExistingSwap(swapIds[index], status, toUtcTimestamp(swap.timestamps.createdAt), expiresAt, swap.confirmations, AmountUtils.trim(swap.rate, _this10._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);
|
|
3484
3527
|
}).flat();
|
|
3485
3528
|
Logger.log("Swap details result " + safeStringify(swaps), loggerSource);
|
|
3486
3529
|
return {
|
|
@@ -3489,7 +3532,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3489
3532
|
};
|
|
3490
3533
|
});
|
|
3491
3534
|
}, function (e) {
|
|
3492
|
-
var _e$
|
|
3535
|
+
var _e$response7, _e$response8;
|
|
3493
3536
|
Logger.logError(e, loggerSource, "Failed to get swap details. Error is: " + safeStringify(e));
|
|
3494
3537
|
var composeFailResult = function composeFailResult(reason) {
|
|
3495
3538
|
return {
|
|
@@ -3497,8 +3540,8 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
|
3497
3540
|
reason: reason
|
|
3498
3541
|
};
|
|
3499
3542
|
};
|
|
3500
|
-
var status = e == null || (_e$
|
|
3501
|
-
var data = e == null || (_e$
|
|
3543
|
+
var status = e == null || (_e$response7 = e.response) == null ? void 0 : _e$response7.status;
|
|
3544
|
+
var data = e == null || (_e$response8 = e.response) == null ? void 0 : _e$response8.data;
|
|
3502
3545
|
if (status === 429) {
|
|
3503
3546
|
Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
|
|
3504
3547
|
return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
|
|
@@ -3876,11 +3919,26 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
3876
3919
|
return Promise.reject(e);
|
|
3877
3920
|
}
|
|
3878
3921
|
};
|
|
3879
|
-
_proto.
|
|
3922
|
+
_proto.getAllSupportedCurrenciesListForPublicSwap = function getAllSupportedCurrenciesListForPublicSwap() {
|
|
3880
3923
|
try {
|
|
3881
3924
|
var _this2 = this;
|
|
3925
|
+
var loggerSource = "getAllSupportedCurrenciesListForPublicSwap";
|
|
3882
3926
|
return Promise.resolve(_catch(function () {
|
|
3883
|
-
return Promise.resolve(_this2.
|
|
3927
|
+
return Promise.resolve(_this2._swapProvider.getAllSupportedCurrencies()).then(function (result) {
|
|
3928
|
+
var _result$coins;
|
|
3929
|
+
if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
|
|
3930
|
+
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
3931
|
+
return {
|
|
3932
|
+
result: false,
|
|
3933
|
+
reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
|
|
3934
|
+
};
|
|
3935
|
+
}
|
|
3936
|
+
Logger.log("Retrieved " + (result == null || (_result$coins = result.coins) == null ? void 0 : _result$coins.length) + " supported currencies for swap", loggerSource);
|
|
3937
|
+
return {
|
|
3938
|
+
result: true,
|
|
3939
|
+
coins: result.coins
|
|
3940
|
+
};
|
|
3941
|
+
});
|
|
3884
3942
|
}, function (e) {
|
|
3885
3943
|
improveAndRethrow(e, "getDepositCurrenciesListForPublicSwap");
|
|
3886
3944
|
}));
|
|
@@ -3888,11 +3946,23 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
3888
3946
|
return Promise.reject(e);
|
|
3889
3947
|
}
|
|
3890
3948
|
};
|
|
3891
|
-
_proto.
|
|
3949
|
+
_proto.getDepositCurrenciesListForPublicSwap = function getDepositCurrenciesListForPublicSwap() {
|
|
3892
3950
|
try {
|
|
3893
3951
|
var _this3 = this;
|
|
3894
3952
|
return Promise.resolve(_catch(function () {
|
|
3895
|
-
return Promise.resolve(_this3._getCurrenciesListForPublicSwap(
|
|
3953
|
+
return Promise.resolve(_this3._getCurrenciesListForPublicSwap(false));
|
|
3954
|
+
}, function (e) {
|
|
3955
|
+
improveAndRethrow(e, "getDepositCurrenciesListForPublicSwap");
|
|
3956
|
+
}));
|
|
3957
|
+
} catch (e) {
|
|
3958
|
+
return Promise.reject(e);
|
|
3959
|
+
}
|
|
3960
|
+
};
|
|
3961
|
+
_proto.getWithdrawCurrenciesListForPublicSwap = function getWithdrawCurrenciesListForPublicSwap() {
|
|
3962
|
+
try {
|
|
3963
|
+
var _this4 = this;
|
|
3964
|
+
return Promise.resolve(_catch(function () {
|
|
3965
|
+
return Promise.resolve(_this4._getCurrenciesListForPublicSwap(true));
|
|
3896
3966
|
}, function (e) {
|
|
3897
3967
|
improveAndRethrow(e, "getWithdrawCurrenciesListForPublicSwap");
|
|
3898
3968
|
}));
|
|
@@ -3905,11 +3975,11 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
3905
3975
|
withdraw = false;
|
|
3906
3976
|
}
|
|
3907
3977
|
try {
|
|
3908
|
-
var
|
|
3978
|
+
var _this5 = this;
|
|
3909
3979
|
var loggerSource = "getCurrenciesListForPublicSwap";
|
|
3910
3980
|
return Promise.resolve(_catch(function () {
|
|
3911
|
-
return Promise.resolve(withdraw ?
|
|
3912
|
-
var _result$
|
|
3981
|
+
return Promise.resolve(withdraw ? _this5._swapProvider.getWithdrawalCurrencies() : _this5._swapProvider.getDepositCurrencies()).then(function (result) {
|
|
3982
|
+
var _result$coins2;
|
|
3913
3983
|
if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
|
|
3914
3984
|
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
3915
3985
|
return {
|
|
@@ -3917,12 +3987,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
3917
3987
|
reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
|
|
3918
3988
|
};
|
|
3919
3989
|
}
|
|
3920
|
-
Logger.log("Retrieved " + (result == null || (_result$
|
|
3921
|
-
if (result.coins.length > 1) {
|
|
3922
|
-
var temp = result.coins[0];
|
|
3923
|
-
result.coins[0] = result.coins[1];
|
|
3924
|
-
result.coins[1] = temp;
|
|
3925
|
-
}
|
|
3990
|
+
Logger.log("Retrieved " + (result == null || (_result$coins2 = result.coins) == null ? void 0 : _result$coins2.length) + " supported currencies for swap", loggerSource);
|
|
3926
3991
|
return {
|
|
3927
3992
|
result: true,
|
|
3928
3993
|
coins: result.coins
|
|
@@ -3955,9 +4020,9 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
3955
4020
|
;
|
|
3956
4021
|
_proto.getInitialPublicSwapData = function getInitialPublicSwapData(fromCoin, toCoin) {
|
|
3957
4022
|
try {
|
|
3958
|
-
var
|
|
4023
|
+
var _this6 = this;
|
|
3959
4024
|
return Promise.resolve(_catch(function () {
|
|
3960
|
-
return Promise.resolve(SwapUtils.getInitialSwapData(
|
|
4025
|
+
return Promise.resolve(SwapUtils.getInitialSwapData(_this6._swapProvider, fromCoin, toCoin)).then(function (result) {
|
|
3961
4026
|
if (!result.result) {
|
|
3962
4027
|
if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
|
|
3963
4028
|
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
@@ -4004,13 +4069,13 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4004
4069
|
;
|
|
4005
4070
|
_proto.getPublicSwapDetails = function getPublicSwapDetails(fromCoin, toCoin, fromAmountCoins) {
|
|
4006
4071
|
try {
|
|
4007
|
-
var
|
|
4072
|
+
var _this7 = this;
|
|
4008
4073
|
var loggerSource = "getPublicSwapDetails";
|
|
4009
4074
|
return Promise.resolve(_catch(function () {
|
|
4010
|
-
return Promise.resolve(
|
|
4011
|
-
var
|
|
4012
|
-
var coinUsdtRate = (
|
|
4013
|
-
return Promise.resolve(
|
|
4075
|
+
return Promise.resolve(_this7._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this7$_swapProvider$) {
|
|
4076
|
+
var _this7$_swapProvider$2;
|
|
4077
|
+
var coinUsdtRate = (_this7$_swapProvider$2 = _this7$_swapProvider$ == null ? void 0 : _this7$_swapProvider$.rate) != null ? _this7$_swapProvider$2 : null;
|
|
4078
|
+
return Promise.resolve(_this7._swapProvider.getSwapInfo(fromCoin, toCoin, fromAmountCoins, coinUsdtRate)).then(function (details) {
|
|
4014
4079
|
var _result$swapCreationI, _result$swapCreationI2;
|
|
4015
4080
|
var min = details.result ? details.min : details.smallestMin;
|
|
4016
4081
|
var max = details.result ? details.max : details.greatestMax;
|
|
@@ -4102,7 +4167,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4102
4167
|
;
|
|
4103
4168
|
_proto.createPublicSwap = function createPublicSwap(fromCoin, toCoin, fromAmount, swapCreationInfo, toAddress, refundAddress, clientIp) {
|
|
4104
4169
|
try {
|
|
4105
|
-
var
|
|
4170
|
+
var _this8 = this;
|
|
4106
4171
|
var loggerSource = "createPublicSwap";
|
|
4107
4172
|
return Promise.resolve(_catch(function () {
|
|
4108
4173
|
var _swapCreationInfo$fro, _swapCreationInfo$toC;
|
|
@@ -4113,10 +4178,10 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4113
4178
|
fromCoin: swapCreationInfo == null || (_swapCreationInfo$fro = swapCreationInfo.fromCoin) == null ? void 0 : _swapCreationInfo$fro.ticker,
|
|
4114
4179
|
toCoin: swapCreationInfo == null || (_swapCreationInfo$toC = swapCreationInfo.toCoin) == null ? void 0 : _swapCreationInfo$toC.ticker
|
|
4115
4180
|
})), loggerSource);
|
|
4116
|
-
return Promise.resolve(
|
|
4181
|
+
return Promise.resolve(_this8._swapProvider.createSwap(fromCoin, toCoin, fromAmount, toAddress, refundAddress, swapCreationInfo.rawSwapData, clientIp)).then(function (result) {
|
|
4117
4182
|
var _exit;
|
|
4118
|
-
function _temp5(
|
|
4119
|
-
if (_exit) return
|
|
4183
|
+
function _temp5(_result8) {
|
|
4184
|
+
if (_exit) return _result8;
|
|
4120
4185
|
throw new Error("Unexpected result from provider " + safeStringify(result));
|
|
4121
4186
|
}
|
|
4122
4187
|
Logger.log("Created:" + safeStringify(_extends({}, result, {
|
|
@@ -4158,7 +4223,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4158
4223
|
durationMinutesRange: swapCreationInfo.durationMinutesRange,
|
|
4159
4224
|
address: result.fromAddress // CRITICAL: this is the address to send coins to swaps provider
|
|
4160
4225
|
};
|
|
4161
|
-
|
|
4226
|
+
_this8._savePublicSwapIdLocally(result.swapId);
|
|
4162
4227
|
Logger.log("Returning: " + safeStringify(_extends({}, toReturn, {
|
|
4163
4228
|
fromCoin: fromCoin == null ? void 0 : fromCoin.ticker,
|
|
4164
4229
|
toCoin: toCoin == null ? void 0 : toCoin.ticker
|
|
@@ -4169,12 +4234,12 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4169
4234
|
var _fromAmountFiat = null,
|
|
4170
4235
|
_toAmountFiat = null;
|
|
4171
4236
|
var _temp2 = _catch(function () {
|
|
4172
|
-
return Promise.resolve(
|
|
4173
|
-
var
|
|
4174
|
-
var fromCoinUsdtRate = (
|
|
4175
|
-
return Promise.resolve(
|
|
4176
|
-
var
|
|
4177
|
-
var toCoinUsdtRate = (
|
|
4237
|
+
return Promise.resolve(_this8._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this8$_swapProvider$) {
|
|
4238
|
+
var _this8$_swapProvider$3;
|
|
4239
|
+
var fromCoinUsdtRate = (_this8$_swapProvider$3 = _this8$_swapProvider$ == null ? void 0 : _this8$_swapProvider$.rate) != null ? _this8$_swapProvider$3 : null;
|
|
4240
|
+
return Promise.resolve(_this8._swapProvider.getCoinToUSDTRate(fromCoin)).then(function (_this8$_swapProvider$2) {
|
|
4241
|
+
var _this8$_swapProvider$4;
|
|
4242
|
+
var toCoinUsdtRate = (_this8$_swapProvider$4 = _this8$_swapProvider$2 == null ? void 0 : _this8$_swapProvider$2.rate) != null ? _this8$_swapProvider$4 : null;
|
|
4178
4243
|
if (fromCoinUsdtRate != null && result.fromAmount != null) {
|
|
4179
4244
|
_fromAmountFiat = BigNumber(result.fromAmount).times(fromCoinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
|
|
4180
4245
|
}
|
|
@@ -4214,10 +4279,10 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4214
4279
|
;
|
|
4215
4280
|
_proto.getPublicExistingSwapDetailsAndStatus = function getPublicExistingSwapDetailsAndStatus(swapIds) {
|
|
4216
4281
|
try {
|
|
4217
|
-
var
|
|
4282
|
+
var _this9 = this;
|
|
4218
4283
|
var loggerSource = "getPublicExistingSwapDetailsAndStatus";
|
|
4219
4284
|
return Promise.resolve(_catch(function () {
|
|
4220
|
-
return Promise.resolve(SwapUtils.getExistingSwapsDetailsWithFiatAmounts(
|
|
4285
|
+
return Promise.resolve(SwapUtils.getExistingSwapsDetailsWithFiatAmounts(_this9._swapProvider, swapIds)).then(function (result) {
|
|
4221
4286
|
if (!(result != null && result.result)) {
|
|
4222
4287
|
if (result.reason === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
|
|
4223
4288
|
SwapUtils.safeHandleRequestsLimitExceeding();
|
|
@@ -4252,20 +4317,20 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4252
4317
|
_proto.getPublicSwapsHistory = function getPublicSwapsHistory() {
|
|
4253
4318
|
try {
|
|
4254
4319
|
var _exit2;
|
|
4255
|
-
var
|
|
4320
|
+
var _this10 = this;
|
|
4256
4321
|
return Promise.resolve(_catch(function () {
|
|
4257
|
-
function _temp7(
|
|
4258
|
-
return _exit2 ?
|
|
4322
|
+
function _temp7(_result10) {
|
|
4323
|
+
return _exit2 ? _result10 : {
|
|
4259
4324
|
result: true,
|
|
4260
4325
|
swaps: []
|
|
4261
4326
|
};
|
|
4262
4327
|
}
|
|
4263
|
-
var swapIds =
|
|
4328
|
+
var swapIds = _this10._getPublicSwapIdsSavedLocally();
|
|
4264
4329
|
var _temp6 = function () {
|
|
4265
4330
|
if (swapIds.length) {
|
|
4266
|
-
return Promise.resolve(
|
|
4331
|
+
return Promise.resolve(_this10.getPublicExistingSwapDetailsAndStatus(swapIds)).then(function (_await$_this10$getPub) {
|
|
4267
4332
|
_exit2 = 1;
|
|
4268
|
-
return _await$
|
|
4333
|
+
return _await$_this10$getPub;
|
|
4269
4334
|
});
|
|
4270
4335
|
}
|
|
4271
4336
|
}();
|
|
@@ -4333,9 +4398,9 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4333
4398
|
*/;
|
|
4334
4399
|
_proto.getAssetToUsdtRate = function getAssetToUsdtRate(asset) {
|
|
4335
4400
|
try {
|
|
4336
|
-
var
|
|
4401
|
+
var _this11 = this;
|
|
4337
4402
|
return Promise.resolve(_catch(function () {
|
|
4338
|
-
return Promise.resolve(
|
|
4403
|
+
return Promise.resolve(_this11._swapProvider.getCoinToUSDTRate(asset)).then(function (result) {
|
|
4339
4404
|
var _result$rate;
|
|
4340
4405
|
return (_result$rate = result == null ? void 0 : result.rate) != null ? _result$rate : null;
|
|
4341
4406
|
});
|