@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/dist/tonconnect-ui.min.js +183 -183
- package/dist/tonconnect-ui.min.js.map +1 -1
- package/lib/index.cjs +271 -235
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.mjs +272 -236
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -2
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
|
|
1916
|
-
const
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
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
|
-
|
|
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
|
|
2064
|
-
|
|
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
|
|
1897
|
+
function toDeeplink(universalLink, deeplink) {
|
|
2106
1898
|
const url = new URL(universalLink);
|
|
2107
|
-
|
|
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() {
|
|
@@ -2835,6 +2617,169 @@ const Image = (props) => {
|
|
|
2835
2617
|
}
|
|
2836
2618
|
})];
|
|
2837
2619
|
};
|
|
2620
|
+
function logError(...args) {
|
|
2621
|
+
{
|
|
2622
|
+
try {
|
|
2623
|
+
console.error("[TON_CONNECT_UI]", ...args);
|
|
2624
|
+
} catch (e2) {
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
function logWarning(...args) {
|
|
2629
|
+
{
|
|
2630
|
+
try {
|
|
2631
|
+
console.warn("[TON_CONNECT_UI]", ...args);
|
|
2632
|
+
} catch (e2) {
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
let initParams = {};
|
|
2637
|
+
try {
|
|
2638
|
+
let locationHash = location.hash.toString();
|
|
2639
|
+
initParams = urlParseHashParams(locationHash);
|
|
2640
|
+
} catch (e2) {
|
|
2641
|
+
}
|
|
2642
|
+
let tmaPlatform = "unknown";
|
|
2643
|
+
if (initParams == null ? void 0 : initParams.tgWebAppPlatform) {
|
|
2644
|
+
tmaPlatform = (_a = initParams.tgWebAppPlatform) != null ? _a : "unknown";
|
|
2645
|
+
}
|
|
2646
|
+
if (tmaPlatform === "unknown") {
|
|
2647
|
+
const window2 = getWindow$1();
|
|
2648
|
+
tmaPlatform = (_d = (_c = (_b = window2 == null ? void 0 : window2.Telegram) == null ? void 0 : _b.WebApp) == null ? void 0 : _c.platform) != null ? _d : "unknown";
|
|
2649
|
+
}
|
|
2650
|
+
let webAppVersion = "6.0";
|
|
2651
|
+
if (initParams == null ? void 0 : initParams.tgWebAppVersion) {
|
|
2652
|
+
webAppVersion = initParams.tgWebAppVersion;
|
|
2653
|
+
}
|
|
2654
|
+
if (!webAppVersion) {
|
|
2655
|
+
const window2 = getWindow$1();
|
|
2656
|
+
webAppVersion = (_g = (_f = (_e = window2 == null ? void 0 : window2.Telegram) == null ? void 0 : _e.WebApp) == null ? void 0 : _f.version) != null ? _g : "6.0";
|
|
2657
|
+
}
|
|
2658
|
+
function isTmaPlatform(...platforms) {
|
|
2659
|
+
return platforms.includes(tmaPlatform);
|
|
2660
|
+
}
|
|
2661
|
+
function isInTMA() {
|
|
2662
|
+
var _a2;
|
|
2663
|
+
return tmaPlatform !== "unknown" || !!((_a2 = getWindow$1()) == null ? void 0 : _a2.TelegramWebviewProxy);
|
|
2664
|
+
}
|
|
2665
|
+
function sendExpand() {
|
|
2666
|
+
postEvent("web_app_expand", {});
|
|
2667
|
+
}
|
|
2668
|
+
function sendOpenTelegramLink(link) {
|
|
2669
|
+
const url = new URL(link);
|
|
2670
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
2671
|
+
throw new TonConnectUIError(`Url protocol is not supported: ${url}`);
|
|
2672
|
+
}
|
|
2673
|
+
if (url.hostname !== "t.me") {
|
|
2674
|
+
throw new TonConnectUIError(`Url host is not supported: ${url}`);
|
|
2675
|
+
}
|
|
2676
|
+
const pathFull = url.pathname + url.search;
|
|
2677
|
+
if (isIframe() || versionAtLeast("6.1")) {
|
|
2678
|
+
postEvent("web_app_open_tg_link", { path_full: pathFull });
|
|
2679
|
+
} else {
|
|
2680
|
+
openLinkBlank("https://t.me" + pathFull);
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
function isIframe() {
|
|
2684
|
+
try {
|
|
2685
|
+
const window2 = getWindow$1();
|
|
2686
|
+
if (!window2) {
|
|
2687
|
+
return false;
|
|
2688
|
+
}
|
|
2689
|
+
return window2.parent != null && window2 !== window2.parent;
|
|
2690
|
+
} catch (e2) {
|
|
2691
|
+
return false;
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
function postEvent(eventType, eventData) {
|
|
2695
|
+
try {
|
|
2696
|
+
const window2 = getWindow$1();
|
|
2697
|
+
if (!window2) {
|
|
2698
|
+
throw new TonConnectUIError(`Can't post event to parent window: window is not defined`);
|
|
2699
|
+
}
|
|
2700
|
+
if (window2.TelegramWebviewProxy !== void 0) {
|
|
2701
|
+
window2.TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
|
|
2702
|
+
} else if (window2.external && "notify" in window2.external) {
|
|
2703
|
+
window2.external.notify(JSON.stringify({ eventType, eventData }));
|
|
2704
|
+
} else if (isIframe()) {
|
|
2705
|
+
const trustedTarget = "*";
|
|
2706
|
+
const message = JSON.stringify({ eventType, eventData });
|
|
2707
|
+
window2.parent.postMessage(message, trustedTarget);
|
|
2708
|
+
} else {
|
|
2709
|
+
throw new TonConnectUIError(`Can't post event to TMA`);
|
|
2710
|
+
}
|
|
2711
|
+
} catch (e2) {
|
|
2712
|
+
logError(`Can't post event to parent window: ${e2}`);
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
function urlParseHashParams(locationHash) {
|
|
2716
|
+
locationHash = locationHash.replace(/^#/, "");
|
|
2717
|
+
let params = {};
|
|
2718
|
+
if (!locationHash.length) {
|
|
2719
|
+
return params;
|
|
2720
|
+
}
|
|
2721
|
+
if (locationHash.indexOf("=") < 0 && locationHash.indexOf("?") < 0) {
|
|
2722
|
+
params._path = urlSafeDecode(locationHash);
|
|
2723
|
+
return params;
|
|
2724
|
+
}
|
|
2725
|
+
let qIndex = locationHash.indexOf("?");
|
|
2726
|
+
if (qIndex >= 0) {
|
|
2727
|
+
let pathParam = locationHash.substr(0, qIndex);
|
|
2728
|
+
params._path = urlSafeDecode(pathParam);
|
|
2729
|
+
locationHash = locationHash.substr(qIndex + 1);
|
|
2730
|
+
}
|
|
2731
|
+
let query_params = urlParseQueryString(locationHash);
|
|
2732
|
+
for (let k in query_params) {
|
|
2733
|
+
params[k] = query_params[k];
|
|
2734
|
+
}
|
|
2735
|
+
return params;
|
|
2736
|
+
}
|
|
2737
|
+
function urlSafeDecode(urlencoded) {
|
|
2738
|
+
try {
|
|
2739
|
+
urlencoded = urlencoded.replace(/\+/g, "%20");
|
|
2740
|
+
return decodeURIComponent(urlencoded);
|
|
2741
|
+
} catch (e2) {
|
|
2742
|
+
return urlencoded;
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
function urlParseQueryString(queryString) {
|
|
2746
|
+
let params = {};
|
|
2747
|
+
if (!queryString.length) {
|
|
2748
|
+
return params;
|
|
2749
|
+
}
|
|
2750
|
+
let queryStringParams = queryString.split("&");
|
|
2751
|
+
let i2, param, paramName, paramValue;
|
|
2752
|
+
for (i2 = 0; i2 < queryStringParams.length; i2++) {
|
|
2753
|
+
param = queryStringParams[i2].split("=");
|
|
2754
|
+
paramName = urlSafeDecode(param[0]);
|
|
2755
|
+
paramValue = param[1] == null ? null : urlSafeDecode(param[1]);
|
|
2756
|
+
params[paramName] = paramValue;
|
|
2757
|
+
}
|
|
2758
|
+
return params;
|
|
2759
|
+
}
|
|
2760
|
+
function versionCompare(v1, v2) {
|
|
2761
|
+
if (typeof v1 !== "string")
|
|
2762
|
+
v1 = "";
|
|
2763
|
+
if (typeof v2 !== "string")
|
|
2764
|
+
v2 = "";
|
|
2765
|
+
let v1List = v1.replace(/^\s+|\s+$/g, "").split(".");
|
|
2766
|
+
let v2List = v2.replace(/^\s+|\s+$/g, "").split(".");
|
|
2767
|
+
let a2, i2, p1, p2;
|
|
2768
|
+
a2 = Math.max(v1List.length, v2List.length);
|
|
2769
|
+
for (i2 = 0; i2 < a2; i2++) {
|
|
2770
|
+
p1 = parseInt(v1List[i2]) || 0;
|
|
2771
|
+
p2 = parseInt(v2List[i2]) || 0;
|
|
2772
|
+
if (p1 === p2)
|
|
2773
|
+
continue;
|
|
2774
|
+
if (p1 > p2)
|
|
2775
|
+
return 1;
|
|
2776
|
+
return -1;
|
|
2777
|
+
}
|
|
2778
|
+
return 0;
|
|
2779
|
+
}
|
|
2780
|
+
function versionAtLeast(ver) {
|
|
2781
|
+
return versionCompare(webAppVersion, ver) >= 0;
|
|
2782
|
+
}
|
|
2838
2783
|
const maxWidth = {
|
|
2839
2784
|
mobile: 440,
|
|
2840
2785
|
tablet: 1020
|
|
@@ -8316,6 +8261,82 @@ const Translation = (props) => {
|
|
|
8316
8261
|
return t2(props.translationKey, props.translationValues, (_a2 = props.children) == null ? void 0 : _a2.toString());
|
|
8317
8262
|
});
|
|
8318
8263
|
};
|
|
8264
|
+
function addReturnStrategy(url, strategy) {
|
|
8265
|
+
let returnStrategy;
|
|
8266
|
+
if (typeof strategy === "string") {
|
|
8267
|
+
returnStrategy = strategy;
|
|
8268
|
+
} else {
|
|
8269
|
+
returnStrategy = isInTMA() ? strategy.twaReturnUrl || strategy.returnStrategy : "none";
|
|
8270
|
+
}
|
|
8271
|
+
const newUrl = addQueryParameter(url, "ret", returnStrategy);
|
|
8272
|
+
if (!sdk.isTelegramUrl(url)) {
|
|
8273
|
+
return newUrl;
|
|
8274
|
+
}
|
|
8275
|
+
const lastParam = newUrl.slice(newUrl.lastIndexOf("&") + 1);
|
|
8276
|
+
return newUrl.slice(0, newUrl.lastIndexOf("&")) + "-" + sdk.encodeTelegramUrlParameters(lastParam);
|
|
8277
|
+
}
|
|
8278
|
+
function redirectToTelegram(universalLink, options) {
|
|
8279
|
+
options = __spreadValues({}, options);
|
|
8280
|
+
const directLink = convertToTGDirectLink(universalLink);
|
|
8281
|
+
const directLinkUrl = new URL(directLink);
|
|
8282
|
+
if (!directLinkUrl.searchParams.has("startapp")) {
|
|
8283
|
+
directLinkUrl.searchParams.append("startapp", "tonconnect");
|
|
8284
|
+
}
|
|
8285
|
+
if (isInTMA()) {
|
|
8286
|
+
if (isTmaPlatform("ios", "android")) {
|
|
8287
|
+
options.returnStrategy = "back";
|
|
8288
|
+
options.twaReturnUrl = void 0;
|
|
8289
|
+
sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8290
|
+
} else if (isTmaPlatform("macos", "tdesktop")) {
|
|
8291
|
+
sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8292
|
+
} else if (isTmaPlatform("weba")) {
|
|
8293
|
+
sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8294
|
+
} else if (isTmaPlatform("web")) {
|
|
8295
|
+
options.returnStrategy = "back";
|
|
8296
|
+
options.twaReturnUrl = void 0;
|
|
8297
|
+
sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8298
|
+
} else {
|
|
8299
|
+
openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8300
|
+
}
|
|
8301
|
+
} else {
|
|
8302
|
+
if (isOS("ios", "android")) {
|
|
8303
|
+
options.returnStrategy = "none";
|
|
8304
|
+
openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options.returnStrategy));
|
|
8305
|
+
} else if (isOS("macos", "windows", "linux")) {
|
|
8306
|
+
options.returnStrategy = "none";
|
|
8307
|
+
options.twaReturnUrl = void 0;
|
|
8308
|
+
if (options.forceRedirect) {
|
|
8309
|
+
openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8310
|
+
} else {
|
|
8311
|
+
const link = addReturnStrategy(directLinkUrl.toString(), options);
|
|
8312
|
+
const deepLink = convertToTGDeepLink(link);
|
|
8313
|
+
openDeeplinkWithFallback(deepLink, () => openLinkBlank(link));
|
|
8314
|
+
}
|
|
8315
|
+
} else {
|
|
8316
|
+
openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8317
|
+
}
|
|
8318
|
+
}
|
|
8319
|
+
}
|
|
8320
|
+
function addQueryParameter(url, key, value) {
|
|
8321
|
+
const parsed = new URL(url);
|
|
8322
|
+
parsed.searchParams.append(key, value);
|
|
8323
|
+
return parsed.toString();
|
|
8324
|
+
}
|
|
8325
|
+
function convertToTGDirectLink(universalLink) {
|
|
8326
|
+
const url = new URL(universalLink);
|
|
8327
|
+
if (url.searchParams.has("attach")) {
|
|
8328
|
+
url.searchParams.delete("attach");
|
|
8329
|
+
url.pathname += "/start";
|
|
8330
|
+
}
|
|
8331
|
+
return url.toString();
|
|
8332
|
+
}
|
|
8333
|
+
function convertToTGDeepLink(directLink) {
|
|
8334
|
+
const parsed = new URL(directLink);
|
|
8335
|
+
const [, domain, appname] = parsed.pathname.split("/");
|
|
8336
|
+
const startapp = parsed.searchParams.get("startapp");
|
|
8337
|
+
return `tg://resolve?domain=${domain}&appname=${appname}&startapp=${startapp}`;
|
|
8338
|
+
}
|
|
8339
|
+
let openDesktopDeeplinkAttempts = 0;
|
|
8319
8340
|
const DesktopConnectionModal = (props) => {
|
|
8320
8341
|
const [mode, setMode] = createSignal("mobile");
|
|
8321
8342
|
const [connectionErrored, setConnectionErrored] = createSignal(false);
|
|
@@ -8356,10 +8377,25 @@ const DesktopConnectionModal = (props) => {
|
|
|
8356
8377
|
generateUniversalLink();
|
|
8357
8378
|
}
|
|
8358
8379
|
setMode("desktop");
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8380
|
+
const linkWithStrategy = addReturnStrategy(universalLink(), appState.returnStrategy);
|
|
8381
|
+
const haveTriedToOpenDeeplinkInSafari = isBrowser("safari") && openDesktopDeeplinkAttempts >= 1;
|
|
8382
|
+
if (props.wallet.deepLink && !haveTriedToOpenDeeplinkInSafari) {
|
|
8383
|
+
openDesktopDeeplinkAttempts++;
|
|
8384
|
+
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
8385
|
+
openMethod: "custom-deeplink"
|
|
8386
|
+
}));
|
|
8387
|
+
openDeeplinkWithFallback(toDeeplink(linkWithStrategy, props.wallet.deepLink), () => {
|
|
8388
|
+
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
8389
|
+
openMethod: "universal-link"
|
|
8390
|
+
}));
|
|
8391
|
+
openLinkBlank(linkWithStrategy);
|
|
8392
|
+
});
|
|
8393
|
+
} else {
|
|
8394
|
+
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
8395
|
+
openMethod: "universal-link"
|
|
8396
|
+
}));
|
|
8397
|
+
openLinkBlank(linkWithStrategy);
|
|
8398
|
+
}
|
|
8363
8399
|
};
|
|
8364
8400
|
const onClickTelegram = () => {
|
|
8365
8401
|
const forceRedirect = !firstClick();
|