@rabbitio/ui-kit 1.0.0-beta.15 → 1.0.0-beta.17

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 CHANGED
@@ -1,11 +1,13 @@
1
1
  var React = require('react');
2
2
  var bignumber_js = require('bignumber.js');
3
3
  var axios = require('axios');
4
+ var EventBusInstance = require('eventbusjs');
4
5
 
5
6
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
6
7
 
7
8
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
8
9
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
10
+ var EventBusInstance__default = /*#__PURE__*/_interopDefaultLegacy(EventBusInstance);
9
11
 
10
12
  function createCommonjsModule(fn) {
11
13
  var module = { exports: {} };
@@ -1479,6 +1481,198 @@ AssetIcon.defaultProps = {
1479
1481
  small: false
1480
1482
  };
1481
1483
 
1484
+ var LogsStorage = /*#__PURE__*/function () {
1485
+ function LogsStorage() {}
1486
+ LogsStorage.saveLog = function saveLog(log) {
1487
+ this._inMemoryStorage.push(log);
1488
+ };
1489
+ LogsStorage.getInMemoryLogs = function getInMemoryLogs() {
1490
+ return this._inMemoryStorage;
1491
+ };
1492
+ LogsStorage.getAllLogs = function getAllLogs() {
1493
+ var storedLogs = "";
1494
+ if (typeof window !== "undefined") {
1495
+ storedLogs = localStorage.getItem(this._logsStorageId);
1496
+ }
1497
+ return storedLogs + "\n" + this._inMemoryStorage.join("\n");
1498
+ }
1499
+
1500
+ /**
1501
+ * @param logger {Logger}
1502
+ */;
1503
+ LogsStorage.saveToTheDisk = function saveToTheDisk(logger) {
1504
+ try {
1505
+ var MAX_LOCAL_STORAGE_VOLUME_BYTES = 5 * 1024 * 1024;
1506
+ var MAX_LOGS_STORAGE_BYTES = MAX_LOCAL_STORAGE_VOLUME_BYTES * 0.65;
1507
+ if (typeof window !== "undefined") {
1508
+ var existingLogs = localStorage.getItem(this._logsStorageId);
1509
+ var logsString = existingLogs + "\n" + this._inMemoryStorage.join("\n");
1510
+ var lettersCountToRemove = logsString.length - Math.round(MAX_LOGS_STORAGE_BYTES / 2);
1511
+ if (lettersCountToRemove > 0) {
1512
+ localStorage.setItem(this._logsStorageId, logsString.slice(lettersCountToRemove, logsString.length));
1513
+ } else {
1514
+ localStorage.setItem(this._logsStorageId, logsString);
1515
+ }
1516
+ this._inMemoryStorage = [];
1517
+ }
1518
+ } catch (e) {
1519
+ logger == null || logger.logError(e, "saveToTheDisk", "Failed to save logs to disk");
1520
+ }
1521
+ };
1522
+ LogsStorage.removeAllClientLogs = function removeAllClientLogs() {
1523
+ if (typeof window !== "undefined") {
1524
+ if (localStorage.getItem("doNotRemoveClientLogsWhenSignedOut") !== "true") {
1525
+ localStorage.removeItem(this._logsStorageId);
1526
+ }
1527
+ }
1528
+ this._inMemoryStorage = [];
1529
+ };
1530
+ LogsStorage.setDoNotRemoveClientLogsWhenSignedOut = function setDoNotRemoveClientLogsWhenSignedOut(value) {
1531
+ if (typeof window !== "undefined") {
1532
+ localStorage.setItem("doNotRemoveClientLogsWhenSignedOut", value);
1533
+ }
1534
+ };
1535
+ return LogsStorage;
1536
+ }();
1537
+ LogsStorage._inMemoryStorage = [];
1538
+ LogsStorage._logsStorageId = "clietnLogs_j203fj2D0n-d1";
1539
+
1540
+ /**
1541
+ * Stringify given object by use of JSON.stringify but handles circular structures and "response", "request" properties
1542
+ * to avoid stringing redundant data when printing errors containing request/response objects.
1543
+ *
1544
+ * @param object - object to be stringed
1545
+ * @param indent - custom indentation
1546
+ * @return {string} - stringed object
1547
+ */
1548
+ function safeStringify(object, indent) {
1549
+ if (indent === void 0) {
1550
+ indent = 2;
1551
+ }
1552
+ var cache = [];
1553
+ if (typeof object === "string" || typeof object === "function" || typeof object === "number" || typeof object === "undefined" || typeof object === "boolean") {
1554
+ return String(object);
1555
+ }
1556
+ var retVal = JSON.stringify(object, function (key, value) {
1557
+ if (key.toLowerCase().includes("request")) {
1558
+ return JSON.stringify({
1559
+ body: value == null ? void 0 : value.body,
1560
+ query: value == null ? void 0 : value.query,
1561
+ headers: value == null ? void 0 : value.headers
1562
+ });
1563
+ }
1564
+ if (key.toLowerCase().includes("response")) {
1565
+ return JSON.stringify({
1566
+ statusText: value == null ? void 0 : value.statusText,
1567
+ status: value == null ? void 0 : value.status,
1568
+ data: value == null ? void 0 : value.data,
1569
+ headers: value == null ? void 0 : value.headers
1570
+ });
1571
+ }
1572
+ return typeof value === "object" && value !== null ? cache.includes(value) ? "duplicated reference" // Duplicated references were found, discarding this key
1573
+ : cache.push(value) && value // Store value in our collection
1574
+ : value;
1575
+ }, indent);
1576
+ cache = null;
1577
+ return retVal;
1578
+ }
1579
+
1580
+ var Logger = /*#__PURE__*/function () {
1581
+ function Logger() {}
1582
+ /**
1583
+ * Logs to client logs storage.
1584
+ *
1585
+ * WARNING! this method should ce used carefully for critical logging as we have the restriction for storing logs
1586
+ * on client side as we store them inside the local storage. Please see details inside storage.js
1587
+ * @param logString {string} log string
1588
+ * @param source {string} source of the log entry
1589
+ */
1590
+ Logger.log = function log(logString, source) {
1591
+ var timestamp = new Date().toISOString();
1592
+ LogsStorage.saveLog(timestamp + "|" + source + ":" + logString);
1593
+ };
1594
+ Logger.logError = function logError(e, settingFunction, additionalMessage, onlyToConsole) {
1595
+ var _e$errorDescription, _e$howToFix;
1596
+ if (additionalMessage === void 0) {
1597
+ additionalMessage = "";
1598
+ }
1599
+ if (onlyToConsole === void 0) {
1600
+ onlyToConsole = false;
1601
+ }
1602
+ var message = "\nFunction call " + (settingFunction != null ? settingFunction : "") + " failed. Error message: " + (e == null ? void 0 : e.message) + ". " + additionalMessage + " ";
1603
+ message += "" + ((_e$errorDescription = e == null ? void 0 : e.errorDescription) != null ? _e$errorDescription : "") + ((_e$howToFix = e == null ? void 0 : e.howToFix) != null ? _e$howToFix : "") + ((e == null ? void 0 : e.httpStatus) === 403 ? "Authentication has expired or was lost. " : "");
1604
+ if (e != null && e.response) {
1605
+ try {
1606
+ var responseData = safeStringify({
1607
+ response: e.response
1608
+ });
1609
+ responseData && (message += "\n" + responseData + ". ");
1610
+ } catch (e) {}
1611
+ }
1612
+ var finalErrorText = message + ". " + safeStringify(e);
1613
+ // eslint-disable-next-line no-console
1614
+ console.error(finalErrorText, e);
1615
+ if (!onlyToConsole) {
1616
+ this.log(finalErrorText, "logError");
1617
+ }
1618
+ };
1619
+ return Logger;
1620
+ }();
1621
+
1622
+ function _catch$4(body, recover) {
1623
+ try {
1624
+ var result = body();
1625
+ } catch (e) {
1626
+ return recover(e);
1627
+ }
1628
+ if (result && result.then) {
1629
+ return result.then(void 0, recover);
1630
+ }
1631
+ return result;
1632
+ }
1633
+ function useCallHandlingErrors() {
1634
+ var _useState = React.useState(),
1635
+ setState = _useState[1];
1636
+ return React.useCallback(function (functionToBeCalled, event) {
1637
+ try {
1638
+ var _temp = _catch$4(function () {
1639
+ return Promise.resolve(functionToBeCalled(event)).then(function () {});
1640
+ }, function (error) {
1641
+ Logger.logError(error, (functionToBeCalled == null ? void 0 : functionToBeCalled.name) || "errorBoundaryTrigger", "Caught by ErrorBoundary");
1642
+ // Triggering ErrorBoundary
1643
+ setState(function () {
1644
+ throw error;
1645
+ });
1646
+ });
1647
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
1648
+ } catch (e) {
1649
+ return Promise.reject(e);
1650
+ }
1651
+ }, []);
1652
+ }
1653
+
1654
+ /**
1655
+ * Adds reference to standard state variable. It is helpful to be able to use state variable value inside
1656
+ * event handlers and other callbacks without the need to call setState(prev => { value = prev; return prev; }).
1657
+ *
1658
+ * @param initialValue {any} to be passed to useState
1659
+ * @return {[React.Ref, function]} reference to state variable and its setter
1660
+ */
1661
+ function useReferredState(initialValue) {
1662
+ var _React$useState = React__default["default"].useState(initialValue),
1663
+ state = _React$useState[0],
1664
+ setState = _React$useState[1];
1665
+ var reference = React__default["default"].useRef(state);
1666
+ var setReferredState = function setReferredState(value) {
1667
+ if (value && {}.toString.call(value) === "[object Function]") {
1668
+ value = value(reference.current);
1669
+ }
1670
+ reference.current = value;
1671
+ setState(value);
1672
+ };
1673
+ return [reference, setReferredState];
1674
+ }
1675
+
1482
1676
  /**
1483
1677
  * This function improves the passed error object (its message) by adding the passed function name
1484
1678
  * and additional message to it.
@@ -2101,144 +2295,6 @@ var Coin = /*#__PURE__*/function () {
2101
2295
  return Coin;
2102
2296
  }();
2103
2297
 
2104
- var LogsStorage = /*#__PURE__*/function () {
2105
- function LogsStorage() {}
2106
- LogsStorage.saveLog = function saveLog(log) {
2107
- this._inMemoryStorage.push(log);
2108
- };
2109
- LogsStorage.getInMemoryLogs = function getInMemoryLogs() {
2110
- return this._inMemoryStorage;
2111
- };
2112
- LogsStorage.getAllLogs = function getAllLogs() {
2113
- var storedLogs = "";
2114
- if (typeof window !== "undefined") {
2115
- storedLogs = localStorage.getItem(this._logsStorageId);
2116
- }
2117
- return storedLogs + "\n" + this._inMemoryStorage.join("\n");
2118
- }
2119
-
2120
- /**
2121
- * @param logger {Logger}
2122
- */;
2123
- LogsStorage.saveToTheDisk = function saveToTheDisk(logger) {
2124
- try {
2125
- var MAX_LOCAL_STORAGE_VOLUME_BYTES = 5 * 1024 * 1024;
2126
- var MAX_LOGS_STORAGE_BYTES = MAX_LOCAL_STORAGE_VOLUME_BYTES * 0.65;
2127
- if (typeof window !== "undefined") {
2128
- var existingLogs = localStorage.getItem(this._logsStorageId);
2129
- var logsString = existingLogs + "\n" + this._inMemoryStorage.join("\n");
2130
- var lettersCountToRemove = logsString.length - Math.round(MAX_LOGS_STORAGE_BYTES / 2);
2131
- if (lettersCountToRemove > 0) {
2132
- localStorage.setItem(this._logsStorageId, logsString.slice(lettersCountToRemove, logsString.length));
2133
- } else {
2134
- localStorage.setItem(this._logsStorageId, logsString);
2135
- }
2136
- this._inMemoryStorage = [];
2137
- }
2138
- } catch (e) {
2139
- logger == null || logger.logError(e, "saveToTheDisk", "Failed to save logs to disk");
2140
- }
2141
- };
2142
- LogsStorage.removeAllClientLogs = function removeAllClientLogs() {
2143
- if (typeof window !== "undefined") {
2144
- if (localStorage.getItem("doNotRemoveClientLogsWhenSignedOut") !== "true") {
2145
- localStorage.removeItem(this._logsStorageId);
2146
- }
2147
- }
2148
- this._inMemoryStorage = [];
2149
- };
2150
- LogsStorage.setDoNotRemoveClientLogsWhenSignedOut = function setDoNotRemoveClientLogsWhenSignedOut(value) {
2151
- if (typeof window !== "undefined") {
2152
- localStorage.setItem("doNotRemoveClientLogsWhenSignedOut", value);
2153
- }
2154
- };
2155
- return LogsStorage;
2156
- }();
2157
- LogsStorage._inMemoryStorage = [];
2158
- LogsStorage._logsStorageId = "clietnLogs_j203fj2D0n-d1";
2159
-
2160
- /**
2161
- * Stringify given object by use of JSON.stringify but handles circular structures and "response", "request" properties
2162
- * to avoid stringing redundant data when printing errors containing request/response objects.
2163
- *
2164
- * @param object - object to be stringed
2165
- * @param indent - custom indentation
2166
- * @return {string} - stringed object
2167
- */
2168
- function safeStringify(object, indent) {
2169
- if (indent === void 0) {
2170
- indent = 2;
2171
- }
2172
- var cache = [];
2173
- if (typeof object === "string" || typeof object === "function" || typeof object === "number" || typeof object === "undefined" || typeof object === "boolean") {
2174
- return String(object);
2175
- }
2176
- var retVal = JSON.stringify(object, function (key, value) {
2177
- if (key.toLowerCase().includes("request")) {
2178
- return JSON.stringify({
2179
- body: value == null ? void 0 : value.body,
2180
- query: value == null ? void 0 : value.query,
2181
- headers: value == null ? void 0 : value.headers
2182
- });
2183
- }
2184
- if (key.toLowerCase().includes("response")) {
2185
- return JSON.stringify({
2186
- statusText: value == null ? void 0 : value.statusText,
2187
- status: value == null ? void 0 : value.status,
2188
- data: value == null ? void 0 : value.data,
2189
- headers: value == null ? void 0 : value.headers
2190
- });
2191
- }
2192
- return typeof value === "object" && value !== null ? cache.includes(value) ? "duplicated reference" // Duplicated references were found, discarding this key
2193
- : cache.push(value) && value // Store value in our collection
2194
- : value;
2195
- }, indent);
2196
- cache = null;
2197
- return retVal;
2198
- }
2199
-
2200
- var Logger = /*#__PURE__*/function () {
2201
- function Logger() {}
2202
- /**
2203
- * Logs to client logs storage.
2204
- *
2205
- * WARNING! this method should ce used carefully for critical logging as we have the restriction for storing logs
2206
- * on client side as we store them inside the local storage. Please see details inside storage.js
2207
- * @param logString {string} log string
2208
- * @param source {string} source of the log entry
2209
- */
2210
- Logger.log = function log(logString, source) {
2211
- var timestamp = new Date().toISOString();
2212
- LogsStorage.saveLog(timestamp + "|" + source + ":" + logString);
2213
- };
2214
- Logger.logError = function logError(e, settingFunction, additionalMessage, onlyToConsole) {
2215
- var _e$errorDescription, _e$howToFix;
2216
- if (additionalMessage === void 0) {
2217
- additionalMessage = "";
2218
- }
2219
- if (onlyToConsole === void 0) {
2220
- onlyToConsole = false;
2221
- }
2222
- var message = "\nFunction call " + (settingFunction != null ? settingFunction : "") + " failed. Error message: " + (e == null ? void 0 : e.message) + ". " + additionalMessage + " ";
2223
- message += "" + ((_e$errorDescription = e == null ? void 0 : e.errorDescription) != null ? _e$errorDescription : "") + ((_e$howToFix = e == null ? void 0 : e.howToFix) != null ? _e$howToFix : "") + ((e == null ? void 0 : e.httpStatus) === 403 ? "Authentication has expired or was lost. " : "");
2224
- if (e != null && e.response) {
2225
- try {
2226
- var responseData = safeStringify({
2227
- response: e.response
2228
- });
2229
- responseData && (message += "\n" + responseData + ". ");
2230
- } catch (e) {}
2231
- }
2232
- var finalErrorText = message + ". " + safeStringify(e);
2233
- // eslint-disable-next-line no-console
2234
- console.error(finalErrorText);
2235
- if (!onlyToConsole) {
2236
- this.log(finalErrorText, "logError");
2237
- }
2238
- };
2239
- return Logger;
2240
- }();
2241
-
2242
2298
  /**
2243
2299
  * TODO: [tests, critical] Ued by payments logic
2244
2300
  *
@@ -2627,7 +2683,7 @@ var ExistingSwapWithFiatData = /*#__PURE__*/function (_ExistingSwap) {
2627
2683
  return ExistingSwapWithFiatData;
2628
2684
  }(ExistingSwap);
2629
2685
 
2630
- var PublicSwapCreationInfo =
2686
+ var BaseSwapCreationInfo =
2631
2687
  /**
2632
2688
  * @param fromCoin {Coin}
2633
2689
  * @param toCoin {Coin}
@@ -2641,7 +2697,7 @@ var PublicSwapCreationInfo =
2641
2697
  * @param fiatMax {number}
2642
2698
  * @param durationMinutesRange {string}
2643
2699
  */
2644
- function PublicSwapCreationInfo(fromCoin, toCoin, fromAmountCoins, toAmountCoins, rate, rawSwapData, min, fiatMin, max, fiatMax, durationMinutesRange) {
2700
+ function BaseSwapCreationInfo(fromCoin, toCoin, fromAmountCoins, toAmountCoins, rate, rawSwapData, min, fiatMin, max, fiatMax, durationMinutesRange) {
2645
2701
  this.fromCoin = fromCoin;
2646
2702
  this.toCoin = toCoin;
2647
2703
  this.fromAmountCoins = fromAmountCoins;
@@ -3320,7 +3376,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3320
3376
  });
3321
3377
  }, function (e) {
3322
3378
  var _e$response4, _e$response5;
3323
- Logger.log("Failed to create swap. Error is: " + safeStringify(e), loggerSource);
3379
+ Logger.logError(e, loggerSource, "Failed to create swap. Error is: " + safeStringify(e));
3324
3380
  var composeFailResult = function composeFailResult(reason) {
3325
3381
  return {
3326
3382
  result: false,
@@ -3429,7 +3485,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
3429
3485
  });
3430
3486
  }, function (e) {
3431
3487
  var _e$response6, _e$response7;
3432
- Logger.log("Failed to get swap details. Error is: " + safeStringify(e), loggerSource);
3488
+ Logger.logError(e, loggerSource, "Failed to get swap details. Error is: " + safeStringify(e));
3433
3489
  var composeFailResult = function composeFailResult(reason) {
3434
3490
  return {
3435
3491
  result: false,
@@ -3705,7 +3761,7 @@ var SwapUtils = /*#__PURE__*/function () {
3705
3761
  });
3706
3762
  });
