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