@tonconnect/ui 2.0.0-beta.1 → 2.0.0-beta.10

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.
@@ -41,8 +41,8 @@ var __async = (__this, __arguments, generator) => {
41
41
  step((generator = generator.apply(__this, __arguments)).next());
42
42
  });
43
43
  };
44
- var _a;
45
- import { TonConnectError, isTelegramUrl, encodeTelegramUrlParameters, isWalletInfoCurrentlyInjected, toUserFriendlyAddress, CHAIN, TonConnect, isWalletInfoRemote, isWalletInfoCurrentlyEmbedded } from "@tonconnect/sdk";
44
+ var _a, _b, _c, _d, _e, _f, _g, _h;
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";
@@ -1706,6 +1706,43 @@ function rgba(color, opacity) {
1706
1706
  function toPx(value) {
1707
1707
  return value.toString() + "px";
1708
1708
  }
1709
+ const _InMemoryStorage = class {
1710
+ constructor() {
1711
+ __publicField(this, "storage", {});
1712
+ }
1713
+ static getInstance() {
1714
+ if (!_InMemoryStorage.instance) {
1715
+ _InMemoryStorage.instance = new _InMemoryStorage();
1716
+ }
1717
+ return _InMemoryStorage.instance;
1718
+ }
1719
+ get length() {
1720
+ return Object.keys(this.storage).length;
1721
+ }
1722
+ clear() {
1723
+ this.storage = {};
1724
+ }
1725
+ getItem(key) {
1726
+ var _a2;
1727
+ return (_a2 = this.storage[key]) != null ? _a2 : null;
1728
+ }
1729
+ key(index) {
1730
+ var _a2;
1731
+ const keys = Object.keys(this.storage);
1732
+ if (index < 0 || index >= keys.length) {
1733
+ return null;
1734
+ }
1735
+ return (_a2 = keys[index]) != null ? _a2 : null;
1736
+ }
1737
+ removeItem(key) {
1738
+ delete this.storage[key];
1739
+ }
1740
+ setItem(key, value) {
1741
+ this.storage[key] = value;
1742
+ }
1743
+ };
1744
+ let InMemoryStorage = _InMemoryStorage;
1745
+ __publicField(InMemoryStorage, "instance");
1709
1746
  class TonConnectUIError extends TonConnectError {
1710
1747
  constructor(...args) {
1711
1748
  super(...args);
@@ -1713,11 +1750,22 @@ class TonConnectUIError extends TonConnectError {
1713
1750
  }
1714
1751
  }
1715
1752
  function openLink(href, target = "_self") {
1716
- return window.open(href, target, "noreferrer noopener");
1753
+ window.open(href, target, "noopener noreferrer");
1717
1754
  }
1718
1755
  function openLinkBlank(href) {
1719
1756
  openLink(href, "_blank");
1720
1757
  }
1758
+ function openDeeplinkWithFallback(href, fallback) {
1759
+ const doFallback = () => {
1760
+ if (isBrowser("safari")) {
1761
+ return;
1762
+ }
1763
+ fallback();
1764
+ };
1765
+ const fallbackTimeout = setTimeout(() => doFallback(), 200);
1766
+ window.addEventListener("blur", () => clearTimeout(fallbackTimeout), { once: true });
1767
+ openLink(href, "_self");
1768
+ }
1721
1769
  function getSystemTheme() {
1722
1770
  if (window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches) {
1723
1771
  return THEME.LIGHT;
@@ -1729,25 +1777,6 @@ function subscribeToThemeChange(callback) {
1729
1777
  window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", handler);
1730
1778
  return () => window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", handler);
1731
1779
  }
1732
- function addQueryParameter(url, key, value) {
1733
- const parsed = new URL(url);
1734
- parsed.searchParams.append(key, value);
1735
- return parsed.toString();
1736
- }
1737
- function addReturnStrategy(url, strategy) {
1738
- let returnStrategy;
1739
- if (typeof strategy === "string") {
1740
- returnStrategy = strategy;
1741
- } else {
1742
- returnStrategy = isInTWA() ? strategy.twaReturnUrl || strategy.returnStrategy : "none";
1743
- }
1744
- const newUrl = addQueryParameter(url, "ret", returnStrategy);
1745
- if (!isTelegramUrl(url)) {
1746
- return newUrl;
1747
- }
1748
- const lastParam = newUrl.slice(newUrl.lastIndexOf("&") + 1);
1749
- return newUrl.slice(0, newUrl.lastIndexOf("&")) + "-" + encodeTelegramUrlParameters(lastParam);
1750
- }
1751
1780
  function disableScroll() {
1752
1781
  if (document.documentElement.scrollHeight === document.documentElement.clientHeight) {
1753
1782
  return;
@@ -1766,22 +1795,25 @@ function fixMobileSafariActiveTransition() {
1766
1795
  }
1767
1796
  }
1768
1797
  function defineStylesRoot() {
1769
- customElements.define(globalStylesTag, class TcRootElement extends HTMLDivElement {
1770
- }, {
1771
- extends: "div"
1798
+ customElements.define(globalStylesTag, class TcRootElement extends HTMLElement {
1772
1799
  });
1773
1800
  }
1774
- function preloadImages(images) {
1775
- images.forEach((img) => {
1776
- const node = new window.Image();
1777
- node.src = img;
1801
+ function createMacrotask(callback) {
1802
+ return __async(this, null, function* () {
1803
+ yield new Promise((resolve) => requestAnimationFrame(resolve));
1804
+ callback();
1778
1805
  });
1779
1806
  }
1780
- function checkLocalStorageExists() {
1781
- if (typeof localStorage === "undefined") {
1782
- throw new TonConnectUIError(
1783
- "window.localStorage is undefined. localStorage is required for TonConnectUI"
1784
- );
1807
+ function preloadImages(images) {
1808
+ if (document.readyState !== "complete") {
1809
+ window.addEventListener("load", () => createMacrotask(() => preloadImages(images)), {
1810
+ once: true
1811
+ });
1812
+ } else {
1813
+ images.forEach((img) => {
1814
+ const node = new window.Image();
1815
+ node.src = img;
1816
+ });
1785
1817
  }
1786
1818
  }
1787
1819
  function getWindow$1() {
@@ -1790,8 +1822,29 @@ function getWindow$1() {
1790
1822
  }
1791
1823
  return void 0;
1792
1824
  }
1825
+ function tryGetLocalStorage() {
1826
+ if (isLocalStorageAvailable()) {
1827
+ return localStorage;
1828
+ }
1829
+ if (isNodeJs()) {
1830
+ throw new TonConnectUIError(
1831
+ "`localStorage` is unavailable, but it is required for TonConnect. For more details, see https://github.com/ton-connect/sdk/tree/main/packages/sdk#init-connector"
1832
+ );
1833
+ }
1834
+ return InMemoryStorage.getInstance();
1835
+ }
1836
+ function isLocalStorageAvailable() {
1837
+ try {
1838
+ return typeof localStorage !== "undefined";
1839
+ } catch (e2) {
1840
+ return false;
1841
+ }
1842
+ }
1843
+ function isNodeJs() {
1844
+ return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1845
+ }
1793
1846
  function getUserAgent() {
1794
- var _a2, _b;
1847
+ var _a2, _b2;
1795
1848
  const results = new UAParser().getResult();
1796
1849
  const osName = (_a2 = results.os.name) == null ? void 0 : _a2.toLowerCase();
1797
1850
  let os;
@@ -1812,7 +1865,7 @@ function getUserAgent() {
1812
1865
  os = "windows";
1813
1866
  break;
1814
1867
  }
1815
- const browserName = (_b = results.browser.name) == null ? void 0 : _b.toLowerCase();
1868
+ const browserName = (_b2 = results.browser.name) == null ? void 0 : _b2.toLowerCase();
1816
1869
  let browser;
1817
1870
  switch (true) {
1818
1871
  case browserName === "chrome":
@@ -1830,21 +1883,21 @@ function getUserAgent() {
1830
1883
  browser
1831
1884
  };
1832
1885
  }
1833
- function redirectToTelegram(universalLink, options) {
1834
- const url = new URL(universalLink);
1835
- url.searchParams.append("startattach", "tonconnect");
1836
- openLinkBlank(addReturnStrategy(url.toString(), options));
1886
+ function isOS(...os) {
1887
+ return os.includes(getUserAgent().os);
1837
1888
  }
1838
- function isInTWA() {
1839
- var _a2;
1840
- return !!((_a2 = getWindow$1()) == null ? void 0 : _a2.TelegramWebviewProxy);
1889
+ function isBrowser(...browser) {
1890
+ return browser.includes(getUserAgent().browser);
1891
+ }
1892
+ function toDeeplink(universalLink, deeplink) {
1893
+ const url = new URL(universalLink);
1894
+ return deeplink + url.search;
1841
1895
  }
1842
1896
  class WalletInfoStorage {
1843
1897
  constructor() {
1844
1898
  __publicField(this, "localStorage");
1845
1899
  __publicField(this, "storageKey", "ton-connect-ui_wallet-info");
1846
- checkLocalStorageExists();
1847
- this.localStorage = localStorage;
1900
+ this.localStorage = tryGetLocalStorage();
1848
1901
  }
1849
1902
  setWalletInfo(walletInfo) {
1850
1903
  this.localStorage.setItem(this.storageKey, JSON.stringify(walletInfo));
@@ -1864,8 +1917,7 @@ class PreferredWalletStorage {
1864
1917
  constructor() {
1865
1918
  __publicField(this, "localStorage");
1866
1919
  __publicField(this, "storageKey", "ton-connect-ui_preferred-wallet");
1867
- checkLocalStorageExists();
1868
- this.localStorage = localStorage;
1920
+ this.localStorage = tryGetLocalStorage();
1869
1921
  }
1870
1922
  setPreferredWalletAppName(name) {
1871
1923
  this.localStorage.setItem(this.storageKey, name);
@@ -1878,8 +1930,7 @@ class LastSelectedWalletInfoStorage {
1878
1930
  constructor() {
1879
1931
  __publicField(this, "localStorage");
1880
1932
  __publicField(this, "storageKey", "ton-connect-ui_last-selected-wallet-info");
1881
- checkLocalStorageExists();
1882
- this.localStorage = localStorage;
1933
+ this.localStorage = tryGetLocalStorage();
1883
1934
  }
1884
1935
  setLastSelectedWalletInfo(walletInfo) {
1885
1936
  this.localStorage.setItem(this.storageKey, JSON.stringify(walletInfo));
@@ -1895,10 +1946,17 @@ class LastSelectedWalletInfoStorage {
1895
1946
  this.localStorage.removeItem(this.storageKey);
1896
1947
  }
1897
1948
  }
1898
- const [walletsModalOpen, setWalletsModalOpen] = createSignal(false);
1899
- const lastSelectedWalletInfoStorage = new LastSelectedWalletInfoStorage();
1900
- const [lastSelectedWalletInfo, _setLastSelectedWalletInfo] = createSignal(lastSelectedWalletInfoStorage.getLastSelectedWalletInfo());
1949
+ const [walletsModalState, setWalletsModalState] = createSignal({
1950
+ status: "closed",
1951
+ closeReason: null
1952
+ });
1953
+ const getWalletsModalIsOpened = createMemo(() => walletsModalState().status === "opened");
1954
+ let lastSelectedWalletInfoStorage = typeof window !== "undefined" ? new LastSelectedWalletInfoStorage() : void 0;
1955
+ const [lastSelectedWalletInfo, _setLastSelectedWalletInfo] = createSignal((lastSelectedWalletInfoStorage == null ? void 0 : lastSelectedWalletInfoStorage.getLastSelectedWalletInfo()) || null);
1901
1956
  const setLastSelectedWalletInfo = (walletInfo) => {
1957
+ if (!lastSelectedWalletInfoStorage) {
1958
+ lastSelectedWalletInfoStorage = new LastSelectedWalletInfoStorage();
1959
+ }
1902
1960
  if (walletInfo) {
1903
1961
  lastSelectedWalletInfoStorage.setLastSelectedWalletInfo(walletInfo);
1904
1962
  } else {
@@ -1952,8 +2010,8 @@ const walletModal$1 = {
1952
2010
  wallets: "Wallets",
1953
2011
  mobileUniversalModal: {
1954
2012
  connectYourWallet: "Connect your wallet",
1955
- openWalletOnTelegramOrSelect: "Open Wallet on Telegram or\xA0select your\xA0wallet\xA0to\xA0connect",
1956
- openWalletOnTelegram: "Open Wallet on Telegram",
2013
+ openWalletOnTelegramOrSelect: "Open Wallet in Telegram or select your wallet to connect",
2014
+ openWalletOnTelegram: "Open Wallet in Telegram",
1957
2015
  openLink: "Open Link",
1958
2016
  scan: "Scan with your mobile wallet"
1959
2017
  },
@@ -1974,7 +2032,7 @@ const walletModal$1 = {
1974
2032
  dontHaveExtension: "Seems you don't have installed {{ name }}\xA0browser\xA0extension",
1975
2033
  getWallet: "Get {{ name }}",
1976
2034
  continueOnDesktop: "Continue in\xA0{{ name }} on desktop\u2026",
1977
- openWalletOnTelegram: "Open Wallet on Telegram on desktop",
2035
+ openWalletOnTelegram: "Open Wallet in Telegram on desktop",
1978
2036
  connectionDeclined: "Connection declined"
1979
2037
  },
1980
2038
  infoModal: {
@@ -2554,6 +2612,169 @@ const Image = (props) => {
2554
2612
  }
2555
2613
  })];
2556
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
+ }
2557
2778
  const maxWidth = {
2558
2779
  mobile: 440,
2559
2780
  tablet: 1020
@@ -2563,6 +2784,9 @@ function isDevice(device) {
2563
2784
  if (!window2) {
2564
2785
  return device === "desktop";
2565
2786
  }
2787
+ if (isTmaPlatform("weba")) {
2788
+ return true;
2789
+ }
2566
2790
  const width = window2.innerWidth;
2567
2791
  switch (device) {
2568
2792
  case "desktop":
@@ -2985,15 +3209,49 @@ function clickOutside$1(el, accessor) {
2985
3209
  }
2986
3210
  function escPressed(_, accessor) {
2987
3211
  const onKeyPress = (e2) => {
2988
- var _a2, _b;
3212
+ var _a2, _b2;
2989
3213
  if (e2.key === "Escape") {
2990
3214
  (_a2 = document.activeElement) == null ? void 0 : _a2.blur();
2991
- (_b = accessor()) == null ? void 0 : _b();
3215
+ (_b2 = accessor()) == null ? void 0 : _b2();
2992
3216
  }
2993
3217
  };
2994
3218
  document.body.addEventListener("keydown", onKeyPress);
2995
3219
  onCleanup(() => document.body.removeEventListener("keydown", onKeyPress));
2996
3220
  }
3221
+ function androidBackHandler$1(_, config) {
3222
+ const {
3223
+ isEnabled,
3224
+ onClose
3225
+ } = config();
3226
+ if (!isEnabled) {
3227
+ return;
3228
+ }
3229
+ const userOSIsAndroid = getUserAgent().os === "android";
3230
+ if (!userOSIsAndroid) {
3231
+ return;
3232
+ }
3233
+ window.history.pushState(ROUTE_STATE, "");
3234
+ const popstateHandler = (event) => {
3235
+ event.preventDefault();
3236
+ onClose();
3237
+ };
3238
+ window.addEventListener("popstate", popstateHandler, {
3239
+ once: true
3240
+ });
3241
+ onCleanup(() => {
3242
+ window.removeEventListener("popstate", popstateHandler);
3243
+ createMacrotask(() => {
3244
+ var _a2;
3245
+ if (((_a2 = window.history.state) == null ? void 0 : _a2[ROUTE_STATE_KEY]) === true) {
3246
+ window.history.back();
3247
+ }
3248
+ });
3249
+ });
3250
+ }
3251
+ const ROUTE_STATE_KEY = "androidBackHandler";
3252
+ const ROUTE_STATE = {
3253
+ [ROUTE_STATE_KEY]: true
3254
+ };
2997
3255
  const _tmpl$$v = /* @__PURE__ */ template$1(`<svg><path fill-rule="evenodd" clip-rule="evenodd" d="M10.2122 14.3407C10.5384 14.0854 10.5959 13.614 10.3406 13.2878L6.20237 8.00003L10.3406 2.71227C10.5959 2.38607 10.5384 1.91469 10.2122 1.6594C9.88604 1.40412 9.41465 1.46161 9.15937 1.7878L4.65937 7.5378C4.44688 7.80932 4.44688 8.19074 4.65937 8.46226L9.15937 14.2123C9.41465 14.5385 9.88604 14.5959 10.2122 14.3407Z"></path></svg>`, 4, true);
2998
3256
  const rotationDegrees = {
2999
3257
  left: 0,
@@ -3201,9 +3459,73 @@ const ModalFooterStyled = styled.div`
3201
3459
  const QuestionButtonStyled = styled(IconButton)`
3202
3460
  background-color: ${(props) => rgba(props.theme.colors.icon.secondary, 0.12)};
3203
3461
  `;
3462
+ class AnimationTimelineNoop {
3463
+ constructor() {
3464
+ __publicField(this, "currentTime", 0);
3465
+ }
3466
+ }
3467
+ const _AnimationNoop = class {
3468
+ constructor() {
3469
+ __publicField(this, "currentTime", 0);
3470
+ __publicField(this, "playbackRate", 1);
3471
+ __publicField(this, "startTime", null);
3472
+ __publicField(this, "timeline", new AnimationTimelineNoop());
3473
+ __publicField(this, "finished", Promise.resolve(this));
3474
+ __publicField(this, "effect", null);
3475
+ __publicField(this, "id", "");
3476
+ __publicField(this, "pending", false);
3477
+ __publicField(this, "playState", "finished");
3478
+ __publicField(this, "replaceState", "active");
3479
+ __publicField(this, "ready", Promise.resolve(this));
3480
+ __publicField(this, "oncancel", null);
3481
+ __publicField(this, "onfinish", null);
3482
+ __publicField(this, "onremove", null);
3483
+ }
3484
+ static create() {
3485
+ if (!_AnimationNoop._instance) {
3486
+ logWarning(
3487
+ "Animation is not supported in this environment: please consider using the `web-animations-js` polyfill to provide a fallback implementation of the Web Animations API."
3488
+ );
3489
+ _AnimationNoop._instance = new _AnimationNoop();
3490
+ }
3491
+ return _AnimationNoop._instance;
3492
+ }
3493
+ cancel() {
3494
+ }
3495
+ finish() {
3496
+ }
3497
+ pause() {
3498
+ }
3499
+ play() {
3500
+ }
3501
+ reverse() {
3502
+ }
3503
+ addEventListener(_type, _listener, _options) {
3504
+ }
3505
+ dispatchEvent(_event) {
3506
+ return false;
3507
+ }
3508
+ removeEventListener(_type, _callback, _options) {
3509
+ }
3510
+ updatePlaybackRate(_playbackRate) {
3511
+ }
3512
+ commitStyles() {
3513
+ }
3514
+ persist() {
3515
+ }
3516
+ };
3517
+ let AnimationNoop = _AnimationNoop;
3518
+ __publicField(AnimationNoop, "_instance", null);
3519
+ function animate(element, keyframes, options) {
3520
+ if ("animate" in element) {
3521
+ return element.animate(keyframes, options);
3522
+ }
3523
+ return AnimationNoop.create();
3524
+ }
3204
3525
  const _tmpl$$t = /* @__PURE__ */ template$1(`<div></div>`);
3205
3526
  const clickOutside = clickOutside$1;
3206
3527
  const keyPressed = escPressed;
3528
+ const androidBackHandler = androidBackHandler$1;
3207
3529
  const Modal = (props) => {
3208
3530
  const theme = useTheme();
3209
3531
  const dataAttrs = useDataAttributes(props);
@@ -3217,7 +3539,7 @@ const Modal = (props) => {
3217
3539
  return createComponent(Transition, {
3218
3540
  onBeforeEnter: (el) => {
3219
3541
  const duration = isDevice("mobile") ? 200 : 100;
3220
- el.animate([{
3542
+ animate(el, [{
3221
3543
  opacity: 0
3222
3544
  }, {
3223
3545
  opacity: 1
@@ -3225,7 +3547,7 @@ const Modal = (props) => {
3225
3547
  duration
3226
3548
  });
3227
3549
  if (isDevice("mobile")) {
3228
- el.firstElementChild.animate([{
3550
+ animate(el.firstElementChild, [{
3229
3551
  transform: "translateY(390px)"
3230
3552
  }, {
3231
3553
  transform: "translateY(0)"
@@ -3236,7 +3558,7 @@ const Modal = (props) => {
3236
3558
  },
3237
3559
  onExit: (el, done) => {
3238
3560
  const duration = isDevice("mobile") ? 200 : 100;
3239
- const backgroundAnimation = el.animate([{
3561
+ const backgroundAnimation = animate(el, [{
3240
3562
  opacity: 1
3241
3563
  }, {
3242
3564
  opacity: 0
@@ -3244,7 +3566,7 @@ const Modal = (props) => {
3244
3566
  duration
3245
3567
  });
3246
3568
  if (isDevice("mobile")) {
3247
- const contentAnimation = el.firstElementChild.animate([{
3569
+ const contentAnimation = animate(el.firstElementChild, [{
3248
3570
  transform: "translateY(0)"
3249
3571
  }, {
3250
3572
  transform: "translateY(390px)"
@@ -3267,6 +3589,10 @@ const Modal = (props) => {
3267
3589
  }, dataAttrs, {
3268
3590
  get children() {
3269
3591
  const _el$ = _tmpl$$t.cloneNode(true);
3592
+ use(androidBackHandler, _el$, () => ({
3593
+ isEnabled: props.enableAndroidBackHandler,
3594
+ onClose: () => props.onClose()
3595
+ }));
3270
3596
  use(keyPressed, _el$, () => () => props.onClose());
3271
3597
  use(clickOutside, _el$, () => () => props.onClose());
3272
3598
  insert(_el$, createComponent(ModalBodyStyled, {
@@ -3300,6 +3626,7 @@ const Modal = (props) => {
3300
3626
  createRenderEffect(() => className(_el$, cn(ModalWrapperClass, u`
3301
3627
  border-radius: ${borders$4[theme.borderRadius]};
3302
3628
  background-color: ${theme.colors.background.tint};
3629
+
3303
3630
  ${media("mobile")} {
3304
3631
  border-radius: ${borders$4[theme.borderRadius]}
3305
3632
  ${borders$4[theme.borderRadius]} 0 0;
@@ -5182,11 +5509,16 @@ var qrcode$1 = { exports: {} };
5182
5509
  })(qrcode$1);
5183
5510
  const qrcode = qrcode$1.exports;
5184
5511
  function copyToClipboard(text) {
5185
- if (navigator == null ? void 0 : navigator.clipboard) {
5186
- return navigator.clipboard.writeText(text);
5187
- }
5188
- fallbackCopyTextToClipboard(text);
5189
- return Promise.resolve();
5512
+ return __async(this, null, function* () {
5513
+ try {
5514
+ if (!(navigator == null ? void 0 : navigator.clipboard)) {
5515
+ throw new TonConnectUIError("Clipboard API not available");
5516
+ }
5517
+ return yield navigator.clipboard.writeText(text);
5518
+ } catch (e2) {
5519
+ }
5520
+ fallbackCopyTextToClipboard(text);
5521
+ });
5190
5522
  }
5191
5523
  function fallbackCopyTextToClipboard(text) {
5192
5524
  const textArea = document.createElement("textarea");
@@ -5283,7 +5615,7 @@ const QRCode = (props) => {
5283
5615
  }
5284
5616
  }), createComponent(Transition, {
5285
5617
  onBeforeEnter: (el) => {
5286
- el.animate([{
5618
+ animate(el, [{
5287
5619
  opacity: 0,
5288
5620
  transform: "translate(-50%, 44px)"
5289
5621
  }, {
@@ -5295,7 +5627,7 @@ const QRCode = (props) => {
5295
5627
  });
5296
5628
  },
5297
5629
  onExit: (el, done) => {
5298
- el.animate([{
5630
+ animate(el, [{
5299
5631
  opacity: 1,
5300
5632
  transform: "translate(-50%, 0)"
5301
5633
  }, {
@@ -6186,13 +6518,15 @@ const ScrollDivider = styled.div`
6186
6518
  margin: 0;
6187
6519
  }
6188
6520
  `;
6189
- const [windowHeight, setWindowHeight] = createSignal(((_a = getWindow$1()) == null ? void 0 : _a.innerHeight) || 0);
6521
+ const [windowHeight, setWindowHeight] = createSignal(((_h = getWindow$1()) == null ? void 0 : _h.innerHeight) || 0);
6190
6522
  if (getWindow$1()) {
6191
6523
  window.addEventListener("resize", () => setWindowHeight(window.innerHeight));
6192
6524
  }
6193
6525
  const [isMobile, setIsMobile] = createSignal(isDevice("mobile"));
6526
+ const updateIsMobile = () => setIsMobile(isDevice("mobile"));
6194
6527
  if (getWindow$1()) {
6195
- window.addEventListener("resize", () => setIsMobile(isDevice("mobile")));
6528
+ window.addEventListener("resize", () => updateIsMobile());
6529
+ window.addEventListener("load", () => updateIsMobile(), { once: true });
6196
6530
  }
6197
6531
  const ScrollContainer = (props) => {
6198
6532
  const [scrolled, setScrolled] = createSignal(false);
@@ -6549,31 +6883,50 @@ const NotificationClass = u`
6549
6883
  transform: translateY(-8px);
6550
6884
  margin-bottom: 12px;
6551
6885
  `;
6552
- const _tmpl$$4 = /* @__PURE__ */ template$1(`<div data-tc-list-notifications="true"></div>`);
6553
- const Notifications = (props) => {
6554
- const timeouts = [];
6886
+ const defaultConfig = {
6887
+ timeout: 4500
6888
+ };
6889
+ const [latestAction, setLatestAction] = createSignal(null);
6890
+ function useOpenedNotifications(config) {
6891
+ const { timeout } = __spreadValues(__spreadValues({}, defaultConfig), config);
6555
6892
  const [openedNotifications, setOpenedNotifications] = createSignal([]);
6556
- let lastId = -1;
6557
- const liveTimeoutMs = 4500;
6558
- createEffect(on(action, (action2) => {
6559
- if (action2 && action2.showNotification) {
6560
- lastId++;
6561
- const id = lastId;
6562
- setOpenedNotifications((notifications2) => notifications2.filter((notification) => notification.action !== "confirm-transaction").concat({
6563
- id,
6564
- action: action2.name
6565
- }));
6566
- timeouts.push(setTimeout(() => setOpenedNotifications((notifications2) => notifications2.filter((notification) => notification.id !== id)), liveTimeoutMs));
6567
- }
6568
- }));
6893
+ const [timeoutIds, setTimeoutIds] = createSignal([]);
6894
+ createEffect(
6895
+ on(action, (action2) => {
6896
+ if (!action2 || !action2.showNotification) {
6897
+ return;
6898
+ }
6899
+ if (latestAction() === action2) {
6900
+ return;
6901
+ }
6902
+ setLatestAction(action2);
6903
+ setOpenedNotifications(
6904
+ (openedNotifications2) => openedNotifications2.filter((n2) => n2.action !== "confirm-transaction")
6905
+ );
6906
+ const notification = { action: action2.name };
6907
+ setOpenedNotifications((openedNotifications2) => [...openedNotifications2, notification]);
6908
+ const timeoutId = setTimeout(() => {
6909
+ setOpenedNotifications(
6910
+ (openedNotifications2) => openedNotifications2.filter((n2) => n2 !== notification)
6911
+ );
6912
+ setTimeoutIds((timeoutIds2) => timeoutIds2.filter((id) => id !== timeoutId));
6913
+ }, timeout);
6914
+ setTimeoutIds((timeoutIds2) => [...timeoutIds2, timeoutId]);
6915
+ })
6916
+ );
6569
6917
  onCleanup(() => {
6570
- timeouts.forEach(clearTimeout);
6918
+ timeoutIds().forEach((id) => clearTimeout(id));
6571
6919
  });
6920
+ return openedNotifications;
6921
+ }
6922
+ const _tmpl$$4 = /* @__PURE__ */ template$1(`<div data-tc-list-notifications="true"></div>`);
6923
+ const Notifications = (props) => {
6924
+ const openedNotifications = useOpenedNotifications();
6572
6925
  return (() => {
6573
6926
  const _el$ = _tmpl$$4.cloneNode(true);
6574
6927
  insert(_el$, createComponent(TransitionGroup, {
6575
6928
  onBeforeEnter: (el) => {
6576
- el.animate([{
6929
+ animate(el, [{
6577
6930
  opacity: 0,
6578
6931
  transform: "translateY(0)"
6579
6932
  }, {
@@ -6584,7 +6937,7 @@ const Notifications = (props) => {
6584
6937
  });
6585
6938
  },
6586
6939
  onExit: (el, done) => {
6587
- const a2 = el.animate([{
6940
+ const a2 = animate(el, [{
6588
6941
  opacity: 1,
6589
6942
  transform: "translateY(-8px)"
6590
6943
  }, {
@@ -7508,7 +7861,7 @@ const AccountButton = () => {
7508
7861
  },
7509
7862
  get children() {
7510
7863
  return createComponent(AccountButtonStyled, {
7511
- onClick: () => tonConnectUI.connectWallet(),
7864
+ onClick: () => tonConnectUI.openModal(),
7512
7865
  "data-tc-connect-button": "true",
7513
7866
  scale: "s",
7514
7867
  get children() {
@@ -7561,7 +7914,7 @@ const AccountButton = () => {
7561
7914
  _el$._$owner = getOwner();
7562
7915
  insert(_el$, createComponent(Transition, {
7563
7916
  onBeforeEnter: (el) => {
7564
- el.animate([{
7917
+ animate(el, [{
7565
7918
  opacity: 0,
7566
7919
  transform: "translateY(-8px)"
7567
7920
  }, {
@@ -7572,7 +7925,7 @@ const AccountButton = () => {
7572
7925
  });
7573
7926
  },
7574
7927
  onExit: (el, done) => {
7575
- const a2 = el.animate([{
7928
+ const a2 = animate(el, [{
7576
7929
  opacity: 1,
7577
7930
  transform: "translateY(0)"
7578
7931
  }, {
@@ -7605,8 +7958,8 @@ const AccountButton = () => {
7605
7958
  }), null);
7606
7959
  insert(_el$, createComponent(NotificationsStyled, {}), null);
7607
7960
  createRenderEffect((_p$) => {
7608
- var _a2, _b;
7609
- const _v$ = position.strategy, _v$2 = `${(_a2 = position.y) != null ? _a2 : 0}px`, _v$3 = `${(_b = position.x) != null ? _b : 0}px`;
7961
+ var _a2, _b2;
7962
+ const _v$ = position.strategy, _v$2 = `${(_a2 = position.y) != null ? _a2 : 0}px`, _v$3 = `${(_b2 = position.x) != null ? _b2 : 0}px`;
7610
7963
  _v$ !== _p$._v$ && _el$.style.setProperty("position", _p$._v$ = _v$);
7611
7964
  _v$2 !== _p$._v$2 && _el$.style.setProperty("top", _p$._v$2 = _v$2);
7612
7965
  _v$3 !== _p$._v$3 && _el$.style.setProperty("left", _p$._v$3 = _v$3);
@@ -7672,7 +8025,8 @@ const [appState, setAppState] = createStore({
7672
8025
  language: "en",
7673
8026
  returnStrategy: "back",
7674
8027
  twaReturnUrl: void 0,
7675
- walletsListConfiguration: {}
8028
+ walletsListConfiguration: {},
8029
+ enableAndroidBackHandler: true
7676
8030
  });
7677
8031
  function uniq(array) {
7678
8032
  return [...new Set(array)];
@@ -7902,10 +8256,87 @@ const Translation = (props) => {
7902
8256
  return t2(props.translationKey, props.translationValues, (_a2 = props.children) == null ? void 0 : _a2.toString());
7903
8257
  });
7904
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;
7905
8335
  const DesktopConnectionModal = (props) => {
7906
8336
  const [mode, setMode] = createSignal("mobile");
7907
8337
  const [connectionErrored, setConnectionErrored] = createSignal(false);
7908
8338
  const [universalLink, setUniversalLink] = createSignal();
8339
+ const [firstClick, setFirstClick] = createSignal(true);
7909
8340
  const connector = useContext(ConnectorContext);
7910
8341
  const unsubscribe = connector.onStatusChange(() => {
7911
8342
  }, () => {
@@ -7941,19 +8372,37 @@ const DesktopConnectionModal = (props) => {
7941
8372
  generateUniversalLink();
7942
8373
  }
7943
8374
  setMode("desktop");
7944
- setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
7945
- openMethod: "universal-link"
7946
- }));
7947
- 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
+ }
7948
8394
  };
7949
8395
  const onClickTelegram = () => {
8396
+ const forceRedirect = !firstClick();
8397
+ setFirstClick(false);
7950
8398
  setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
7951
8399
  openMethod: "universal-link"
7952
8400
  }));
7953
- openLinkBlank(addReturnStrategy(universalLink(), {
8401
+ redirectToTelegram(universalLink(), {
7954
8402
  returnStrategy: appState.returnStrategy,
7955
- twaReturnUrl: appState.twaReturnUrl
7956
- }));
8403
+ twaReturnUrl: appState.twaReturnUrl,
8404
+ forceRedirect
8405
+ });
7957
8406
  };
7958
8407
  const onClickExtension = () => {
7959
8408
  setConnectionErrored(false);
@@ -8219,7 +8668,7 @@ const DesktopConnectionModal = (props) => {
8219
8668
  get children() {
8220
8669
  return createComponent(Translation, {
8221
8670
  translationKey: "walletModal.desktopConnectionModal.openWalletOnTelegram",
8222
- children: "Open Wallet on Telegram on desktop"
8671
+ children: "Open Wallet in Telegram on desktop"
8223
8672
  });
8224
8673
  }
8225
8674
  });
@@ -8856,13 +9305,14 @@ const MobileUniversalQR = (props) => {
8856
9305
  const _tmpl$$1 = /* @__PURE__ */ template$1(`<li></li>`), _tmpl$2 = /* @__PURE__ */ template$1(`<div data-tc-wallets-modal-universal-mobile="true"></div>`);
8857
9306
  const MobileUniversalModal = (props) => {
8858
9307
  const [showQR, setShowQR] = createSignal(false);
9308
+ const [firstClick, setFirstClick] = createSignal(true);
8859
9309
  const connector = appState.connector;
8860
9310
  const walletsList = () => props.walletsList.filter((w) => supportsMobile(w) && w.appName !== AT_WALLET_APP_NAME);
8861
9311
  const shouldShowMoreButton = () => walletsList().length > 7;
8862
9312
  const walletsBridges = () => [...new Set(props.walletsList.filter(isWalletInfoRemote).map((item) => item.bridgeUrl)).values()].map((bridgeUrl) => ({
8863
9313
  bridgeUrl
8864
9314
  }));
8865
- const universalLink = createMemo(() => connector.connect(walletsBridges(), props.additionalRequest));
9315
+ const getUniversalLink = () => connector.connect(walletsBridges(), props.additionalRequest);
8866
9316
  setLastSelectedWalletInfo({
8867
9317
  openMethod: "universal-link"
8868
9318
  });
@@ -8871,12 +9321,12 @@ const MobileUniversalModal = (props) => {
8871
9321
  if (isCopiedShown() !== void 0) {
8872
9322
  clearTimeout(isCopiedShown());
8873
9323
  }
8874
- yield copyToClipboard(universalLink());
9324
+ yield copyToClipboard(getUniversalLink());
8875
9325
  const timeoutId = setTimeout(() => setIsCopiedShown(void 0), 1500);
8876
9326
  setIsCopiedShown(timeoutId);
8877
9327
  });
8878
9328
  const onSelectUniversal = () => {
8879
- openLinkBlank(addReturnStrategy(universalLink(), appState.returnStrategy));
9329
+ openLinkBlank(addReturnStrategy(getUniversalLink(), appState.returnStrategy));
8880
9330
  };
8881
9331
  const onSelectTelegram = () => {
8882
9332
  const atWallet = props.walletsList.find((wallet) => wallet.appName === AT_WALLET_APP_NAME);
@@ -8887,10 +9337,13 @@ const MobileUniversalModal = (props) => {
8887
9337
  bridgeUrl: atWallet.bridgeUrl,
8888
9338
  universalLink: atWallet.universalLink
8889
9339
  }, props.additionalRequest);
8890
- openLinkBlank(addReturnStrategy(walletLink, {
9340
+ const forceRedirect = !firstClick();
9341
+ setFirstClick(false);
9342
+ redirectToTelegram(walletLink, {
8891
9343
  returnStrategy: appState.returnStrategy,
8892
- twaReturnUrl: appState.twaReturnUrl
8893
- }));
9344
+ twaReturnUrl: appState.twaReturnUrl,
9345
+ forceRedirect
9346
+ });
8894
9347
  };
8895
9348
  const onOpenQR = () => {
8896
9349
  setShowQR(true);
@@ -8916,7 +9369,7 @@ const MobileUniversalModal = (props) => {
8916
9369
  onClick: onCloseQR
8917
9370
  }), createComponent(MobileUniversalQR, {
8918
9371
  get universalLink() {
8919
- return universalLink();
9372
+ return getUniversalLink();
8920
9373
  }
8921
9374
  })];
8922
9375
  }
@@ -8936,7 +9389,7 @@ const MobileUniversalModal = (props) => {
8936
9389
  children: "Connect your wallet"
8937
9390
  }), createComponent(H2Styled$2, {
8938
9391
  translationKey: "walletModal.mobileUniversalModal.openWalletOnTelegramOrSelect",
8939
- children: "Open Wallet on Telegram or select your wallet to connect"
9392
+ children: "Open Wallet in Telegram or select your wallet to connect"
8940
9393
  }), createComponent(TelegramButtonStyled, {
8941
9394
  get leftIcon() {
8942
9395
  return createComponent(AtWalletIcon, {});
@@ -8953,7 +9406,7 @@ const MobileUniversalModal = (props) => {
8953
9406
  get children() {
8954
9407
  return createComponent(Translation, {
8955
9408
  translationKey: "walletModal.mobileUniversalModal.openWalletOnTelegram",
8956
- children: "Open Wallet on Telegram"
9409
+ children: "Open Wallet in Telegram"
8957
9410
  });
8958
9411
  }
8959
9412
  }), createComponent(UlStyled, {
@@ -9200,6 +9653,11 @@ const WalletsModal = () => {
9200
9653
  locale
9201
9654
  } = useI18n()[1];
9202
9655
  createEffect(() => locale(appState.language));
9656
+ createEffect(() => {
9657
+ if (getWalletsModalIsOpened()) {
9658
+ updateIsMobile();
9659
+ }
9660
+ });
9203
9661
  const connector = useContext(ConnectorContext);
9204
9662
  const tonConnectUI = useContext(TonConnectUiContext);
9205
9663
  const [fetchedWalletsList] = createResource(() => tonConnectUI.getWallets());
@@ -9239,22 +9697,28 @@ const WalletsModal = () => {
9239
9697
  }
9240
9698
  return (_a2 = appState.connectRequestParameters) == null ? void 0 : _a2.value;
9241
9699
  });
9242
- const onClose = () => {
9243
- setWalletsModalOpen(false);
9700
+ const onClose = (closeReason) => {
9701
+ setWalletsModalState({
9702
+ status: "closed",
9703
+ closeReason
9704
+ });
9244
9705
  setSelectedWalletInfo(null);
9245
9706
  setInfoTab(false);
9246
9707
  };
9247
9708
  const unsubscribe = connector.onStatusChange((wallet) => {
9248
9709
  if (wallet) {
9249
- onClose();
9710
+ onClose("wallet-selected");
9250
9711
  }
9251
9712
  });
9252
9713
  onCleanup(unsubscribe);
9253
9714
  return createComponent(StyledModal, {
9254
9715
  get opened() {
9255
- return walletsModalOpen();
9716
+ return getWalletsModalIsOpened();
9256
9717
  },
9257
- onClose,
9718
+ get enableAndroidBackHandler() {
9719
+ return appState.enableAndroidBackHandler;
9720
+ },
9721
+ onClose: () => onClose("action-cancelled"),
9258
9722
  onClickQuestion: () => setInfoTab((v) => !v),
9259
9723
  "data-tc-wallets-modal-container": "true",
9260
9724
  get children() {
@@ -9379,17 +9843,21 @@ const ButtonStyled = styled(Button)`
9379
9843
  const ActionModal = (props) => {
9380
9844
  const dataAttrs = useDataAttributes(props);
9381
9845
  const tonConnectUI = useContext(TonConnectUiContext);
9846
+ const [firstClick, setFirstClick] = createSignal(true);
9382
9847
  let universalLink;
9383
- if ((tonConnectUI == null ? void 0 : tonConnectUI.wallet) && "universalLink" in tonConnectUI.wallet && (tonConnectUI.wallet.openMethod === "universal-link" || isTelegramUrl(tonConnectUI.wallet.universalLink) && isInTWA())) {
9848
+ if ((tonConnectUI == null ? void 0 : tonConnectUI.wallet) && "universalLink" in tonConnectUI.wallet && (tonConnectUI.wallet.openMethod === "universal-link" || isTelegramUrl(tonConnectUI.wallet.universalLink) && isInTMA())) {
9384
9849
  universalLink = tonConnectUI.wallet.universalLink;
9385
9850
  }
9386
9851
  const onOpenWallet = () => {
9387
9852
  const currentAction = action();
9388
9853
  const returnStrategy = "returnStrategy" in currentAction ? currentAction.returnStrategy : appState.returnStrategy;
9389
9854
  if (isTelegramUrl(universalLink)) {
9855
+ const forceRedirect = !firstClick();
9856
+ setFirstClick(false);
9390
9857
  redirectToTelegram(universalLink, {
9391
9858
  returnStrategy,
9392
- twaReturnUrl: "twaReturnUrl" in currentAction ? currentAction.twaReturnUrl : appState.twaReturnUrl
9859
+ twaReturnUrl: "twaReturnUrl" in currentAction ? currentAction.twaReturnUrl : appState.twaReturnUrl,
9860
+ forceRedirect
9393
9861
  });
9394
9862
  } else {
9395
9863
  openLinkBlank(addReturnStrategy(universalLink, returnStrategy));
@@ -9499,6 +9967,9 @@ const ActionsModal = () => {
9499
9967
  var _a2;
9500
9968
  return createMemo(() => action() !== null)() && ((_a2 = action()) == null ? void 0 : _a2.openModal) === true;
9501
9969
  },
9970
+ get enableAndroidBackHandler() {
9971
+ return appState.enableAndroidBackHandler;
9972
+ },
9502
9973
  onClose: () => setAction(null),
9503
9974
  "data-tc-actions-modal-container": "true",
9504
9975
  get children() {
@@ -9587,8 +10058,14 @@ const App = (props) => {
9587
10058
  });
9588
10059
  };
9589
10060
  const widgetController = {
9590
- openWalletsModal: () => void setTimeout(() => setWalletsModalOpen(true)),
9591
- closeWalletsModal: () => void setTimeout(() => setWalletsModalOpen(false)),
10061
+ openWalletsModal: () => void setTimeout(() => setWalletsModalState({
10062
+ status: "opened",
10063
+ closeReason: null
10064
+ })),
10065
+ closeWalletsModal: (reason) => void setTimeout(() => setWalletsModalState({
10066
+ status: "closed",
10067
+ closeReason: reason
10068
+ })),
9592
10069
  setAction: (action2) => void setTimeout(() => setAction(action2)),
9593
10070
  clearAction: () => void setTimeout(() => setAction(null)),
9594
10071
  getSelectedWalletInfo: () => lastSelectedWalletInfo(),
@@ -9597,16 +10074,99 @@ const widgetController = {
9597
10074
  tonConnectUI
9598
10075
  }), document.getElementById(root))
9599
10076
  };
10077
+ class WalletsModalManager {
10078
+ constructor(options) {
10079
+ __publicField(this, "connector");
10080
+ __publicField(this, "setConnectRequestParametersCallback");
10081
+ __publicField(this, "consumers", []);
10082
+ __publicField(this, "state", walletsModalState());
10083
+ this.connector = options.connector;
10084
+ this.setConnectRequestParametersCallback = options.setConnectRequestParametersCallback;
10085
+ createEffect(() => {
10086
+ const state = walletsModalState();
10087
+ this.state = state;
10088
+ this.consumers.forEach((consumer) => consumer(state));
10089
+ });
10090
+ }
10091
+ open() {
10092
+ return __async(this, null, function* () {
10093
+ const walletsList = yield this.connector.getWallets();
10094
+ const embeddedWallet = walletsList.find(isWalletInfoCurrentlyEmbedded);
10095
+ if (embeddedWallet) {
10096
+ return this.connectEmbeddedWallet(embeddedWallet);
10097
+ } else {
10098
+ return this.connectExternalWallet();
10099
+ }
10100
+ });
10101
+ }
10102
+ close() {
10103
+ widgetController.closeWalletsModal("action-cancelled");
10104
+ }
10105
+ onStateChange(onChange) {
10106
+ this.consumers.push(onChange);
10107
+ return () => {
10108
+ this.consumers = this.consumers.filter((consumer) => consumer !== onChange);
10109
+ };
10110
+ }
10111
+ connectEmbeddedWallet(embeddedWallet) {
10112
+ const connect = (parameters) => {
10113
+ setLastSelectedWalletInfo(embeddedWallet);
10114
+ this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey }, parameters);
10115
+ };
10116
+ const additionalRequest = appState.connectRequestParameters;
10117
+ if ((additionalRequest == null ? void 0 : additionalRequest.state) === "loading") {
10118
+ this.setConnectRequestParametersCallback(connect);
10119
+ } else {
10120
+ connect(additionalRequest == null ? void 0 : additionalRequest.value);
10121
+ }
10122
+ }
10123
+ connectExternalWallet() {
10124
+ return __async(this, null, function* () {
10125
+ if (isInTMA()) {
10126
+ sendExpand();
10127
+ }
10128
+ widgetController.openWalletsModal();
10129
+ return new Promise((resolve) => {
10130
+ const unsubscribe = this.onStateChange((state) => {
10131
+ const { status } = state;
10132
+ if (status === "opened") {
10133
+ unsubscribe();
10134
+ resolve();
10135
+ }
10136
+ });
10137
+ });
10138
+ });
10139
+ }
10140
+ }
10141
+ class TransactionModalManager {
10142
+ constructor(options) {
10143
+ __publicField(this, "connector");
10144
+ __publicField(this, "consumers", []);
10145
+ this.connector = options.connector;
10146
+ createEffect(() => {
10147
+ const _ = action();
10148
+ this.consumers.forEach((consumer) => consumer(_));
10149
+ });
10150
+ }
10151
+ onStateChange(consumer) {
10152
+ this.consumers.push(consumer);
10153
+ return () => {
10154
+ this.consumers = this.consumers.filter((c2) => c2 !== consumer);
10155
+ };
10156
+ }
10157
+ }
9600
10158
  class TonConnectUI {
9601
10159
  constructor(options) {
9602
10160
  __publicField(this, "walletInfoStorage", new WalletInfoStorage());
9603
10161
  __publicField(this, "preferredWalletStorage", new PreferredWalletStorage());
9604
- __publicField(this, "connector");
9605
10162
  __publicField(this, "walletInfo", null);
9606
10163
  __publicField(this, "systemThemeChangeUnsubscribe", null);
9607
10164
  __publicField(this, "actionsConfiguration");
9608
10165
  __publicField(this, "walletsList");
9609
10166
  __publicField(this, "connectRequestParametersCallback");
10167
+ __publicField(this, "connector");
10168
+ __publicField(this, "modal");
10169
+ __publicField(this, "transactionModal");
9610
10170
  __publicField(this, "connectionRestored", Promise.resolve(false));
9611
10171
  if (options && "connector" in options && options.connector) {
9612
10172
  this.connector = options.connector;
@@ -9617,6 +10177,15 @@ class TonConnectUI {
9617
10177
  "You have to specify a `manifestUrl` or a `connector` in the options."
9618
10178
  );
9619
10179
  }
10180
+ this.modal = new WalletsModalManager({
10181
+ connector: this.connector,
10182
+ setConnectRequestParametersCallback: (callback) => {
10183
+ this.connectRequestParametersCallback = callback;
10184
+ }
10185
+ });
10186
+ this.transactionModal = new TransactionModalManager({
10187
+ connector: this.connector
10188
+ });
9620
10189
  this.walletsList = this.getWallets();
9621
10190
  this.walletsList.then((list) => preloadImages(uniq(list.map((item) => item.imageUrl))));
9622
10191
  const rootId = this.normalizeWidgetRoot(options == null ? void 0 : options.widgetRootId);
@@ -9654,12 +10223,12 @@ class TonConnectUI {
9654
10223
  return __spreadValues(__spreadValues({}, this.connector.wallet), this.walletInfo);
9655
10224
  }
9656
10225
  set uiOptions(options) {
9657
- var _a2, _b, _c, _d, _e;
10226
+ var _a2, _b2, _c2, _d2, _e2;
9658
10227
  this.checkButtonRootExist(options.buttonRootId);
9659
10228
  this.actionsConfiguration = options.actionsConfiguration;
9660
10229
  if ((_a2 = options.uiPreferences) == null ? void 0 : _a2.theme) {
9661
- if (((_b = options.uiPreferences) == null ? void 0 : _b.theme) !== "SYSTEM") {
9662
- (_c = this.systemThemeChangeUnsubscribe) == null ? void 0 : _c.call(this);
10230
+ if (((_b2 = options.uiPreferences) == null ? void 0 : _b2.theme) !== "SYSTEM") {
10231
+ (_c2 = this.systemThemeChangeUnsubscribe) == null ? void 0 : _c2.call(this);
9663
10232
  setTheme(options.uiPreferences.theme, options.uiPreferences.colorsSet);
9664
10233
  } else {
9665
10234
  setTheme(getSystemTheme(), options.uiPreferences.colorsSet);
@@ -9668,19 +10237,19 @@ class TonConnectUI {
9668
10237
  }
9669
10238
  }
9670
10239
  } else {
9671
- if ((_d = options.uiPreferences) == null ? void 0 : _d.colorsSet) {
10240
+ if ((_d2 = options.uiPreferences) == null ? void 0 : _d2.colorsSet) {
9672
10241
  setColors(options.uiPreferences.colorsSet);
9673
10242
  }
9674
10243
  }
9675
- if ((_e = options.uiPreferences) == null ? void 0 : _e.borderRadius) {
10244
+ if ((_e2 = options.uiPreferences) == null ? void 0 : _e2.borderRadius) {
9676
10245
  setBorderRadius(options.uiPreferences.borderRadius);
9677
10246
  }
9678
10247
  setAppState((state) => {
9679
- var _a3, _b2;
10248
+ var _a3, _b3;
9680
10249
  const merged = mergeOptions(
9681
10250
  __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, options.language && { language: options.language }), !!((_a3 = options.actionsConfiguration) == null ? void 0 : _a3.returnStrategy) && {
9682
10251
  returnStrategy: options.actionsConfiguration.returnStrategy
9683
- }), !!((_b2 = options.actionsConfiguration) == null ? void 0 : _b2.twaReturnUrl) && {
10252
+ }), !!((_b3 = options.actionsConfiguration) == null ? void 0 : _b3.twaReturnUrl) && {
9684
10253
  twaReturnUrl: options.actionsConfiguration.twaReturnUrl
9685
10254
  }), !!options.walletsListConfiguration && {
9686
10255
  walletsListConfiguration: options.walletsListConfiguration
@@ -9690,6 +10259,9 @@ class TonConnectUI {
9690
10259
  if (options.buttonRootId !== void 0) {
9691
10260
  merged.buttonRootId = options.buttonRootId;
9692
10261
  }
10262
+ if (options.enableAndroidBackHandler !== void 0) {
10263
+ merged.enableAndroidBackHandler = options.enableAndroidBackHandler;
10264
+ }
9693
10265
  return merged;
9694
10266
  });
9695
10267
  }
@@ -9715,35 +10287,29 @@ class TonConnectUI {
9715
10287
  }
9716
10288
  }), errorsHandler);
9717
10289
  }
10290
+ openModal() {
10291
+ return __async(this, null, function* () {
10292
+ return this.modal.open();
10293
+ });
10294
+ }
10295
+ closeModal() {
10296
+ this.modal.close();
10297
+ }
10298
+ onModalStateChange(onChange) {
10299
+ return this.modal.onStateChange(onChange);
10300
+ }
10301
+ get modalState() {
10302
+ return this.modal.state;
10303
+ }
9718
10304
  connectWallet() {
9719
10305
  return __async(this, null, function* () {
9720
10306
  const walletsList = yield this.getWallets();
9721
10307
  const embeddedWallet = walletsList.find(isWalletInfoCurrentlyEmbedded);
9722
10308
  if (embeddedWallet) {
9723
- const connect = (parameters) => {
9724
- setLastSelectedWalletInfo(embeddedWallet);
9725
- this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey }, parameters);
9726
- };
9727
- const additionalRequest = appState.connectRequestParameters;
9728
- if ((additionalRequest == null ? void 0 : additionalRequest.state) === "loading") {
9729
- this.connectRequestParametersCallback = connect;
9730
- } else {
9731
- connect(additionalRequest == null ? void 0 : additionalRequest.value);
9732
- }
10309
+ return yield this.connectEmbeddedWallet(embeddedWallet);
9733
10310
  } else {
9734
- widgetController.openWalletsModal();
10311
+ return yield this.connectExternalWallet();
9735
10312
  }
9736
- return new Promise((resolve, reject) => {
9737
- const unsubscribe = this.connector.onStatusChange((wallet) => __async(this, null, function* () {
9738
- unsubscribe();
9739
- if (wallet) {
9740
- const lastSelectedWalletInfo2 = yield this.getSelectedWalletInfo(wallet);
9741
- resolve(__spreadValues(__spreadValues({}, wallet), lastSelectedWalletInfo2 || this.walletInfoStorage.getWalletInfo()));
9742
- } else {
9743
- reject(new TonConnectUIError("Wallet was not connected"));
9744
- }
9745
- }), reject);
9746
- });
9747
10313
  });
9748
10314
  }
9749
10315
  disconnect() {
@@ -9757,23 +10323,48 @@ class TonConnectUI {
9757
10323
  if (!this.connected) {
9758
10324
  throw new TonConnectUIError("Connect wallet to send a transaction.");
9759
10325
  }
9760
- const { notifications: notifications2, modals, returnStrategy, twaReturnUrl, skipRedirectToWallet } = this.getModalsAndNotificationsConfiguration(options);
9761
- const userOSIsIos = getUserAgent().os === "ios";
9762
- const shouldSkipRedirectToWallet = skipRedirectToWallet === "ios" && userOSIsIos || skipRedirectToWallet === "always";
9763
- if (this.walletInfo && "universalLink" in this.walletInfo && this.walletInfo.openMethod === "universal-link" && !shouldSkipRedirectToWallet) {
9764
- if (isTelegramUrl(this.walletInfo.universalLink)) {
9765
- redirectToTelegram(this.walletInfo.universalLink, { returnStrategy, twaReturnUrl });
9766
- } else {
9767
- openLinkBlank(addReturnStrategy(this.walletInfo.universalLink, returnStrategy));
9768
- }
10326
+ if (isInTMA()) {
10327
+ sendExpand();
9769
10328
  }
10329
+ const { notifications: notifications2, modals, returnStrategy, twaReturnUrl, skipRedirectToWallet } = this.getModalsAndNotificationsConfiguration(options);
9770
10330
  widgetController.setAction({
9771
10331
  name: "confirm-transaction",
9772
10332
  showNotification: notifications2.includes("before"),
9773
10333
  openModal: modals.includes("before")
9774
10334
  });
10335
+ const onRequestSent = () => {
10336
+ const userOSIsIos = getUserAgent().os === "ios";
10337
+ const shouldSkipRedirectToWallet = skipRedirectToWallet === "ios" && userOSIsIos || skipRedirectToWallet === "always";
10338
+ if (this.walletInfo && "universalLink" in this.walletInfo && this.walletInfo.openMethod === "universal-link" && !shouldSkipRedirectToWallet) {
10339
+ if (isTelegramUrl(this.walletInfo.universalLink)) {
10340
+ redirectToTelegram(this.walletInfo.universalLink, {
10341
+ returnStrategy,
10342
+ twaReturnUrl: twaReturnUrl || appState.twaReturnUrl,
10343
+ forceRedirect: false
10344
+ });
10345
+ } else {
10346
+ openLinkBlank(addReturnStrategy(this.walletInfo.universalLink, returnStrategy));
10347
+ }
10348
+ }
10349
+ };
10350
+ const abortController = new AbortController();
10351
+ const unsubscribe = this.onTransactionModalStateChange((action2) => {
10352
+ if (action2 == null ? void 0 : action2.openModal) {
10353
+ return;
10354
+ }
10355
+ unsubscribe();
10356
+ if (!action2) {
10357
+ abortController.abort();
10358
+ }
10359
+ });
9775
10360
  try {
9776
- const result = yield this.connector.sendTransaction(tx);
10361
+ const result = yield this.waitForSendTransaction(
10362
+ {
10363
+ transaction: tx,
10364
+ abortSignal: abortController.signal
10365
+ },
10366
+ onRequestSent
10367
+ );
9777
10368
  widgetController.setAction({
9778
10369
  name: "transaction-sent",
9779
10370
  showNotification: notifications2.includes("success"),
@@ -9792,9 +10383,110 @@ class TonConnectUI {
9792
10383
  console.error(e2);
9793
10384
  throw new TonConnectUIError("Unhandled error:" + e2);
9794
10385
  }
10386
+ } finally {
10387
+ unsubscribe();
10388
+ }
10389
+ });
10390
+ }
10391
+ connectEmbeddedWallet(embeddedWallet) {
10392
+ return __async(this, null, function* () {
10393
+ const connect = (parameters) => {
10394
+ setLastSelectedWalletInfo(embeddedWallet);
10395
+ this.connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey }, parameters);
10396
+ };
10397
+ const additionalRequest = appState.connectRequestParameters;
10398
+ if ((additionalRequest == null ? void 0 : additionalRequest.state) === "loading") {
10399
+ this.connectRequestParametersCallback = connect;
10400
+ } else {
10401
+ connect(additionalRequest == null ? void 0 : additionalRequest.value);
9795
10402
  }
10403
+ return yield this.waitForWalletConnection({
10404
+ ignoreErrors: false
10405
+ });
9796
10406
  });
9797
10407
  }
10408
+ connectExternalWallet() {
10409
+ return __async(this, null, function* () {
10410
+ const abortController = new AbortController();
10411
+ widgetController.openWalletsModal();
10412
+ const unsubscribe = this.onModalStateChange((state) => {
10413
+ const { status, closeReason } = state;
10414
+ if (status === "opened") {
10415
+ return;
10416
+ }
10417
+ unsubscribe();
10418
+ if (closeReason === "action-cancelled") {
10419
+ abortController.abort();
10420
+ }
10421
+ });
10422
+ return yield this.waitForWalletConnection({
10423
+ ignoreErrors: true,
10424
+ abortSignal: abortController.signal
10425
+ });
10426
+ });
10427
+ }
10428
+ waitForWalletConnection(options) {
10429
+ return __async(this, null, function* () {
10430
+ return new Promise((resolve, reject) => {
10431
+ const { ignoreErrors = false, abortSignal = null } = options;
10432
+ if (abortSignal && abortSignal.aborted) {
10433
+ return reject(new TonConnectUIError("Wallet was not connected"));
10434
+ }
10435
+ const onStatusChangeHandler = (wallet) => __async(this, null, function* () {
10436
+ if (!wallet) {
10437
+ if (ignoreErrors) {
10438
+ return;
10439
+ }
10440
+ unsubscribe();
10441
+ reject(new TonConnectUIError("Wallet was not connected"));
10442
+ } else {
10443
+ unsubscribe();
10444
+ resolve(wallet);
10445
+ }
10446
+ });
10447
+ const onErrorsHandler = (reason) => {
10448
+ if (ignoreErrors) {
10449
+ return;
10450
+ }
10451
+ unsubscribe();
10452
+ reject(reason);
10453
+ };
10454
+ const unsubscribe = this.onStatusChange(
10455
+ (wallet) => onStatusChangeHandler(wallet),
10456
+ (reason) => onErrorsHandler(reason)
10457
+ );
10458
+ if (abortSignal) {
10459
+ abortSignal.addEventListener("abort", () => {
10460
+ unsubscribe();
10461
+ reject(new TonConnectUIError("Wallet was not connected"));
10462
+ });
10463
+ }
10464
+ });
10465
+ });
10466
+ }
10467
+ waitForSendTransaction(options, onRequestSent) {
10468
+ return __async(this, null, function* () {
10469
+ return new Promise((resolve, reject) => {
10470
+ const { transaction, abortSignal } = options;
10471
+ if (abortSignal.aborted) {
10472
+ return reject(new TonConnectUIError("Transaction was not sent"));
10473
+ }
10474
+ const onTransactionHandler = (transaction2) => __async(this, null, function* () {
10475
+ resolve(transaction2);
10476
+ });
10477
+ const onErrorsHandler = (reason) => {
10478
+ reject(reason);
10479
+ };
10480
+ this.connector.sendTransaction(transaction, onRequestSent).then((result) => onTransactionHandler(result)).catch((reason) => onErrorsHandler(reason));
10481
+ abortSignal.addEventListener("abort", () => {
10482
+ reject(new TonConnectUIError("Transaction was not sent"));
10483
+ });
10484
+ });
10485
+ });
10486
+ }
10487
+ onTransactionModalStateChange(onChange) {
10488
+ return this.transactionModal.onStateChange(onChange);
10489
+ }
9798
10490
  subscribeToWalletChange() {
9799
10491
  this.connector.onStatusChange((wallet) => __async(this, null, function* () {
9800
10492
  var _a2;
@@ -9871,14 +10563,14 @@ class TonConnectUI {
9871
10563
  }
9872
10564
  }
9873
10565
  getModalsAndNotificationsConfiguration(options) {
9874
- var _a2, _b, _c, _d, _e, _f;
10566
+ var _a2, _b2, _c2, _d2, _e2, _f2;
9875
10567
  const allActions = [
9876
10568
  "before",
9877
10569
  "success",
9878
10570
  "error"
9879
10571
  ];
9880
10572
  let notifications2 = allActions;
9881
- if (((_a2 = this.actionsConfiguration) == null ? void 0 : _a2.notifications) && ((_b = this.actionsConfiguration) == null ? void 0 : _b.notifications) !== "all") {
10573
+ if (((_a2 = this.actionsConfiguration) == null ? void 0 : _a2.notifications) && ((_b2 = this.actionsConfiguration) == null ? void 0 : _b2.notifications) !== "all") {
9882
10574
  notifications2 = this.actionsConfiguration.notifications;
9883
10575
  }
9884
10576
  if (options == null ? void 0 : options.notifications) {
@@ -9889,7 +10581,7 @@ class TonConnectUI {
9889
10581
  }
9890
10582
  }
9891
10583
  let modals = ["before"];
9892
- if ((_c = this.actionsConfiguration) == null ? void 0 : _c.modals) {
10584
+ if ((_c2 = this.actionsConfiguration) == null ? void 0 : _c2.modals) {
9893
10585
  if (this.actionsConfiguration.modals === "all") {
9894
10586
  modals = allActions;
9895
10587
  } else {
@@ -9903,9 +10595,12 @@ class TonConnectUI {
9903
10595
  modals = options.modals;
9904
10596
  }
9905
10597
  }
9906
- const returnStrategy = (options == null ? void 0 : options.returnStrategy) || ((_d = this.actionsConfiguration) == null ? void 0 : _d.returnStrategy) || "back";
9907
- const twaReturnUrl = (options == null ? void 0 : options.twaReturnUrl) || ((_e = this.actionsConfiguration) == null ? void 0 : _e.twaReturnUrl);
9908
- const skipRedirectToWallet = (options == null ? void 0 : options.skipRedirectToWallet) || ((_f = this.actionsConfiguration) == null ? void 0 : _f.skipRedirectToWallet) || "ios";
10598
+ const returnStrategy = (options == null ? void 0 : options.returnStrategy) || ((_d2 = this.actionsConfiguration) == null ? void 0 : _d2.returnStrategy) || "back";
10599
+ const twaReturnUrl = (options == null ? void 0 : options.twaReturnUrl) || ((_e2 = this.actionsConfiguration) == null ? void 0 : _e2.twaReturnUrl);
10600
+ let skipRedirectToWallet = (options == null ? void 0 : options.skipRedirectToWallet) || ((_f2 = this.actionsConfiguration) == null ? void 0 : _f2.skipRedirectToWallet) || "ios";
10601
+ if (isInTMA()) {
10602
+ skipRedirectToWallet = "never";
10603
+ }
9909
10604
  return {
9910
10605
  notifications: notifications2,
9911
10606
  modals,
@@ -9920,4 +10615,4 @@ export {
9920
10615
  TonConnectUI,
9921
10616
  TonConnectUIError
9922
10617
  };
9923
- //# sourceMappingURL=index.js.map
10618
+ //# sourceMappingURL=index.mjs.map