3707
3763
  }, function (e) {
3708
- Logger.log("Failed to init swap: " + safeStringify(e), loggerSource);
3764
+ Logger.logError(e, loggerSource, "Failed to init swap: " + safeStringify(e));
3709
3765
  improveAndRethrow(e, loggerSource);
3710
3766
  }));
3711
3767
  } catch (e) {
@@ -3805,9 +3861,7 @@ var PublicSwapService = /*#__PURE__*/function () {
3805
3861
  try {
3806
3862
  var _this = this;
3807
3863
  var _temp = _catch(function () {
3808
- return Promise.resolve(_this._swapProvider.initialize()).then(function () {
3809
- SwapUtils.safeHandleRequestsLimitExceeding();
3810
- });
3864
+ return Promise.resolve(_this._swapProvider.initialize()).then(function () {});
3811
3865
  }, function (e) {
3812
3866
  Logger.logError(e, "PublicSwapService.initialize");
3813
3867
  });
@@ -3831,7 +3885,7 @@ var PublicSwapService = /*#__PURE__*/function () {
3831
3885
  SwapUtils.safeHandleRequestsLimitExceeding();
3832
3886
  return {
3833
3887
  result: false,
3834
- reason: _this2.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3888
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3835
3889
  };
3836
3890
  }
3837
3891
  Logger.log("Retrieved " + (result == null || (_result$coins = result.coins) == null ? void 0 : _result$coins.length) + " supported currencies for swap", loggerSource);
@@ -3880,13 +3934,13 @@ var PublicSwapService = /*#__PURE__*/function () {
3880
3934
  SwapUtils.safeHandleRequestsLimitExceeding();
3881
3935
  return {
3882
3936
  result: false,
3883
- reason: _this3.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3937
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
3884
3938
  };
3885
3939
  }
3886
3940
  if (result.reason === SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED) {
3887
3941
  return {
3888
3942
  result: false,
3889
- reason: _this3.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED
3943
+ reason: PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED
3890
3944
  };
3891
3945
  }
3892
3946
  }
@@ -3915,7 +3969,7 @@ var PublicSwapService = /*#__PURE__*/function () {
3915
3969
  * fiatMax: (number|null)
3916
3970
  * }|{
3917
3971
  * result: true,
3918
- * swapCreationInfo: PublicSwapCreationInfo
3972
+ * swapCreationInfo: BaseSwapCreationInfo
3919
3973
  * }>}
3920
3974
  */
3921
3975
  ;
@@ -3935,10 +3989,10 @@ var PublicSwapService = /*#__PURE__*/function () {
3935
3989
  fiatMax = null;
3936
3990
  if (coinUsdtRate != null) {
3937
3991
  if (min != null) {
3938
- fiatMin = bignumber_js.BigNumber(min).times(coinUsdtRate).toFixed(_this4._fiatDecimalsCount);
3992
+ fiatMin = bignumber_js.BigNumber(min).times(coinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
3939
3993
  }
3940
3994
  if (max != null) {
3941
- fiatMax = bignumber_js.BigNumber(max).times(coinUsdtRate).toFixed(_this4._fiatDecimalsCount);
3995
+ fiatMax = bignumber_js.BigNumber(max).times(coinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
3942
3996
  }
3943
3997
  }
3944
3998
  var composeFailResult = function composeFailResult(reason) {
@@ -3954,21 +4008,21 @@ var PublicSwapService = /*#__PURE__*/function () {
3954
4008
  };
3955
4009
  };
3956
4010
  if (!details.result) {
3957
- if ((details == null ? void 0 : details.reason) === SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED) return composeFailResult(_this4.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED);else if ((details == null ? void 0 : details.reason) === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
4011
+ if ((details == null ? void 0 : details.reason) === SwapProvider.NO_SWAPS_REASONS.NOT_SUPPORTED) return composeFailResult(PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.PAIR_NOT_SUPPORTED);else if ((details == null ? void 0 : details.reason) === SwapProvider.COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED) {
3958
4012
  SwapUtils.safeHandleRequestsLimitExceeding();
3959
- return composeFailResult(_this4.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
4013
+ return composeFailResult(PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED);
3960
4014
  }
3961
4015
  }
3962
4016
  var fromAmountBigNumber = bignumber_js.BigNumber(fromAmountCoins);
3963
4017
  if (typeof min === "string" && fromAmountBigNumber.lt(min)) {
3964
- return composeFailResult(_this4.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_LESS_THAN_MIN_SWAPPABLE);
4018
+ return composeFailResult(PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_LESS_THAN_MIN_SWAPPABLE);
3965
4019
  } else if (typeof max === "string" && fromAmountBigNumber.gt(max)) {
3966
- return composeFailResult(_this4.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_HIGHER_THAN_MAX_SWAPPABLE);
4020
+ return composeFailResult(PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS.AMOUNT_HIGHER_THAN_MAX_SWAPPABLE);
3967
4021
  }
3968
4022
  var toAmountCoins = AmountUtils.trim(fromAmountBigNumber.times(details.rate), fromCoin.digits);
3969
4023
  var result = {
3970
4024
  result: true,
3971
- swapCreationInfo: new PublicSwapCreationInfo(fromCoin, toCoin, fromAmountCoins, toAmountCoins, details.rate, details.rawSwapData, min, fiatMin, max, fiatMax, details.durationMinutesRange)
4025
+ swapCreationInfo: new BaseSwapCreationInfo(fromCoin, toCoin, fromAmountCoins, toAmountCoins, details.rate, details.rawSwapData, min, fiatMin, max, fiatMax, details.durationMinutesRange)
3972
4026
  };
3973
4027
  Logger.log("Result: " + safeStringify({
3974
4028
  result: result.result,
@@ -3993,9 +4047,10 @@ var PublicSwapService = /*#__PURE__*/function () {
3993
4047
  * @param fromCoin {Coin}
3994
4048
  * @param toCoin {Coin}
3995
4049
  * @param fromAmount {string}
3996
- * @param swapCreationInfo {PublicSwapCreationInfo}
4050
+ * @param swapCreationInfo {BaseSwapCreationInfo}
3997
4051
  * @param toAddress {string}
3998
4052
  * @param refundAddress {string}
4053
+ * @param clientIp {string}
3999
4054
  * @return {Promise<{
4000
4055
  * result: true,
4001
4056
  * fiatCurrencyCode: string,
@@ -4022,7 +4077,7 @@ var PublicSwapService = /*#__PURE__*/function () {
4022
4077
  var loggerSource = "createPublicSwap";
4023
4078
  return Promise.resolve(_catch(function () {
4024
4079
  var _swapCreationInfo$fro, _swapCreationInfo$toC;
4025
- if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof fromAmount !== "string" || typeof toAddress !== "string" || typeof refundAddress !== "string" || !(swapCreationInfo instanceof PublicSwapCreationInfo)) {
4080
+ if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof fromAmount !== "string" || typeof toAddress !== "string" || typeof refundAddress !== "string" || !(swapCreationInfo instanceof BaseSwapCreationInfo)) {
4026
4081
  throw new Error("Wrong input: " + fromCoin.ticker + " " + toCoin.ticker + " " + fromAmount + " " + swapCreationInfo);
4027
4082
  }
4028
4083
  Logger.log("Start: " + fromAmount + " " + fromCoin.ticker + " -> " + toCoin.ticker + ". Details: " + safeStringify(_extends({}, swapCreationInfo, {
@@ -4044,21 +4099,21 @@ var PublicSwapService = /*#__PURE__*/function () {
4044
4099
  SwapUtils.safeHandleRequestsLimitExceeding();
4045
4100
  return {
4046
4101
  result: false,
4047
- reason: _this5.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
4102
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
4048
4103
  };
4049
4104
  }
4050
4105
  if ((result == null ? void 0 : result.reason) === SwapProvider.CREATION_FAIL_REASONS.RETRIABLE_FAIL) {
4051
4106
  // TODO: [feature, high] implement retrying if one partner fail and we have another partners task_id=a07e367e488f4a4899613ac9056fa359
4052
4107
  // return {
4053
4108
  // result: false,
4054
- // reason: this.SWAP_CREATION_FAIL_REASONS.RETRIABLE_FAIL,
4109
+ // reason: PublicSwapService.SWAP_CREATION_FAIL_REASONS.RETRIABLE_FAIL,
4055
4110
  // };
4056
4111
  }
4057
4112
  }
4058
4113
  var _temp4 = function () {
4059
4114
  if (result.result && result != null && result.swapId) {
4060
4115
  var _temp3 = function _temp3() {
4061
- EventBusInstance.dispatch(_this5.PUBLIC_SWAP_CREATED_EVENT, null, fromCoin.ticker, toCoin.ticker, _fromAmountFiat);
4116
+ EventBusInstance__default["default"].dispatch(PublicSwapService.PUBLIC_SWAP_CREATED_EVENT, null, fromCoin.ticker, toCoin.ticker, _fromAmountFiat);
4062
4117
  var toReturn = {
4063
4118
  result: true,
4064
4119
  swapId: result.swapId,
@@ -4069,7 +4124,7 @@ var PublicSwapService = /*#__PURE__*/function () {
4069
4124
  fromAmountFiat: _fromAmountFiat,
4070
4125
  toAmountFiat: _toAmountFiat,
4071
4126
  fiatCurrencyCode: "USD",
4072
- fiatCurrencyDecimals: _this5._fiatDecimalsCount,
4127
+ fiatCurrencyDecimals: PublicSwapService._fiatDecimalsCount,
4073
4128
  rate: result.rate,
4074
4129
  durationMinutesRange: swapCreationInfo.durationMinutesRange,
4075
4130
  address: result.fromAddress // CRITICAL: this is the address to send coins to swaps provider
@@ -4092,10 +4147,10 @@ var PublicSwapService = /*#__PURE__*/function () {
4092
4147
  var _this5$_swapProvider$4;
4093
4148
  var toCoinUsdtRate = (_this5$_swapProvider$4 = _this5$_swapProvider$2 == null ? void 0 : _this5$_swapProvider$2.rate) != null ? _this5$_swapProvider$4 : null;
4094
4149
  if (fromCoinUsdtRate != null && result.fromAmount != null) {
4095
- _fromAmountFiat = bignumber_js.BigNumber(result.fromAmount).times(fromCoinUsdtRate).toFixed(_this5._fiatDecimalsCount);
4150
+ _fromAmountFiat = bignumber_js.BigNumber(result.fromAmount).times(fromCoinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
4096
4151
  }
4097
4152
  if (toCoinUsdtRate != null && result.toAmount != null) {
4098
- _toAmountFiat = bignumber_js.BigNumber(result.toAmount).times(toCoinUsdtRate).toFixed(_this5._fiatDecimalsCount);
4153
+ _toAmountFiat = bignumber_js.BigNumber(result.toAmount).times(toCoinUsdtRate).toFixed(PublicSwapService._fiatDecimalsCount);
4099
4154
  }
4100
4155
  });
4101
4156
  });
@@ -4139,7 +4194,7 @@ var PublicSwapService = /*#__PURE__*/function () {
4139
4194
  SwapUtils.safeHandleRequestsLimitExceeding();
4140
4195
  return {
4141
4196
  result: false,
4142
- reason: _this6.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
4197
+ reason: PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS.REQUESTS_LIMIT_EXCEEDED
4143
4198
  };
4144
4199
  }
4145
4200
  throw new Error("Unknown reason: " + (result == null ? void 0 : result.reason));
@@ -4290,6 +4345,7 @@ PublicSwapService._fiatDecimalsCount = FiatCurrenciesService.getCurrencyDecimalC
4290
4345
 
4291
4346
  exports.AmountUtils = AmountUtils;
4292
4347
  exports.AssetIcon = AssetIcon;
4348
+ exports.BaseSwapCreationInfo = BaseSwapCreationInfo;
4293
4349
  exports.Blockchain = Blockchain;
4294
4350
  exports.Button = Button;
4295
4351
  exports.Cache = Cache;
@@ -4302,7 +4358,6 @@ exports.LoadingDots = LoadingDots;
4302
4358
  exports.Logger = Logger;
4303
4359
  exports.LogsStorage = LogsStorage;
4304
4360
  exports.Protocol = Protocol;
4305
- exports.PublicSwapCreationInfo = PublicSwapCreationInfo;
4306
4361
  exports.PublicSwapService = PublicSwapService;
4307
4362
  exports.SupportChat = SupportChat;
4308
4363
  exports.SwapProvider = SwapProvider;
@@ -4310,4 +4365,6 @@ exports.SwapUtils = SwapUtils;
4310
4365
  exports.SwapspaceSwapProvider = SwapspaceSwapProvider;
4311
4366
  exports.improveAndRethrow = improveAndRethrow;
4312
4367
  exports.safeStringify = safeStringify;
4368
+ exports.useCallHandlingErrors = useCallHandlingErrors;
4369
+ exports.useReferredState = useReferredState;
4313
4370
  //# sourceMappingURL=index.cjs.map