@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/README.md +34 -0
- package/dist/tonconnect-ui.min.js +190 -190
- package/dist/tonconnect-ui.min.js.map +1 -1
- package/lib/index.cjs +532 -244
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +65 -1
- package/lib/index.mjs +533 -245
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -2
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,
|
|
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
|
|
1911
|
-
const
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
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
|
-
|
|
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
|
|
2059
|
-
|
|
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
|
|
1892
|
+
function toDeeplink(universalLink, deeplink) {
|
|
2101
1893
|
const url = new URL(universalLink);
|
|
2102
|
-
|
|
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() {
|
|
@@ -2169,6 +1951,20 @@ const [walletsModalState, setWalletsModalState] = createSignal({
|
|
|
2169
1951
|
closeReason: null
|
|
2170
1952
|
});
|
|
2171
1953
|
const getWalletsModalIsOpened = createMemo(() => walletsModalState().status === "opened");
|
|
1954
|
+
const [singleWalletModalState, setSingleWalletModalState] = createSignal({
|
|
1955
|
+
status: "closed",
|
|
1956
|
+
closeReason: null
|
|
1957
|
+
});
|
|
1958
|
+
const getSingleWalletModalIsOpened = createMemo(
|
|
1959
|
+
() => singleWalletModalState().status === "opened"
|
|
1960
|
+
);
|
|
1961
|
+
const getSingleWalletModalWalletInfo = createMemo(() => {
|
|
1962
|
+
const state = singleWalletModalState();
|
|
1963
|
+
if (state.status === "opened") {
|
|
1964
|
+
return state.walletInfo;
|
|
1965
|
+
}
|
|
1966
|
+
return null;
|
|
1967
|
+
});
|
|
2172
1968
|
let lastSelectedWalletInfoStorage = typeof window !== "undefined" ? new LastSelectedWalletInfoStorage() : void 0;
|
|
2173
1969
|
const [lastSelectedWalletInfo, _setLastSelectedWalletInfo] = createSignal((lastSelectedWalletInfoStorage == null ? void 0 : lastSelectedWalletInfoStorage.getLastSelectedWalletInfo()) || null);
|
|
2174
1970
|
const setLastSelectedWalletInfo = (walletInfo) => {
|
|
@@ -2830,6 +2626,169 @@ const Image = (props) => {
|
|
|
2830
2626
|
}
|
|
2831
2627
|
})];
|
|
2832
2628
|
};
|
|
2629
|
+
function logError(...args) {
|
|
2630
|
+
{
|
|
2631
|
+
try {
|
|
2632
|
+
console.error("[TON_CONNECT_UI]", ...args);
|
|
2633
|
+
} catch (e2) {
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
function logWarning(...args) {
|
|
2638
|
+
{
|
|
2639
|
+
try {
|
|
2640
|
+
console.warn("[TON_CONNECT_UI]", ...args);
|
|
2641
|
+
} catch (e2) {
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
let initParams = {};
|
|
2646
|
+
try {
|
|
2647
|
+
let locationHash = location.hash.toString();
|
|
2648
|
+
initParams = urlParseHashParams(locationHash);
|
|
2649
|
+
} catch (e2) {
|
|
2650
|
+
}
|
|
2651
|
+
let tmaPlatform = "unknown";
|
|
2652
|
+
if (initParams == null ? void 0 : initParams.tgWebAppPlatform) {
|
|
2653
|
+
tmaPlatform = (_a = initParams.tgWebAppPlatform) != null ? _a : "unknown";
|
|
2654
|
+
}
|
|
2655
|
+
if (tmaPlatform === "unknown") {
|
|
2656
|
+
const window2 = getWindow$1();
|
|
2657
|
+
tmaPlatform = (_d = (_c = (_b = window2 == null ? void 0 : window2.Telegram) == null ? void 0 : _b.WebApp) == null ? void 0 : _c.platform) != null ? _d : "unknown";
|
|
2658
|
+
}
|
|
2659
|
+
let webAppVersion = "6.0";
|
|
2660
|
+
if (initParams == null ? void 0 : initParams.tgWebAppVersion) {
|
|
2661
|
+
webAppVersion = initParams.tgWebAppVersion;
|
|
2662
|
+
}
|
|
2663
|
+
if (!webAppVersion) {
|
|
2664
|
+
const window2 = getWindow$1();
|
|
2665
|
+
webAppVersion = (_g = (_f = (_e = window2 == null ? void 0 : window2.Telegram) == null ? void 0 : _e.WebApp) == null ? void 0 : _f.version) != null ? _g : "6.0";
|
|
2666
|
+
}
|
|
2667
|
+
function isTmaPlatform(...platforms) {
|
|
2668
|
+
return platforms.includes(tmaPlatform);
|
|
2669
|
+
}
|
|
2670
|
+
function isInTMA() {
|
|
2671
|
+
var _a2;
|
|
2672
|
+
return tmaPlatform !== "unknown" || !!((_a2 = getWindow$1()) == null ? void 0 : _a2.TelegramWebviewProxy);
|
|
2673
|
+
}
|
|
2674
|
+
function sendExpand() {
|
|
2675
|
+
postEvent("web_app_expand", {});
|
|
2676
|
+
}
|
|
2677
|
+
function sendOpenTelegramLink(link) {
|
|
2678
|
+
const url = new URL(link);
|
|
2679
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
2680
|
+
throw new TonConnectUIError(`Url protocol is not supported: ${url}`);
|
|
2681
|
+
}
|
|
2682
|
+
if (url.hostname !== "t.me") {
|
|
2683
|
+
throw new TonConnectUIError(`Url host is not supported: ${url}`);
|
|
2684
|
+
}
|
|
2685
|
+
const pathFull = url.pathname + url.search;
|
|
2686
|
+
if (isIframe() || versionAtLeast("6.1")) {
|
|
2687
|
+
postEvent("web_app_open_tg_link", { path_full: pathFull });
|
|
2688
|
+
} else {
|
|
2689
|
+
openLinkBlank("https://t.me" + pathFull);
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
function isIframe() {
|
|
2693
|
+
try {
|
|
2694
|
+
const window2 = getWindow$1();
|
|
2695
|
+
if (!window2) {
|
|
2696
|
+
return false;
|
|
2697
|
+
}
|
|
2698
|
+
return window2.parent != null && window2 !== window2.parent;
|
|
2699
|
+
} catch (e2) {
|
|
2700
|
+
return false;
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
function postEvent(eventType, eventData) {
|
|
2704
|
+
try {
|
|
2705
|
+
const window2 = getWindow$1();
|
|
2706
|
+
if (!window2) {
|
|
2707
|
+
throw new TonConnectUIError(`Can't post event to parent window: window is not defined`);
|
|
2708
|
+
}
|
|
2709
|
+
if (window2.TelegramWebviewProxy !== void 0) {
|
|
2710
|
+
window2.TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
|
|
2711
|
+
} else if (window2.external && "notify" in window2.external) {
|
|
2712
|
+
window2.external.notify(JSON.stringify({ eventType, eventData }));
|
|
2713
|
+
} else if (isIframe()) {
|
|
2714
|
+
const trustedTarget = "*";
|
|
2715
|
+
const message = JSON.stringify({ eventType, eventData });
|
|
2716
|
+
window2.parent.postMessage(message, trustedTarget);
|
|
2717
|
+
} else {
|
|
2718
|
+
throw new TonConnectUIError(`Can't post event to TMA`);
|
|
2719
|
+
}
|
|
2720
|
+
} catch (e2) {
|
|
2721
|
+
logError(`Can't post event to parent window: ${e2}`);
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
function urlParseHashParams(locationHash) {
|
|
2725
|
+
locationHash = locationHash.replace(/^#/, "");
|
|
2726
|
+
let params = {};
|
|
2727
|
+
if (!locationHash.length) {
|
|
2728
|
+
return params;
|
|
2729
|
+
}
|
|
2730
|
+
if (locationHash.indexOf("=") < 0 && locationHash.indexOf("?") < 0) {
|
|
2731
|
+
params._path = urlSafeDecode(locationHash);
|
|
2732
|
+
return params;
|
|
2733
|
+
}
|
|
2734
|
+
let qIndex = locationHash.indexOf("?");
|
|
2735
|
+
if (qIndex >= 0) {
|
|
2736
|
+
let pathParam = locationHash.substr(0, qIndex);
|
|
2737
|
+
params._path = urlSafeDecode(pathParam);
|
|
2738
|
+
locationHash = locationHash.substr(qIndex + 1);
|
|
2739
|
+
}
|
|
2740
|
+
let query_params = urlParseQueryString(locationHash);
|
|
2741
|
+
for (let k in query_params) {
|
|
2742
|
+
params[k] = query_params[k];
|
|
2743
|
+
}
|
|
2744
|
+
return params;
|
|
2745
|
+
}
|
|
2746
|
+
function urlSafeDecode(urlencoded) {
|
|
2747
|
+
try {
|
|
2748
|
+
urlencoded = urlencoded.replace(/\+/g, "%20");
|
|
2749
|
+
return decodeURIComponent(urlencoded);
|
|
2750
|
+
} catch (e2) {
|
|
2751
|
+
return urlencoded;
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
function urlParseQueryString(queryString) {
|
|
2755
|
+
let params = {};
|
|
2756
|
+
if (!queryString.length) {
|
|
2757
|
+
return params;
|
|
2758
|
+
}
|
|
2759
|
+
let queryStringParams = queryString.split("&");
|
|
2760
|
+
let i2, param, paramName, paramValue;
|
|
2761
|
+
for (i2 = 0; i2 < queryStringParams.length; i2++) {
|
|
2762
|
+
param = queryStringParams[i2].split("=");
|
|
2763
|
+
paramName = urlSafeDecode(param[0]);
|
|
2764
|
+
paramValue = param[1] == null ? null : urlSafeDecode(param[1]);
|
|
2765
|
+
params[paramName] = paramValue;
|
|
2766
|
+
}
|
|
2767
|
+
return params;
|
|
2768
|
+
}
|
|
2769
|
+
function versionCompare(v1, v2) {
|
|
2770
|
+
if (typeof v1 !== "string")
|
|
2771
|
+
v1 = "";
|
|
2772
|
+
if (typeof v2 !== "string")
|
|
2773
|
+
v2 = "";
|
|
2774
|
+
let v1List = v1.replace(/^\s+|\s+$/g, "").split(".");
|
|
2775
|
+
let v2List = v2.replace(/^\s+|\s+$/g, "").split(".");
|
|
2776
|
+
let a2, i2, p1, p2;
|
|
2777
|
+
a2 = Math.max(v1List.length, v2List.length);
|
|
2778
|
+
for (i2 = 0; i2 < a2; i2++) {
|
|
2779
|
+
p1 = parseInt(v1List[i2]) || 0;
|
|
2780
|
+
p2 = parseInt(v2List[i2]) || 0;
|
|
2781
|
+
if (p1 === p2)
|
|
2782
|
+
continue;
|
|
2783
|
+
if (p1 > p2)
|
|
2784
|
+
return 1;
|
|
2785
|
+
return -1;
|
|
2786
|
+
}
|
|
2787
|
+
return 0;
|
|
2788
|
+
}
|
|
2789
|
+
function versionAtLeast(ver) {
|
|
2790
|
+
return versionCompare(webAppVersion, ver) >= 0;
|
|
2791
|
+
}
|
|
2833
2792
|
const maxWidth = {
|
|
2834
2793
|
mobile: 440,
|
|
2835
2794
|
tablet: 1020
|
|
@@ -8311,6 +8270,82 @@ const Translation = (props) => {
|
|
|
8311
8270
|
return t2(props.translationKey, props.translationValues, (_a2 = props.children) == null ? void 0 : _a2.toString());
|
|
8312
8271
|
});
|
|
8313
8272
|
};
|
|
8273
|
+
function addReturnStrategy(url, strategy) {
|
|
8274
|
+
let returnStrategy;
|
|
8275
|
+
if (typeof strategy === "string") {
|
|
8276
|
+
returnStrategy = strategy;
|
|
8277
|
+
} else {
|
|
8278
|
+
returnStrategy = isInTMA() ? strategy.twaReturnUrl || strategy.returnStrategy : "none";
|
|
8279
|
+
}
|
|
8280
|
+
const newUrl = addQueryParameter(url, "ret", returnStrategy);
|
|
8281
|
+
if (!isTelegramUrl(url)) {
|
|
8282
|
+
return newUrl;
|
|
8283
|
+
}
|
|
8284
|
+
const lastParam = newUrl.slice(newUrl.lastIndexOf("&") + 1);
|
|
8285
|
+
return newUrl.slice(0, newUrl.lastIndexOf("&")) + "-" + encodeTelegramUrlParameters(lastParam);
|
|
8286
|
+
}
|
|
8287
|
+
function redirectToTelegram(universalLink, options) {
|
|
8288
|
+
options = __spreadValues({}, options);
|
|
8289
|
+
const directLink = convertToTGDirectLink(universalLink);
|
|
8290
|
+
const directLinkUrl = new URL(directLink);
|
|
8291
|
+
if (!directLinkUrl.searchParams.has("startapp")) {
|
|
8292
|
+
directLinkUrl.searchParams.append("startapp", "tonconnect");
|
|
8293
|
+
}
|
|
8294
|
+
if (isInTMA()) {
|
|
8295
|
+
if (isTmaPlatform("ios", "android")) {
|
|
8296
|
+
options.returnStrategy = "back";
|
|
8297
|
+
options.twaReturnUrl = void 0;
|
|
8298
|
+
sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8299
|
+
} else if (isTmaPlatform("macos", "tdesktop")) {
|
|
8300
|
+
sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8301
|
+
} else if (isTmaPlatform("weba")) {
|
|
8302
|
+
sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8303
|
+
} else if (isTmaPlatform("web")) {
|
|
8304
|
+
options.returnStrategy = "back";
|
|
8305
|
+
options.twaReturnUrl = void 0;
|
|
8306
|
+
sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8307
|
+
} else {
|
|
8308
|
+
openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8309
|
+
}
|
|
8310
|
+
} else {
|
|
8311
|
+
if (isOS("ios", "android")) {
|
|
8312
|
+
options.returnStrategy = "none";
|
|
8313
|
+
openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options.returnStrategy));
|
|
8314
|
+
} else if (isOS("macos", "windows", "linux")) {
|
|
8315
|
+
options.returnStrategy = "none";
|
|
8316
|
+
options.twaReturnUrl = void 0;
|
|
8317
|
+
if (options.forceRedirect) {
|
|
8318
|
+
openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8319
|
+
} else {
|
|
8320
|
+
const link = addReturnStrategy(directLinkUrl.toString(), options);
|
|
8321
|
+
const deepLink = convertToTGDeepLink(link);
|
|
8322
|
+
openDeeplinkWithFallback(deepLink, () => openLinkBlank(link));
|
|
8323
|
+
}
|
|
8324
|
+
} else {
|
|
8325
|
+
openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
|
|
8326
|
+
}
|
|
8327
|
+
}
|
|
8328
|
+
}
|
|
8329
|
+
function addQueryParameter(url, key, value) {
|
|
8330
|
+
const parsed = new URL(url);
|
|
8331
|
+
parsed.searchParams.append(key, value);
|
|
8332
|
+
return parsed.toString();
|
|
8333
|
+
}
|
|
8334
|
+
function convertToTGDirectLink(universalLink) {
|
|
8335
|
+
const url = new URL(universalLink);
|
|
8336
|
+
if (url.searchParams.has("attach")) {
|
|
8337
|
+
url.searchParams.delete("attach");
|
|
8338
|
+
url.pathname += "/start";
|
|
8339
|
+
}
|
|
8340
|
+
return url.toString();
|
|
8341
|
+
}
|
|
8342
|
+
function convertToTGDeepLink(directLink) {
|
|
8343
|
+
const parsed = new URL(directLink);
|
|
8344
|
+
const [, domain, appname] = parsed.pathname.split("/");
|
|
8345
|
+
const startapp = parsed.searchParams.get("startapp");
|
|
8346
|
+
return `tg://resolve?domain=${domain}&appname=${appname}&startapp=${startapp}`;
|
|
8347
|
+
}
|
|
8348
|
+
let openDesktopDeeplinkAttempts = 0;
|
|
8314
8349
|
const DesktopConnectionModal = (props) => {
|
|
8315
8350
|
const [mode, setMode] = createSignal("mobile");
|
|
8316
8351
|
const [connectionErrored, setConnectionErrored] = createSignal(false);
|
|
@@ -8351,10 +8386,25 @@ const DesktopConnectionModal = (props) => {
|
|
|
8351
8386
|
generateUniversalLink();
|
|
8352
8387
|
}
|
|
8353
8388
|
setMode("desktop");
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8389
|
+
const linkWithStrategy = addReturnStrategy(universalLink(), appState.returnStrategy);
|
|
8390
|
+
const haveTriedToOpenDeeplinkInSafari = isBrowser("safari") && openDesktopDeeplinkAttempts >= 1;
|
|
8391
|
+
if (props.wallet.deepLink && !haveTriedToOpenDeeplinkInSafari) {
|
|
8392
|
+
openDesktopDeeplinkAttempts++;
|
|
8393
|
+
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
8394
|
+
openMethod: "custom-deeplink"
|
|
8395
|
+
}));
|
|
8396
|
+
openDeeplinkWithFallback(toDeeplink(linkWithStrategy, props.wallet.deepLink), () => {
|
|
8397
|
+
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
8398
|
+
openMethod: "universal-link"
|
|
8399
|
+
}));
|
|
8400
|
+
openLinkBlank(linkWithStrategy);
|
|
8401
|
+
});
|
|
8402
|
+
} else {
|
|
8403
|
+
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
8404
|
+
openMethod: "universal-link"
|
|
8405
|
+
}));
|
|
8406
|
+
openLinkBlank(linkWithStrategy);
|
|
8407
|
+
}
|
|
8358
8408
|
};
|
|
8359
8409
|
const onClickTelegram = () => {
|
|
8360
8410
|
const forceRedirect = !firstClick();
|
|
@@ -8388,9 +8438,16 @@ const DesktopConnectionModal = (props) => {
|
|
|
8388
8438
|
return createComponent(DesktopConnectionModalStyled, {
|
|
8389
8439
|
"data-tc-wallets-modal-connection-desktop": "true",
|
|
8390
8440
|
get children() {
|
|
8391
|
-
return [createComponent(
|
|
8392
|
-
|
|
8393
|
-
|
|
8441
|
+
return [createComponent(Show, {
|
|
8442
|
+
get when() {
|
|
8443
|
+
return !props.backDisabled;
|
|
8444
|
+
},
|
|
8445
|
+
get children() {
|
|
8446
|
+
return createComponent(StyledIconButton$2, {
|
|
8447
|
+
icon: "arrow",
|
|
8448
|
+
onClick: () => props.onBackClick()
|
|
8449
|
+
});
|
|
8450
|
+
}
|
|
8394
8451
|
}), createComponent(H1Styled$6, {
|
|
8395
8452
|
get children() {
|
|
8396
8453
|
return props.wallet.name;
|
|
@@ -8928,7 +8985,22 @@ const MobileConnectionModal = (props) => {
|
|
|
8928
8985
|
universalLink: props.wallet.universalLink,
|
|
8929
8986
|
bridgeUrl: props.wallet.bridgeUrl
|
|
8930
8987
|
}, props.additionalRequest));
|
|
8988
|
+
const onClickTelegram = () => {
|
|
8989
|
+
const alwaysForceRedirect = true;
|
|
8990
|
+
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
8991
|
+
openMethod: "universal-link"
|
|
8992
|
+
}));
|
|
8993
|
+
redirectToTelegram(universalLink(), {
|
|
8994
|
+
returnStrategy: appState.returnStrategy,
|
|
8995
|
+
twaReturnUrl: appState.twaReturnUrl,
|
|
8996
|
+
forceRedirect: alwaysForceRedirect
|
|
8997
|
+
});
|
|
8998
|
+
};
|
|
8931
8999
|
const onRetry = () => {
|
|
9000
|
+
const currentUniversalLink = universalLink();
|
|
9001
|
+
if (isTelegramUrl(currentUniversalLink)) {
|
|
9002
|
+
return onClickTelegram();
|
|
9003
|
+
}
|
|
8932
9004
|
setConnectionErrored(false);
|
|
8933
9005
|
setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
|
|
8934
9006
|
openMethod: "universal-link"
|
|
@@ -8960,9 +9032,16 @@ const MobileConnectionModal = (props) => {
|
|
|
8960
9032
|
return createComponent(MobileConnectionModalStyled, {
|
|
8961
9033
|
"data-tc-wallets-modal-connection-mobile": "true",
|
|
8962
9034
|
get children() {
|
|
8963
|
-
return [createComponent(
|
|
8964
|
-
|
|
8965
|
-
|
|
9035
|
+
return [createComponent(Show, {
|
|
9036
|
+
get when() {
|
|
9037
|
+
return !props.backDisabled || showQR();
|
|
9038
|
+
},
|
|
9039
|
+
get children() {
|
|
9040
|
+
return createComponent(StyledIconButton, {
|
|
9041
|
+
icon: "arrow",
|
|
9042
|
+
onClick: onBack
|
|
9043
|
+
});
|
|
9044
|
+
}
|
|
8966
9045
|
}), createComponent(Show, {
|
|
8967
9046
|
get when() {
|
|
8968
9047
|
return showQR();
|
|
@@ -9972,6 +10051,109 @@ const ActionsModal = () => {
|
|
|
9972
10051
|
}
|
|
9973
10052
|
});
|
|
9974
10053
|
};
|
|
10054
|
+
const SingleWalletModal = () => {
|
|
10055
|
+
const {
|
|
10056
|
+
locale
|
|
10057
|
+
} = useI18n()[1];
|
|
10058
|
+
createEffect(() => locale(appState.language));
|
|
10059
|
+
createEffect(() => {
|
|
10060
|
+
if (getSingleWalletModalIsOpened()) {
|
|
10061
|
+
updateIsMobile();
|
|
10062
|
+
}
|
|
10063
|
+
});
|
|
10064
|
+
const connector = useContext(ConnectorContext);
|
|
10065
|
+
const [infoTab, setInfoTab] = createSignal(false);
|
|
10066
|
+
const additionalRequestLoading = () => {
|
|
10067
|
+
var _a2;
|
|
10068
|
+
return ((_a2 = appState.connectRequestParameters) == null ? void 0 : _a2.state) === "loading";
|
|
10069
|
+
};
|
|
10070
|
+
const additionalRequest = createMemo(() => {
|
|
10071
|
+
var _a2;
|
|
10072
|
+
if (additionalRequestLoading()) {
|
|
10073
|
+
return void 0;
|
|
10074
|
+
}
|
|
10075
|
+
return (_a2 = appState.connectRequestParameters) == null ? void 0 : _a2.value;
|
|
10076
|
+
});
|
|
10077
|
+
const onClose = (closeReason) => {
|
|
10078
|
+
setSingleWalletModalState({
|
|
10079
|
+
status: "closed",
|
|
10080
|
+
closeReason
|
|
10081
|
+
});
|
|
10082
|
+
setInfoTab(false);
|
|
10083
|
+
};
|
|
10084
|
+
const unsubscribe = connector.onStatusChange((wallet) => {
|
|
10085
|
+
if (wallet) {
|
|
10086
|
+
onClose("wallet-selected");
|
|
10087
|
+
}
|
|
10088
|
+
});
|
|
10089
|
+
onCleanup(unsubscribe);
|
|
10090
|
+
return createComponent(StyledModal, {
|
|
10091
|
+
get opened() {
|
|
10092
|
+
return getSingleWalletModalIsOpened();
|
|
10093
|
+
},
|
|
10094
|
+
get enableAndroidBackHandler() {
|
|
10095
|
+
return appState.enableAndroidBackHandler;
|
|
10096
|
+
},
|
|
10097
|
+
onClose: () => onClose("action-cancelled"),
|
|
10098
|
+
onClickQuestion: () => setInfoTab((v) => !v),
|
|
10099
|
+
"data-tc-wallets-modal-container": "true",
|
|
10100
|
+
get children() {
|
|
10101
|
+
return [createComponent(Show, {
|
|
10102
|
+
get when() {
|
|
10103
|
+
return infoTab();
|
|
10104
|
+
},
|
|
10105
|
+
get children() {
|
|
10106
|
+
return createComponent(InfoModal, {
|
|
10107
|
+
onBackClick: () => setInfoTab(false)
|
|
10108
|
+
});
|
|
10109
|
+
}
|
|
10110
|
+
}), createComponent(Show, {
|
|
10111
|
+
get when() {
|
|
10112
|
+
return !infoTab();
|
|
10113
|
+
},
|
|
10114
|
+
get children() {
|
|
10115
|
+
return [createComponent(Show, {
|
|
10116
|
+
get when() {
|
|
10117
|
+
return additionalRequestLoading();
|
|
10118
|
+
},
|
|
10119
|
+
get children() {
|
|
10120
|
+
return [createComponent(H1Styled$8, {
|
|
10121
|
+
translationKey: "walletModal.loading",
|
|
10122
|
+
children: "Wallets list is loading"
|
|
10123
|
+
}), createComponent(LoaderContainerStyled, {
|
|
10124
|
+
get children() {
|
|
10125
|
+
return createComponent(LoaderIcon, {
|
|
10126
|
+
size: "m"
|
|
10127
|
+
});
|
|
10128
|
+
}
|
|
10129
|
+
})];
|
|
10130
|
+
}
|
|
10131
|
+
}), createComponent(Show, {
|
|
10132
|
+
get when() {
|
|
10133
|
+
return !additionalRequestLoading();
|
|
10134
|
+
},
|
|
10135
|
+
get children() {
|
|
10136
|
+
return createComponent(Dynamic, {
|
|
10137
|
+
get component() {
|
|
10138
|
+
return isMobile() ? MobileConnectionModal : DesktopConnectionModal;
|
|
10139
|
+
},
|
|
10140
|
+
get wallet() {
|
|
10141
|
+
return getSingleWalletModalWalletInfo();
|
|
10142
|
+
},
|
|
10143
|
+
get additionalRequest() {
|
|
10144
|
+
return additionalRequest();
|
|
10145
|
+
},
|
|
10146
|
+
onBackClick: () => {
|
|
10147
|
+
},
|
|
10148
|
+
backDisabled: true
|
|
10149
|
+
});
|
|
10150
|
+
}
|
|
10151
|
+
})];
|
|
10152
|
+
}
|
|
10153
|
+
})];
|
|
10154
|
+
}
|
|
10155
|
+
});
|
|
10156
|
+
};
|
|
9975
10157
|
const App = (props) => {
|
|
9976
10158
|
const translations = createI18nContext(i18nDictionary, appState.language);
|
|
9977
10159
|
defineStylesRoot();
|
|
@@ -10009,7 +10191,7 @@ const App = (props) => {
|
|
|
10009
10191
|
}), createComponent(Dynamic, {
|
|
10010
10192
|
component: globalStylesTag,
|
|
10011
10193
|
get children() {
|
|
10012
|
-
return [createComponent(WalletsModal, {}), createComponent(ActionsModal, {})];
|
|
10194
|
+
return [createComponent(WalletsModal, {}), createComponent(SingleWalletModal, {}), createComponent(ActionsModal, {})];
|
|
10013
10195
|
}
|
|
10014
10196
|
})];
|
|
10015
10197
|
}
|
|
@@ -10030,6 +10212,17 @@ const widgetController = {
|
|
|
10030
10212
|
status: "closed",
|
|
10031
10213
|
closeReason: reason
|
|
10032
10214
|
})),
|
|
10215
|
+
openSingleWalletModal: (walletInfo) => {
|
|
10216
|
+
void setTimeout(() => setSingleWalletModalState({
|
|
10217
|
+
status: "opened",
|
|
10218
|
+
closeReason: null,
|
|
10219
|
+
walletInfo
|
|
10220
|
+
}));
|
|
10221
|
+
},
|
|
10222
|
+
closeSingleWalletModal: (reason) => void setTimeout(() => setSingleWalletModalState({
|
|
10223
|
+
status: "closed",
|
|
10224
|
+
closeReason: reason
|
|
10225
|
+
})),
|
|
10033
10226
|
setAction: (action2) => void setTimeout(() => setAction(action2)),
|
|
10034
10227
|
clearAction: () => void setTimeout(() => setAction(null)),
|
|
10035
10228
|
getSelectedWalletInfo: () => lastSelectedWalletInfo(),
|
|
@@ -10059,7 +10252,7 @@ class WalletsModalManager {
|
|
|
10059
10252
|
if (embeddedWallet) {
|
|
10060
10253
|
return this.connectEmbeddedWallet(embeddedWallet);
|
|
10061
10254
|
} else {
|
|
10062
|
-
return this.
|
|
10255
|
+
return this.openWalletsModal();
|
|
10063
10256
|
}
|
|
10064
10257
|
});
|
|
10065
10258
|
}
|
|
@@ -10084,7 +10277,7 @@ class WalletsModalManager {
|
|
|
10084
10277
|
connect(additionalRequest == null ? void 0 : additionalRequest.value);
|
|
10085
10278
|
}
|
|
10086
10279
|
}
|
|
10087
|
-
|
|
10280
|
+
openWalletsModal() {
|
|
10088
10281
|
return __async(this, null, function* () {
|
|
10089
10282
|
if (isInTMA()) {
|
|
10090
10283
|
sendExpand();
|
|
@@ -10119,6 +10312,80 @@ class TransactionModalManager {
|
|
|
10119
10312
|
};
|
|
10120
10313
|
}
|
|
10121
10314
|
}
|
|
10315
|
+
class SingleWalletModalManager {
|
|
10316
|
+
constructor(options) {
|
|
10317
|
+
__publicField(this, "connector");
|
|
10318
|
+
__publicField(this, "setConnectRequestParametersCallback");
|
|
10319
|
+
__publicField(this, "consumers", []);
|
|
10320
|
+
__publicField(this, "state", singleWalletModalState());
|
|
10321
|
+
this.connector = options.connector;
|
|
10322
|
+
this.setConnectRequestParametersCallback = options.setConnectRequestParametersCallback;
|
|
10323
|
+
createEffect(() => {
|
|
10324
|
+
const state = singleWalletModalState();
|
|
10325
|
+
this.state = state;
|
|
10326
|
+
this.consumers.forEach((consumer) => consumer(state));
|
|
10327
|
+
});
|
|
10328
|
+
}
|
|
10329
|
+
open(wallet) {
|
|
10330
|
+
return __async(this, null, function* () {
|
|
10331
|
+
const fetchedWalletsList = yield this.connector.getWallets();
|
|
10332
|
+
const walletsList = applyWalletsListConfiguration(
|
|
10333
|
+
fetchedWalletsList,
|
|
10334
|
+
appState.walletsListConfiguration
|
|
10335
|
+
);
|
|
10336
|
+
const embeddedWallet = walletsList.find(isWalletInfoCurrentlyEmbedded);
|
|
10337
|
+
const isEmbeddedWalletExist = !!embeddedWallet;
|
|
10338
|
+
if (isEmbeddedWalletExist) {
|
|
10339
|
+
return this.connectEmbeddedWallet(embeddedWallet);
|
|
10340
|
+
}
|
|
10341
|
+
const externalWallets = walletsList.filter(isWalletInfoRemote);
|
|
10342
|
+
const externalWallet = externalWallets.find((walletInfo) => eqWalletName(walletInfo, wallet));
|
|
10343
|
+
const isExternalWalletExist = !!externalWallet;
|
|
10344
|
+
if (isExternalWalletExist) {
|
|
10345
|
+
return this.openSingleWalletModal(externalWallet);
|
|
10346
|
+
}
|
|
10347
|
+
throw new TonConnectUIError(`Trying to open modal window with unknown wallet "${wallet}".`);
|
|
10348
|
+
});
|
|
10349
|
+
}
|
|
10350
|
+
close() {
|
|
10351
|
+
widgetController.closeSingleWalletModal("action-cancelled");
|
|
10352
|
+
}
|
|
10353
|
+
onStateChange(onChange) {
|
|
10354
|
+
this.consumers.push(onChange);
|
|
10355
|
+
return () => {
|
|
10356
|
+
this.consumers = this.consumers.filter((consumer) => consumer !== onChange);
|
|
10357
|
+
};
|
|
10358
|
+
}
|
|
10359
|
+
connectEmbeddedWallet(embeddedWallet) {
|
|
10360
|
+
const connect = (parameters) => {
|
|
10361
|
+
setLastSelectedWalletInfo(embeddedWallet);
|
|
10362
|
+
this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey }, parameters);
|
|
10363
|
+
};
|
|
10364
|
+
const additionalRequest = appState.connectRequestParameters;
|
|
10365
|
+
if ((additionalRequest == null ? void 0 : additionalRequest.state) === "loading") {
|
|
10366
|
+
this.setConnectRequestParametersCallback(connect);
|
|
10367
|
+
} else {
|
|
10368
|
+
connect(additionalRequest == null ? void 0 : additionalRequest.value);
|
|
10369
|
+
}
|
|
10370
|
+
}
|
|
10371
|
+
openSingleWalletModal(wallet) {
|
|
10372
|
+
return __async(this, null, function* () {
|
|
10373
|
+
if (isInTMA()) {
|
|
10374
|
+
sendExpand();
|
|
10375
|
+
}
|
|
10376
|
+
widgetController.openSingleWalletModal(wallet);
|
|
10377
|
+
return new Promise((resolve) => {
|
|
10378
|
+
const unsubscribe = this.onStateChange((state) => {
|
|
10379
|
+
const { status } = state;
|
|
10380
|
+
if (status === "opened") {
|
|
10381
|
+
unsubscribe();
|
|
10382
|
+
resolve();
|
|
10383
|
+
}
|
|
10384
|
+
});
|
|
10385
|
+
});
|
|
10386
|
+
});
|
|
10387
|
+
}
|
|
10388
|
+
}
|
|
10122
10389
|
class TonConnectUI {
|
|
10123
10390
|
constructor(options) {
|
|
10124
10391
|
__publicField(this, "walletInfoStorage", new WalletInfoStorage());
|
|
@@ -10130,6 +10397,7 @@ class TonConnectUI {
|
|
|
10130
10397
|
__publicField(this, "connectRequestParametersCallback");
|
|
10131
10398
|
__publicField(this, "connector");
|
|
10132
10399
|
__publicField(this, "modal");
|
|
10400
|
+
__publicField(this, "singleWalletModal");
|
|
10133
10401
|
__publicField(this, "transactionModal");
|
|
10134
10402
|
__publicField(this, "connectionRestored", Promise.resolve(false));
|
|
10135
10403
|
if (options && "connector" in options && options.connector) {
|
|
@@ -10147,6 +10415,12 @@ class TonConnectUI {
|
|
|
10147
10415
|
this.connectRequestParametersCallback = callback;
|
|
10148
10416
|
}
|
|
10149
10417
|
});
|
|
10418
|
+
this.singleWalletModal = new SingleWalletModalManager({
|
|
10419
|
+
connector: this.connector,
|
|
10420
|
+
setConnectRequestParametersCallback: (callback) => {
|
|
10421
|
+
this.connectRequestParametersCallback = callback;
|
|
10422
|
+
}
|
|
10423
|
+
});
|
|
10150
10424
|
this.transactionModal = new TransactionModalManager({
|
|
10151
10425
|
connector: this.connector
|
|
10152
10426
|
});
|
|
@@ -10265,6 +10539,20 @@ class TonConnectUI {
|
|
|
10265
10539
|
get modalState() {
|
|
10266
10540
|
return this.modal.state;
|
|
10267
10541
|
}
|
|
10542
|
+
openSingleWalletModal(wallet) {
|
|
10543
|
+
return __async(this, null, function* () {
|
|
10544
|
+
return this.singleWalletModal.open(wallet);
|
|
10545
|
+
});
|
|
10546
|
+
}
|
|
10547
|
+
closeSingleWalletModal() {
|
|
10548
|
+
this.singleWalletModal.close();
|
|
10549
|
+
}
|
|
10550
|
+
onSingleWalletModalStateChange(onChange) {
|
|
10551
|
+
return this.singleWalletModal.onStateChange(onChange);
|
|
10552
|
+
}
|
|
10553
|
+
get singleWalletModalState() {
|
|
10554
|
+
return this.singleWalletModal.state;
|
|
10555
|
+
}
|
|
10268
10556
|
connectWallet() {
|
|
10269
10557
|
return __async(this, null, function* () {
|
|
10270
10558
|
const walletsList = yield this.getWallets();
|