@tonconnect/ui 2.0.0-beta.9 → 2.0.1-beta.0

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/lib/index.cjs CHANGED
@@ -1754,172 +1754,22 @@ class TonConnectUIError extends sdk.TonConnectError {
1754
1754
  Object.setPrototypeOf(this, TonConnectUIError.prototype);
1755
1755
  }
1756
1756
  }
1757
- function logError(...args) {
1758
- {
1759
- try {
1760
- console.error("[TON_CONNECT_UI]", ...args);
1761
- } catch (e2) {
1762
- }
1763
- }
1764
- }
1765
- function logWarning(...args) {
1766
- {
1767
- try {
1768
- console.warn("[TON_CONNECT_UI]", ...args);
1769
- } catch (e2) {
1770
- }
1771
- }
1772
- }
1773
- let initParams = {};
1774
- try {
1775
- let locationHash = location.hash.toString();
1776
- initParams = urlParseHashParams(locationHash);
1777
- } catch (e2) {
1778
- }
1779
- let tmaPlatform = "unknown";
1780
- if (initParams == null ? void 0 : initParams.tgWebAppPlatform) {
1781
- tmaPlatform = (_a = initParams.tgWebAppPlatform) != null ? _a : "unknown";
1782
- }
1783
- if (tmaPlatform === "unknown") {
1784
- tmaPlatform = (_d = (_c = (_b = window == null ? void 0 : window.Telegram) == null ? void 0 : _b.WebApp) == null ? void 0 : _c.platform) != null ? _d : "unknown";
1785
- }
1786
- let webAppVersion = "6.0";
1787
- if (initParams == null ? void 0 : initParams.tgWebAppVersion) {
1788
- webAppVersion = initParams.tgWebAppVersion;
1789
- }
1790
- if (!webAppVersion) {
1791
- webAppVersion = (_g = (_f = (_e = window == null ? void 0 : window.Telegram) == null ? void 0 : _e.WebApp) == null ? void 0 : _f.version) != null ? _g : "6.0";
1792
- }
1793
- function isTmaPlatform(...platforms) {
1794
- return platforms.includes(tmaPlatform);
1795
- }
1796
- function isInTMA() {
1797
- var _a2;
1798
- return tmaPlatform !== "unknown" || !!((_a2 = getWindow$1()) == null ? void 0 : _a2.TelegramWebviewProxy);
1799
- }
1800
- function sendExpand() {
1801
- postEvent("web_app_expand", {});
1802
- }
1803
- function sendOpenTelegramLink(link) {
1804
- const url = new URL(link);
1805
- if (url.protocol !== "http:" && url.protocol !== "https:") {
1806
- throw new TonConnectUIError(`Url protocol is not supported: ${url}`);
1807
- }
1808
- if (url.hostname !== "t.me") {
1809
- throw new TonConnectUIError(`Url host is not supported: ${url}`);
1810
- }
1811
- const pathFull = url.pathname + url.search;
1812
- if (isIframe() || versionAtLeast("6.1")) {
1813
- postEvent("web_app_open_tg_link", { path_full: pathFull });
1814
- } else {
1815
- window.open("https://t.me" + pathFull, "_blank", "noreferrer noopener");
1816
- }
1817
- }
1818
- function isIframe() {
1819
- try {
1820
- return window.parent != null && window !== window.parent;
1821
- } catch (e2) {
1822
- return false;
1823
- }
1824
- }
1825
- function postEvent(eventType, eventData) {
1826
- try {
1827
- if (window.TelegramWebviewProxy !== void 0) {
1828
- window.TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
1829
- } else if (window.external && "notify" in window.external) {
1830
- window.external.notify(JSON.stringify({ eventType, eventData }));
1831
- } else if (isIframe()) {
1832
- const trustedTarget = "*";
1833
- const message = JSON.stringify({ eventType, eventData });
1834
- window.parent.postMessage(message, trustedTarget);
1835
- }
1836
- throw new TonConnectUIError(`Can't post event to TMA`);
1837
- } catch (e2) {
1838
- logError(`Can't post event to parent window: ${e2}`);
1839
- }
1840
- }
1841
- function urlParseHashParams(locationHash) {
1842
- locationHash = locationHash.replace(/^#/, "");
1843
- let params = {};
1844
- if (!locationHash.length) {
1845
- return params;
1846
- }
1847
- if (locationHash.indexOf("=") < 0 && locationHash.indexOf("?") < 0) {
1848
- params._path = urlSafeDecode(locationHash);
1849
- return params;
1850
- }
1851
- let qIndex = locationHash.indexOf("?");
1852
- if (qIndex >= 0) {
1853
- let pathParam = locationHash.substr(0, qIndex);
1854
- params._path = urlSafeDecode(pathParam);
1855
- locationHash = locationHash.substr(qIndex + 1);
1856
- }
1857
- let query_params = urlParseQueryString(locationHash);
1858
- for (let k in query_params) {
1859
- params[k] = query_params[k];
1860
- }
1861
- return params;
1862
- }
1863
- function urlSafeDecode(urlencoded) {
1864
- try {
1865
- urlencoded = urlencoded.replace(/\+/g, "%20");
1866
- return decodeURIComponent(urlencoded);
1867
- } catch (e2) {
1868
- return urlencoded;
1869
- }
1870
- }
1871
- function urlParseQueryString(queryString) {
1872
- let params = {};
1873
- if (!queryString.length) {
1874
- return params;
1875
- }
1876
- let queryStringParams = queryString.split("&");
1877
- let i2, param, paramName, paramValue;
1878
- for (i2 = 0; i2 < queryStringParams.length; i2++) {
1879
- param = queryStringParams[i2].split("=");
1880
- paramName = urlSafeDecode(param[0]);
1881
- paramValue = param[1] == null ? null : urlSafeDecode(param[1]);
1882
- params[paramName] = paramValue;
1883
- }
1884
- return params;
1885
- }
1886
- function versionCompare(v1, v2) {
1887
- if (typeof v1 !== "string")
1888
- v1 = "";
1889
- if (typeof v2 !== "string")
1890
- v2 = "";
1891
- let v1List = v1.replace(/^\s+|\s+$/g, "").split(".");
1892
- let v2List = v2.replace(/^\s+|\s+$/g, "").split(".");
1893
- let a2, i2, p1, p2;
1894
- a2 = Math.max(v1List.length, v2List.length);
1895
- for (i2 = 0; i2 < a2; i2++) {
1896
- p1 = parseInt(v1List[i2]) || 0;
1897
- p2 = parseInt(v2List[i2]) || 0;
1898
- if (p1 === p2)
1899
- continue;
1900
- if (p1 > p2)
1901
- return 1;
1902
- return -1;
1903
- }
1904
- return 0;
1905
- }
1906
- function versionAtLeast(ver) {
1907
- return versionCompare(webAppVersion, ver) >= 0;
1908
- }
1909
1757
  function openLink(href, target = "_self") {
1910
1758
  window.open(href, target, "noopener noreferrer");
1911
1759
  }
1912
1760
  function openLinkBlank(href) {
1913
1761
  openLink(href, "_blank");
1914
1762
  }
1915
- function openIframeLink(href, fallback) {
1916
- const iframe = document.createElement("iframe");
1917
- iframe.style.display = "none";
1918
- iframe.src = href;
1919
- document.body.appendChild(iframe);
1920
- const fallbackTimeout = setTimeout(() => fallback(), 1e3);
1763
+ function openDeeplinkWithFallback(href, fallback) {
1764
+ const doFallback = () => {
1765
+ if (isBrowser("safari")) {
1766
+ return;
1767
+ }
1768
+ fallback();
1769
+ };
1770
+ const fallbackTimeout = setTimeout(() => doFallback(), 200);
1921
1771
  window.addEventListener("blur", () => clearTimeout(fallbackTimeout), { once: true });
1922
- setTimeout(() => document.body.removeChild(iframe), 1e3);
1772
+ openLink(href, "_self");
1923
1773
  }
1924
1774
  function getSystemTheme() {
1925
1775
  if (window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches) {
@@ -1932,25 +1782,6 @@ function subscribeToThemeChange(callback) {
1932
1782
  window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", handler);
1933
1783
  return () => window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", handler);
1934
1784
  }
1935
- function addQueryParameter(url, key, value) {
1936
- const parsed = new URL(url);
1937
- parsed.searchParams.append(key, value);
1938
- return parsed.toString();
1939
- }
1940
- function addReturnStrategy(url, strategy) {
1941
- let returnStrategy;
1942
- if (typeof strategy === "string") {
1943
- returnStrategy = strategy;
1944
- } else {
1945
- returnStrategy = isInTMA() ? strategy.twaReturnUrl || strategy.returnStrategy : "none";
1946
- }
1947
- const newUrl = addQueryParameter(url, "ret", returnStrategy);
1948
- if (!sdk.isTelegramUrl(url)) {
1949
- return newUrl;
1950
- }
1951
- const lastParam = newUrl.slice(newUrl.lastIndexOf("&") + 1);
1952
- return newUrl.slice(0, newUrl.lastIndexOf("&")) + "-" + sdk.encodeTelegramUrlParameters(lastParam);
1953
- }
1954
1785
  function disableScroll() {
1955
1786
  if (document.documentElement.scrollHeight === document.documentElement.clientHeight) {
1956
1787
  return;
@@ -2060,61 +1891,12 @@ function getUserAgent() {
2060
1891
  function isOS(...os) {
2061
1892
  return os.includes(getUserAgent().os);
2062
1893
  }
2063
- function redirectToTelegram(universalLink, options) {
2064
- options = __spreadValues({}, options);
2065
- const directLink = convertToDirectLink(universalLink);
2066
- const directLinkUrl = new URL(directLink);
2067
- if (!directLinkUrl.searchParams.has("startapp")) {
2068
- directLinkUrl.searchParams.append("startapp", "tonconnect");
2069
- }
2070
- if (isInTMA()) {
2071
- if (isTmaPlatform("ios", "android")) {
2072
- options.returnStrategy = "back";
2073
- options.twaReturnUrl = void 0;
2074
- sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2075
- } else if (isTmaPlatform("macos", "tdesktop")) {
2076
- sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2077
- } else if (isTmaPlatform("weba")) {
2078
- sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2079
- } else if (isTmaPlatform("web")) {
2080
- options.returnStrategy = "back";
2081
- options.twaReturnUrl = void 0;
2082
- sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2083
- } else {
2084
- openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
2085
- }
2086
- } else {
2087
- if (isOS("ios", "android")) {
2088
- options.returnStrategy = "none";
2089
- openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options.returnStrategy));
2090
- } else if (isOS("macos", "windows", "linux")) {
2091
- options.returnStrategy = "none";
2092
- options.twaReturnUrl = void 0;
2093
- if (options.forceRedirect) {
2094
- openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
2095
- } else {
2096
- const link = addReturnStrategy(directLinkUrl.toString(), options);
2097
- const deepLink = convertToDeepLink(link);
2098
- openIframeLink(deepLink, () => openLinkBlank(link));
2099
- }
2100
- } else {
2101
- openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
2102
- }
2103
- }
1894
+ function isBrowser(...browser) {
1895
+ return browser.includes(getUserAgent().browser);
2104
1896
  }
2105
- function convertToDirectLink(universalLink) {
1897
+ function toDeeplink(universalLink, deeplink) {
2106
1898
  const url = new URL(universalLink);
2107
- if (url.searchParams.has("attach")) {
2108
- url.searchParams.delete("attach");
2109
- url.pathname += "/start";
2110
- }
2111
- return url.toString();
2112
- }
2113
- function convertToDeepLink(directLink) {
2114
- const parsed = new URL(directLink);
2115
- const [, domain, appname] = parsed.pathname.split("/");
2116
- const startapp = parsed.searchParams.get("startapp");
2117
- return `tg://resolve?domain=${domain}&appname=${appname}&startapp=${startapp}`;
1899
+ return deeplink + url.search;
2118
1900
  }
2119
1901
  class WalletInfoStorage {
2120
1902
  constructor() {
@@ -2174,6 +1956,20 @@ const [walletsModalState, setWalletsModalState] = createSignal({
2174
1956
  closeReason: null
2175
1957
  });
2176
1958
  const getWalletsModalIsOpened = createMemo(() => walletsModalState().status === "opened");
1959
+ const [singleWalletModalState, setSingleWalletModalState] = createSignal({
1960
+ status: "closed",
1961
+ closeReason: null
1962
+ });
1963
+ const getSingleWalletModalIsOpened = createMemo(
1964
+ () => singleWalletModalState().status === "opened"
1965
+ );
1966
+ const getSingleWalletModalWalletInfo = createMemo(() => {
1967
+ const state = singleWalletModalState();
1968
+ if (state.status === "opened") {
1969
+ return state.walletInfo;
1970
+ }
1971
+ return null;
1972
+ });
2177
1973
  let lastSelectedWalletInfoStorage = typeof window !== "undefined" ? new LastSelectedWalletInfoStorage() : void 0;
2178
1974
  const [lastSelectedWalletInfo, _setLastSelectedWalletInfo] = createSignal((lastSelectedWalletInfoStorage == null ? void 0 : lastSelectedWalletInfoStorage.getLastSelectedWalletInfo()) || null);
2179
1975
  const setLastSelectedWalletInfo = (walletInfo) => {
@@ -2835,6 +2631,169 @@ const Image = (props) => {
2835
2631
  }
2836
2632
  })];
2837
2633
  };
2634
+ function logError(...args) {
2635
+ {
2636
+ try {
2637
+ console.error("[TON_CONNECT_UI]", ...args);
2638
+ } catch (e2) {
2639
+ }
2640
+ }
2641
+ }
2642
+ function logWarning(...args) {
2643
+ {
2644
+ try {
2645
+ console.warn("[TON_CONNECT_UI]", ...args);
2646
+ } catch (e2) {
2647
+ }
2648
+ }
2649
+ }
2650
+ let initParams = {};
2651
+ try {
2652
+ let locationHash = location.hash.toString();
2653
+ initParams = urlParseHashParams(locationHash);
2654
+ } catch (e2) {
2655
+ }
2656
+ let tmaPlatform = "unknown";
2657
+ if (initParams == null ? void 0 : initParams.tgWebAppPlatform) {
2658
+ tmaPlatform = (_a = initParams.tgWebAppPlatform) != null ? _a : "unknown";
2659
+ }
2660
+ if (tmaPlatform === "unknown") {
2661
+ const window2 = getWindow$1();
2662
+ tmaPlatform = (_d = (_c = (_b = window2 == null ? void 0 : window2.Telegram) == null ? void 0 : _b.WebApp) == null ? void 0 : _c.platform) != null ? _d : "unknown";
2663
+ }
2664
+ let webAppVersion = "6.0";
2665
+ if (initParams == null ? void 0 : initParams.tgWebAppVersion) {
2666
+ webAppVersion = initParams.tgWebAppVersion;
2667
+ }
2668
+ if (!webAppVersion) {
2669
+ const window2 = getWindow$1();
2670
+ webAppVersion = (_g = (_f = (_e = window2 == null ? void 0 : window2.Telegram) == null ? void 0 : _e.WebApp) == null ? void 0 : _f.version) != null ? _g : "6.0";
2671
+ }
2672
+ function isTmaPlatform(...platforms) {
2673
+ return platforms.includes(tmaPlatform);
2674
+ }
2675
+ function isInTMA() {
2676
+ var _a2;
2677
+ return tmaPlatform !== "unknown" || !!((_a2 = getWindow$1()) == null ? void 0 : _a2.TelegramWebviewProxy);
2678
+ }
2679
+ function sendExpand() {
2680
+ postEvent("web_app_expand", {});
2681
+ }
2682
+ function sendOpenTelegramLink(link) {
2683
+ const url = new URL(link);
2684
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
2685
+ throw new TonConnectUIError(`Url protocol is not supported: ${url}`);
2686
+ }
2687
+ if (url.hostname !== "t.me") {
2688
+ throw new TonConnectUIError(`Url host is not supported: ${url}`);
2689
+ }
2690
+ const pathFull = url.pathname + url.search;
2691
+ if (isIframe() || versionAtLeast("6.1")) {
2692
+ postEvent("web_app_open_tg_link", { path_full: pathFull });
2693
+ } else {
2694
+ openLinkBlank("https://t.me" + pathFull);
2695
+ }
2696
+ }
2697
+ function isIframe() {
2698
+ try {
2699
+ const window2 = getWindow$1();
2700
+ if (!window2) {
2701
+ return false;
2702
+ }
2703
+ return window2.parent != null && window2 !== window2.parent;
2704
+ } catch (e2) {
2705
+ return false;
2706
+ }
2707
+ }
2708
+ function postEvent(eventType, eventData) {
2709
+ try {
2710
+ const window2 = getWindow$1();
2711
+ if (!window2) {
2712
+ throw new TonConnectUIError(`Can't post event to parent window: window is not defined`);
2713
+ }
2714
+ if (window2.TelegramWebviewProxy !== void 0) {
2715
+ window2.TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
2716
+ } else if (window2.external && "notify" in window2.external) {
2717
+ window2.external.notify(JSON.stringify({ eventType, eventData }));
2718
+ } else if (isIframe()) {
2719
+ const trustedTarget = "*";
2720
+ const message = JSON.stringify({ eventType, eventData });
2721
+ window2.parent.postMessage(message, trustedTarget);
2722
+ } else {
2723
+ throw new TonConnectUIError(`Can't post event to TMA`);
2724
+ }
2725
+ } catch (e2) {
2726
+ logError(`Can't post event to parent window: ${e2}`);
2727
+ }
2728
+ }
2729
+ function urlParseHashParams(locationHash) {
2730
+ locationHash = locationHash.replace(/^#/, "");
2731
+ let params = {};
2732
+ if (!locationHash.length) {
2733
+ return params;
2734
+ }
2735
+ if (locationHash.indexOf("=") < 0 && locationHash.indexOf("?") < 0) {
2736
+ params._path = urlSafeDecode(locationHash);
2737
+ return params;
2738
+ }
2739
+ let qIndex = locationHash.indexOf("?");
2740
+ if (qIndex >= 0) {
2741
+ let pathParam = locationHash.substr(0, qIndex);
2742
+ params._path = urlSafeDecode(pathParam);
2743
+ locationHash = locationHash.substr(qIndex + 1);
2744
+ }
2745
+ let query_params = urlParseQueryString(locationHash);
2746
+ for (let k in query_params) {
2747
+ params[k] = query_params[k];
2748
+ }
2749
+ return params;
2750
+ }
2751
+ function urlSafeDecode(urlencoded) {
2752
+ try {
2753
+ urlencoded = urlencoded.replace(/\+/g, "%20");
2754
+ return decodeURIComponent(urlencoded);
2755
+ } catch (e2) {
2756
+ return urlencoded;
2757
+ }
2758
+ }
2759
+ function urlParseQueryString(queryString) {
2760
+ let params = {};
2761
+ if (!queryString.length) {
2762
+ return params;
2763
+ }
2764
+ let queryStringParams = queryString.split("&");
2765
+ let i2, param, paramName, paramValue;
2766
+ for (i2 = 0; i2 < queryStringParams.length; i2++) {
2767
+ param = queryStringParams[i2].split("=");
2768
+ paramName = urlSafeDecode(param[0]);
2769
+ paramValue = param[1] == null ? null : urlSafeDecode(param[1]);
2770
+ params[paramName] = paramValue;
2771
+ }
2772
+ return params;
2773
+ }
2774
+ function versionCompare(v1, v2) {
2775
+ if (typeof v1 !== "string")
2776
+ v1 = "";
2777
+ if (typeof v2 !== "string")
2778
+ v2 = "";
2779
+ let v1List = v1.replace(/^\s+|\s+$/g, "").split(".");
2780
+ let v2List = v2.replace(/^\s+|\s+$/g, "").split(".");
2781
+ let a2, i2, p1, p2;
2782
+ a2 = Math.max(v1List.length, v2List.length);
2783
+ for (i2 = 0; i2 < a2; i2++) {
2784
+ p1 = parseInt(v1List[i2]) || 0;
2785
+ p2 = parseInt(v2List[i2]) || 0;
2786
+ if (p1 === p2)
2787
+ continue;
2788
+ if (p1 > p2)
2789
+ return 1;
2790
+ return -1;
2791
+ }
2792
+ return 0;
2793
+ }
2794
+ function versionAtLeast(ver) {
2795
+ return versionCompare(webAppVersion, ver) >= 0;
2796
+ }
2838
2797
  const maxWidth = {
2839
2798
  mobile: 440,
2840
2799
  tablet: 1020
@@ -8316,6 +8275,82 @@ const Translation = (props) => {
8316
8275
  return t2(props.translationKey, props.translationValues, (_a2 = props.children) == null ? void 0 : _a2.toString());
8317
8276
  });
8318
8277
  };
8278
+ function addReturnStrategy(url, strategy) {
8279
+ let returnStrategy;
8280
+ if (typeof strategy === "string") {
8281
+ returnStrategy = strategy;
8282
+ } else {
8283
+ returnStrategy = isInTMA() ? strategy.twaReturnUrl || strategy.returnStrategy : "none";
8284
+ }
8285
+ const newUrl = addQueryParameter(url, "ret", returnStrategy);
8286
+ if (!sdk.isTelegramUrl(url)) {
8287
+ return newUrl;
8288
+ }
8289
+ const lastParam = newUrl.slice(newUrl.lastIndexOf("&") + 1);
8290
+ return newUrl.slice(0, newUrl.lastIndexOf("&")) + "-" + sdk.encodeTelegramUrlParameters(lastParam);
8291
+ }
8292
+ function redirectToTelegram(universalLink, options) {
8293
+ options = __spreadValues({}, options);
8294
+ const directLink = convertToTGDirectLink(universalLink);
8295
+ const directLinkUrl = new URL(directLink);
8296
+ if (!directLinkUrl.searchParams.has("startapp")) {
8297
+ directLinkUrl.searchParams.append("startapp", "tonconnect");
8298
+ }
8299
+ if (isInTMA()) {
8300
+ if (isTmaPlatform("ios", "android")) {
8301
+ options.returnStrategy = "back";
8302
+ options.twaReturnUrl = void 0;
8303
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
8304
+ } else if (isTmaPlatform("macos", "tdesktop")) {
8305
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
8306
+ } else if (isTmaPlatform("weba")) {
8307
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
8308
+ } else if (isTmaPlatform("web")) {
8309
+ options.returnStrategy = "back";
8310
+ options.twaReturnUrl = void 0;
8311
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
8312
+ } else {
8313
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
8314
+ }
8315
+ } else {
8316
+ if (isOS("ios", "android")) {
8317
+ options.returnStrategy = "none";
8318
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options.returnStrategy));
8319
+ } else if (isOS("macos", "windows", "linux")) {
8320
+ options.returnStrategy = "none";
8321
+ options.twaReturnUrl = void 0;
8322
+ if (options.forceRedirect) {
8323
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
8324
+ } else {
8325
+ const link = addReturnStrategy(directLinkUrl.toString(), options);
8326
+ const deepLink = convertToTGDeepLink(link);
8327
+ openDeeplinkWithFallback(deepLink, () => openLinkBlank(link));
8328
+ }
8329
+ } else {
8330
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
8331
+ }
8332
+ }
8333
+ }
8334
+ function addQueryParameter(url, key, value) {
8335
+ const parsed = new URL(url);
8336
+ parsed.searchParams.append(key, value);
8337
+ return parsed.toString();
8338
+ }
8339
+ function convertToTGDirectLink(universalLink) {
8340
+ const url = new URL(universalLink);
8341
+ if (url.searchParams.has("attach")) {
8342
+ url.searchParams.delete("attach");
8343
+ url.pathname += "/start";
8344
+ }
8345
+ return url.toString();
8346
+ }
8347
+ function convertToTGDeepLink(directLink) {
8348
+ const parsed = new URL(directLink);
8349
+ const [, domain, appname] = parsed.pathname.split("/");
8350
+ const startapp = parsed.searchParams.get("startapp");
8351
+ return `tg://resolve?domain=${domain}&appname=${appname}&startapp=${startapp}`;
8352
+ }
8353
+ let openDesktopDeeplinkAttempts = 0;
8319
8354
  const DesktopConnectionModal = (props) => {
8320
8355
  const [mode, setMode] = createSignal("mobile");
8321
8356
  const [connectionErrored, setConnectionErrored] = createSignal(false);
@@ -8356,10 +8391,25 @@ const DesktopConnectionModal = (props) => {
8356
8391
  generateUniversalLink();
8357
8392
  }
8358
8393
  setMode("desktop");
8359
- setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8360
- openMethod: "universal-link"
8361
- }));
8362
- openLinkBlank(addReturnStrategy(universalLink(), appState.returnStrategy));
8394
+ const linkWithStrategy = addReturnStrategy(universalLink(), appState.returnStrategy);
8395
+ const haveTriedToOpenDeeplinkInSafari = isBrowser("safari") && openDesktopDeeplinkAttempts >= 1;
8396
+ if (props.wallet.deepLink && !haveTriedToOpenDeeplinkInSafari) {
8397
+ openDesktopDeeplinkAttempts++;
8398
+ setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8399
+ openMethod: "custom-deeplink"
8400
+ }));
8401
+ openDeeplinkWithFallback(toDeeplink(linkWithStrategy, props.wallet.deepLink), () => {
8402
+ setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8403
+ openMethod: "universal-link"
8404
+ }));
8405
+ openLinkBlank(linkWithStrategy);
8406
+ });
8407
+ } else {
8408
+ setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8409
+ openMethod: "universal-link"
8410
+ }));
8411
+ openLinkBlank(linkWithStrategy);
8412
+ }
8363
8413
  };
