@tonconnect/ui 2.0.0-beta.9 → 2.0.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.d.ts CHANGED
@@ -195,7 +195,7 @@ interface TonConnectUiCreateOptionsBase extends TonConnectUiOptions {
195
195
  widgetRootId?: string;
196
196
  }
197
197
 
198
- declare type WalletOpenMethod = 'qrcode' | 'universal-link';
198
+ declare type WalletOpenMethod = 'qrcode' | 'universal-link' | 'custom-deeplink';
199
199
  declare type WalletInfoWithOpenMethod = WalletInfoInjectable | WalletInfoRemoteWithOpenMethod | (WalletInfoInjectable & WalletInfoRemoteWithOpenMethod);
200
200
  declare type WalletInfoRemoteWithOpenMethod = WalletInfoRemote & {
201
201
  openMethod?: WalletOpenMethod;
package/lib/index.mjs CHANGED
@@ -42,7 +42,7 @@ var __async = (__this, __arguments, generator) => {
42
42
  });
43
43
  };
44
44
  var _a, _b, _c, _d, _e, _f, _g, _h;
45
- import { TonConnectError, isTelegramUrl, encodeTelegramUrlParameters, isWalletInfoCurrentlyInjected, toUserFriendlyAddress, CHAIN, TonConnect, isWalletInfoRemote, isWalletInfoCurrentlyEmbedded } from "@tonconnect/sdk";
45
+ import { TonConnectError, isWalletInfoCurrentlyInjected, toUserFriendlyAddress, CHAIN, TonConnect, isTelegramUrl, encodeTelegramUrlParameters, isWalletInfoRemote, isWalletInfoCurrentlyEmbedded } from "@tonconnect/sdk";
46
46
  export * from "@tonconnect/sdk";
47
47
  import UAParser from "ua-parser-js";
48
48
  import deepmerge from "deepmerge";
@@ -1749,172 +1749,22 @@ class TonConnectUIError extends TonConnectError {
1749
1749
  Object.setPrototypeOf(this, TonConnectUIError.prototype);
1750
1750
  }
1751
1751
  }
