@rabbitio/ui-kit 1.0.0-beta.14 → 1.0.0-beta.16
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 +222 -207
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +183 -187
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +220 -206
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +226 -210
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/hooks/useCallHandlingErrors.js +26 -0
- package/src/components/hooks/useReferredState.js +24 -0
- package/src/index.js +4 -1
- package/src/swaps-lib/models/{publicSwapCreationInfo.js → baseSwapCreationInfo.js} +1 -1
- package/src/swaps-lib/services/publicSwapService.js +27 -72
package/dist/index.umd.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
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'
|
|
4
|
-
(global = global || self, factory(global.uiKit = {}, global.react, global.bignumber_js, global.axios
|
|
5
|
-
})(this, (function (exports, React, bignumber_js, axios
|
|
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
9
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
10
|
-
var EventBusInstance__default = /*#__PURE__*/_interopDefaultLegacy(EventBusInstance);
|
|
11
10
|
|
|
12
11
|
function createCommonjsModule(fn) {
|
|
13
12
|
var module = { exports: {} };
|
|
@@ -1481,6 +1480,198 @@
|
|
|
1481
1480
|
small: false
|
|
1482
1481
|
};
|
|
1483
1482
|
|
|
1483
|
+
var LogsStorage = /*#__PURE__*/function () {
|
|
1484
|
+
function LogsStorage() {}
|
|
1485
|
+
LogsStorage.saveLog = function saveLog(log) {
|
|
1486
|
+
this._inMemoryStorage.push(log);
|
|
1487
|
+
};
|
|
1488
|
+
LogsStorage.getInMemoryLogs = function getInMemoryLogs() {
|
|
1489
|
+
return this._inMemoryStorage;
|
|
1490
|
+
};
|
|
1491
|
+
LogsStorage.getAllLogs = function getAllLogs() {
|
|
1492
|
+
var storedLogs = "";
|
|
1493
|
+
if (typeof window !== "undefined") {
|
|
1494
|
+
storedLogs = localStorage.getItem(this._logsStorageId);
|
|
1495
|
+
}
|
|
1496
|
+
return storedLogs + "\n" + this._inMemoryStorage.join("\n");
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
/**
|
|
1500
|
+
* @param logger {Logger}
|
|
1501
|
+
*/;
|
|
1502
|
+
LogsStorage.saveToTheDisk = function saveToTheDisk(logger) {
|
|
1503
|
+
try {
|
|
1504
|
+
var MAX_LOCAL_STORAGE_VOLUME_BYTES = 5 * 1024 * 1024;
|
|
1505
|
+
var MAX_LOGS_STORAGE_BYTES = MAX_LOCAL_STORAGE_VOLUME_BYTES * 0.65;
|
|
1506
|
+
if (typeof window !== "undefined") {
|
|
1507
|
+
var existingLogs = localStorage.getItem(this._logsStorageId);
|
|
1508
|
+
var logsString = existingLogs + "\n" + this._inMemoryStorage.join("\n");
|
|
1509
|
+
var lettersCountToRemove = logsString.length - Math.round(MAX_LOGS_STORAGE_BYTES / 2);
|
|
1510
|
+
if (lettersCountToRemove > 0) {
|
|
1511
|
+
localStorage.setItem(this._logsStorageId, logsString.slice(lettersCountToRemove, logsString.length));
|
|
1512
|
+
} else {
|
|
1513
|
+
localStorage.setItem(this._logsStorageId, logsString);
|
|
1514
|
+
}
|
|
1515
|
+
this._inMemoryStorage = [];
|
|
1516
|
+
}
|
|
1517
|
+
} catch (e) {
|
|
1518
|
+
logger == null || logger.logError(e, "saveToTheDisk", "Failed to save logs to disk");
|
|
1519
|
+
}
|
|
1520
|
+
};
|
|
1521
|
+
LogsStorage.removeAllClientLogs = function removeAllClientLogs() {
|
|
1522
|
+
if (typeof window !== "undefined") {
|
|
1523
|
+
if (localStorage.getItem("doNotRemoveClientLogsWhenSignedOut") !== "true") {
|
|
1524
|
+
localStorage.removeItem(this._logsStorageId);
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
this._inMemoryStorage = [];
|
|
1528
|
+
};
|
|
1529
|
+
LogsStorage.setDoNotRemoveClientLogsWhenSignedOut = function setDoNotRemoveClientLogsWhenSignedOut(value) {
|
|
1530
|
+
if (typeof window !== "undefined") {
|
|
1531
|
+
localStorage.setItem("doNotRemoveClientLogsWhenSignedOut", value);
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
return LogsStorage;
|
|
1535
|
+
}();
|
|
1536
|
+
LogsStorage._inMemoryStorage = [];
|
|
1537
|
+
LogsStorage._logsStorageId = "clietnLogs_j203fj2D0n-d1";
|
|
1538
|
+
|
|
1539
|
+
/**
|
|
1540
|
+
* Stringify given object by use of JSON.stringify but handles circular structures and "response", "request" properties
|
|
1541
|
+
* to avoid stringing redundant data when printing errors containing request/response objects.
|
|
1542
|
+
*
|
|
1543
|
+
* @param object - object to be stringed
|
|
1544
|
+
* @param indent - custom indentation
|
|
1545
|
+
* @return {string} - stringed object
|
|
1546
|
+
*/
|
|
1547
|
+
function safeStringify(object, indent) {
|
|
1548
|
+
if (indent === void 0) {
|
|
1549
|
+
indent = 2;
|
|
1550
|
+
}
|
|
1551
|
+
var cache = [];
|
|
1552
|
+
if (typeof object === "string" || typeof object === "function" || typeof object === "number" || typeof object === "undefined" || typeof object === "boolean") {
|
|
1553
|
+
return String(object);
|
|
1554
|
+
}
|
|
1555
|
+
var retVal = JSON.stringify(object, function (key, value) {
|
|
1556
|
+
if (key.toLowerCase().includes("request")) {
|
|
1557
|
+
return JSON.stringify({
|
|
1558
|
+
body: value == null ? void 0 : value.body,
|
|
1559
|
+
query: value == null ? void 0 : value.query,
|
|
1560
|
+
headers: value == null ? void 0 : value.headers
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
if (key.toLowerCase().includes("response")) {
|
|
1564
|
+
return JSON.stringify({
|
|
1565
|
+
statusText: value == null ? void 0 : value.statusText,
|
|
1566
|
+
status: value == null ? void 0 : value.status,
|
|
1567
|
+
data: value == null ? void 0 : value.data,
|
|
1568
|
+
headers: value == null ? void 0 : value.headers
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
return typeof value === "object" && value !== null ? cache.includes(value) ? "duplicated reference" // Duplicated references were found, discarding this key
|
|
1572
|
+
: cache.push(value) && value // Store value in our collection
|
|
1573
|
+
: value;
|
|
1574
|
+
}, indent);
|
|
1575
|
+
cache = null;
|
|
1576
|
+
return retVal;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
var Logger = /*#__PURE__*/function () {
|
|
1580
|
+
function Logger() {}
|
|
1581
|
+
/**
|
|
1582
|
+
* Logs to client logs storage.
|
|
1583
|
+
*
|
|
1584
|
+
* WARNING! this method should ce used carefully for critical logging as we have the restriction for storing logs
|
|
1585
|
+
* on client side as we store them inside the local storage. Please see details inside storage.js
|
|
1586
|
+
* @param logString {string} log string
|
|
1587
|
+
* @param source {string} source of the log entry
|
|
1588
|
+
*/
|
|
1589
|
+
Logger.log = function log(logString, source) {
|
|
1590
|
+
var timestamp = new Date().toISOString();
|
|
1591
|
+
LogsStorage.saveLog(timestamp + "|" + source + ":" + logString);
|
|
1592
|
+
};
|
|
1593
|
+
Logger.logError = function logError(e, settingFunction, additionalMessage, onlyToConsole) {
|
|
1594
|
+
var _e$errorDescription, _e$howToFix;
|
|
1595
|
+
if (additionalMessage === void 0) {
|
|
1596
|
+
additionalMessage = "";
|
|
1597
|
+
}
|
|
1598
|
+
if (onlyToConsole === void 0) {
|
|
1599
|
+
onlyToConsole = false;
|
|
1600
|
+
}
|
|
1601
|
+
var message = "\nFunction call " + (settingFunction != null ? settingFunction : "") + " failed. Error message: " + (e == null ? void 0 : e.message) + ". " + additionalMessage + " ";
|
|
1602
|
+
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. " : "");
|
|
1603
|
+
if (e != null && e.response) {
|
|
1604
|
+
try {
|
|
1605
|
+
var responseData = safeStringify({
|
|
1606
|
+
response: e.response
|
|
1607
|
+
});
|
|
1608
|
+
responseData && (message += "\n" + responseData + ". ");
|
|
1609
|
+
} catch (e) {}
|
|
1610
|
+
}
|
|
1611
|
+
var finalErrorText = message + ". " + safeStringify(e);
|
|
1612
|
+
// eslint-disable-next-line no-console
|
|
1613
|
+
console.error(finalErrorText);
|
|
1614
|
+
if (!onlyToConsole) {
|
|
1615
|
+
this.log(finalErrorText, "logError");
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
return Logger;
|
|
1619
|
+
}();
|
|
1620
|
+
|
|
1621
|
+
function _catch$4(body, recover) {
|
|
1622
|
+
try {
|
|
1623
|
+
var result = body();
|
|
1624
|
+
} catch (e) {
|
|
1625
|
+
return recover(e);
|
|
1626
|
+
}
|
|
1627
|
+
if (result && result.then) {
|
|
1628
|
+
return result.then(void 0, recover);
|
|
1629
|
+
}
|
|
1630
|
+
return result;
|
|
1631
|
+
}
|
|
1632
|
+
function useCallHandlingErrors() {
|
|
1633
|
+
var _useState = React.useState(),
|
|
1634
|
+
setState = _useState[1];
|
|
1635
|
+
return React.useCallback(function (functionToBeCalled, event) {
|
|
1636
|
+
try {
|
|
1637
|
+
var _temp = _catch$4(function () {
|
|
1638
|
+
return Promise.resolve(functionToBeCalled(event)).then(function () {});
|
|
1639
|
+
}, function (error) {
|
|
1640
|
+
Logger.logError(error, (functionToBeCalled == null ? void 0 : functionToBeCalled.name) || "errorBoundaryTrigger", "Caught by ErrorBoundary");
|
|
1641
|
+
// Triggering ErrorBoundary
|
|
1642
|
+
setState(function () {
|
|
1643
|
+
throw error;
|
|
1644
|
+
});
|
|
1645
|
+
});
|
|
1646
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
|
1647
|
+
} catch (e) {
|
|
1648
|
+
return Promise.reject(e);
|
|
1649
|
+
}
|
|
1650
|
+
}, []);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
/**
|
|
1654
|
+
* Adds reference to standard state variable. It is helpful to be able to use state variable value inside
|
|
1655
|
+
* event handlers and other callbacks without the need to call setState(prev => { value = prev; return prev; }).
|
|
1656
|
+
*
|
|
1657
|
+
* @param initialValue {any} to be passed to useState
|
|
1658
|
+
* @return {[React.Ref, function]} reference to state variable and its setter
|
|
1659
|
+
*/
|
|
1660
|
+
function useReferredState(initialValue) {
|
|
1661
|
+
var _React$useState = React__default["default"].useState(initialValue),
|
|
1662
|
+
state = _React$useState[0],
|
|
1663
|
+
setState = _React$useState[1];
|
|
1664
|
+
var reference = React__default["default"].useRef(state);
|
|
1665
|
+
var setReferredState = function setReferredState(value) {
|
|
1666
|
+
if (value && {}.toString.call(value) === "[object Function]") {
|
|
1667
|
+
value = value(reference.current);
|
|
1668
|
+
}
|
|
1669
|
+
reference.current = value;
|
|
1670
|
+
setState(value);
|
|
1671
|
+
};
|
|
1672
|
+
return [reference, setReferredState];
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1484
1675
|
/**
|
|
1485
1676
|
* This function improves the passed error object (its message) by adding the passed function name
|
|
1486
1677
|
* and additional message to it.
|
|
@@ -2103,144 +2294,6 @@
|
|
|
2103
2294
|
return Coin;
|
|
2104
2295
|
}();
|
|
2105
2296
|
|
|
2106
|
-
var LogsStorage = /*#__PURE__*/function () {
|
|
2107
|
-
function LogsStorage() {}
|
|
2108
|
-
LogsStorage.saveLog = function saveLog(log) {
|
|
2109
|
-
this._inMemoryStorage.push(log);
|
|
2110
|
-
};
|
|
2111
|
-
LogsStorage.getInMemoryLogs = function getInMemoryLogs() {
|
|
2112
|
-
return this._inMemoryStorage;
|
|
2113
|
-
};
|
|
2114
|
-
LogsStorage.getAllLogs = function getAllLogs() {
|
|
2115
|
-
var storedLogs = "";
|
|
2116
|
-
if (typeof window !== "undefined") {
|
|
2117
|
-
storedLogs = localStorage.getItem(this._logsStorageId);
|
|
2118
|
-
}
|
|
2119
|
-
return storedLogs + "\n" + this._inMemoryStorage.join("\n");
|
|
2120
|
-
}
|
|
2121
|
-
|
|
2122
|
-
/**
|
|
2123
|
-
* @param logger {Logger}
|
|
2124
|
-
*/;
|
|
2125
|
-
LogsStorage.saveToTheDisk = function saveToTheDisk(logger) {
|
|
2126
|
-
try {
|
|
2127
|
-
var MAX_LOCAL_STORAGE_VOLUME_BYTES = 5 * 1024 * 1024;
|
|
2128
|
-
var MAX_LOGS_STORAGE_BYTES = MAX_LOCAL_STORAGE_VOLUME_BYTES * 0.65;
|
|
2129
|
-
if (typeof window !== "undefined") {
|
|
2130
|
-
var existingLogs = localStorage.getItem(this._logsStorageId);
|
|
2131
|
-
var logsString = existingLogs + "\n" + this._inMemoryStorage.join("\n");
|
|
2132
|
-
var lettersCountToRemove = logsString.length - Math.round(MAX_LOGS_STORAGE_BYTES / 2);
|
|
2133
|
-
if (lettersCountToRemove > 0) {
|
|
2134
|
-
localStorage.setItem(this._logsStorageId, logsString.slice(lettersCountToRemove, logsString.length));
|
|
2135
|
-
} else {
|
|
2136
|
-
localStorage.setItem(this._logsStorageId, logsString);
|
|
2137
|
-
}
|
|
2138
|
-
this._inMemoryStorage = [];
|
|
2139
|
-
}
|
|
2140
|
-
} catch (e) {
|
|
2141
|
-
logger == null || logger.logError(e, "saveToTheDisk", "Failed to save logs to disk");
|
|
2142
|
-
}
|
|
2143
|
-
};
|
|
2144
|
-
LogsStorage.removeAllClientLogs = function removeAllClientLogs() {
|
|
2145
|
-
if (typeof window !== "undefined") {
|
|
2146
|
-
if (localStorage.getItem("doNotRemoveClientLogsWhenSignedOut") !== "true") {
|
|
2147
|
-
localStorage.removeItem(this._logsStorageId);
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
this._inMemoryStorage = [];
|
|
2151
|
-
};
|
|
2152
|
-
LogsStorage.setDoNotRemoveClientLogsWhenSignedOut = function setDoNotRemoveClientLogsWhenSignedOut(value) {
|
|
2153
|
-
if (typeof window !== "undefined") {
|
|
2154
|
-
localStorage.setItem("doNotRemoveClientLogsWhenSignedOut", value);
|
|
2155
|
-
}
|
|
2156
|
-
};
|
|
2157
|
-
return LogsStorage;
|
|
2158
|
-
}();
|
|
2159
|
-
LogsStorage._inMemoryStorage = [];
|
|
2160
|
-
LogsStorage._logsStorageId = "clietnLogs_j203fj2D0n-d1";
|
|
2161
|
-
|
|
2162
|
-
/**
|
|
2163
|
-
* Stringify given object by use of JSON.stringify but handles circular structures and "response", "request" properties
|
|
2164
|
-
* to avoid stringing redundant data when printing errors containing request/response objects.
|
|
2165
|
-
*
|
|
2166
|
-
* @param object - object to be stringed
|
|
2167
|
-
* @param indent - custom indentation
|
|
2168
|
-
* @return {string} - stringed object
|
|
2169
|
-
*/
|
|
2170
|
-
function safeStringify(object, indent) {
|
|
2171
|
-
if (indent === void 0) {
|
|
2172
|
-
indent = 2;
|
|
2173
|
-
}
|
|
2174
|
-
var cache = [];
|
|
2175
|
-
if (typeof object === "string" || typeof object === "function" || typeof object === "number" || typeof object === "undefined" || typeof object === "boolean") {
|
|
2176
|
-
return String(object);
|
|
2177
|
-
}
|
|
2178
|
-
var retVal = JSON.stringify(object, function (key, value) {
|
|
2179
|
-
if (key.toLowerCase().includes("request")) {
|
|
2180
|
-
return JSON.stringify({
|
|
2181
|
-
body: value == null ? void 0 : value.body,
|
|
2182
|
-
query: value == null ? void 0 : value.query,
|
|
2183
|
-
headers: value == null ? void 0 : value.headers
|
|
2184
|
-
});
|
|
2185
|
-
}
|
|
2186
|
-
if (key.toLowerCase().includes("response")) {
|
|
2187
|
-
return JSON.stringify({
|
|
2188
|
-
statusText: value == null ? void 0 : value.statusText,
|
|
2189
|
-
status: value == null ? void 0 : value.status,
|
|
2190
|
-
data: value == null ? void 0 : value.data,
|
|
2191
|
-
headers: value == null ? void 0 : value.headers
|
|
2192
|
-
});
|
|
2193
|
-
}
|
|
2194
|
-
return typeof value === "object" && value !== null ? cache.includes(value) ? "duplicated reference" // Duplicated references were found, discarding this key
|
|
2195
|
-
: cache.push(value) && value // Store value in our collection
|
|
2196
|
-
: value;
|
|
2197
|
-
}, indent);
|
|
2198
|
-
cache = null;
|
|
2199
|
-
return retVal;
|
|
2200
|
-
}
|
|
2201
|
-
|
|
2202
|
-
var Logger = /*#__PURE__*/function () {
|
|
2203
|
-
function Logger() {}
|
|
2204
|
-
/**
|
|
2205
|
-
* Logs to client logs storage.
|
|
2206
|
-
*
|
|
2207
|
-
* WARNING! this method should ce used carefully for critical logging as we have the restriction for storing logs
|
|
2208
|
-
* on client side as we store them inside the local storage. Please see details inside storage.js
|
|
2209
|
-
* @param logString {string} log string
|
|
2210
|
-
* @param source {string} source of the log entry
|
|
2211
|
-
*/
|
|
2212
|
-
Logger.log = function log(logString, source) {
|
|
2213
|
-
var timestamp = new Date().toISOString();
|
|
2214
|
-
LogsStorage.saveLog(timestamp + "|" + source + ":" + logString);
|
|
2215
|
-
};
|
|
2216
|
-
Logger.logError = function logError(e, settingFunction, additionalMessage, onlyToConsole) {
|
|
2217
|
-
var _e$errorDescription, _e$howToFix;
|
|
2218
|
-
if (additionalMessage === void 0) {
|
|
2219
|
-
additionalMessage = "";
|
|
2220
|
-
}
|
|
2221
|
-
if (onlyToConsole === void 0) {
|
|
2222
|
-
onlyToConsole = false;
|
|
2223
|
-
}
|
|
2224
|
-
var message = "\nFunction call " + (settingFunction != null ? settingFunction : "") + " failed. Error message: " + (e == null ? void 0 : e.message) + ". " + additionalMessage + " ";
|
|
2225
|
-
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. " : "");
|
|
2226
|
-
if (e != null && e.response) {
|
|
2227
|
-
try {
|
|
2228
|
-
var responseData = safeStringify({
|
|
2229
|
-
response: e.response
|
|
2230
|
-
});
|
|
2231
|
-
responseData && (message += "\n" + responseData + ". ");
|
|
2232
|
-
} catch (e) {}
|
|
2233
|
-
}
|
|
2234
|
-
var finalErrorText = message + ". " + safeStringify(e);
|
|
2235
|
-
// eslint-disable-next-line no-console
|
|
2236
|
-
console.error(finalErrorText);
|
|
2237
|
-
if (!onlyToConsole) {
|
|
2238
|
-
this.log(finalErrorText, "logError");
|
|
2239
|
-
}
|
|
2240
|
-
};
|
|
2241
|
-
return Logger;
|
|
2242
|
-
}();
|
|
2243
|
-
|
|
2244
2297
|
/**
|
|
2245
2298
|
* TODO: [tests, critical] Ued by payments logic
|
|
2246
2299
|
*
|
|
@@ -2629,7 +2682,7 @@
|
|
|
2629
2682
|
return ExistingSwapWithFiatData;
|
|
2630
2683
|
}(ExistingSwap);
|
|
2631
2684
|
|
|
2632
|
-
var
|
|
2685
|
+
var BaseSwapCreationInfo =
|
|
2633
2686
|
/**
|
|
2634
2687
|
* @param fromCoin {Coin}
|
|
2635
2688
|
* @param toCoin {Coin}
|
|
@@ -2643,7 +2696,7 @@
|
|
|
2643
2696
|
* @param fiatMax {number}
|
|
2644
2697
|
* @param durationMinutesRange {string}
|
|
2645
2698
|
*/
|
|
2646
|
-
function
|
|
2699
|
+
function BaseSwapCreationInfo(fromCoin, toCoin, fromAmountCoins, toAmountCoins, rate, rawSwapData, min, fiatMin, max, fiatMax, durationMinutesRange) {
|
|
2647
2700
|
this.fromCoin = fromCoin;
|
|
2648
2701
|
this.toCoin = toCoin;
|
|
2649
2702
|
this.fromAmountCoins = fromAmountCoins;
|
|
@@ -3796,11 +3849,14 @@
|
|
|
3796
3849
|
}
|
|
3797
3850
|
return result;
|
|
3798
3851
|
}
|
|
3799
|
-
var API_KEYS_PROXY_URL = window.location.protocol + "//" + window.location.host + "/api/v1/proxy";
|
|
3800
|
-
var cache = new Cache(EventBusInstance__default["default"]);
|
|
3801
3852
|
var PublicSwapService = /*#__PURE__*/function () {
|
|
3802
|
-
function PublicSwapService() {
|
|
3803
|
-
|
|
3853
|
+
function PublicSwapService(API_KEYS_PROXY_URL, cache) {
|
|
3854
|
+
this._swapProvider = new SwapspaceSwapProvider(API_KEYS_PROXY_URL, cache, function () {
|
|
3855
|
+
return null;
|
|
3856
|
+
}, false);
|
|
3857
|
+
}
|
|
3858
|
+
var _proto = PublicSwapService.prototype;
|
|
3859
|
+
_proto.initialize = function initialize() {
|
|
3804
3860
|
try {
|
|
3805
3861
|
var _this = this;
|
|
3806
3862
|
var _temp = _catch(function () {
|
|
@@ -3815,7 +3871,7 @@
|
|
|
3815
3871
|
return Promise.reject(e);
|
|
3816
3872
|
}
|
|
3817
3873
|
};
|
|
3818
|
-
|
|
3874
|
+
_proto.getCurrenciesListForPublicSwap = function getCurrenciesListForPublicSwap(currencyThatShouldNotBeFirst) {
|
|
3819
3875
|
if (currencyThatShouldNotBeFirst === void 0) {
|
|
3820
3876
|
currencyThatShouldNotBeFirst = null;
|
|
3821
3877
|
}
|
|
@@ -3869,7 +3925,7 @@
|
|
|
3869
3925
|
* }>}
|
|
3870
3926
|
*/
|
|
3871
3927
|
;
|
|
3872
|
-
|
|
3928
|
+
_proto.getInitialPublicSwapData = function getInitialPublicSwapData(fromCoin, toCoin) {
|
|
3873
3929
|
try {
|
|
3874
3930
|
var _this3 = this;
|
|
3875
3931
|
return Promise.resolve(_catch(function () {
|
|
@@ -3914,11 +3970,11 @@
|
|
|
3914
3970
|
* fiatMax: (number|null)
|
|
3915
3971
|
* }|{
|
|
3916
3972
|
* result: true,
|
|
3917
|
-
* swapCreationInfo:
|
|
3973
|
+
* swapCreationInfo: BaseSwapCreationInfo
|
|
3918
3974
|
* }>}
|
|
3919
3975
|
*/
|
|
3920
3976
|
;
|
|
3921
|
-
|
|
3977
|
+
_proto.getPublicSwapDetails = function getPublicSwapDetails(fromCoin, toCoin, fromAmountCoins) {
|
|
3922
3978
|
try {
|
|
3923
3979
|
var _this4 = this;
|
|
3924
3980
|
var loggerSource = "getPublicSwapDetails";
|
|
@@ -3967,7 +4023,7 @@
|
|
|
3967
4023
|
var toAmountCoins = AmountUtils.trim(fromAmountBigNumber.times(details.rate), fromCoin.digits);
|
|
3968
4024
|
var result = {
|
|
3969
4025
|
result: true,
|
|
3970
|
-
swapCreationInfo: new
|
|
4026
|
+
swapCreationInfo: new BaseSwapCreationInfo(fromCoin, toCoin, fromAmountCoins, toAmountCoins, details.rate, details.rawSwapData, min, fiatMin, max, fiatMax, details.durationMinutesRange)
|
|
3971
4027
|
};
|
|
3972
4028
|
Logger.log("Result: " + safeStringify({
|
|
3973
4029
|
result: result.result,
|
|
@@ -3992,7 +4048,7 @@
|
|
|
3992
4048
|
* @param fromCoin {Coin}
|
|
3993
4049
|
* @param toCoin {Coin}
|
|
3994
4050
|
* @param fromAmount {string}
|
|
3995
|
-
* @param swapCreationInfo {
|
|
4051
|
+
* @param swapCreationInfo {BaseSwapCreationInfo}
|
|
3996
4052
|
* @param toAddress {string}
|
|
3997
4053
|
* @param refundAddress {string}
|
|
3998
4054
|
* @return {Promise<{
|
|
@@ -4015,13 +4071,13 @@
|
|
|
4015
4071
|
* }>}
|
|
4016
4072
|
*/
|
|
4017
4073
|
;
|
|
4018
|
-
|
|
4074
|
+
_proto.createPublicSwap = function createPublicSwap(fromCoin, toCoin, fromAmount, swapCreationInfo, toAddress, refundAddress, clientIp) {
|
|
4019
4075
|
try {
|
|
4020
4076
|
var _this5 = this;
|
|
4021
4077
|
var loggerSource = "createPublicSwap";
|
|
4022
4078
|
return Promise.resolve(_catch(function () {
|
|
4023
4079
|
var _swapCreationInfo$fro, _swapCreationInfo$toC;
|
|
4024
|
-
if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof fromAmount !== "string" || typeof toAddress !== "string" || typeof refundAddress !== "string" || !(swapCreationInfo instanceof
|
|
4080
|
+
if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof fromAmount !== "string" || typeof toAddress !== "string" || typeof refundAddress !== "string" || !(swapCreationInfo instanceof BaseSwapCreationInfo)) {
|
|
4025
4081
|
throw new Error("Wrong input: " + fromCoin.ticker + " " + toCoin.ticker + " " + fromAmount + " " + swapCreationInfo);
|
|
4026
4082
|
}
|
|
4027
4083
|
Logger.log("Start: " + fromAmount + " " + fromCoin.ticker + " -> " + toCoin.ticker + ". Details: " + safeStringify(_extends({}, swapCreationInfo, {
|
|
@@ -4057,7 +4113,7 @@
|
|
|
4057
4113
|
var _temp4 = function () {
|
|
4058
4114
|
if (result.result && result != null && result.swapId) {
|
|
4059
4115
|
var _temp3 = function _temp3() {
|
|
4060
|
-
|
|
4116
|
+
EventBusInstance.dispatch(_this5.PUBLIC_SWAP_CREATED_EVENT, null, fromCoin.ticker, toCoin.ticker, _fromAmountFiat);
|
|
4061
4117
|
var toReturn = {
|
|
4062
4118
|
result: true,
|
|
4063
4119
|
swapId: result.swapId,
|
|
@@ -4127,7 +4183,7 @@
|
|
|
4127
4183
|
* error reason is one of PUBLIC_SWAPS_COMMON_ERRORS
|
|
4128
4184
|
*/
|
|
4129
4185
|
;
|
|
4130
|
-
|
|
4186
|
+
_proto.getPublicExistingSwapDetailsAndStatus = function getPublicExistingSwapDetailsAndStatus(swapIds) {
|
|
4131
4187
|
try {
|
|
4132
4188
|
var _this6 = this;
|
|
4133
4189
|
var loggerSource = "getPublicExistingSwapDetailsAndStatus";
|
|
@@ -4164,7 +4220,7 @@
|
|
|
4164
4220
|
* }>}
|
|
4165
4221
|
*/
|
|
4166
4222
|
;
|
|
4167
|
-
|
|
4223
|
+
_proto.getPublicSwapsHistory = function getPublicSwapsHistory() {
|
|
4168
4224
|
try {
|
|
4169
4225
|
var _exit2;
|
|
4170
4226
|
var _this7 = this;
|
|
@@ -4197,7 +4253,7 @@
|
|
|
4197
4253
|
* @private
|
|
4198
4254
|
*/
|
|
4199
4255
|
;
|
|
4200
|
-
|
|
4256
|
+
_proto._savePublicSwapIdLocally = function _savePublicSwapIdLocally(swapId) {
|
|
4201
4257
|
if (typeof window !== "undefined") {
|
|
4202
4258
|
try {
|
|
4203
4259
|
var saved = localStorage.getItem("publicSwapIds");
|
|
@@ -4214,7 +4270,7 @@
|
|
|
4214
4270
|
* @private
|
|
4215
4271
|
* @return {string[]}
|
|
4216
4272
|
*/;
|
|
4217
|
-
|
|
4273
|
+
_proto._getPublicSwapIdsSavedLocally = function _getPublicSwapIdsSavedLocally() {
|
|
4218
4274
|
if (typeof window !== "undefined") {
|
|
4219
4275
|
try {
|
|
4220
4276
|
var saved = localStorage.getItem("publicSwapIds");
|
|
@@ -4229,7 +4285,7 @@
|
|
|
4229
4285
|
* @param coinOrTicker {Coin|string}
|
|
4230
4286
|
* @return {string} icon URL (ready to use)
|
|
4231
4287
|
*/;
|
|
4232
|
-
|
|
4288
|
+
_proto.getAssetIconUrl = function getAssetIconUrl(coinOrTicker) {
|
|
4233
4289
|
return this._swapProvider.getIconUrl(coinOrTicker);
|
|
4234
4290
|
}
|
|
4235
4291
|
|
|
@@ -4237,7 +4293,7 @@
|
|
|
4237
4293
|
* @param ticker {string}
|
|
4238
4294
|
* @return {Coin|null}
|
|
4239
4295
|
*/;
|
|
4240
|
-
|
|
4296
|
+
_proto.getCoinByTickerIfPresent = function getCoinByTickerIfPresent(ticker) {
|
|
4241
4297
|
return this._swapProvider.getCoinByTickerIfPresent(ticker);
|
|
4242
4298
|
}
|
|
4243
4299
|
|
|
@@ -4246,7 +4302,7 @@
|
|
|
4246
4302
|
* @param asset {Coin}
|
|
4247
4303
|
* @return {Promise<string|null>}
|
|
4248
4304
|
*/;
|
|
4249
|
-
|
|
4305
|
+
_proto.getAssetToUsdtRate = function getAssetToUsdtRate(asset) {
|
|
4250
4306
|
try {
|
|
4251
4307
|
var _this8 = this;
|
|
4252
4308
|
return Promise.resolve(_catch(function () {
|
|
@@ -4267,58 +4323,16 @@
|
|
|
4267
4323
|
* @return {boolean}
|
|
4268
4324
|
*/
|
|
4269
4325
|
;
|
|
4270
|
-
|
|
4326
|
+
_proto.isAddressValidForAsset = function isAddressValidForAsset(asset, address) {
|
|
4271
4327
|
try {
|
|
4272
4328
|
return this._swapProvider.isAddressValidForAsset(asset, address);
|
|
4273
4329
|
} catch (e) {
|
|
4274
4330
|
improveAndRethrow(e, "isAddressValidForAsset");
|
|
4275
4331
|
}
|
|
4276
|
-
}
|
|
4277
|
-
|
|
4278
|
-
// TODO: [dev] Remove if we don't need this inside the public swap steps
|
|
4279
|
-
// /**
|
|
4280
|
-
// * TODO: [feature, moderate] add other fiat currencies support. task_id=5490e21b8b9c4f89a2247b28db3c9e0a
|
|
4281
|
-
// * @param asset {Coin}
|
|
4282
|
-
// * @param amount {string}
|
|
4283
|
-
// * @return {Promise<string|null>}
|
|
4284
|
-
// */
|
|
4285
|
-
// static async convertSingleCoinAmountToUsdtOrNull(asset, amount) {
|
|
4286
|
-
// try {
|
|
4287
|
-
// const result = await this._swapProvider.getCoinToUSDTRate(asset);
|
|
4288
|
-
// if (result?.rate != null) {
|
|
4289
|
-
// const decimals = FiatCurrenciesService.getCurrencyDecimalCountByCode("USD");
|
|
4290
|
-
// return BigNumber(amount).div(result?.rate).toFixed(decimals);
|
|
4291
|
-
// }
|
|
4292
|
-
// return null;
|
|
4293
|
-
// } catch (e) {
|
|
4294
|
-
// improveAndRethrow(e, "convertSingleCoinAmountToUsdtOrNull");
|
|
4295
|
-
// }
|
|
4296
|
-
// }
|
|
4297
|
-
//
|
|
4298
|
-
// /**
|
|
4299
|
-
// * TODO: [feature, moderate] add other fiat currencies support. task_id=5490e21b8b9c4f89a2247b28db3c9e0a
|
|
4300
|
-
// * @param asset {Coin}
|
|
4301
|
-
// * @param amount {string}
|
|
4302
|
-
// * @return {Promise<string|null>}
|
|
4303
|
-
// */
|
|
4304
|
-
// static async convertSingleUsdtAmountToCoinOrNull(asset, amount) {
|
|
4305
|
-
// try {
|
|
4306
|
-
// const result = await this._swapProvider.getCoinToUSDTRate(asset);
|
|
4307
|
-
// if (result?.rate != null) {
|
|
4308
|
-
// return BigNumber(amount).times(result?.rate).toFixed(asset.digits);
|
|
4309
|
-
// }
|
|
4310
|
-
// return null;
|
|
4311
|
-
// } catch (e) {
|
|
4312
|
-
// improveAndRethrow(e, "convertSingleUsdtAmountToCoinOrNull");
|
|
4313
|
-
// }
|
|
4314
|
-
// }
|
|
4315
|
-
;
|
|
4332
|
+
};
|
|
4316
4333
|
return PublicSwapService;
|
|
4317
4334
|
}();
|
|
4318
4335
|
PublicSwapService.PUBLIC_SWAP_CREATED_EVENT = "publicSwapCreatedEvent";
|
|
4319
|
-
PublicSwapService._swapProvider = new SwapspaceSwapProvider(API_KEYS_PROXY_URL, cache, function () {
|
|
4320
|
-
return null;
|
|
4321
|
-
}, false);
|
|
4322
4336
|
PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS = {
|
|
4323
4337
|
REQUESTS_LIMIT_EXCEEDED: "requestsLimitExceeded"
|
|
4324
4338
|
};
|
|
@@ -4331,6 +4345,7 @@
|
|
|
4331
4345
|
|
|
4332
4346
|
exports.AmountUtils = AmountUtils;
|
|
4333
4347
|
exports.AssetIcon = AssetIcon;
|
|
4348
|
+
exports.BaseSwapCreationInfo = BaseSwapCreationInfo;
|
|
4334
4349
|
exports.Blockchain = Blockchain;
|
|
4335
4350
|
exports.Button = Button;
|
|
4336
4351
|
exports.Cache = Cache;
|
|
@@ -4343,7 +4358,6 @@
|
|
|
4343
4358
|
exports.Logger = Logger;
|
|
4344
4359
|
exports.LogsStorage = LogsStorage;
|
|
4345
4360
|
exports.Protocol = Protocol;
|
|
4346
|
-
exports.PublicSwapCreationInfo = PublicSwapCreationInfo;
|
|
4347
4361
|
exports.PublicSwapService = PublicSwapService;
|
|
4348
4362
|
exports.SupportChat = SupportChat;
|
|
4349
4363
|
exports.SwapProvider = SwapProvider;
|
|
@@ -4351,6 +4365,8 @@
|
|
|
4351
4365
|
exports.SwapspaceSwapProvider = SwapspaceSwapProvider;
|
|
4352
4366
|
exports.improveAndRethrow = improveAndRethrow;
|
|
4353
4367
|
exports.safeStringify = safeStringify;
|
|
4368
|
+
exports.useCallHandlingErrors = useCallHandlingErrors;
|
|
4369
|
+
exports.useReferredState = useReferredState;
|
|
4354
4370
|
|
|
4355
4371
|
}));
|
|
4356
4372
|
//# sourceMappingURL=index.umd.js.map
|