@rabbitio/ui-kit 1.0.0-beta.11 → 1.0.0-beta.13
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 +736 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +561 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +732 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +739 -4
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -1
- package/src/common/utils/emailAPI.js +18 -0
- package/src/index.js +5 -0
- package/src/swaps-lib/external-apis/swapspaceSwapProvider.js +798 -0
- package/src/swaps-lib/models/existingSwapWithFiatData.js +115 -0
- package/src/swaps-lib/models/publicSwapCreationInfo.js +40 -0
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
var React = require('react');
|
|
2
2
|
var bignumber_js = require('bignumber.js');
|
|
3
|
+
var axios = require('axios');
|
|
3
4
|
|
|
4
5
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
5
6
|
|
|
6
7
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
8
|
+
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
7
9
|
|
|
8
10
|
function createCommonjsModule(fn) {
|
|
9
11
|
var module = { exports: {} };
|
|
@@ -1572,6 +1574,18 @@ function _extends() {
|
|
|
1572
1574
|
};
|
|
1573
1575
|
return _extends.apply(this, arguments);
|
|
1574
1576
|
}
|
|
1577
|
+
function _inheritsLoose(subClass, superClass) {
|
|
1578
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
1579
|
+
subClass.prototype.constructor = subClass;
|
|
1580
|
+
_setPrototypeOf(subClass, superClass);
|
|
1581
|
+
}
|
|
1582
|
+
function _setPrototypeOf(o, p) {
|
|
1583
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
1584
|
+
o.__proto__ = p;
|
|
1585
|
+
return o;
|
|
1586
|
+
};
|
|
1587
|
+
return _setPrototypeOf(o, p);
|
|
1588
|
+
}
|
|
1575
1589
|
function _unsupportedIterableToArray(o, minLen) {
|
|
1576
1590
|
if (!o) return;
|
|
1577
1591
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -2491,6 +2505,40 @@ var Cache = /*#__PURE__*/function () {
|
|
|
2491
2505
|
return Cache;
|
|
2492
2506
|
}();
|
|
2493
2507
|
|
|
2508
|
+
function _catch$1(body, recover) {
|
|
2509
|
+
try {
|
|
2510
|
+
var result = body();
|
|
2511
|
+
} catch (e) {
|
|
2512
|
+
return recover(e);
|
|
2513
|
+
}
|
|
2514
|
+
if (result && result.then) {
|
|
2515
|
+
return result.then(void 0, recover);
|
|
2516
|
+
}
|
|
2517
|
+
return result;
|
|
2518
|
+
}
|
|
2519
|
+
var EmailsApi = /*#__PURE__*/function () {
|
|
2520
|
+
function EmailsApi() {}
|
|
2521
|
+
EmailsApi.sendEmail = function sendEmail(subject, body) {
|
|
2522
|
+
try {
|
|
2523
|
+
var _this = this;
|
|
2524
|
+
var _temp = _catch$1(function () {
|
|
2525
|
+
var url = window.location.protocol + "//" + window.location.host + "/api/v1/" + _this.serverEndpointEntity;
|
|
2526
|
+
return Promise.resolve(axios__default["default"].post(url, {
|
|
2527
|
+
subject: subject,
|
|
2528
|
+
body: body
|
|
2529
|
+
})).then(function () {});
|
|
2530
|
+
}, function (e) {
|
|
2531
|
+
improveAndRethrow(e, "sendEmail", subject + body);
|
|
2532
|
+
});
|
|
2533
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
|
2534
|
+
} catch (e) {
|
|
2535
|
+
return Promise.reject(e);
|
|
2536
|
+
}
|
|
2537
|
+
};
|
|
2538
|
+
return EmailsApi;
|
|
2539
|
+
}();
|
|
2540
|
+
EmailsApi.serverEndpointEntity = "emails";
|
|
2541
|
+
|
|
2494
2542
|
var ExistingSwap =
|
|
2495
2543
|
/**
|
|
2496
2544
|
* @param swapId {string}
|
|
@@ -2532,6 +2580,81 @@ partner) {
|
|
|
2532
2580
|
this.partner = partner;
|
|
2533
2581
|
};
|
|
2534
2582
|
|
|
2583
|
+
var ExistingSwapWithFiatData = /*#__PURE__*/function (_ExistingSwap) {
|
|
2584
|
+
_inheritsLoose(ExistingSwapWithFiatData, _ExistingSwap);
|
|
2585
|
+
/**
|
|
2586
|
+
* @param swapId {string}
|
|
2587
|
+
* @param status {SwapProvider.SWAP_STATUSES}
|
|
2588
|
+
* @param createdAt {number}
|
|
2589
|
+
* @param expiresAt {number}
|
|
2590
|
+
* @param confirmations {number}
|
|
2591
|
+
* @param rate {string}
|
|
2592
|
+
* @param refundAddress {string}
|
|
2593
|
+
* @param fromCoin {Coin}
|
|
2594
|
+
* @param fromAmount {string}
|
|
2595
|
+
* @param fromTransactionId {string}
|
|
2596
|
+
* @param toCoin {Coin}
|
|
2597
|
+
* @param toAmount {string}
|
|
2598
|
+
* @param toTransactionId {string|null}
|
|
2599
|
+
* @param toAddress {string}
|
|
2600
|
+
* @param partner {string}
|
|
2601
|
+
* @param fromAmountFiat {number}
|
|
2602
|
+
* @param toAmountFiat {number}
|
|
2603
|
+
* @param fiatCurrencyCode {string}
|
|
2604
|
+
* @param fiatCurrencyDecimals {number}
|
|
2605
|
+
*/
|
|
2606
|
+
function ExistingSwapWithFiatData(swapId, status, createdAt, expiresAt, confirmations, rate, refundAddress, payToAddress, fromCoin, fromAmount, fromTransactionId, fromTransactionLink, toCoin, toAmount, toTransactionId, toTransactionLink, toAddress, partner, fromAmountFiat, toAmountFiat, fiatCurrencyCode, fiatCurrencyDecimals) {
|
|
2607
|
+
var _this;
|
|
2608
|
+
_this = _ExistingSwap.call(this, swapId, status, createdAt, expiresAt, confirmations, rate, refundAddress, payToAddress, fromCoin, fromAmount, fromTransactionId, fromTransactionLink, toCoin, toAmount, toTransactionId, toTransactionLink, toAddress, partner) || this;
|
|
2609
|
+
_this.fromAmountFiat = fromAmountFiat;
|
|
2610
|
+
_this.toAmountFiat = toAmountFiat;
|
|
2611
|
+
_this.fiatCurrencyCode = fiatCurrencyCode;
|
|
2612
|
+
_this.fiatCurrencyDecimals = fiatCurrencyDecimals;
|
|
2613
|
+
return _this;
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
/**
|
|
2617
|
+
* @param existingSwap {ExistingSwap}
|
|
2618
|
+
* @param fromAmountFiat {number}
|
|
2619
|
+
* @param toAmountFiat {number}
|
|
2620
|
+
* @param fiatCurrencyCode {string}
|
|
2621
|
+
* @param fiatCurrencyDecimals {number}
|
|
2622
|
+
* @return {ExistingSwapWithFiatData}
|
|
2623
|
+
*/
|
|
2624
|
+
ExistingSwapWithFiatData.fromExistingSwap = function fromExistingSwap(existingSwap, fromAmountFiat, toAmountFiat, fiatCurrencyCode, fiatCurrencyDecimals) {
|
|
2625
|
+
return new ExistingSwapWithFiatData(existingSwap.swapId, existingSwap.status, existingSwap.createdAt, existingSwap.expiresAt, existingSwap.confirmations, existingSwap.rate, existingSwap.refundAddress, existingSwap.payToAddress, existingSwap.fromCoin, existingSwap.fromAmount, existingSwap.fromTransactionId, existingSwap.fromTransactionLink, existingSwap.toCoin, existingSwap.toAmount, existingSwap.toTransactionId, existingSwap.toTransactionLink, existingSwap.toAddress, existingSwap.partner, fromAmountFiat, toAmountFiat, fiatCurrencyCode, fiatCurrencyDecimals);
|
|
2626
|
+
};
|
|
2627
|
+
return ExistingSwapWithFiatData;
|
|
2628
|
+
}(ExistingSwap);
|
|
2629
|
+
|
|
2630
|
+
var PublicSwapCreationInfo =
|
|
2631
|
+
/**
|
|
2632
|
+
* @param fromCoin {Coin}
|
|
2633
|
+
* @param toCoin {Coin}
|
|
2634
|
+
* @param fromAmountCoins {string}
|
|
2635
|
+
* @param toAmountCoins {string}
|
|
2636
|
+
* @param rate {string}
|
|
2637
|
+
* @param rawSwapData {Object}
|
|
2638
|
+
* @param min {string}
|
|
2639
|
+
* @param fiatMin {number}
|
|
2640
|
+
* @param max {string}
|
|
2641
|
+
* @param fiatMax {number}
|
|
2642
|
+
* @param durationMinutesRange {string}
|
|
2643
|
+
*/
|
|
2644
|
+
function PublicSwapCreationInfo(fromCoin, toCoin, fromAmountCoins, toAmountCoins, rate, rawSwapData, min, fiatMin, max, fiatMax, durationMinutesRange) {
|
|
2645
|
+
this.fromCoin = fromCoin;
|
|
2646
|
+
this.toCoin = toCoin;
|
|
2647
|
+
this.fromAmountCoins = fromAmountCoins;
|
|
2648
|
+
this.toAmountCoins = toAmountCoins;
|
|
2649
|
+
this.rate = rate;
|
|
2650
|
+
this.rawSwapData = rawSwapData;
|
|
2651
|
+
this.min = min;
|
|
2652
|
+
this.fiatMin = fiatMin;
|
|
2653
|
+
this.max = max;
|
|
2654
|
+
this.fiatMax = fiatMax;
|
|
2655
|
+
this.durationMinutesRange = durationMinutesRange;
|
|
2656
|
+
};
|
|
2657
|
+
|
|
2535
2658
|
var SwapProvider = /*#__PURE__*/function () {
|
|
2536
2659
|
function SwapProvider() {}
|
|
2537
2660
|
var _proto = SwapProvider.prototype;
|
|
@@ -2735,20 +2858,633 @@ SwapProvider.SWAP_STATUSES = {
|
|
|
2735
2858
|
FAILED: "failed" // public +
|
|
2736
2859
|
};
|
|
2737
2860
|
|
|
2861
|
+
function _catch(body, recover) {
|
|
2862
|
+
try {
|
|
2863
|
+
var result = body();
|
|
2864
|
+
} catch (e) {
|
|
2865
|
+
return recover(e);
|
|
2866
|
+
}
|
|
2867
|
+
if (result && result.then) {
|
|
2868
|
+
return result.then(void 0, recover);
|
|
2869
|
+
}
|
|
2870
|
+
return result;
|
|
2871
|
+
}
|
|
2872
|
+
var BANNED_PARTNERS = ["stealthex", "changee", "coincraddle"];
|
|
2873
|
+
var FALLBACK_ICON_URL = "https://rabbit.io/asset-icons/fallback.svg";
|
|
2874
|
+
var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
|
|
2875
|
+
_inheritsLoose(SwapspaceSwapProvider, _SwapProvider);
|
|
2876
|
+
function SwapspaceSwapProvider(apiKeysProxyUrl, cache, customCoinBuilder, useRestrictedCoinsSet) {
|
|
2877
|
+
var _this;
|
|
2878
|
+
if (customCoinBuilder === void 0) {
|
|
2879
|
+
customCoinBuilder = function customCoinBuilder(coin, network) {
|
|
2880
|
+
return null;
|
|
2881
|
+
};
|
|
2882
|
+
}
|
|
2883
|
+
if (useRestrictedCoinsSet === void 0) {
|
|
2884
|
+
useRestrictedCoinsSet = true;
|
|
2885
|
+
}
|
|
2886
|
+
_this = _SwapProvider.call(this) || this;
|
|
2887
|
+
_this._supportedCoins = [];
|
|
2888
|
+
_this._URL = apiKeysProxyUrl + "/swapspace";
|
|
2889
|
+
_this._maxRateDigits = 20;
|
|
2890
|
+
_this.useRestrictedCoinsSet = useRestrictedCoinsSet;
|
|
2891
|
+
_this._customCoinBuilder = customCoinBuilder;
|
|
2892
|
+
_this._cache = cache;
|
|
2893
|
+
return _this;
|
|
2894
|
+
}
|
|
2895
|
+
var _proto = SwapspaceSwapProvider.prototype;
|
|
2896
|
+
_proto.getSwapCreationInfoTtlMs = function getSwapCreationInfoTtlMs() {
|
|
2897
|
+
/* Actually 2 minutes and only relevant for some partners, but we use it
|
|
2898
|
+
* (and even a bit smaller value) for better consistency */
|
|
2899
|
+
return 110000;
|
|
2900
|
+
};
|
|
2901
|
+
_proto.getDepositCurrencies = function getDepositCurrencies() {
|
|
2902
|
+
try {
|
|
2903
|
+
var _this2 = this;
|
|
2904
|
+
var loggerSource = "getDepositCurrencies";
|
|
2905
|
+
return Promise.resolve(_catch(function () {
|
|
2906
|
+
return Promise.resolve(_this2._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
2907
|
+
var _this2$_supportedCoin;
|
|
2908
|
+
Logger.log("We have " + ((_this2$_supportedCoin = _this2._supportedCoins) == null ? void 0 : _this2$_supportedCoin.length) + " supported coins, getting depositable", loggerSource);
|
|
2909
|
+
return {
|
|
2910
|
+
result: true,
|
|
2911
|
+
coins: _this2._supportedCoins.filter(function (item) {
|
|
2912
|
+
return item.deposit;
|
|
2913
|
+
}).map(function (item) {
|
|
2914
|
+
return item.coin;
|
|
2915
|
+
})
|
|
2916
|
+
};
|
|
2917
|
+
});
|
|
2918
|
+
}, function (e) {
|
|
2919
|
+
var _e$response;
|
|
2920
|
+
if ((e == null || (_e$response = e.response) == null ? void 0 : _e$response.status) === 429) {
|
|
2921
|
+
return {
|
|
2922
|
+
result: false,
|
|
2923
|
+
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
|
|
2924
|
+
};
|
|
2925
|
+
}
|
|
2926
|
+
improveAndRethrow(e, loggerSource);
|
|
2927
|
+
}));
|
|
2928
|
+
} catch (e) {
|
|
2929
|
+
return Promise.reject(e);
|
|
2930
|
+
}
|
|
2931
|
+
};
|
|
2932
|
+
_proto.getWithdrawalCurrencies = function getWithdrawalCurrencies(exceptCurrency) {
|
|
2933
|
+
if (exceptCurrency === void 0) {
|
|
2934
|
+
exceptCurrency = null;
|
|
2935
|
+
}
|
|
2936
|
+
try {
|
|
2937
|
+
var _this3 = this;
|
|
2938
|
+
var loggerSource = "getWithdrawalCurrencies";
|
|
2939
|
+
return Promise.resolve(_catch(function () {
|
|
2940
|
+
return Promise.resolve(_this3._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
2941
|
+
var _this3$_supportedCoin;
|
|
2942
|
+
Logger.log("We have " + ((_this3$_supportedCoin = _this3._supportedCoins) == null ? void 0 : _this3$_supportedCoin.length) + " supported coins, getting withdrawable", loggerSource);
|
|
2943
|
+
return {
|
|
2944
|
+
result: true,
|
|
2945
|
+
coins: _this3._supportedCoins.filter(function (item) {
|
|
2946
|
+
return item.withdrawal && (!exceptCurrency || item.coin !== exceptCurrency);
|
|
2947
|
+
}).map(function (item) {
|
|
2948
|
+
return item.coin;
|
|
2949
|
+
})
|
|
2950
|
+
};
|
|
2951
|
+
});
|
|
2952
|
+
}, function (e) {
|
|
2953
|
+
var _e$response2;
|
|
2954
|
+
if ((e == null || (_e$response2 = e.response) == null ? void 0 : _e$response2.status) === 429) {
|
|
2955
|
+
return {
|
|
2956
|
+
result: false,
|
|
2957
|
+
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
|
|
2958
|
+
};
|
|
2959
|
+
}
|
|
2960
|
+
improveAndRethrow(e, loggerSource);
|
|
2961
|
+
}));
|
|
2962
|
+
} catch (e) {
|
|
2963
|
+
return Promise.reject(e);
|
|
2964
|
+
}
|
|
2965
|
+
};
|
|
2966
|
+
_proto.initialize = function initialize() {
|
|
2967
|
+
try {
|
|
2968
|
+
var _this4 = this;
|
|
2969
|
+
return Promise.resolve(_this4._fetchSupportedCurrenciesIfNeeded()).then(function () {});
|
|
2970
|
+
} catch (e) {
|
|
2971
|
+
return Promise.reject(e);
|
|
2972
|
+
}
|
|
2973
|
+
};
|
|
2974
|
+
_proto.getIconUrl = function getIconUrl(coinOrTicker) {
|
|
2975
|
+
var loggerSource = "getIconUrl";
|
|
2976
|
+
try {
|
|
2977
|
+
var _this$_supportedCoins2, _this$_supportedCoins3;
|
|
2978
|
+
var coin = coinOrTicker;
|
|
2979
|
+
if (!(coinOrTicker instanceof Coin)) {
|
|
2980
|
+
var _this$_supportedCoins;
|
|
2981
|
+
coin = (_this$_supportedCoins = this._supportedCoins.find(function (i) {
|
|
2982
|
+
return i.coin.ticker === coinOrTicker;
|
|
2983
|
+
})) == null ? void 0 : _this$_supportedCoins.coin;
|
|
2984
|
+
}
|
|
2985
|
+
return (_this$_supportedCoins2 = (_this$_supportedCoins3 = this._supportedCoins.find(function (item) {
|
|
2986
|
+
return item.coin === coin;
|
|
2987
|
+
})) == null ? void 0 : _this$_supportedCoins3.iconURL) != null ? _this$_supportedCoins2 : FALLBACK_ICON_URL;
|
|
2988
|
+
} catch (e) {
|
|
2989
|
+
improveAndRethrow(e, loggerSource);
|
|
2990
|
+
}
|
|
2991
|
+
};
|
|
2992
|
+
_proto._fetchSupportedCurrenciesIfNeeded = function _fetchSupportedCurrenciesIfNeeded() {
|
|
2993
|
+
try {
|
|
2994
|
+
var _this5 = this;
|
|
2995
|
+
var loggerSource = "_fetchSupportedCurrenciesIfNeeded";
|
|
2996
|
+
return Promise.resolve(_catch(function () {
|
|
2997
|
+
var _temp = function (_this5$_supportedCoin) {
|
|
2998
|
+
if (!((_this5$_supportedCoin = _this5._supportedCoins) != null && _this5$_supportedCoin.length)) {
|
|
2999
|
+
return Promise.resolve(axios__default["default"].get(_this5._URL + "/api/v2/currencies")).then(function (rawResponse) {
|
|
3000
|
+
var _rawResponse$data, _rawResponse$data2;
|
|
3001
|
+
Logger.log("Retrieved " + (rawResponse == null || (_rawResponse$data = rawResponse.data) == null ? void 0 : _rawResponse$data.length) + " currencies", loggerSource);
|
|
3002
|
+
_this5._supportedCoins = ((_rawResponse$data2 = rawResponse == null ? void 0 : rawResponse.data) != null ? _rawResponse$data2 : []).map(function (item) {
|
|
3003
|
+
var coin = _this5._customCoinBuilder(item.code, item.network);
|
|
3004
|
+
if (!coin && !_this5.useRestrictedCoinsSet) {
|
|
3005
|
+
/** Building coin object for coin that isn't supported OOB in Rabbit.
|
|
3006
|
+
* We are doing this way to be able to use extended coins set for swaps.
|
|
3007
|
+
* These temporary built coins are only for in-swap use, and we omit some usual
|
|
3008
|
+
* coin details here.
|
|
3009
|
+
* Ideally we should add some new abstractions e.g. BaseCoin:
|
|
3010
|
+
* Coin will extend BaseCoin, SwapCoin will extend BaseCoin etc.
|
|
3011
|
+
* But for now it is reasonable to use this simpler approach.
|
|
3012
|
+
*/
|
|
3013
|
+
var code = item.code.toUpperCase();
|
|
3014
|
+
var network = item.network.toUpperCase();
|
|
3015
|
+
var ticker = "" + code + (code === network ? "" : network);
|
|
3016
|
+
var defaultDecimalPlacesForCoinNotSupportedOOB = 8;
|
|
3017
|
+
var defaultMinConfirmationsForCoinNotSupportedOOB = 1;
|
|
3018
|
+
coin = new Coin(item.name, ticker, code, defaultDecimalPlacesForCoinNotSupportedOOB, null, "", null, null, defaultMinConfirmationsForCoinNotSupportedOOB, null, [], 60000, null,
|
|
3019
|
+
// We cannot recognize blockchain from swapspace data
|
|
3020
|
+
new Protocol(network),
|
|
3021
|
+
// TODO: [dev] maybe we should recognize standard protocols?
|
|
3022
|
+
item.contractAddress || null, false);
|
|
3023
|
+
}
|
|
3024
|
+
if (coin) {
|
|
3025
|
+
var _item$deposit, _item$withdrawal, _item$validationRegex;
|
|
3026
|
+
return {
|
|
3027
|
+
coin: coin,
|
|
3028
|
+
code: item.code,
|
|
3029
|
+
network: item.network,
|
|
3030
|
+
extraId: item.extraIdName,
|
|
3031
|
+
isPopular: !!(item != null && item.popular),
|
|
3032
|
+
iconURL: item.icon ? "https://storage.swapspace.co" + item.icon : FALLBACK_ICON_URL,
|
|
3033
|
+
deposit: (_item$deposit = item.deposit) != null ? _item$deposit : false,
|
|
3034
|
+
withdrawal: (_item$withdrawal = item.withdrawal) != null ? _item$withdrawal : false,
|
|
3035
|
+
validationRegexp: (_item$validationRegex = item.validationRegexp) != null ? _item$validationRegex : null
|
|
3036
|
+
};
|
|
3037
|
+
}
|
|
3038
|
+
return [];
|
|
3039
|
+
}).flat();
|
|
3040
|
+
_this5._putPopularCoinsFirst();
|
|
3041
|
+
});
|
|
3042
|
+
}
|
|
3043
|
+
}();
|
|
3044
|
+
if (_temp && _temp.then) return _temp.then(function () {});
|
|
3045
|
+
}, function (e) {
|
|
3046
|
+
improveAndRethrow(e, loggerSource);
|
|
3047
|
+
}));
|
|
3048
|
+
} catch (e) {
|
|
3049
|
+
return Promise.reject(e);
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
/**
|
|
3053
|
+
* This method sort internal list putting popular (as swapspace thinks) coins to the top.
|
|
3054
|
+
* This is just for users of this API if they don't care about the sorting - we just improve a list a bit this way.
|
|
3055
|
+
* @private
|
|
3056
|
+
*/
|
|
3057
|
+
;
|
|
3058
|
+
_proto._putPopularCoinsFirst = function _putPopularCoinsFirst() {
|
|
3059
|
+
this._supportedCoins.sort(function (i1, i2) {
|
|
3060
|
+
if (i1.isPopular && !i2.isPopular) return -1;
|
|
3061
|
+
if (i2.isPopular && !i1.isPopular) return 1;
|
|
3062
|
+
return i1.coin.ticker > i2.coin.ticker ? 1 : i1.coin.ticker < i2.coin.ticker ? -1 : 0;
|
|
3063
|
+
});
|
|
3064
|
+
};
|
|
3065
|
+
_proto.getCoinToUSDTRate = function getCoinToUSDTRate(coin) {
|
|
3066
|
+
try {
|
|
3067
|
+
var _this6 = this;
|
|
3068
|
+
var loggerSource = "getCoinToUSDTRate";
|
|
3069
|
+
return Promise.resolve(_catch(function () {
|
|
3070
|
+
return Promise.resolve(_this6._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
3071
|
+
var _this6$_supportedCoin;
|
|
3072
|
+
// Using USDT TRC20 as usually fee in this network is smaller than ERC20 and this network is widely used for USDT
|
|
3073
|
+
var usdtTrc20 = (_this6$_supportedCoin = _this6._supportedCoins.find(function (i) {
|
|
3074
|
+
return i.code === "usdt" && i.network === "trc20";
|
|
3075
|
+
})) == null ? void 0 : _this6$_supportedCoin.coin;
|
|
3076
|
+
if (!usdtTrc20) {
|
|
3077
|
+
return {
|
|
3078
|
+
result: false
|
|
3079
|
+
};
|
|
3080
|
+
}
|
|
3081
|
+
var cached = _this6._cache.get("swapspace_usdt_rate_" + coin.ticker);
|
|
3082
|
+
if (cached != null) {
|
|
3083
|
+
return {
|
|
3084
|
+
result: true,
|
|
3085
|
+
rate: cached
|
|
3086
|
+
};
|
|
3087
|
+
}
|
|
3088
|
+
Logger.log("Loading USDT -> coin rate as not found in cache:", coin == null ? void 0 : coin.ticker);
|
|
3089
|
+
return Promise.resolve(_this6.getSwapInfo(usdtTrc20, coin, "5000")).then(function (result) {
|
|
3090
|
+
if (!result.result) {
|
|
3091
|
+
return {
|
|
3092
|
+
result: false
|
|
3093
|
+
};
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3096
|
+
// This calculation is not precise as we cannot recognize the actual fee and network fee. Just approximate.
|
|
3097
|
+
var standardSwapspaceFeeMultiplier = 1.002; // usually 0.2%
|
|
3098
|
+
var rate = bignumber_js.BigNumber(1).div(bignumber_js.BigNumber(result.rate).times(standardSwapspaceFeeMultiplier)).toString();
|
|
3099
|
+
_this6._cache.put("swapspace_usdt_rate_" + coin.ticker, rate, 15 * 60000);
|
|
3100
|
+
return {
|
|
3101
|
+
result: true,
|
|
3102
|
+
rate: rate
|
|
3103
|
+
};
|
|
3104
|
+
});
|
|
3105
|
+
});
|
|
3106
|
+
}, function (e) {
|
|
3107
|
+
improveAndRethrow(e, loggerSource);
|
|
3108
|
+
}));
|
|
3109
|
+
} catch (e) {
|
|
3110
|
+
return Promise.reject(e);
|
|
3111
|
+
}
|
|
3112
|
+
};
|
|
3113
|
+
_proto.getCoinByTickerIfPresent = function getCoinByTickerIfPresent(ticker) {
|
|
3114
|
+
try {
|
|
3115
|
+
var _item$coin;
|
|
3116
|
+
var item = this._supportedCoins.find(function (i) {
|
|
3117
|
+
return i.coin.ticker === ticker;
|
|
3118
|
+
});
|
|
3119
|
+
return (_item$coin = item == null ? void 0 : item.coin) != null ? _item$coin : null;
|
|
3120
|
+
} catch (e) {
|
|
3121
|
+
improveAndRethrow(e, "getCoinByTickerIfPresent");
|
|
3122
|
+
}
|
|
3123
|
+
};
|
|
3124
|
+
_proto.getSwapInfo = function getSwapInfo(fromCoin, toCoin, amountCoins, fromCoinToUsdRate) {
|
|
3125
|
+
if (fromCoinToUsdRate === void 0) {
|
|
3126
|
+
fromCoinToUsdRate = null;
|
|
3127
|
+
}
|
|
3128
|
+
try {
|
|
3129
|
+
var _this7 = this;
|
|
3130
|
+
var loggerSource = "getSwapInfo";
|
|
3131
|
+
return Promise.resolve(_catch(function () {
|
|
3132
|
+
if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amountCoins !== "string" || bignumber_js.BigNumber(amountCoins).lt("0")) {
|
|
3133
|
+
throw new Error("Wrong input params: " + amountCoins + " " + fromCoin.ticker + " -> " + toCoin.ticker + (fromCoin instanceof Coin) + (toCoin instanceof Coin));
|
|
3134
|
+
}
|
|
3135
|
+
var fromCoinSwapspaceDetails = _this7._supportedCoins.find(function (i) {
|
|
3136
|
+
return i.coin === fromCoin;
|
|
3137
|
+
});
|
|
3138
|
+
var toCoinSwapspaceDetails = _this7._supportedCoins.find(function (i) {
|
|
3139
|
+
return i.coin === toCoin;
|
|
3140
|
+
});
|
|
3141
|
+
if (!fromCoinSwapspaceDetails || !toCoinSwapspaceDetails) {
|
|
3142
|
+
throw new Error("Failed to find swapspace coin details for: " + fromCoin.ticker + " -> " + toCoin.ticker);
|
|
3143
|
+
}
|
|
3144
|
+
/* Here we use not documented parameter 'estimated=false'. This parameter controls whether we want to use
|
|
3145
|
+
* cached rate values stored in swapspace cache. Their support says they store at most for 30 sec.
|
|
3146
|
+
* But we are better off using the most actual rates.
|
|
3147
|
+
*/
|
|
3148
|
+
return Promise.resolve(axios__default["default"].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) {
|
|
3149
|
+
var _response$data;
|
|
3150
|
+
Logger.log("Retrieved " + (response == null || (_response$data = response.data) == null ? void 0 : _response$data.length) + " options", loggerSource);
|
|
3151
|
+
var options = Array.isArray(response.data) ? response.data : [];
|
|
3152
|
+
var exchangesSupportingThePair = options.filter(function (exchange) {
|
|
3153
|
+
return (exchange == null ? void 0 : exchange.exists) && !BANNED_PARTNERS.find(function (bannedPartner) {
|
|
3154
|
+
return bannedPartner === (exchange == null ? void 0 : exchange.partner);
|
|
3155
|
+
}) && (exchange == null ? void 0 : exchange.fixed) === false && (exchange.min === 0 || exchange.max === 0 || exchange.max > exchange.min || (typeof exchange.min !== "number" || typeof exchange.max !== "number") && exchange.toAmount > 0);
|
|
3156
|
+
});
|
|
3157
|
+
Logger.log((exchangesSupportingThePair == null ? void 0 : exchangesSupportingThePair.length) + " of them have exist=true", loggerSource);
|
|
3158
|
+
if (!exchangesSupportingThePair.length) {
|
|
3159
|
+
return {
|
|
3160
|
+
result: false,
|
|
3161
|
+
reason: SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED
|
|
3162
|
+
};
|
|
3163
|
+
}
|
|
3164
|
+
var availableExchanges = exchangesSupportingThePair.filter(function (exchange) {
|
|
3165
|
+
return typeof (exchange == null ? void 0 : exchange.toAmount) === "number" && exchange.toAmount > 0;
|
|
3166
|
+
});
|
|
3167
|
+
Logger.log("Available (having amountTo): " + safeStringify(availableExchanges), loggerSource);
|
|
3168
|
+
// min=0 or max=0 means there is no limit for the partner
|
|
3169
|
+
var smallestMin = null;
|
|
3170
|
+
if (exchangesSupportingThePair.find(function (ex) {
|
|
3171
|
+
return bignumber_js.BigNumber(ex.min).isZero();
|
|
3172
|
+
}) == null) {
|
|
3173
|
+
smallestMin = exchangesSupportingThePair.reduce(function (prev, cur) {
|
|
3174
|
+
if (typeof cur.min === "number" && (prev === null || bignumber_js.BigNumber(cur.min).lt(prev))) return bignumber_js.BigNumber(cur.min);
|
|
3175
|
+
return prev;
|
|
3176
|
+
}, null);
|
|
3177
|
+
}
|
|
3178
|
+
var greatestMax = null;
|
|
3179
|
+
if (exchangesSupportingThePair.find(function (ex) {
|
|
3180
|
+
return bignumber_js.BigNumber(ex.max).isZero();
|
|
3181
|
+
}) == null) {
|
|
3182
|
+
greatestMax = exchangesSupportingThePair.reduce(function (prev, cur) {
|
|
3183
|
+
if (typeof cur.max === "number" && (prev === null || bignumber_js.BigNumber(cur.max).gt(prev))) return bignumber_js.BigNumber(cur.max);
|
|
3184
|
+
return prev;
|
|
3185
|
+
}, null);
|
|
3186
|
+
}
|
|
3187
|
+
var extraCoinsToFitMinMax = "0";
|
|
3188
|
+
if (typeof fromCoinToUsdRate === "string" && bignumber_js.BigNumber(fromCoinToUsdRate).gt("0")) {
|
|
3189
|
+
var extraUsdToFitMinMax = bignumber_js.BigNumber("1"); // We correct the limits as the exact limit can fluctuate and cause failed swap creation
|
|
3190
|
+
extraCoinsToFitMinMax = AmountUtils.trim(extraUsdToFitMinMax.div(fromCoinToUsdRate), fromCoin.digits);
|
|
3191
|
+
}
|
|
3192
|
+
if (smallestMin instanceof bignumber_js.BigNumber) {
|
|
3193
|
+
smallestMin = AmountUtils.trim(smallestMin.plus(extraCoinsToFitMinMax), fromCoin.digits);
|
|
3194
|
+
}
|
|
3195
|
+
if (greatestMax instanceof bignumber_js.BigNumber) {
|
|
3196
|
+
if (greatestMax > extraCoinsToFitMinMax) {
|
|
3197
|
+
greatestMax = AmountUtils.trim(greatestMax.minus(extraCoinsToFitMinMax), fromCoin.digits);
|
|
3198
|
+
} else {
|
|
3199
|
+
greatestMax = "0";
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
if (availableExchanges.length) {
|
|
3203
|
+
var _bestOpt$duration;
|
|
3204
|
+
var sorted = availableExchanges.sort(function (op1, op2) {
|
|
3205
|
+
return op2.toAmount - op1.toAmount;
|
|
3206
|
+
});
|
|
3207
|
+
var bestOpt = sorted[0];
|
|
3208
|
+
Logger.log("Returning first option after sorting: " + safeStringify(bestOpt), loggerSource);
|
|
3209
|
+
var max = null;
|
|
3210
|
+
var min = null;
|
|
3211
|
+
if (extraCoinsToFitMinMax != null) {
|
|
3212
|
+
if (typeof bestOpt.max === "number" && bestOpt.max !== 0) {
|
|
3213
|
+
max = bignumber_js.BigNumber(bestOpt.max).minus(extraCoinsToFitMinMax);
|
|
3214
|
+
max = AmountUtils.trim(max.lt(0) ? "0" : max, fromCoin.digits);
|
|
3215
|
+
}
|
|
3216
|
+
if (typeof bestOpt.min === "number" && bestOpt.min !== 0) {
|
|
3217
|
+
min = AmountUtils.trim(bignumber_js.BigNumber(bestOpt.min).plus(extraCoinsToFitMinMax), fromCoin.digits);
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
var rate = bestOpt.toAmount && bestOpt.fromAmount ? bignumber_js.BigNumber(bestOpt.toAmount).div(bestOpt.fromAmount) : null;
|
|
3221
|
+
return {
|
|
3222
|
+
result: true,
|
|
3223
|
+
min: min,
|
|
3224
|
+
max: max,
|
|
3225
|
+
smallestMin: smallestMin,
|
|
3226
|
+
greatestMax: greatestMax,
|
|
3227
|
+
rate: rate != null ? AmountUtils.trim(rate, _this7._maxRateDigits) : null,
|
|
3228
|
+
durationMinutesRange: (_bestOpt$duration = bestOpt.duration) != null ? _bestOpt$duration : null,
|
|
3229
|
+
rawSwapData: bestOpt
|
|
3230
|
+
};
|
|
3231
|
+
}
|
|
3232
|
+
var result = {
|
|
3233
|
+
result: false,
|
|
3234
|
+
reason: smallestMin && bignumber_js.BigNumber(amountCoins).lt(smallestMin) ? SwapProvider.NO_SWAPS_REASONS.TOO_LOW : greatestMax && bignumber_js.BigNumber(amountCoins).gt(greatestMax) ? SwapProvider.NO_SWAPS_REASONS.TOO_HIGH : SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED,
|
|
3235
|
+
smallestMin: smallestMin,
|
|
3236
|
+
greatestMax: greatestMax
|
|
3237
|
+
};
|
|
3238
|
+
Logger.log("Returning result " + safeStringify(result), loggerSource);
|
|
3239
|
+
return result;
|
|
3240
|
+
});
|
|
3241
|
+
}, function (e) {
|
|
3242
|
+
var _e$response3;
|
|
3243
|
+
if ((e == null || (_e$response3 = e.response) == null ? void 0 : _e$response3.status) === 429) {
|
|
3244
|
+
return {
|
|
3245
|
+
result: false,
|
|
3246
|
+
reason: SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
|
|
3247
|
+
};
|
|
3248
|
+
}
|
|
3249
|
+
Logger.log("Internal swapspace/rabbit error when getting swap options " + safeStringify(e), loggerSource);
|
|
3250
|
+
improveAndRethrow(e, loggerSource);
|
|
3251
|
+
}));
|
|
3252
|
+
} catch (e) {
|
|
3253
|
+
return Promise.reject(e);
|
|
3254
|
+
}
|
|
3255
|
+
};
|
|
3256
|
+
_proto.createSwap = function createSwap(fromCoin, toCoin, amount, toAddress, refundAddress, rawSwapData, clientIpAddress) {
|
|
3257
|
+
try {
|
|
3258
|
+
var _this8 = this;
|
|
3259
|
+
var loggerSource = "createSwap";
|
|
3260
|
+
var partner = rawSwapData == null ? void 0 : rawSwapData.partner;
|
|
3261
|
+
return Promise.resolve(_catch(function () {
|
|
3262
|
+
if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof amount !== "string" || typeof toAddress !== "string" || typeof refundAddress !== "string") {
|
|
3263
|
+
throw new Error("Invalid input: " + fromCoin + " " + toCoin + " " + amount + " " + toAddress + " " + refundAddress);
|
|
3264
|
+
}
|
|
3265
|
+
if (typeof partner !== "string" || typeof (rawSwapData == null ? void 0 : rawSwapData.fromCurrency) !== "string" || typeof (rawSwapData == null ? void 0 : rawSwapData.fromNetwork) !== "string" || typeof (rawSwapData == null ? void 0 : rawSwapData.toCurrency) !== "string" || typeof (rawSwapData == null ? void 0 : rawSwapData.toNetwork) !== "string" || typeof (rawSwapData == null ? void 0 : rawSwapData.id) !== "string" // can be just empty
|
|
3266
|
+
) {
|
|
3267
|
+
throw new Error("Invalid raw swap data: " + safeStringify(rawSwapData));
|
|
3268
|
+
}
|
|
3269
|
+
return Promise.resolve(_this8._fetchSupportedCurrenciesIfNeeded()).then(function () {
|
|
3270
|
+
var _this8$_supportedCoin, _this8$_supportedCoin2;
|
|
3271
|
+
var toCurrencyExtraId = (_this8$_supportedCoin = (_this8$_supportedCoin2 = _this8._supportedCoins.find(function (item) {
|
|
3272
|
+
return item.coin === toCoin;
|
|
3273
|
+
})) == null ? void 0 : _this8$_supportedCoin2.extraId) != null ? _this8$_supportedCoin : "";
|
|
3274
|
+
var requestData = {
|
|
3275
|
+
partner: partner,
|
|
3276
|
+
fromCurrency: rawSwapData == null ? void 0 : rawSwapData.fromCurrency,
|
|
3277
|
+
fromNetwork: rawSwapData == null ? void 0 : rawSwapData.fromNetwork,
|
|
3278
|
+
toCurrency: rawSwapData == null ? void 0 : rawSwapData.toCurrency,
|
|
3279
|
+
toNetwork: rawSwapData == null ? void 0 : rawSwapData.toNetwork,
|
|
3280
|
+
address: toAddress,
|
|
3281
|
+
amount: amount,
|
|
3282
|
+
fixed: false,
|
|
3283
|
+
extraId: toCurrencyExtraId != null ? toCurrencyExtraId : "",
|
|
3284
|
+
rateId: rawSwapData == null ? void 0 : rawSwapData.id,
|
|
3285
|
+
userIp: clientIpAddress,
|
|
3286
|
+
refund: refundAddress
|
|
3287
|
+
};
|
|
3288
|
+
Logger.log("Sending create request: " + safeStringify(requestData), loggerSource);
|
|
3289
|
+
return Promise.resolve(axios__default["default"].post(_this8._URL + "/api/v2/exchange", requestData)).then(function (response) {
|
|
3290
|
+
var result = response.data;
|
|
3291
|
+
Logger.log("Creation result " + safeStringify(result), loggerSource);
|
|
3292
|
+
if (result != null && result.id) {
|
|
3293
|
+
var _result$from, _result$from2, _result$to, _result$to2, _result$from4, _result$from5, _result$to4, _result$to5;
|
|
3294
|
+
if (typeof (result == null || (_result$from = result.from) == null ? void 0 : _result$from.amount) !== "number" || typeof (result == null || (_result$from2 = result.from) == null ? void 0 : _result$from2.address) !== "string" || typeof (result == null || (_result$to = result.to) == null ? void 0 : _result$to.amount) !== "number" || typeof (result == null || (_result$to2 = result.to) == null ? void 0 : _result$to2.address) !== "string") throw new Error("Wrong swap creation result " + result);
|
|
3295
|
+
/* We use the returned rate preferably but if the retrieved
|
|
3296
|
+
* rate 0/null/undefined we calculate it manually */
|
|
3297
|
+
var rate = result.rate;
|
|
3298
|
+
if (typeof rate !== "number" || bignumber_js.BigNumber(rate).isZero()) {
|
|
3299
|
+
var _result$to3, _result$from3;
|
|
3300
|
+
rate = bignumber_js.BigNumber(result == null || (_result$to3 = result.to) == null ? void 0 : _result$to3.amount).div(result == null || (_result$from3 = result.from) == null ? void 0 : _result$from3.amount);
|
|
3301
|
+
} else {
|
|
3302
|
+
rate = bignumber_js.BigNumber(rate);
|
|
3303
|
+
}
|
|
3304
|
+
return {
|
|
3305
|
+
result: true,
|
|
3306
|
+
swapId: result == null ? void 0 : result.id,
|
|
3307
|
+
fromCoin: fromCoin,
|
|
3308
|
+
fromAmount: AmountUtils.trim(result == null || (_result$from4 = result.from) == null ? void 0 : _result$from4.amount, fromCoin.digits),
|
|
3309
|
+
fromAddress: result == null || (_result$from5 = result.from) == null ? void 0 : _result$from5.address,
|
|
3310
|
+
toCoin: toCoin,
|
|
3311
|
+
toAmount: AmountUtils.trim(result == null || (_result$to4 = result.to) == null ? void 0 : _result$to4.amount, toCoin.digits),
|
|
3312
|
+
toAddress: result == null || (_result$to5 = result.to) == null ? void 0 : _result$to5.address,
|
|
3313
|
+
rate: AmountUtils.trim(rate, _this8._maxRateDigits)
|
|
3314
|
+
};
|
|
3315
|
+
}
|
|
3316
|
+
var errorMessage = "Swap creation succeeded but the response is wrong: " + safeStringify(response);
|
|
3317
|
+
Logger.log(errorMessage, loggerSource);
|
|
3318
|
+
throw new Error(errorMessage);
|
|
3319
|
+
});
|
|
3320
|
+
});
|
|
3321
|
+
}, function (e) {
|
|
3322
|
+
var _e$response4, _e$response5;
|
|
3323
|
+
Logger.log("Failed to create swap. Error is: " + safeStringify(e), loggerSource);
|
|
3324
|
+
var composeFailResult = function composeFailResult(reason) {
|
|
3325
|
+
return {
|
|
3326
|
+
result: false,
|
|
3327
|
+
reason: reason,
|
|
3328
|
+
partner: partner
|
|
3329
|
+
};
|
|
3330
|
+
};
|
|
3331
|
+
var status = e == null || (_e$response4 = e.response) == null ? void 0 : _e$response4.status;
|
|
3332
|
+
var data = e == null || (_e$response5 = e.response) == null ? void 0 : _e$response5.data;
|
|
3333
|
+
if (status === 429) {
|
|
3334
|
+
Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
|
|
3335
|
+
return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
|
|
3336
|
+
}
|
|
3337
|
+
var texts422 = ["Pair cannot be processed by", "Currency not found", "Amount maximum is", "Amount minimum is"];
|
|
3338
|
+
var text403 = "IP address is forbidden";
|
|
3339
|
+
if (typeof data === "string" && (status === 403 && data.includes(text403) || status === 422 && texts422.find(function (text) {
|
|
3340
|
+
return data.includes(text);
|
|
3341
|
+
}))) {
|
|
3342
|
+
Logger.log("Returning retriable fail: " + status + " - " + data + ", " + partner, loggerSource);
|
|
3343
|
+
return composeFailResult(SwapProvider.CREATION_FAIL_REASONS.RETRIABLE_FAIL);
|
|
3344
|
+
}
|
|
3345
|
+
Logger.log("Internal swapspace/rabbit error for " + partner + ": " + safeStringify(e), loggerSource);
|
|
3346
|
+
improveAndRethrow(e, loggerSource);
|
|
3347
|
+
}));
|
|
3348
|
+
} catch (e) {
|
|
3349
|
+
return Promise.reject(e);
|
|
3350
|
+
}
|
|
3351
|
+
};
|
|
3352
|
+
_proto._mapSwapspaceStatusToRabbitStatus = function _mapSwapspaceStatusToRabbitStatus(status) {
|
|
3353
|
+
switch (status) {
|
|
3354
|
+
case "waiting":
|
|
3355
|
+
return SwapProvider.SWAP_STATUSES.WAITING_FOR_PAYMENT;
|
|
3356
|
+
case "confirming":
|
|
3357
|
+
return SwapProvider.SWAP_STATUSES.CONFIRMING;
|
|
3358
|
+
case "exchanging":
|
|
3359
|
+
return SwapProvider.SWAP_STATUSES.EXCHANGING;
|
|
3360
|
+
case "sending":
|
|
3361
|
+
return SwapProvider.SWAP_STATUSES.PAYMENT_RECEIVED;
|
|
3362
|
+
case "finished":
|
|
3363
|
+
return SwapProvider.SWAP_STATUSES.COMPLETED;
|
|
3364
|
+
case "verifying":
|
|
3365
|
+
return SwapProvider.SWAP_STATUSES.EXCHANGING;
|
|
3366
|
+
case "refunded":
|
|
3367
|
+
return SwapProvider.SWAP_STATUSES.REFUNDED;
|
|
3368
|
+
case "expired":
|
|
3369
|
+
return SwapProvider.SWAP_STATUSES.EXPIRED;
|
|
3370
|
+
case "failed":
|
|
3371
|
+
return SwapProvider.SWAP_STATUSES.FAILED;
|
|
3372
|
+
default:
|
|
3373
|
+
throw new Error("Unknown swapspace status: " + status);
|
|
3374
|
+
}
|
|
3375
|
+
};
|
|
3376
|
+
_proto.getExistingSwapsDetailsAndStatus = function getExistingSwapsDetailsAndStatus(swapIds) {
|
|
3377
|
+
try {
|
|
3378
|
+
var _this9 = this;
|
|
3379
|
+
var loggerSource = "getExistingSwapsDetailsAndStatus";
|
|
3380
|
+
return Promise.resolve(_catch(function () {
|
|
3381
|
+
if (swapIds.find(function (id) {
|
|
3382
|
+
return typeof id !== "string";
|
|
3383
|
+
})) {
|
|
3384
|
+
throw new Error("Swap id is not string: " + safeStringify(swapIds));
|
|
3385
|
+
}
|
|
3386
|
+
var getNotFailingOn404 = function getNotFailingOn404(swapId) {
|
|
3387
|
+
try {
|
|
3388
|
+
return Promise.resolve(_catch(function () {
|
|
3389
|
+
return Promise.resolve(axios__default["default"].get(_this9._URL + "/api/v2/exchange/" + swapId));
|
|
3390
|
+
}, function (error) {
|
|
3391
|
+
var _error$response;
|
|
3392
|
+
if ((error == null || (_error$response = error.response) == null ? void 0 : _error$response.status) === 404) return [];
|
|
3393
|
+
throw error;
|
|
3394
|
+
}));
|
|
3395
|
+
} catch (e) {
|
|
3396
|
+
return Promise.reject(e);
|
|
3397
|
+
}
|
|
3398
|
+
};
|
|
3399
|
+
return Promise.resolve(Promise.all(swapIds.map(function (swapId) {
|
|
3400
|
+
return getNotFailingOn404(swapId);
|
|
3401
|
+
}))).then(function (responses) {
|
|
3402
|
+
var wo404 = responses.flat();
|
|
3403
|
+
var swaps = wo404.map(function (r) {
|
|
3404
|
+
return r.data;
|
|
3405
|
+
}).map(function (swap, index) {
|
|
3406
|
+
var _this9$_supportedCoin, _this9$_supportedCoin2;
|
|
3407
|
+
var fromCoin = (_this9$_supportedCoin = _this9._supportedCoins.find(function (i) {
|
|
3408
|
+
return i.code === swap.from.code && i.network === swap.from.network;
|
|
3409
|
+
})) == null ? void 0 : _this9$_supportedCoin.coin;
|
|
3410
|
+
var toCoin = (_this9$_supportedCoin2 = _this9._supportedCoins.find(function (i) {
|
|
3411
|
+
return i.code === swap.to.code && i.network === swap.to.network;
|
|
3412
|
+
})) == null ? void 0 : _this9$_supportedCoin2.coin;
|
|
3413
|
+
if (!fromCoin || !toCoin) {
|
|
3414
|
+
return []; // We skip swaps with not supported coins for now
|
|
3415
|
+
}
|
|
3416
|
+
var status = _this9._mapSwapspaceStatusToRabbitStatus(swap.status);
|
|
3417
|
+
var toDigits = status === SwapProvider.SWAP_STATUSES.REFUNDED ? fromCoin.digits : toCoin.digits;
|
|
3418
|
+
var addressToSendCoinsToSwapspace = swap.from.address;
|
|
3419
|
+
var toUtcTimestamp = function toUtcTimestamp(timeStr) {
|
|
3420
|
+
return Date.parse(timeStr.match(/.+[Zz]$/) ? timeStr : timeStr + "Z");
|
|
3421
|
+
};
|
|
3422
|
+
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);
|
|
3423
|
+
}).flat();
|
|
3424
|
+
Logger.log("Swap details result " + safeStringify(swaps), loggerSource);
|
|
3425
|
+
return {
|
|
3426
|
+
result: true,
|
|
3427
|
+
swaps: swaps
|
|
3428
|
+
};
|
|
3429
|
+
});
|
|
3430
|
+
}, function (e) {
|
|
3431
|
+
var _e$response6, _e$response7;
|
|
3432
|
+
Logger.log("Failed to get swap details. Error is: " + safeStringify(e), loggerSource);
|
|
3433
|
+
var composeFailResult = function composeFailResult(reason) {
|
|
3434
|
+
return {
|
|
3435
|
+
result: false,
|
|
3436
|
+
reason: reason
|
|
3437
|
+
};
|
|
3438
|
+
};
|
|
3439
|
+
var status = e == null || (_e$response6 = e.response) == null ? void 0 : _e$response6.status;
|
|
3440
|
+
var data = e == null || (_e$response7 = e.response) == null ? void 0 : _e$response7.data;
|
|
3441
|
+
if (status === 429) {
|
|
3442
|
+
Logger.log("Returning fail - RPS limit exceeded " + data, loggerSource);
|
|
3443
|
+
return composeFailResult(SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
|
|
3444
|
+
}
|
|
3445
|
+
improveAndRethrow(e, loggerSource);
|
|
3446
|
+
}));
|
|
3447
|
+
} catch (e) {
|
|
3448
|
+
return Promise.reject(e);
|
|
3449
|
+
}
|
|
3450
|
+
};
|
|
3451
|
+
_proto.isAddressValidForAsset = function isAddressValidForAsset(asset, address) {
|
|
3452
|
+
try {
|
|
3453
|
+
var assetData = this._supportedCoins.find(function (i) {
|
|
3454
|
+
return i.coin === asset;
|
|
3455
|
+
});
|
|
3456
|
+
if (assetData) {
|
|
3457
|
+
var corrected = assetData.validationRegexp.trim();
|
|
3458
|
+
corrected = corrected[0] === "/" ? corrected.slice(1) : corrected;
|
|
3459
|
+
corrected = corrected[corrected.length - 1] === "/" ? corrected.slice(0, corrected.length - 1) : corrected;
|
|
3460
|
+
return address.match(corrected) != null;
|
|
3461
|
+
}
|
|
3462
|
+
} catch (e) {
|
|
3463
|
+
Logger.logError(e, "isAddressValidForAsset");
|
|
3464
|
+
}
|
|
3465
|
+
return false;
|
|
3466
|
+
};
|
|
3467
|
+
return SwapspaceSwapProvider;
|
|
3468
|
+
}(SwapProvider);
|
|
3469
|
+
|
|
2738
3470
|
exports.AmountUtils = AmountUtils;
|
|
2739
3471
|
exports.AssetIcon = AssetIcon;
|
|
2740
3472
|
exports.Blockchain = Blockchain;
|
|
2741
3473
|
exports.Button = Button;
|
|
2742
3474
|
exports.Cache = Cache;
|
|
2743
3475
|
exports.Coin = Coin;
|
|
3476
|
+
exports.EmailsApi = EmailsApi;
|
|
2744
3477
|
exports.ExistingSwap = ExistingSwap;
|
|
3478
|
+
exports.ExistingSwapWithFiatData = ExistingSwapWithFiatData;
|
|
2745
3479
|
exports.FiatCurrenciesService = FiatCurrenciesService;
|
|
2746
3480
|
exports.LoadingDots = LoadingDots;
|
|
2747
3481
|
exports.Logger = Logger;
|
|
2748
3482
|
exports.LogsStorage = LogsStorage;
|
|
2749
3483
|
exports.Protocol = Protocol;
|
|
3484
|
+
exports.PublicSwapCreationInfo = PublicSwapCreationInfo;
|
|
2750
3485
|
exports.SupportChat = SupportChat;
|
|
2751
3486
|
exports.SwapProvider = SwapProvider;
|
|
3487
|
+
exports.SwapspaceSwapProvider = SwapspaceSwapProvider;
|
|
2752
3488
|
exports.improveAndRethrow = improveAndRethrow;
|
|
2753
3489
|
exports.safeStringify = safeStringify;
|
|
2754
3490
|
//# sourceMappingURL=index.cjs.map
|