1752
- function logError(...args) {
1753
- {
1754
- try {
1755
- console.error("[TON_CONNECT_UI]", ...args);
1756
- } catch (e2) {
1757
- }
1758
- }
1759
- }
1760
- function logWarning(...args) {
1761
- {
1762
- try {
1763
- console.warn("[TON_CONNECT_UI]", ...args);
1764
- } catch (e2) {
1765
- }
1766
- }
1767
- }
1768
- let initParams = {};
1769
- try {
1770
- let locationHash = location.hash.toString();
1771
- initParams = urlParseHashParams(locationHash);
1772
- } catch (e2) {
1773
- }
1774
- let tmaPlatform = "unknown";
1775
- if (initParams == null ? void 0 : initParams.tgWebAppPlatform) {
1776
- tmaPlatform = (_a = initParams.tgWebAppPlatform) != null ? _a : "unknown";
1777
- }
1778
- if (tmaPlatform === "unknown") {
1779
- tmaPlatform = (_d = (_c = (_b = window == null ? void 0 : window.Telegram) == null ? void 0 : _b.WebApp) == null ? void 0 : _c.platform) != null ? _d : "unknown";
1780
- }
1781
- let webAppVersion = "6.0";
1782
- if (initParams == null ? void 0 : initParams.tgWebAppVersion) {
1783
- webAppVersion = initParams.tgWebAppVersion;
1784
- }
1785
- if (!webAppVersion) {
1786
- webAppVersion = (_g = (_f = (_e = window == null ? void 0 : window.Telegram) == null ? void 0 : _e.WebApp) == null ? void 0 : _f.version) != null ? _g : "6.0";
1787
- }
1788
- function isTmaPlatform(...platforms) {
1789
- return platforms.includes(tmaPlatform);
1790
- }
1791
- function isInTMA() {
1792
- var _a2;
1793
- return tmaPlatform !== "unknown" || !!((_a2 = getWindow$1()) == null ? void 0 : _a2.TelegramWebviewProxy);
1794
- }
1795
- function sendExpand() {
1796
- postEvent("web_app_expand", {});
1797
- }
1798
- function sendOpenTelegramLink(link) {
1799
- const url = new URL(link);
1800
- if (url.protocol !== "http:" && url.protocol !== "https:") {
1801
- throw new TonConnectUIError(`Url protocol is not supported: ${url}`);
1802
- }
1803
- if (url.hostname !== "t.me") {
1804
- throw new TonConnectUIError(`Url host is not supported: ${url}`);
1805
- }
1806
- const pathFull = url.pathname + url.search;
1807
- if (isIframe() || versionAtLeast("6.1")) {
1808
- postEvent("web_app_open_tg_link", { path_full: pathFull });
1809
- } else {
1810
- window.open("https://t.me" + pathFull, "_blank", "noreferrer noopener");
1811
- }
1812
- }
1813
- function isIframe() {
1814
- try {
1815
- return window.parent != null && window !== window.parent;
1816
- } catch (e2) {
1817
- return false;
1818
- }
1819
- }
1820
- function postEvent(eventType, eventData) {
1821
- try {
1822
- if (window.TelegramWebviewProxy !== void 0) {
1823
- window.TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
1824
- } else if (window.external && "notify" in window.external) {
1825
- window.external.notify(JSON.stringify({ eventType, eventData }));
1826
- } else if (isIframe()) {
1827
- const trustedTarget = "*";
1828
- const message = JSON.stringify({ eventType, eventData });
1829
- window.parent.postMessage(message, trustedTarget);
1830
- }
1831
- throw new TonConnectUIError(`Can't post event to TMA`);
1832
- } catch (e2) {
1833
- logError(`Can't post event to parent window: ${e2}`);
1834
- }
1835
- }
1836
- function urlParseHashParams(locationHash) {
1837
- locationHash = locationHash.replace(/^#/, "");
1838
- let params = {};
1839
- if (!locationHash.length) {
1840
- return params;
1841
- }
1842
- if (locationHash.indexOf("=") < 0 && locationHash.indexOf("?") < 0) {
1843
- params._path = urlSafeDecode(locationHash);
1844
- return params;
1845
- }
1846
- let qIndex = locationHash.indexOf("?");
1847
- if (qIndex >= 0) {
1848
- let pathParam = locationHash.substr(0, qIndex);
1849
- params._path = urlSafeDecode(pathParam);
1850
- locationHash = locationHash.substr(qIndex + 1);
1851
- }
1852
- let query_params = urlParseQueryString(locationHash);
1853
- for (let k in query_params) {
1854
- params[k] = query_params[k];
1855
- }
1856
- return params;
1857
- }
1858
- function urlSafeDecode(urlencoded) {
1859
- try {
1860
- urlencoded = urlencoded.replace(/\+/g, "%20");
1861
- return decodeURIComponent(urlencoded);
1862
- } catch (e2) {
1863
- return urlencoded;
1864
- }
1865
- }
1866
- function urlParseQueryString(queryString) {
1867
- let params = {};
1868
- if (!queryString.length) {
1869
- return params;
1870
- }
1871
- let queryStringParams = queryString.split("&");
1872
- let i2, param, paramName, paramValue;
1873
- for (i2 = 0; i2 < queryStringParams.length; i2++) {
1874
- param = queryStringParams[i2].split("=");
1875
- paramName = urlSafeDecode(param[0]);
1876
- paramValue = param[1] == null ? null : urlSafeDecode(param[1]);
1877
- params[paramName] = paramValue;
1878
- }
1879
- return params;
1880
- }
1881
- function versionCompare(v1, v2) {
1882
- if (typeof v1 !== "string")
1883
- v1 = "";
1884
- if (typeof v2 !== "string")
1885
- v2 = "";
1886
- let v1List = v1.replace(/^\s+|\s+$/g, "").split(".");
1887
- let v2List = v2.replace(/^\s+|\s+$/g, "").split(".");
1888
- let a2, i2, p1, p2;
1889
- a2 = Math.max(v1List.length, v2List.length);
1890
- for (i2 = 0; i2 < a2; i2++) {
1891
- p1 = parseInt(v1List[i2]) || 0;
1892
- p2 = parseInt(v2List[i2]) || 0;
1893
- if (p1 === p2)
1894
- continue;
1895
- if (p1 > p2)
1896
- return 1;
1897
- return -1;
1898
- }
1899
- return 0;
1900
- }
1901
- function versionAtLeast(ver) {
1902
- return versionCompare(webAppVersion, ver) >= 0;
1903
- }
1904
1752
  function openLink(href, target = "_self") {
1905
1753
  window.open(href, target, "noopener noreferrer");
1906
1754
  }
1907
1755
  function openLinkBlank(href) {
1908
1756
  openLink(href, "_blank");
1909
1757
  }
1910
- function openIframeLink(href, fallback) {
1911
- const iframe = document.createElement("iframe");
1912
- iframe.style.display = "none";
1913
- iframe.src = href;
1914
- document.body.appendChild(iframe);
1915
- const fallbackTimeout = setTimeout(() => fallback(), 1e3);
1758
+ function openDeeplinkWithFallback(href, fallback) {
1759
+ const doFallback = () => {
1760
+ if (isBrowser("safari")) {
1761
+ return;
1762
+ }
1763
+ fallback();
1764
+ };
1765
+ const fallbackTimeout = setTimeout(() => doFallback(), 200);
1916
1766
  window.addEventListener("blur", () => clearTimeout(fallbackTimeout), { once: true });
1917
- setTimeout(() => document.body.removeChild(iframe), 1e3);
1767
+ openLink(href, "_self");
1918
1768
  }
1919
1769
  function getSystemTheme() {
1920
1770
  if (window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches) {
@@ -1927,25 +1777,6 @@ function subscribeToThemeChange(callback) {
1927
1777
  window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", handler);
1928
1778
  return () => window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", handler);
1929
1779
  }
1930
- function addQueryParameter(url, key, value) {
1931
- const parsed = new URL(url);
1932
- parsed.searchParams.append(key, value);
1933
- return parsed.toString();
1934
- }
1935
- function addReturnStrategy(url, strategy) {
1936
- let returnStrategy;
1937
- if (typeof strategy === "string") {
1938
- returnStrategy = strategy;
1939
- } else {
1940
- returnStrategy = isInTMA() ? strategy.twaReturnUrl || strategy.returnStrategy : "none";
1941
- }
1942
- const newUrl = addQueryParameter(url, "ret", returnStrategy);
1943
- if (!isTelegramUrl(url)) {
1944
- return newUrl;
1945
- }
1946
- const lastParam = newUrl.slice(newUrl.lastIndexOf("&") + 1);
1947
- return newUrl.slice(0, newUrl.lastIndexOf("&")) + "-" + encodeTelegramUrlParameters(lastParam);
1948
- }
1949
1780
  function disableScroll() {
1950
1781
  if (document.documentElement.scrollHeight === document.documentElement.clientHeight) {
1951
1782
  return;
@@ -2055,61 +1886,12 @@ function getUserAgent() {
2055
1886
  function isOS(...os) {
2056
1887
  return os.includes(getUserAgent().os);
2057
1888
  }
2058
- function redirectToTelegram(universalLink, options) {
2059
- options = __spreadValues({}, options);
2060
- const directLink = convertToDirectLink(universalLink);
2061
- const directLinkUrl = new URL(directLink);
2062
- if (!directLinkUrl.searchParams.has("startapp")) {
2063
- directLinkUrl.searchParams.append("startapp", "tonconnect");
2064
- }
2065
- if (isInTMA()) {
2066
- if (isTmaPlatform("ios", "android")) {
2067
- options.returnStrategy = "back";
2068
- options.twaReturnUrl = void 0;
2069
- sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2070
- } else if (isTmaPlatform("macos", "tdesktop")) {
2071
- sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2072
- } else if (isTmaPlatform("weba")) {
2073
- sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2074
- } else if (isTmaPlatform("web")) {
2075
- options.returnStrategy = "back";
2076
- options.twaReturnUrl = void 0;
2077
- sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2078
- } else {
2079
- openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
2080
- }
2081
- } else {
2082
- if (isOS("ios", "android")) {
2083
- options.returnStrategy = "none";
2084
- openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options.returnStrategy));
2085
- } else if (isOS("macos", "windows", "linux")) {
2086
- options.returnStrategy = "none";
2087
- options.twaReturnUrl = void 0;
2088
- if (options.forceRedirect) {
2089
- openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
2090
- } else {
2091
- const link = addReturnStrategy(directLinkUrl.toString(), options);
2092
- const deepLink = convertToDeepLink(link);
2093
- openIframeLink(deepLink, () => openLinkBlank(link));
2094
- }
2095
- } else {
2096
- openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
2097
- }
2098
- }
1889
+ function isBrowser(...browser) {
1890
+ return browser.includes(getUserAgent().browser);
2099
1891
  }
2100
- function convertToDirectLink(universalLink) {
1892
+ function toDeeplink(universalLink, deeplink) {
2101
1893
  const url = new URL(universalLink);
2102
- if (url.searchParams.has("attach")) {
2103
- url.searchParams.delete("attach");
2104
- url.pathname += "/start";
2105
- }
2106
- return url.toString();
2107
- }
2108
- function convertToDeepLink(directLink) {
2109
- const parsed = new URL(directLink);
2110
- const [, domain, appname] = parsed.pathname.split("/");
2111
- const startapp = parsed.searchParams.get("startapp");
2112
- return `tg://resolve?domain=${domain}&appname=${appname}&startapp=${startapp}`;
1894
+ return deeplink + url.search;
2113
1895
  }
2114
1896
  class WalletInfoStorage {
2115
1897
  constructor() {
@@ -2830,6 +2612,169 @@ const Image = (props) => {
2830
2612
  }
2831
2613
  })];
2832
2614
  };
2615
+ function logError(...args) {
2616
+ {
2617
+ try {
2618
+ console.error("[TON_CONNECT_UI]", ...args);
2619
+ } catch (e2) {
2620
+ }
2621
+ }
2622
+ }
2623
+ function logWarning(...args) {
2624
+ {
2625
+ try {
2626
+ console.warn("[TON_CONNECT_UI]", ...args);
2627
+ } catch (e2) {
2628
+ }
2629
+ }
2630
+ }
2631
+ let initParams = {};
2632
+ try {
2633
+ let locationHash = location.hash.toString();
2634
+ initParams = urlParseHashParams(locationHash);
2635
+ } catch (e2) {
2636
+ }
2637
+ let tmaPlatform = "unknown";
2638
+ if (initParams == null ? void 0 : initParams.tgWebAppPlatform) {
2639
+ tmaPlatform = (_a = initParams.tgWebAppPlatform) != null ? _a : "unknown";
2640
+ }
2641
+ if (tmaPlatform === "unknown") {
2642
+ const window2 = getWindow$1();
2643
+ tmaPlatform = (_d = (_c = (_b = window2 == null ? void 0 : window2.Telegram) == null ? void 0 : _b.WebApp) == null ? void 0 : _c.platform) != null ? _d : "unknown";
2644
+ }
2645
+ let webAppVersion = "6.0";
2646
+ if (initParams == null ? void 0 : initParams.tgWebAppVersion) {
2647
+ webAppVersion = initParams.tgWebAppVersion;
2648
+ }
2649
+ if (!webAppVersion) {
2650
+ const window2 = getWindow$1();
2651
+ webAppVersion = (_g = (_f = (_e = window2 == null ? void 0 : window2.Telegram) == null ? void 0 : _e.WebApp) == null ? void 0 : _f.version) != null ? _g : "6.0";
2652
+ }
2653
+ function isTmaPlatform(...platforms) {
2654
+ return platforms.includes(tmaPlatform);
2655
+ }
2656
+ function isInTMA() {
2657
+ var _a2;
2658
+ return tmaPlatform !== "unknown" || !!((_a2 = getWindow$1()) == null ? void 0 : _a2.TelegramWebviewProxy);
2659
+ }
2660
+ function sendExpand() {
2661
+ postEvent("web_app_expand", {});
2662
+ }
2663
+ function sendOpenTelegramLink(link) {
2664
+ const url = new URL(link);
2665
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
2666
+ throw new TonConnectUIError(`Url protocol is not supported: ${url}`);
2667
+ }
2668
+ if (url.hostname !== "t.me") {
2669
+ throw new TonConnectUIError(`Url host is not supported: ${url}`);
2670
+ }
2671
+ const pathFull = url.pathname + url.search;
2672
+ if (isIframe() || versionAtLeast("6.1")) {
2673
+ postEvent("web_app_open_tg_link", { path_full: pathFull });
2674
+ } else {
2675
+ openLinkBlank("https://t.me" + pathFull);
2676
+ }
2677
+ }
2678
+ function isIframe() {
2679
+ try {
2680
+ const window2 = getWindow$1();
2681
+ if (!window2) {
2682
+ return false;
2683
+ }
2684
+ return window2.parent != null && window2 !== window2.parent;
2685
+ } catch (e2) {
2686
+ return false;
2687
+ }
2688
+ }
2689
+ function postEvent(eventType, eventData) {
2690
+ try {
2691
+ const window2 = getWindow$1();
2692
+ if (!window2) {
2693
+ throw new TonConnectUIError(`Can't post event to parent window: window is not defined`);
2694
+ }
2695
+ if (window2.TelegramWebviewProxy !== void 0) {
2696
+ window2.TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
2697
+ } else if (window2.external && "notify" in window2.external) {
2698
+ window2.external.notify(JSON.stringify({ eventType, eventData }));
2699
+ } else if (isIframe()) {
2700
+ const trustedTarget = "*";
2701
+ const message = JSON.stringify({ eventType, eventData });
2702
+ window2.parent.postMessage(message, trustedTarget);
2703
+ } else {
2704
+ throw new TonConnectUIError(`Can't post event to TMA`);
2705
+ }
2706
+ } catch (e2) {
2707
+ logError(`Can't post event to parent window: ${e2}`);
2708
+ }
2709
+ }
2710
+ function urlParseHashParams(locationHash) {
2711
+ locationHash = locationHash.replace(/^#/, "");
2712
+ let params = {};
2713
+ if (!locationHash.length) {
2714
+ return params;
2715
+ }
2716
+ if (locationHash.indexOf("=") < 0 && locationHash.indexOf("?") < 0) {
2717
+ params._path = urlSafeDecode(locationHash);
2718
+ return params;
2719
+ }
2720
+ let qIndex = locationHash.indexOf("?");
2721
+ if (qIndex >= 0) {
2722
+ let pathParam = locationHash.substr(0, qIndex);
2723
+ params._path = urlSafeDecode(pathParam);
2724
+ locationHash = locationHash.substr(qIndex + 1);
2725
+ }
2726
+ let query_params = urlParseQueryString(locationHash);
2727
+ for (let k in query_params) {
2728
+ params[k] = query_params[k];
2729
+ }
2730
+ return params;
2731
+ }
2732
+ function urlSafeDecode(urlencoded) {
2733
+ try {
2734
+ urlencoded = urlencoded.replace(/\+/g, "%20");
2735
+ return decodeURIComponent(urlencoded);
2736
+ } catch (e2) {
2737
+ return urlencoded;
2738
+ }
2739
+ }
2740
+ function urlParseQueryString(queryString) {
2741
+ let params = {};
2742
+ if (!queryString.length) {
2743
+ return params;
2744
+ }
2745
+ let queryStringParams = queryString.split("&");
2746
+ let i2, param, paramName, paramValue;
2747
+ for (i2 = 0; i2 < queryStringParams.length; i2++) {
2748
+ param = queryStringParams[i2].split("=");
2749
+ paramName = urlSafeDecode(param[0]);
2750
+ paramValue = param[1] == null ? null : urlSafeDecode(param[1]);
2751
+ params[paramName] = paramValue;
2752
+ }
2753
+ return params;
2754
+ }
2755
+ function versionCompare(v1, v2) {
2756
+ if (typeof v1 !== "string")
2757
+ v1 = "";
2758
+ if (typeof v2 !== "string")
2759
+ v2 = "";
2760
+ let v1List = v1.replace(/^\s+|\s+$/g, "").split(".");
2761
+ let v2List = v2.replace(/^\s+|\s+$/g, "").split(".");
2762
+ let a2, i2, p1, p2;
2763
+ a2 = Math.max(v1List.length, v2List.length);
2764
+ for (i2 = 0; i2 < a2; i2++) {
2765
+ p1 = parseInt(v1List[i2]) || 0;
2766
+ p2 = parseInt(v2List[i2]) || 0;
2767
+ if (p1 === p2)
2768
+ continue;
2769
+ if (p1 > p2)
2770
+ return 1;
2771
+ return -1;
2772
+ }
2773
+ return 0;
2774
+ }
2775
+ function versionAtLeast(ver) {
2776
+ return versionCompare(webAppVersion, ver) >= 0;
2777
+ }
2833
2778
  const maxWidth = {
2834
2779
  mobile: 440,
2835
2780
  tablet: 1020
@@ -8311,6 +8256,82 @@ const Translation = (props) => {
8311
8256
  return t2(props.translationKey, props.translationValues, (_a2 = props.children) == null ? void 0 : _a2.toString());
8312
8257
  });
8313
8258
  };
8259
+ function addReturnStrategy(url, strategy) {
8260
+ let returnStrategy;
8261
+ if (typeof strategy === "string") {
8262
+ returnStrategy = strategy;
8263
+ } else {
8264
+ returnStrategy = isInTMA() ? strategy.twaReturnUrl || strategy.returnStrategy : "none";
8265
+ }
8266
+ const newUrl = addQueryParameter(url, "ret", returnStrategy);
8267
+ if (!isTelegramUrl(url)) {
8268
+ return newUrl;
8269
+ }
8270
+ const lastParam = newUrl.slice(newUrl.lastIndexOf("&") + 1);
8271
+ return newUrl.slice(0, newUrl.lastIndexOf("&")) + "-" + encodeTelegramUrlParameters(lastParam);
8272
+ }
8273
+ function redirectToTelegram(universalLink, options) {
8274
+ options = __spreadValues({}, options);
8275
+ const directLink = convertToTGDirectLink(universalLink);
8276
+ const directLinkUrl = new URL(directLink);
8277
+ if (!directLinkUrl.searchParams.has("startapp")) {
8278
+ directLinkUrl.searchParams.append("startapp", "tonconnect");
8279
+ }
8280
+ if (isInTMA()) {
8281
+ if (isTmaPlatform("ios", "android")) {
8282
+ options.returnStrategy = "back";
8283
+ options.twaReturnUrl = void 0;
8284
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
8285
+ } else if (isTmaPlatform("macos", "tdesktop")) {
8286
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
8287
+ } else if (isTmaPlatform("weba")) {
8288
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
8289
+ } else if (isTmaPlatform("web")) {
8290
+ options.returnStrategy = "back";
8291
+ options.twaReturnUrl = void 0;
8292
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
8293
+ } else {
8294
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
8295
+ }
8296
+ } else {
8297
+ if (isOS("ios", "android")) {
8298
+ options.returnStrategy = "none";
8299
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options.returnStrategy));
8300
+ } else if (isOS("macos", "windows", "linux")) {
8301
+ options.returnStrategy = "none";
8302
+ options.twaReturnUrl = void 0;
8303
+ if (options.forceRedirect) {
8304
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
8305
+ } else {
8306
+ const link = addReturnStrategy(directLinkUrl.toString(), options);
8307
+ const deepLink = convertToTGDeepLink(link);
8308
+ openDeeplinkWithFallback(deepLink, () => openLinkBlank(link));
8309
+ }
8310
+ } else {
8311
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
8312
+ }
8313
+ }
8314
+ }
8315
+ function addQueryParameter(url, key, value) {
8316
+ const parsed = new URL(url);
8317
+ parsed.searchParams.append(key, value);
8318
+ return parsed.toString();
8319
+ }
8320
+ function convertToTGDirectLink(universalLink) {
8321
+ const url = new URL(universalLink);
8322
+ if (url.searchParams.has("attach")) {
8323
+ url.searchParams.delete("attach");
8324
+ url.pathname += "/start";
8325
+ }
8326
+ return url.toString();
8327
+ }
8328
+ function convertToTGDeepLink(directLink) {
8329
+ const parsed = new URL(directLink);
8330
+ const [, domain, appname] = parsed.pathname.split("/");
8331
+ const startapp = parsed.searchParams.get("startapp");
8332
+ return `tg://resolve?domain=${domain}&appname=${appname}&startapp=${startapp}`;
8333
+ }
8334
+ let openDesktopDeeplinkAttempts = 0;
8314
8335
  const DesktopConnectionModal = (props) => {
8315
8336
  const [mode, setMode] = createSignal("mobile");
8316
8337
  const [connectionErrored, setConnectionErrored] = createSignal(false);
@@ -8351,10 +8372,25 @@ const DesktopConnectionModal = (props) => {
8351
8372
  generateUniversalLink();
8352
8373
  }
8353
8374
  setMode("desktop");
8354
- setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8355
- openMethod: "universal-link"
8356
- }));
8357
- openLinkBlank(addReturnStrategy(universalLink(), appState.returnStrategy));
8375
+ const linkWithStrategy = addReturnStrategy(universalLink(), appState.returnStrategy);
8376
+ const haveTriedToOpenDeeplinkInSafari = isBrowser("safari") && openDesktopDeeplinkAttempts >= 1;
8377
+ if (props.wallet.deepLink && !haveTriedToOpenDeeplinkInSafari) {
8378
+ openDesktopDeeplinkAttempts++;
8379
+ setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8380
+ openMethod: "custom-deeplink"
8381
+ }));
8382
+ openDeeplinkWithFallback(toDeeplink(linkWithStrategy, props.wallet.deepLink), () => {
8383
+ setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8384
+ openMethod: "universal-link"
8385
+ }));
8386
+ openLinkBlank(linkWithStrategy);
8387
+ });
8388
+ } else {
8389
+ setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8390
+ openMethod: "universal-link"
8391
+ }));
8392
+ openLinkBlank(linkWithStrategy);
8393
+ }
8358
8394
  };
8359
8395
  const onClickTelegram = () => {
8360
8396
  const forceRedirect = !firstClick();