@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.module.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React, { useState, useRef, useEffect } from 'react';
|
|
1
|
+
import React, { useState, useRef, useEffect, useCallback } from 'react';
|
|
2
2
|
import { BigNumber } from 'bignumber.js';
|
|
3
3
|
import axios from 'axios';
|
|
4
|
-
import EventBusInstance from 'eventbusjs';
|
|
5
4
|
|
|
6
5
|
function createCommonjsModule(fn) {
|
|
7
6
|
var module = { exports: {} };
|
|
@@ -1475,6 +1474,198 @@ AssetIcon.defaultProps = {
|
|
|
1475
1474
|
small: false
|
|
1476
1475
|
};
|
|
1477
1476
|
|
|
1477
|
+
var LogsStorage = /*#__PURE__*/function () {
|
|
1478
|
+
function LogsStorage() {}
|
|
1479
|
+
LogsStorage.saveLog = function saveLog(log) {
|
|
1480
|
+
this._inMemoryStorage.push(log);
|
|
1481
|
+
};
|
|
1482
|
+
LogsStorage.getInMemoryLogs = function getInMemoryLogs() {
|
|
1483
|
+
return this._inMemoryStorage;
|
|
1484
|
+
};
|
|
1485
|
+
LogsStorage.getAllLogs = function getAllLogs() {
|
|
1486
|
+
var storedLogs = "";
|
|
1487
|
+
if (typeof window !== "undefined") {
|
|
1488
|
+
storedLogs = localStorage.getItem(this._logsStorageId);
|
|
1489
|
+
}
|
|
1490
|
+
return storedLogs + "\n" + this._inMemoryStorage.join("\n");
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
/**
|
|
1494
|
+
* @param logger {Logger}
|
|
1495
|
+
*/;
|
|
1496
|
+
LogsStorage.saveToTheDisk = function saveToTheDisk(logger) {
|
|
1497
|
+
try {
|
|
1498
|
+
var MAX_LOCAL_STORAGE_VOLUME_BYTES = 5 * 1024 * 1024;
|
|
1499
|
+
var MAX_LOGS_STORAGE_BYTES = MAX_LOCAL_STORAGE_VOLUME_BYTES * 0.65;
|
|
1500
|
+
if (typeof window !== "undefined") {
|
|
1501
|
+
var existingLogs = localStorage.getItem(this._logsStorageId);
|
|
1502
|
+
var logsString = existingLogs + "\n" + this._inMemoryStorage.join("\n");
|
|
1503
|
+
var lettersCountToRemove = logsString.length - Math.round(MAX_LOGS_STORAGE_BYTES / 2);
|
|
1504
|
+
if (lettersCountToRemove > 0) {
|
|
1505
|
+
localStorage.setItem(this._logsStorageId, logsString.slice(lettersCountToRemove, logsString.length));
|
|
1506
|
+
} else {
|
|
1507
|
+
localStorage.setItem(this._logsStorageId, logsString);
|
|
1508
|
+
}
|
|
1509
|
+
this._inMemoryStorage = [];
|
|
1510
|
+
}
|
|
1511
|
+
} catch (e) {
|
|
1512
|
+
logger == null || logger.logError(e, "saveToTheDisk", "Failed to save logs to disk");
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
LogsStorage.removeAllClientLogs = function removeAllClientLogs() {
|
|
1516
|
+
if (typeof window !== "undefined") {
|
|
1517
|
+
if (localStorage.getItem("doNotRemoveClientLogsWhenSignedOut") !== "true") {
|
|
1518
|
+
localStorage.removeItem(this._logsStorageId);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
this._inMemoryStorage = [];
|
|
1522
|
+
};
|
|
1523
|
+
LogsStorage.setDoNotRemoveClientLogsWhenSignedOut = function setDoNotRemoveClientLogsWhenSignedOut(value) {
|
|
1524
|
+
if (typeof window !== "undefined") {
|
|
1525
|
+
localStorage.setItem("doNotRemoveClientLogsWhenSignedOut", value);
|
|
1526
|
+
}
|
|
1527
|
+
};
|
|
1528
|
+
return LogsStorage;
|
|
1529
|
+
}();
|
|
1530
|
+
LogsStorage._inMemoryStorage = [];
|
|
1531
|
+
LogsStorage._logsStorageId = "clietnLogs_j203fj2D0n-d1";
|
|
1532
|
+
|
|
1533
|
+
/**
|
|
1534
|
+
* Stringify given object by use of JSON.stringify but handles circular structures and "response", "request" properties
|
|
1535
|
+
* to avoid stringing redundant data when printing errors containing request/response objects.
|
|
1536
|
+
*
|
|
1537
|
+
* @param object - object to be stringed
|
|
1538
|
+
* @param indent - custom indentation
|
|
1539
|
+
* @return {string} - stringed object
|
|
1540
|
+
*/
|
|
1541
|
+
function safeStringify(object, indent) {
|
|
1542
|
+
if (indent === void 0) {
|
|
1543
|
+
indent = 2;
|
|
1544
|
+
}
|
|
1545
|
+
var cache = [];
|
|
1546
|
+
if (typeof object === "string" || typeof object === "function" || typeof object === "number" || typeof object === "undefined" || typeof object === "boolean") {
|
|
1547
|
+
return String(object);
|
|
1548
|
+
}
|
|
1549
|
+
var retVal = JSON.stringify(object, function (key, value) {
|
|
1550
|
+
if (key.toLowerCase().includes("request")) {
|
|
1551
|
+
return JSON.stringify({
|
|
1552
|
+
body: value == null ? void 0 : value.body,
|
|
1553
|
+
query: value == null ? void 0 : value.query,
|
|
1554
|
+
headers: value == null ? void 0 : value.headers
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
if (key.toLowerCase().includes("response")) {
|
|
1558
|
+
return JSON.stringify({
|
|
1559
|
+
statusText: value == null ? void 0 : value.statusText,
|
|
1560
|
+
status: value == null ? void 0 : value.status,
|
|
1561
|
+
data: value == null ? void 0 : value.data,
|
|
1562
|
+
headers: value == null ? void 0 : value.headers
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
return typeof value === "object" && value !== null ? cache.includes(value) ? "duplicated reference" // Duplicated references were found, discarding this key
|
|
1566
|
+
: cache.push(value) && value // Store value in our collection
|
|
1567
|
+
: value;
|
|
1568
|
+
}, indent);
|
|
1569
|
+
cache = null;
|
|
1570
|
+
return retVal;
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
var Logger = /*#__PURE__*/function () {
|
|
1574
|
+
function Logger() {}
|
|
1575
|
+
/**
|
|
1576
|
+
* Logs to client logs storage.
|
|
1577
|
+
*
|
|
1578
|
+
* WARNING! this method should ce used carefully for critical logging as we have the restriction for storing logs
|
|
1579
|
+
* on client side as we store them inside the local storage. Please see details inside storage.js
|
|
1580
|
+
* @param logString {string} log string
|
|
1581
|
+
* @param source {string} source of the log entry
|
|
1582
|
+
*/
|
|
1583
|
+
Logger.log = function log(logString, source) {
|
|
1584
|
+
var timestamp = new Date().toISOString();
|
|
1585
|
+
LogsStorage.saveLog(timestamp + "|" + source + ":" + logString);
|
|
1586
|
+
};
|
|
1587
|
+
Logger.logError = function logError(e, settingFunction, additionalMessage, onlyToConsole) {
|
|
1588
|
+
var _e$errorDescription, _e$howToFix;
|
|
1589
|
+
if (additionalMessage === void 0) {
|
|
1590
|
+
additionalMessage = "";
|
|
1591
|
+
}
|
|
1592
|
+
if (onlyToConsole === void 0) {
|
|
1593
|
+
onlyToConsole = false;
|
|
1594
|
+
}
|
|
1595
|
+
var message = "\nFunction call " + (settingFunction != null ? settingFunction : "") + " failed. Error message: " + (e == null ? void 0 : e.message) + ". " + additionalMessage + " ";
|
|
1596
|
+
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. " : "");
|
|
1597
|
+
if (e != null && e.response) {
|
|
1598
|
+
try {
|
|
1599
|
+
var responseData = safeStringify({
|
|
1600
|
+
response: e.response
|
|
1601
|
+
});
|
|
1602
|
+
responseData && (message += "\n" + responseData + ". ");
|
|
1603
|
+
} catch (e) {}
|
|
1604
|
+
}
|
|
1605
|
+
var finalErrorText = message + ". " + safeStringify(e);
|
|
1606
|
+
// eslint-disable-next-line no-console
|
|
1607
|
+
console.error(finalErrorText);
|
|
1608
|
+
if (!onlyToConsole) {
|
|
1609
|
+
this.log(finalErrorText, "logError");
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
return Logger;
|
|
1613
|
+
}();
|
|
1614
|
+
|
|
1615
|
+
function _catch$4(body, recover) {
|
|
1616
|
+
try {
|
|
1617
|
+
var result = body();
|
|
1618
|
+
} catch (e) {
|
|
1619
|
+
return recover(e);
|
|
1620
|
+
}
|
|
1621
|
+
if (result && result.then) {
|
|
1622
|
+
return result.then(void 0, recover);
|
|
1623
|
+
}
|
|
1624
|
+
return result;
|
|
1625
|
+
}
|
|
1626
|
+
function useCallHandlingErrors() {
|
|
1627
|
+
var _useState = useState(),
|
|
1628
|
+
setState = _useState[1];
|
|
1629
|
+
return useCallback(function (functionToBeCalled, event) {
|
|
1630
|
+
try {
|
|
1631
|
+
var _temp = _catch$4(function () {
|
|
1632
|
+
return Promise.resolve(functionToBeCalled(event)).then(function () {});
|
|
1633
|
+
}, function (error) {
|
|
1634
|
+
Logger.logError(error, (functionToBeCalled == null ? void 0 : functionToBeCalled.name) || "errorBoundaryTrigger", "Caught by ErrorBoundary");
|
|
1635
|
+
// Triggering ErrorBoundary
|
|
1636
|
+
setState(function () {
|
|
1637
|
+
throw error;
|
|
1638
|
+
});
|
|
1639
|
+
});
|
|
1640
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
|
1641
|
+
} catch (e) {
|
|
1642
|
+
return Promise.reject(e);
|
|
1643
|
+
}
|
|
1644
|
+
}, []);
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
/**
|
|
1648
|
+
* Adds reference to standard state variable. It is helpful to be able to use state variable value inside
|
|
1649
|
+
* event handlers and other callbacks without the need to call setState(prev => { value = prev; return prev; }).
|
|
1650
|
+
*
|
|
1651
|
+
* @param initialValue {any} to be passed to useState
|
|
1652
|
+
* @return {[React.Ref, function]} reference to state variable and its setter
|
|
1653
|
+
*/
|
|
1654
|
+
function useReferredState(initialValue) {
|
|
1655
|
+
var _React$useState = React.useState(initialValue),
|
|
1656
|
+
state = _React$useState[0],
|
|
1657
|
+
setState = _React$useState[1];
|
|
1658
|
+
var reference = React.useRef(state);
|
|
1659
|
+
var setReferredState = function setReferredState(value) {
|
|
1660
|
+
if (value && {}.toString.call(value) === "[object Function]") {
|
|
1661
|
+
value = value(reference.current);
|
|
1662
|
+
}
|
|
1663
|
+
reference.current = value;
|
|
1664
|
+
setState(value);
|
|
1665
|
+
};
|
|
1666
|
+
return [reference, setReferredState];
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1478
1669
|
/**
|
|
1479
1670
|
* This function improves the passed error object (its message) by adding the passed function name
|
|
1480
1671
|
* and additional message to it.
|
|
@@ -2097,144 +2288,6 @@ var Coin = /*#__PURE__*/function () {
|
|
|
2097
2288
|
return Coin;
|
|
2098
2289
|
}();
|
|
2099
2290
|
|
|
2100
|
-
var LogsStorage = /*#__PURE__*/function () {
|
|
2101
|
-
function LogsStorage() {}
|
|
2102
|
-
LogsStorage.saveLog = function saveLog(log) {
|
|
2103
|
-
this._inMemoryStorage.push(log);
|
|
2104
|
-
};
|
|
2105
|
-
LogsStorage.getInMemoryLogs = function getInMemoryLogs() {
|
|
2106
|
-
return this._inMemoryStorage;
|
|
2107
|
-
};
|
|
2108
|
-
LogsStorage.getAllLogs = function getAllLogs() {
|
|
2109
|
-
var storedLogs = "";
|
|
2110
|
-
if (typeof window !== "undefined") {
|
|
2111
|
-
storedLogs = localStorage.getItem(this._logsStorageId);
|
|
2112
|
-
}
|
|
2113
|
-
return storedLogs + "\n" + this._inMemoryStorage.join("\n");
|
|
2114
|
-
}
|
|
2115
|
-
|
|
2116
|
-
/**
|
|
2117
|
-
* @param logger {Logger}
|
|
2118
|
-
*/;
|
|
2119
|
-
LogsStorage.saveToTheDisk = function saveToTheDisk(logger) {
|
|
2120
|
-
try {
|
|
2121
|
-
var MAX_LOCAL_STORAGE_VOLUME_BYTES = 5 * 1024 * 1024;
|
|
2122
|
-
var MAX_LOGS_STORAGE_BYTES = MAX_LOCAL_STORAGE_VOLUME_BYTES * 0.65;
|
|
2123
|
-
if (typeof window !== "undefined") {
|
|
2124
|
-
var existingLogs = localStorage.getItem(this._logsStorageId);
|
|
2125
|
-
var logsString = existingLogs + "\n" + this._inMemoryStorage.join("\n");
|
|
2126
|
-
var lettersCountToRemove = logsString.length - Math.round(MAX_LOGS_STORAGE_BYTES / 2);
|
|
2127
|
-
if (lettersCountToRemove > 0) {
|
|
2128
|
-
localStorage.setItem(this._logsStorageId, logsString.slice(lettersCountToRemove, logsString.length));
|
|
2129
|
-
} else {
|
|
2130
|
-
localStorage.setItem(this._logsStorageId, logsString);
|
|
2131
|
-
}
|
|
2132
|
-
this._inMemoryStorage = [];
|
|
2133
|
-
}
|
|
2134
|
-
} catch (e) {
|
|
2135
|
-
logger == null || logger.logError(e, "saveToTheDisk", "Failed to save logs to disk");
|
|
2136
|
-
}
|
|
2137
|
-
};
|
|
2138
|
-
LogsStorage.removeAllClientLogs = function removeAllClientLogs() {
|
|
2139
|
-
if (typeof window !== "undefined") {
|
|
2140
|
-
if (localStorage.getItem("doNotRemoveClientLogsWhenSignedOut") !== "true") {
|
|
2141
|
-
localStorage.removeItem(this._logsStorageId);
|
|
2142
|
-
}
|
|
2143
|
-
}
|
|
2144
|
-
this._inMemoryStorage = [];
|
|
2145
|
-
};
|
|
2146
|
-
LogsStorage.setDoNotRemoveClientLogsWhenSignedOut = function setDoNotRemoveClientLogsWhenSignedOut(value) {
|
|
2147
|
-
if (typeof window !== "undefined") {
|
|
2148
|
-
localStorage.setItem("doNotRemoveClientLogsWhenSignedOut", value);
|
|
2149
|
-
}
|
|
2150
|
-
};
|
|
2151
|
-
return LogsStorage;
|
|
2152
|
-
}();
|
|
2153
|
-
LogsStorage._inMemoryStorage = [];
|
|
2154
|
-
LogsStorage._logsStorageId = "clietnLogs_j203fj2D0n-d1";
|
|
2155
|
-
|
|
2156
|
-
/**
|
|
2157
|
-
* Stringify given object by use of JSON.stringify but handles circular structures and "response", "request" properties
|
|
2158
|
-
* to avoid stringing redundant data when printing errors containing request/response objects.
|
|
2159
|
-
*
|
|
2160
|
-
* @param object - object to be stringed
|
|
2161
|
-
* @param indent - custom indentation
|
|
2162
|
-
* @return {string} - stringed object
|
|
2163
|
-
*/
|
|
2164
|
-
function safeStringify(object, indent) {
|
|
2165
|
-
if (indent === void 0) {
|
|
2166
|
-
indent = 2;
|
|
2167
|
-
}
|
|
2168
|
-
var cache = [];
|
|
2169
|
-
if (typeof object === "string" || typeof object === "function" || typeof object === "number" || typeof object === "undefined" || typeof object === "boolean") {
|
|
2170
|
-
return String(object);
|
|
2171
|
-
}
|
|
2172
|
-
var retVal = JSON.stringify(object, function (key, value) {
|
|
2173
|
-
if (key.toLowerCase().includes("request")) {
|
|
2174
|
-
return JSON.stringify({
|
|
2175
|
-
body: value == null ? void 0 : value.body,
|
|
2176
|
-
query: value == null ? void 0 : value.query,
|
|
2177
|
-
headers: value == null ? void 0 : value.headers
|
|
2178
|
-
});
|
|
2179
|
-
}
|
|
2180
|
-
if (key.toLowerCase().includes("response")) {
|
|
2181
|
-
return JSON.stringify({
|
|
2182
|
-
statusText: value == null ? void 0 : value.statusText,
|
|
2183
|
-
status: value == null ? void 0 : value.status,
|
|
2184
|
-
data: value == null ? void 0 : value.data,
|
|
2185
|
-
headers: value == null ? void 0 : value.headers
|
|
2186
|
-
});
|
|
2187
|
-
}
|
|
2188
|
-
return typeof value === "object" && value !== null ? cache.includes(value) ? "duplicated reference" // Duplicated references were found, discarding this key
|
|
2189
|
-
: cache.push(value) && value // Store value in our collection
|
|
2190
|
-
: value;
|
|
2191
|
-
}, indent);
|
|
2192
|
-
cache = null;
|
|
2193
|
-
return retVal;
|
|
2194
|
-
}
|
|
2195
|
-
|
|
2196
|
-
var Logger = /*#__PURE__*/function () {
|
|
2197
|
-
function Logger() {}
|
|
2198
|
-
/**
|
|
2199
|
-
* Logs to client logs storage.
|
|
2200
|
-
*
|
|
2201
|
-
* WARNING! this method should ce used carefully for critical logging as we have the restriction for storing logs
|
|
2202
|
-
* on client side as we store them inside the local storage. Please see details inside storage.js
|
|
2203
|
-
* @param logString {string} log string
|
|
2204
|
-
* @param source {string} source of the log entry
|
|
2205
|
-
*/
|
|
2206
|
-
Logger.log = function log(logString, source) {
|
|
2207
|
-
var timestamp = new Date().toISOString();
|
|
2208
|
-
LogsStorage.saveLog(timestamp + "|" + source + ":" + logString);
|
|
2209
|
-
};
|
|
2210
|
-
Logger.logError = function logError(e, settingFunction, additionalMessage, onlyToConsole) {
|
|
2211
|
-
var _e$errorDescription, _e$howToFix;
|
|
2212
|
-
if (additionalMessage === void 0) {
|
|
2213
|
-
additionalMessage = "";
|
|
2214
|
-
}
|
|
2215
|
-
if (onlyToConsole === void 0) {
|
|
2216
|
-
onlyToConsole = false;
|
|
2217
|
-
}
|
|
2218
|
-
var message = "\nFunction call " + (settingFunction != null ? settingFunction : "") + " failed. Error message: " + (e == null ? void 0 : e.message) + ". " + additionalMessage + " ";
|
|
2219
|
-
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. " : "");
|
|
2220
|
-
if (e != null && e.response) {
|
|
2221
|
-
try {
|
|
2222
|
-
var responseData = safeStringify({
|
|
2223
|
-
response: e.response
|
|
2224
|
-
});
|
|
2225
|
-
responseData && (message += "\n" + responseData + ". ");
|
|
2226
|
-
} catch (e) {}
|
|
2227
|
-
}
|
|
2228
|
-
var finalErrorText = message + ". " + safeStringify(e);
|
|
2229
|
-
// eslint-disable-next-line no-console
|
|
2230
|
-
console.error(finalErrorText);
|
|
2231
|
-
if (!onlyToConsole) {
|
|
2232
|
-
this.log(finalErrorText, "logError");
|
|
2233
|
-
}
|
|
2234
|
-
};
|
|
2235
|
-
return Logger;
|
|
2236
|
-
}();
|
|
2237
|
-
|
|
2238
2291
|
/**
|
|
2239
2292
|
* TODO: [tests, critical] Ued by payments logic
|
|
2240
2293
|
*
|
|
@@ -2623,7 +2676,7 @@ var ExistingSwapWithFiatData = /*#__PURE__*/function (_ExistingSwap) {
|
|
|
2623
2676
|
return ExistingSwapWithFiatData;
|
|
2624
2677
|
}(ExistingSwap);
|
|
2625
2678
|
|
|
2626
|
-
var
|
|
2679
|
+
var BaseSwapCreationInfo =
|
|
2627
2680
|
/**
|
|
2628
2681
|
* @param fromCoin {Coin}
|
|
2629
2682
|
* @param toCoin {Coin}
|
|
@@ -2637,7 +2690,7 @@ var PublicSwapCreationInfo =
|
|
|
2637
2690
|
* @param fiatMax {number}
|
|
2638
2691
|
* @param durationMinutesRange {string}
|
|
2639
2692
|
*/
|
|
2640
|
-
function
|
|
2693
|
+
function BaseSwapCreationInfo(fromCoin, toCoin, fromAmountCoins, toAmountCoins, rate, rawSwapData, min, fiatMin, max, fiatMax, durationMinutesRange) {
|
|
2641
2694
|
this.fromCoin = fromCoin;
|
|
2642
2695
|
this.toCoin = toCoin;
|
|
2643
2696
|
this.fromAmountCoins = fromAmountCoins;
|
|
@@ -3790,11 +3843,14 @@ function _catch(body, recover) {
|
|
|
3790
3843
|
}
|
|
3791
3844
|
return result;
|
|
3792
3845
|
}
|
|
3793
|
-
var API_KEYS_PROXY_URL = window.location.protocol + "//" + window.location.host + "/api/v1/proxy";
|
|
3794
|
-
var cache = new Cache(EventBusInstance);
|
|
3795
3846
|
var PublicSwapService = /*#__PURE__*/function () {
|
|
3796
|
-
function PublicSwapService() {
|
|
3797
|
-
|
|
3847
|
+
function PublicSwapService(API_KEYS_PROXY_URL, cache) {
|
|
3848
|
+
this._swapProvider = new SwapspaceSwapProvider(API_KEYS_PROXY_URL, cache, function () {
|
|
3849
|
+
return null;
|
|
3850
|
+
}, false);
|
|
3851
|
+
}
|
|
3852
|
+
var _proto = PublicSwapService.prototype;
|
|
3853
|
+
_proto.initialize = function initialize() {
|
|
3798
3854
|
try {
|
|
3799
3855
|
var _this = this;
|
|
3800
3856
|
var _temp = _catch(function () {
|
|
@@ -3809,7 +3865,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
3809
3865
|
return Promise.reject(e);
|
|
3810
3866
|
}
|
|
3811
3867
|
};
|
|
3812
|
-
|
|
3868
|
+
_proto.getCurrenciesListForPublicSwap = function getCurrenciesListForPublicSwap(currencyThatShouldNotBeFirst) {
|
|
3813
3869
|
if (currencyThatShouldNotBeFirst === void 0) {
|
|
3814
3870
|
currencyThatShouldNotBeFirst = null;
|
|
3815
3871
|
}
|
|
@@ -3863,7 +3919,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
3863
3919
|
* }>}
|
|
3864
3920
|
*/
|
|
3865
3921
|
;
|
|
3866
|
-
|
|
3922
|
+
_proto.getInitialPublicSwapData = function getInitialPublicSwapData(fromCoin, toCoin) {
|
|
3867
3923
|
try {
|
|
3868
3924
|
var _this3 = this;
|
|
3869
3925
|
return Promise.resolve(_catch(function () {
|
|
@@ -3908,11 +3964,11 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
3908
3964
|
* fiatMax: (number|null)
|
|
3909
3965
|
* }|{
|
|
3910
3966
|
* result: true,
|
|
3911
|
-
* swapCreationInfo:
|
|
3967
|
+
* swapCreationInfo: BaseSwapCreationInfo
|
|
3912
3968
|
* }>}
|
|
3913
3969
|
*/
|
|
3914
3970
|
;
|
|
3915
|
-
|
|
3971
|
+
_proto.getPublicSwapDetails = function getPublicSwapDetails(fromCoin, toCoin, fromAmountCoins) {
|
|
3916
3972
|
try {
|
|
3917
3973
|
var _this4 = this;
|
|
3918
3974
|
var loggerSource = "getPublicSwapDetails";
|
|
@@ -3961,7 +4017,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
3961
4017
|
var toAmountCoins = AmountUtils.trim(fromAmountBigNumber.times(details.rate), fromCoin.digits);
|
|
3962
4018
|
var result = {
|
|
3963
4019
|
result: true,
|
|
3964
|
-
swapCreationInfo: new
|
|
4020
|
+
swapCreationInfo: new BaseSwapCreationInfo(fromCoin, toCoin, fromAmountCoins, toAmountCoins, details.rate, details.rawSwapData, min, fiatMin, max, fiatMax, details.durationMinutesRange)
|
|
3965
4021
|
};
|
|
3966
4022
|
Logger.log("Result: " + safeStringify({
|
|
3967
4023
|
result: result.result,
|
|
@@ -3986,7 +4042,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
3986
4042
|
* @param fromCoin {Coin}
|
|
3987
4043
|
* @param toCoin {Coin}
|
|
3988
4044
|
* @param fromAmount {string}
|
|
3989
|
-
* @param swapCreationInfo {
|
|
4045
|
+
* @param swapCreationInfo {BaseSwapCreationInfo}
|
|
3990
4046
|
* @param toAddress {string}
|
|
3991
4047
|
* @param refundAddress {string}
|
|
3992
4048
|
* @return {Promise<{
|
|
@@ -4009,13 +4065,13 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4009
4065
|
* }>}
|
|
4010
4066
|
*/
|
|
4011
4067
|
;
|
|
4012
|
-
|
|
4068
|
+
_proto.createPublicSwap = function createPublicSwap(fromCoin, toCoin, fromAmount, swapCreationInfo, toAddress, refundAddress, clientIp) {
|
|
4013
4069
|
try {
|
|
4014
4070
|
var _this5 = this;
|
|
4015
4071
|
var loggerSource = "createPublicSwap";
|
|
4016
4072
|
return Promise.resolve(_catch(function () {
|
|
4017
4073
|
var _swapCreationInfo$fro, _swapCreationInfo$toC;
|
|
4018
|
-
if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof fromAmount !== "string" || typeof toAddress !== "string" || typeof refundAddress !== "string" || !(swapCreationInfo instanceof
|
|
4074
|
+
if (!(fromCoin instanceof Coin) || !(toCoin instanceof Coin) || typeof fromAmount !== "string" || typeof toAddress !== "string" || typeof refundAddress !== "string" || !(swapCreationInfo instanceof BaseSwapCreationInfo)) {
|
|
4019
4075
|
throw new Error("Wrong input: " + fromCoin.ticker + " " + toCoin.ticker + " " + fromAmount + " " + swapCreationInfo);
|
|
4020
4076
|
}
|
|
4021
4077
|
Logger.log("Start: " + fromAmount + " " + fromCoin.ticker + " -> " + toCoin.ticker + ". Details: " + safeStringify(_extends({}, swapCreationInfo, {
|
|
@@ -4121,7 +4177,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4121
4177
|
* error reason is one of PUBLIC_SWAPS_COMMON_ERRORS
|
|
4122
4178
|
*/
|
|
4123
4179
|
;
|
|
4124
|
-
|
|
4180
|
+
_proto.getPublicExistingSwapDetailsAndStatus = function getPublicExistingSwapDetailsAndStatus(swapIds) {
|
|
4125
4181
|
try {
|
|
4126
4182
|
var _this6 = this;
|
|
4127
4183
|
var loggerSource = "getPublicExistingSwapDetailsAndStatus";
|
|
@@ -4158,7 +4214,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4158
4214
|
* }>}
|
|
4159
4215
|
*/
|
|
4160
4216
|
;
|
|
4161
|
-
|
|
4217
|
+
_proto.getPublicSwapsHistory = function getPublicSwapsHistory() {
|
|
4162
4218
|
try {
|
|
4163
4219
|
var _exit2;
|
|
4164
4220
|
var _this7 = this;
|
|
@@ -4191,7 +4247,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4191
4247
|
* @private
|
|
4192
4248
|
*/
|
|
4193
4249
|
;
|
|
4194
|
-
|
|
4250
|
+
_proto._savePublicSwapIdLocally = function _savePublicSwapIdLocally(swapId) {
|
|
4195
4251
|
if (typeof window !== "undefined") {
|
|
4196
4252
|
try {
|
|
4197
4253
|
var saved = localStorage.getItem("publicSwapIds");
|
|
@@ -4208,7 +4264,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4208
4264
|
* @private
|
|
4209
4265
|
* @return {string[]}
|
|
4210
4266
|
*/;
|
|
4211
|
-
|
|
4267
|
+
_proto._getPublicSwapIdsSavedLocally = function _getPublicSwapIdsSavedLocally() {
|
|
4212
4268
|
if (typeof window !== "undefined") {
|
|
4213
4269
|
try {
|
|
4214
4270
|
var saved = localStorage.getItem("publicSwapIds");
|
|
@@ -4223,7 +4279,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4223
4279
|
* @param coinOrTicker {Coin|string}
|
|
4224
4280
|
* @return {string} icon URL (ready to use)
|
|
4225
4281
|
*/;
|
|
4226
|
-
|
|
4282
|
+
_proto.getAssetIconUrl = function getAssetIconUrl(coinOrTicker) {
|
|
4227
4283
|
return this._swapProvider.getIconUrl(coinOrTicker);
|
|
4228
4284
|
}
|
|
4229
4285
|
|
|
@@ -4231,7 +4287,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4231
4287
|
* @param ticker {string}
|
|
4232
4288
|
* @return {Coin|null}
|
|
4233
4289
|
*/;
|
|
4234
|
-
|
|
4290
|
+
_proto.getCoinByTickerIfPresent = function getCoinByTickerIfPresent(ticker) {
|
|
4235
4291
|
return this._swapProvider.getCoinByTickerIfPresent(ticker);
|
|
4236
4292
|
}
|
|
4237
4293
|
|
|
@@ -4240,7 +4296,7 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4240
4296
|
* @param asset {Coin}
|
|
4241
4297
|
* @return {Promise<string|null>}
|
|
4242
4298
|
*/;
|
|
4243
|
-
|
|
4299
|
+
_proto.getAssetToUsdtRate = function getAssetToUsdtRate(asset) {
|
|
4244
4300
|
try {
|
|
4245
4301
|
var _this8 = this;
|
|
4246
4302
|
return Promise.resolve(_catch(function () {
|
|
@@ -4261,58 +4317,16 @@ var PublicSwapService = /*#__PURE__*/function () {
|
|
|
4261
4317
|
* @return {boolean}
|
|
4262
4318
|
*/
|
|
4263
4319
|
;
|
|
4264
|
-
|
|
4320
|
+
_proto.isAddressValidForAsset = function isAddressValidForAsset(asset, address) {
|
|
4265
4321
|
try {
|
|
4266
4322
|
return this._swapProvider.isAddressValidForAsset(asset, address);
|
|
4267
4323
|
} catch (e) {
|
|
4268
4324
|
improveAndRethrow(e, "isAddressValidForAsset");
|
|
4269
4325
|
}
|
|
4270
|
-
}
|
|
4271
|
-
|
|
4272
|
-
// TODO: [dev] Remove if we don't need this inside the public swap steps
|
|
4273
|
-
// /**
|
|
4274
|
-
// * TODO: [feature, moderate] add other fiat currencies support. task_id=5490e21b8b9c4f89a2247b28db3c9e0a
|
|
4275
|
-
// * @param asset {Coin}
|
|
4276
|
-
// * @param amount {string}
|
|
4277
|
-
// * @return {Promise<string|null>}
|
|
4278
|
-
// */
|
|
4279
|
-
// static async convertSingleCoinAmountToUsdtOrNull(asset, amount) {
|
|
4280
|
-
// try {
|
|
4281
|
-
// const result = await this._swapProvider.getCoinToUSDTRate(asset);
|
|
4282
|
-
// if (result?.rate != null) {
|
|
4283
|
-
// const decimals = FiatCurrenciesService.getCurrencyDecimalCountByCode("USD");
|
|
4284
|
-
// return BigNumber(amount).div(result?.rate).toFixed(decimals);
|
|
4285
|
-
// }
|
|
4286
|
-
// return null;
|
|
4287
|
-
// } catch (e) {
|
|
4288
|
-
// improveAndRethrow(e, "convertSingleCoinAmountToUsdtOrNull");
|
|
4289
|
-
// }
|
|
4290
|
-
// }
|
|
4291
|
-
//
|
|
4292
|
-
// /**
|
|
4293
|
-
// * TODO: [feature, moderate] add other fiat currencies support. task_id=5490e21b8b9c4f89a2247b28db3c9e0a
|
|
4294
|
-
// * @param asset {Coin}
|
|
4295
|
-
// * @param amount {string}
|
|
4296
|
-
// * @return {Promise<string|null>}
|
|
4297
|
-
// */
|
|
4298
|
-
// static async convertSingleUsdtAmountToCoinOrNull(asset, amount) {
|
|
4299
|
-
// try {
|
|
4300
|
-
// const result = await this._swapProvider.getCoinToUSDTRate(asset);
|
|
4301
|
-
// if (result?.rate != null) {
|
|
4302
|
-
// return BigNumber(amount).times(result?.rate).toFixed(asset.digits);
|
|
4303
|
-
// }
|
|
4304
|
-
// return null;
|
|
4305
|
-
// } catch (e) {
|
|
4306
|
-
// improveAndRethrow(e, "convertSingleUsdtAmountToCoinOrNull");
|
|
4307
|
-
// }
|
|
4308
|
-
// }
|
|
4309
|
-
;
|
|
4326
|
+
};
|
|
4310
4327
|
return PublicSwapService;
|
|
4311
4328
|
}();
|
|
4312
4329
|
PublicSwapService.PUBLIC_SWAP_CREATED_EVENT = "publicSwapCreatedEvent";
|
|
4313
|
-
PublicSwapService._swapProvider = new SwapspaceSwapProvider(API_KEYS_PROXY_URL, cache, function () {
|
|
4314
|
-
return null;
|
|
4315
|
-
}, false);
|
|
4316
4330
|
PublicSwapService.PUBLIC_SWAPS_COMMON_ERRORS = {
|
|
4317
4331
|
REQUESTS_LIMIT_EXCEEDED: "requestsLimitExceeded"
|
|
4318
4332
|
};
|
|
@@ -4323,5 +4337,5 @@ PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS = {
|
|
|
4323
4337
|
};
|
|
4324
4338
|
PublicSwapService._fiatDecimalsCount = FiatCurrenciesService.getCurrencyDecimalCountByCode("USD");
|
|
4325
4339
|
|
|
4326
|
-
export { AmountUtils, AssetIcon, Blockchain, Button, Cache, Coin, EmailsApi, ExistingSwap, ExistingSwapWithFiatData, FiatCurrenciesService, LoadingDots, Logger, LogsStorage, Protocol,
|
|
4340
|
+
export { AmountUtils, AssetIcon, BaseSwapCreationInfo, Blockchain, Button, Cache, Coin, EmailsApi, ExistingSwap, ExistingSwapWithFiatData, FiatCurrenciesService, LoadingDots, Logger, LogsStorage, Protocol, PublicSwapService, SupportChat, SwapProvider, SwapUtils, SwapspaceSwapProvider, improveAndRethrow, safeStringify, useCallHandlingErrors, useReferredState };
|
|
4327
4341
|
//# sourceMappingURL=index.module.js.map
|