8364
8414
  const onClickTelegram = () => {
8365
8415
  const forceRedirect = !firstClick();
@@ -8393,9 +8443,16 @@ const DesktopConnectionModal = (props) => {
8393
8443
  return createComponent(DesktopConnectionModalStyled, {
8394
8444
  "data-tc-wallets-modal-connection-desktop": "true",
8395
8445
  get children() {
8396
- return [createComponent(StyledIconButton$2, {
8397
- icon: "arrow",
8398
- onClick: () => props.onBackClick()
8446
+ return [createComponent(Show, {
8447
+ get when() {
8448
+ return !props.backDisabled;
8449
+ },
8450
+ get children() {
8451
+ return createComponent(StyledIconButton$2, {
8452
+ icon: "arrow",
8453
+ onClick: () => props.onBackClick()
8454
+ });
8455
+ }
8399
8456
  }), createComponent(H1Styled$6, {
8400
8457
  get children() {
8401
8458
  return props.wallet.name;
@@ -8933,7 +8990,22 @@ const MobileConnectionModal = (props) => {
8933
8990
  universalLink: props.wallet.universalLink,
8934
8991
  bridgeUrl: props.wallet.bridgeUrl
8935
8992
  }, props.additionalRequest));
8993
+ const onClickTelegram = () => {
8994
+ const alwaysForceRedirect = true;
8995
+ setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8996
+ openMethod: "universal-link"
8997
+ }));
8998
+ redirectToTelegram(universalLink(), {
8999
+ returnStrategy: appState.returnStrategy,
9000
+ twaReturnUrl: appState.twaReturnUrl,
9001
+ forceRedirect: alwaysForceRedirect
9002
+ });
9003
+ };
8936
9004
  const onRetry = () => {
9005
+ const currentUniversalLink = universalLink();
9006
+ if (sdk.isTelegramUrl(currentUniversalLink)) {
9007
+ return onClickTelegram();
9008
+ }
8937
9009
  setConnectionErrored(false);
8938
9010
  setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8939
9011
  openMethod: "universal-link"
@@ -8965,9 +9037,16 @@ const MobileConnectionModal = (props) => {
8965
9037
  return createComponent(MobileConnectionModalStyled, {
8966
9038
  "data-tc-wallets-modal-connection-mobile": "true",
8967
9039
  get children() {
8968
- return [createComponent(StyledIconButton, {
8969
- icon: "arrow",
8970
- onClick: onBack
9040
+ return [createComponent(Show, {
9041
+ get when() {
9042
+ return !props.backDisabled || showQR();
9043
+ },
9044
+ get children() {
9045
+ return createComponent(StyledIconButton, {
9046
+ icon: "arrow",
9047
+ onClick: onBack
9048
+ });
9049
+ }
8971
9050
  }), createComponent(Show, {
8972
9051
  get when() {
8973
9052
  return showQR();
@@ -9977,6 +10056,109 @@ const ActionsModal = () => {
9977
10056
  }
9978
10057
  });
9979
10058
  };
10059
+ const SingleWalletModal = () => {
10060
+ const {
10061
+ locale
10062
+ } = useI18n()[1];
10063
+ createEffect(() => locale(appState.language));
10064
+ createEffect(() => {
10065
+ if (getSingleWalletModalIsOpened()) {
10066
+ updateIsMobile();
10067
+ }
10068
+ });
10069
+ const connector = useContext(ConnectorContext);
10070
+ const [infoTab, setInfoTab] = createSignal(false);
10071
+ const additionalRequestLoading = () => {
10072
+ var _a2;
10073
+ return ((_a2 = appState.connectRequestParameters) == null ? void 0 : _a2.state) === "loading";
10074
+ };
10075
+ const additionalRequest = createMemo(() => {
10076
+ var _a2;
10077
+ if (additionalRequestLoading()) {
10078
+ return void 0;
10079
+ }
10080
+ return (_a2 = appState.connectRequestParameters) == null ? void 0 : _a2.value;
10081
+ });
10082
+ const onClose = (closeReason) => {
10083
+ setSingleWalletModalState({
10084
+ status: "closed",
10085
+ closeReason
10086
+ });
10087
+ setInfoTab(false);
10088
+ };
10089
+ const unsubscribe = connector.onStatusChange((wallet) => {
10090
+ if (wallet) {
10091
+ onClose("wallet-selected");
10092
+ }
10093
+ });
10094
+ onCleanup(unsubscribe);
10095
+ return createComponent(StyledModal, {
10096
+ get opened() {
10097
+ return getSingleWalletModalIsOpened();
10098
+ },
10099
+ get enableAndroidBackHandler() {
10100
+ return appState.enableAndroidBackHandler;
10101
+ },
10102
+ onClose: () => onClose("action-cancelled"),
10103
+ onClickQuestion: () => setInfoTab((v) => !v),
10104
+ "data-tc-wallets-modal-container": "true",
10105
+ get children() {
10106
+ return [createComponent(Show, {
10107
+ get when() {
10108
+ return infoTab();
10109
+ },
10110
+ get children() {
10111
+ return createComponent(InfoModal, {
10112
+ onBackClick: () => setInfoTab(false)
10113
+ });
10114
+ }
10115
+ }), createComponent(Show, {
10116
+ get when() {
10117
+ return !infoTab();
10118
+ },
10119
+ get children() {
10120
+ return [createComponent(Show, {
10121
+ get when() {
10122
+ return additionalRequestLoading();
10123
+ },
10124
+ get children() {
10125
+ return [createComponent(H1Styled$8, {
10126
+ translationKey: "walletModal.loading",
10127
+ children: "Wallets list is loading"
10128
+ }), createComponent(LoaderContainerStyled, {
10129
+ get children() {
10130
+ return createComponent(LoaderIcon, {
10131
+ size: "m"
10132
+ });
10133
+ }
10134
+ })];
10135
+ }
10136
+ }), createComponent(Show, {
10137
+ get when() {
10138
+ return !additionalRequestLoading();
10139
+ },
10140
+ get children() {
10141
+ return createComponent(Dynamic, {
10142
+ get component() {
10143
+ return isMobile() ? MobileConnectionModal : DesktopConnectionModal;
10144
+ },
10145
+ get wallet() {
10146
+ return getSingleWalletModalWalletInfo();
10147
+ },
10148
+ get additionalRequest() {
10149
+ return additionalRequest();
10150
+ },
10151
+ onBackClick: () => {
10152
+ },
10153
+ backDisabled: true
10154
+ });
10155
+ }
10156
+ })];
10157
+ }
10158
+ })];
10159
+ }
10160
+ });
10161
+ };
9980
10162
  const App = (props) => {
9981
10163
  const translations = createI18nContext(i18nDictionary, appState.language);
9982
10164
  defineStylesRoot();
@@ -10014,7 +10196,7 @@ const App = (props) => {
10014
10196
  }), createComponent(Dynamic, {
10015
10197
  component: globalStylesTag,
10016
10198
  get children() {
10017
- return [createComponent(WalletsModal, {}), createComponent(ActionsModal, {})];
10199
+ return [createComponent(WalletsModal, {}), createComponent(SingleWalletModal, {}), createComponent(ActionsModal, {})];
10018
10200
  }
10019
10201
  })];
10020
10202
  }
@@ -10035,6 +10217,17 @@ const widgetController = {
10035
10217
  status: "closed",
10036
10218
  closeReason: reason
10037
10219
  })),
10220
+ openSingleWalletModal: (walletInfo) => {
10221
+ void setTimeout(() => setSingleWalletModalState({
10222
+ status: "opened",
10223
+ closeReason: null,
10224
+ walletInfo
10225
+ }));
10226
+ },
10227
+ closeSingleWalletModal: (reason) => void setTimeout(() => setSingleWalletModalState({
10228
+ status: "closed",
10229
+ closeReason: reason
10230
+ })),
10038
10231
  setAction: (action2) => void setTimeout(() => setAction(action2)),
10039
10232
  clearAction: () => void setTimeout(() => setAction(null)),
10040
10233
  getSelectedWalletInfo: () => lastSelectedWalletInfo(),
@@ -10064,7 +10257,7 @@ class WalletsModalManager {
10064
10257
  if (embeddedWallet) {
10065
10258
  return this.connectEmbeddedWallet(embeddedWallet);
10066
10259
  } else {
10067
- return this.connectExternalWallet();
10260
+ return this.openWalletsModal();
10068
10261
  }
10069
10262
  });
10070
10263
  }
@@ -10089,7 +10282,7 @@ class WalletsModalManager {
10089
10282
  connect(additionalRequest == null ? void 0 : additionalRequest.value);
10090
10283
  }
10091
10284
  }
10092
- connectExternalWallet() {
10285
+ openWalletsModal() {
10093
10286
  return __async(this, null, function* () {
10094
10287
  if (isInTMA()) {
10095
10288
  sendExpand();
@@ -10124,6 +10317,80 @@ class TransactionModalManager {
10124
10317
  };
10125
10318
  }
10126
10319
  }
10320
+ class SingleWalletModalManager {
10321
+ constructor(options) {
10322
+ __publicField(this, "connector");
10323
+ __publicField(this, "setConnectRequestParametersCallback");
10324
+ __publicField(this, "consumers", []);
10325
+ __publicField(this, "state", singleWalletModalState());
10326
+ this.connector = options.connector;
10327
+ this.setConnectRequestParametersCallback = options.setConnectRequestParametersCallback;
10328
+ createEffect(() => {
10329
+ const state = singleWalletModalState();
10330
+ this.state = state;
10331
+ this.consumers.forEach((consumer) => consumer(state));
10332
+ });
10333
+ }
10334
+ open(wallet) {
10335
+ return __async(this, null, function* () {
10336
+ const fetchedWalletsList = yield this.connector.getWallets();
10337
+ const walletsList = applyWalletsListConfiguration(
10338
+ fetchedWalletsList,
10339
+ appState.walletsListConfiguration
10340
+ );
10341
+ const embeddedWallet = walletsList.find(sdk.isWalletInfoCurrentlyEmbedded);
10342
+ const isEmbeddedWalletExist = !!embeddedWallet;
10343
+ if (isEmbeddedWalletExist) {
10344
+ return this.connectEmbeddedWallet(embeddedWallet);
10345
+ }
10346
+ const externalWallets = walletsList.filter(sdk.isWalletInfoRemote);
10347
+ const externalWallet = externalWallets.find((walletInfo) => eqWalletName(walletInfo, wallet));
10348
+ const isExternalWalletExist = !!externalWallet;
10349
+ if (isExternalWalletExist) {
10350
+ return this.openSingleWalletModal(externalWallet);
10351
+ }
10352
+ throw new TonConnectUIError(`Trying to open modal window with unknown wallet "${wallet}".`);
10353
+ });
10354
+ }
10355
+ close() {
10356
+ widgetController.closeSingleWalletModal("action-cancelled");
10357
+ }
10358
+ onStateChange(onChange) {
10359
+ this.consumers.push(onChange);
10360
+ return () => {
10361
+ this.consumers = this.consumers.filter((consumer) => consumer !== onChange);
10362
+ };
10363
+ }
10364
+ connectEmbeddedWallet(embeddedWallet) {
10365
+ const connect = (parameters) => {
10366
+ setLastSelectedWalletInfo(embeddedWallet);
10367
+ this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey }, parameters);
10368
+ };
10369
+ const additionalRequest = appState.connectRequestParameters;
10370
+ if ((additionalRequest == null ? void 0 : additionalRequest.state) === "loading") {
10371
+ this.setConnectRequestParametersCallback(connect);
10372
+ } else {
10373
+ connect(additionalRequest == null ? void 0 : additionalRequest.value);
10374
+ }
10375
+ }
10376
+ openSingleWalletModal(wallet) {
10377
+ return __async(this, null, function* () {
10378
+ if (isInTMA()) {
10379
+ sendExpand();
10380
+ }
10381
+ widgetController.openSingleWalletModal(wallet);
10382
+ return new Promise((resolve) => {
10383
+ const unsubscribe = this.onStateChange((state) => {
10384
+ const { status } = state;
10385
+ if (status === "opened") {
10386
+ unsubscribe();
10387
+ resolve();
10388
+ }
10389
+ });
10390
+ });
10391
+ });
10392
+ }
10393
+ }
10127
10394
  class TonConnectUI {
10128
10395
  constructor(options) {
10129
10396
  __publicField(this, "walletInfoStorage", new WalletInfoStorage());
@@ -10135,6 +10402,7 @@ class TonConnectUI {
10135
10402
  __publicField(this, "connectRequestParametersCallback");
10136
10403
  __publicField(this, "connector");
10137
10404
  __publicField(this, "modal");
10405
+ __publicField(this, "singleWalletModal");
10138
10406
  __publicField(this, "transactionModal");
10139
10407
  __publicField(this, "connectionRestored", Promise.resolve(false));
10140
10408
  if (options && "connector" in options && options.connector) {
@@ -10152,6 +10420,12 @@ class TonConnectUI {
10152
10420
  this.connectRequestParametersCallback = callback;
10153
10421
  }
10154
10422
  });
10423
+ this.singleWalletModal = new SingleWalletModalManager({
10424
+ connector: this.connector,
10425
+ setConnectRequestParametersCallback: (callback) => {
10426
+ this.connectRequestParametersCallback = callback;
10427
+ }
10428
+ });
10155
10429
  this.transactionModal = new TransactionModalManager({
10156
10430
  connector: this.connector
10157
10431
  });
@@ -10270,6 +10544,20 @@ class TonConnectUI {
10270
10544
  get modalState() {
10271
10545
  return this.modal.state;
10272
10546
  }
10547
+ openSingleWalletModal(wallet) {
10548
+ return __async(this, null, function* () {
10549
+ return this.singleWalletModal.open(wallet);
10550
+ });
10551
+ }
10552
+ closeSingleWalletModal() {
10553
+ this.singleWalletModal.close();
10554
+ }
10555
+ onSingleWalletModalStateChange(onChange) {
10556
+ return this.singleWalletModal.onStateChange(onChange);
10557
+ }
10558
+ get singleWalletModalState() {
10559
+ return this.singleWalletModal.state;
10560
+ }
10273
10561
  connectWallet() {
10274
10562
  return __async(this, null, function* () {
10275
10563
  const walletsList = yield this.getWallets();