@rabbitio/ui-kit 1.0.0-beta.36 → 1.0.0-beta.38

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.
@@ -1675,6 +1675,96 @@ function useReferredState(initialValue) {
1675
1675
  return [reference, setReferredState];
1676
1676
  }
1677
1677
 
1678
+ var handleClickOutside = function handleClickOutside(exceptionsRefs, callback) {
1679
+ function handleClick(event) {
1680
+ var isExceptionClicked = exceptionsRefs.find(function (ref) {
1681
+ return (ref == null ? void 0 : ref.current) && ref.current.contains(event.target);
1682
+ });
1683
+ if (!isExceptionClicked) {
1684
+ callback();
1685
+ }
1686
+ }
1687
+ document.addEventListener("click", handleClick);
1688
+ return function () {
1689
+ return document.removeEventListener("click", handleClick);
1690
+ };
1691
+ };
1692
+
1693
+ var PARAMETER_VALUES_SEPARATOR = "|*|"; // Sting that with high probability will not be in the user's data
1694
+
1695
+ /**
1696
+ * Adds specified parameter with values to the URL query string
1697
+ *
1698
+ * @param parameterName - String - name of the parameter
1699
+ * @param values - Array of String values
1700
+ * @param updateURLCallback - callback that will be called with the updated query string. Can be used to save it to URL
1701
+ */
1702
+ function saveQueryParameterAndValues(parameterName, values, updateURLCallback) {
1703
+ if (updateURLCallback === void 0) {
1704
+ updateURLCallback = function updateURLCallback(newQueryString) {};
1705
+ }
1706
+ var parametersAndValues = parseSearchString();
1707
+ parametersAndValues = parametersAndValues.filter(function (parameterAndValues) {
1708
+ return parameterAndValues[0] !== parameterName;
1709
+ });
1710
+ var parameterValuesForURL = encodeURIComponent(values.join(PARAMETER_VALUES_SEPARATOR));
1711
+ parametersAndValues.push([parameterName, parameterValuesForURL]);
1712
+ var newQueryString = "?" + parametersAndValues.map(function (parameterAndValues) {
1713
+ return parameterAndValues.join("=");
1714
+ }).join("&");
1715
+ updateURLCallback(newQueryString);
1716
+ return newQueryString;
1717
+ }
1718
+
1719
+ /**
1720
+ * Removes specified parameter with values from the URL query string
1721
+ *
1722
+ * @param parameterName - String - name of the parameter
1723
+ * @param updateURLCallback - callback that will be called with the updated query string. Can be used to save it to URL
1724
+ */
1725
+ // TODO: [tests, moderate] units required the same as or other functions in this module
1726
+ function removeQueryParameterAndValues(parameterName, updateURLCallback) {
1727
+ if (updateURLCallback === void 0) {
1728
+ updateURLCallback = function updateURLCallback(newQueryString) {};
1729
+ }
1730
+ var parametersAndValues = parseSearchString();
1731
+ parametersAndValues = parametersAndValues.filter(function (parameterAndValues) {
1732
+ return parameterAndValues[0] !== parameterName;
1733
+ });
1734
+ var newQueryString = "?" + parametersAndValues.map(function (parameterAndValues) {
1735
+ return parameterAndValues.join("=");
1736
+ }).join("&");
1737
+ updateURLCallback(newQueryString);
1738
+ return newQueryString;
1739
+ }
1740
+
1741
+ /**
1742
+ * Retrieves parameter values from the URL query string.
1743
+ *
1744
+ * If there are several parameters with the same name in the URL then all their values are returned
1745
+ *
1746
+ * @param name {string} - parameter name
1747
+ * @return {string[]} [] - if the parameter is not present in URL. [""] - if parameter present but has empty value
1748
+ */
1749
+ function getQueryParameterValues(name) {
1750
+ return parseSearchString().filter(function (parameterAndValue) {
1751
+ return parameterAndValue[0] === name;
1752
+ }).reduce(function (allValues, parameterAndValue) {
1753
+ var values = decodeURIComponent(parameterAndValue[1] || "").split(PARAMETER_VALUES_SEPARATOR);
1754
+ return [].concat(allValues, values);
1755
+ }, []);
1756
+ }
1757
+ function parseSearchString() {
1758
+ var _window$location$sear;
1759
+ var trimmed = (((_window$location$sear = window.location.search) == null ? void 0 : _window$location$sear.slice(1)) || "").trim();
1760
+ return trimmed && trimmed.split("&").map(function (parameterAndValue) {
1761
+ return parameterAndValue.split("=");
1762
+ }) || [];
1763
+ }
1764
+ function getQueryParameterSingleValue(name) {
1765
+ return (getQueryParameterValues(name) || [])[0];
1766
+ }
1767
+
1678
1768
  /**
1679
1769
  * This function improves the passed error object (its message) by adding the passed function name
1680
1770
  * and additional message to it.
@@ -1703,6 +1793,17 @@ function improvedErrorMessage(e, settingFunction, additionalMessage) {
1703
1793
  additionalMessage && (message += additionalMessage + " ");
1704
1794
  return message;
1705
1795
  }
1796
+ function logErrorOrOutputToConsole(e) {
1797
+ try {
1798
+ // TODO: [dev] remove this after few weeks of testing output in real life
1799
+ // eslint-disable-next-line no-console
1800
+ console.log("BEFORE SAFE", e);
1801
+ Logger.log("logErrorOrOutputToConsole", safeStringify(e));
1802
+ } catch (e) {
1803
+ // eslint-disable-next-line no-console
1804
+ console.log("logErrorOrOutputToConsole", e);
1805
+ }
1806
+ }
1706
1807
 
1707
1808
  var FiatCurrenciesService = /*#__PURE__*/function () {
1708
1809
  function FiatCurrenciesService() {}
@@ -2995,7 +3096,7 @@ var SwapspaceSwapProvider = /*#__PURE__*/function (_SwapProvider) {
2995
3096
  }
2996
3097
  _this = _SwapProvider.call(this) || this;
2997
3098
  _this._supportedCoins = [];
2998
- _this._URL = apiKeysProxyUrl + "/swapspace";
3099
+ _this._URL = "" + apiKeysProxyUrl;
2999
3100
  _this._maxRateDigits = 20;
3000
3101
  _this.useRestrictedCoinsSet = useRestrictedCoinsSet;
3001
3102
  _this._customCoinBuilder = customCoinBuilder;
@@ -4580,5 +4681,5 @@ PublicSwapService.PUBLIC_SWAP_DETAILS_FAIL_REASONS = {
4580
4681
  };
4581
4682
  PublicSwapService._fiatDecimalsCount = FiatCurrenciesService.getCurrencyDecimalCountByCode("USD");
4582
4683
 
4583
- 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 };
4684
+ export { AmountUtils, AssetIcon, BaseSwapCreationInfo, Blockchain, Button, Cache, Coin, EmailsApi, ExistingSwap, ExistingSwapWithFiatData, FiatCurrenciesService, LoadingDots, Logger, LogsStorage, Protocol, PublicSwapService, SupportChat, SwapProvider, SwapUtils, SwapspaceSwapProvider, getQueryParameterSingleValue, getQueryParameterValues, handleClickOutside, improveAndRethrow, logErrorOrOutputToConsole, removeQueryParameterAndValues, safeStringify, saveQueryParameterAndValues, useCallHandlingErrors, useReferredState };
4584
4685
  //# sourceMappingURL=index.module.js.map