@tonconnect/ui 2.0.0-beta.5 → 2.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -131,6 +131,7 @@ interface ActionConfiguration {
131
131
  */
132
132
  twaReturnUrl?: `${string}://${string}`;
133
133
  /**
134
+ * @deprecated Shouldn't be used anymore, SDK will automatically detect return strategy for TWA-TWA connections.
134
135
  * Specifies whether the method should redirect user to the connected wallet
135
136
  * @default 'ios'
136
137
  */
@@ -389,6 +390,7 @@ declare class TonConnectUI {
389
390
  * @options.transaction - Transaction to send.
390
391
  * @options.ignoreErrors - If true, ignores errors during waiting, waiting continues until a valid transaction is sent. Default is false.
391
392
  * @options.abortSignal - Optional AbortSignal for external cancellation. Throws TonConnectUIError if aborted.
393
+ * @param onRequestSent (optional) will be called after the transaction is sent to the wallet.
392
394
  * @throws TonConnectUIError if waiting is aborted or no valid transaction response is received and ignoreErrors is false.
393
395
  * @internal
394
396
  */
package/lib/index.mjs CHANGED
@@ -1749,12 +1749,167 @@ 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.tgWebAppPlatform) {
1776
+ tmaPlatform = initParams.tgWebAppPlatform;
1777
+ }
1778
+ let webAppVersion = "6.0";
1779
+ if (initParams.tgWebAppVersion) {
1780
+ webAppVersion = initParams.tgWebAppVersion;
1781
+ }
1782
+ function isTmaPlatform(...platforms) {
1783
+ return platforms.includes(tmaPlatform);
1784
+ }
1785
+ function isInTMA() {
1786
+ var _a2;
1787
+ return tmaPlatform !== "unknown" || !!((_a2 = getWindow$1()) == null ? void 0 : _a2.TelegramWebviewProxy);
1788
+ }
1789
+ function sendExpand() {
1790
+ postEvent("web_app_expand", {});
1791
+ }
1792
+ function sendOpenTelegramLink(link) {
1793
+ const url = new URL(link);
1794
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
1795
+ throw new TonConnectUIError(`Url protocol is not supported: ${url}`);
1796
+ }
1797
+ if (url.hostname !== "t.me") {
1798
+ throw new TonConnectUIError(`Url host is not supported: ${url}`);
1799
+ }
1800
+ const pathFull = url.pathname + url.search;
1801
+ if (isIframe() || versionAtLeast("6.1")) {
1802
+ postEvent("web_app_open_tg_link", { path_full: pathFull });
1803
+ } else {
1804
+ window.open("https://t.me" + pathFull, "_blank", "noreferrer noopener");
1805
+ }
1806
+ }
1807
+ function isIframe() {
1808
+ try {
1809
+ return window.parent != null && window !== window.parent;
1810
+ } catch (e2) {
1811
+ return false;
1812
+ }
1813
+ }
1814
+ function postEvent(eventType, eventData) {
1815
+ try {
1816
+ if (window.TelegramWebviewProxy !== void 0) {
1817
+ window.TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
1818
+ } else if (window.external && "notify" in window.external) {
1819
+ window.external.notify(JSON.stringify({ eventType, eventData }));
1820
+ } else if (isIframe()) {
1821
+ const trustedTarget = "*";
1822
+ const message = JSON.stringify({ eventType, eventData });
1823
+ window.parent.postMessage(message, trustedTarget);
1824
+ }
1825
+ throw new TonConnectUIError(`Can't post event to TMA`);
1826
+ } catch (e2) {
1827
+ logError(`Can't post event to parent window: ${e2}`);
1828
+ }
1829
+ }
1830
+ function urlParseHashParams(locationHash) {
1831
+ locationHash = locationHash.replace(/^#/, "");
1832
+ let params = {};
1833
+ if (!locationHash.length) {
1834
+ return params;
1835
+ }
1836
+ if (locationHash.indexOf("=") < 0 && locationHash.indexOf("?") < 0) {
1837
+ params._path = urlSafeDecode(locationHash);
1838
+ return params;
1839
+ }
1840
+ let qIndex = locationHash.indexOf("?");
1841
+ if (qIndex >= 0) {
1842
+ let pathParam = locationHash.substr(0, qIndex);
1843
+ params._path = urlSafeDecode(pathParam);
1844
+ locationHash = locationHash.substr(qIndex + 1);
1845
+ }
1846
+ let query_params = urlParseQueryString(locationHash);
1847
+ for (let k in query_params) {
1848
+ params[k] = query_params[k];
1849
+ }
1850
+ return params;
1851
+ }
1852
+ function urlSafeDecode(urlencoded) {
1853
+ try {
1854
+ urlencoded = urlencoded.replace(/\+/g, "%20");
1855
+ return decodeURIComponent(urlencoded);
1856
+ } catch (e2) {
1857
+ return urlencoded;
1858
+ }
1859
+ }
1860
+ function urlParseQueryString(queryString) {
1861
+ let params = {};
1862
+ if (!queryString.length) {
1863
+ return params;
1864
+ }
1865
+ let queryStringParams = queryString.split("&");
1866
+ let i2, param, paramName, paramValue;
1867
+ for (i2 = 0; i2 < queryStringParams.length; i2++) {
1868
+ param = queryStringParams[i2].split("=");
1869
+ paramName = urlSafeDecode(param[0]);
1870
+ paramValue = param[1] == null ? null : urlSafeDecode(param[1]);
1871
+ params[paramName] = paramValue;
1872
+ }
1873
+ return params;
1874
+ }
1875
+ function versionCompare(v1, v2) {
1876
+ if (typeof v1 !== "string")
1877
+ v1 = "";
1878
+ if (typeof v2 !== "string")
1879
+ v2 = "";
1880
+ let v1List = v1.replace(/^\s+|\s+$/g, "").split(".");
1881
+ let v2List = v2.replace(/^\s+|\s+$/g, "").split(".");
1882
+ let a2, i2, p1, p2;
1883
+ a2 = Math.max(v1List.length, v2List.length);
1884
+ for (i2 = 0; i2 < a2; i2++) {
1885
+ p1 = parseInt(v1List[i2]) || 0;
1886
+ p2 = parseInt(v2List[i2]) || 0;
1887
+ if (p1 === p2)
1888
+ continue;
1889
+ if (p1 > p2)
1890
+ return 1;
1891
+ return -1;
1892
+ }
1893
+ return 0;
1894
+ }
1895
+ function versionAtLeast(ver) {
1896
+ return versionCompare(webAppVersion, ver) >= 0;
1897
+ }
1752
1898
  function openLink(href, target = "_self") {
1753
- return window.open(href, target, "noreferrer noopener");
1899
+ window.open(href, target, "noopener noreferrer");
1754
1900
  }
1755
1901
  function openLinkBlank(href) {
1756
1902
  openLink(href, "_blank");
1757
1903
  }
1904
+ function openIframeLink(href, fallback) {
1905
+ const iframe = document.createElement("iframe");
1906
+ iframe.style.display = "none";
1907
+ iframe.src = href;
1908
+ document.body.appendChild(iframe);
1909
+ const fallbackTimeout = setTimeout(() => fallback(), 1e3);
1910
+ window.addEventListener("blur", () => clearTimeout(fallbackTimeout), { once: true });
1911
+ setTimeout(() => document.body.removeChild(iframe), 1e3);
1912
+ }
1758
1913
  function getSystemTheme() {
1759
1914
  if (window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches) {
1760
1915
  return THEME.LIGHT;
@@ -1776,7 +1931,7 @@ function addReturnStrategy(url, strategy) {
1776
1931
  if (typeof strategy === "string") {
1777
1932
  returnStrategy = strategy;
1778
1933
  } else {
1779
- returnStrategy = isInTWA() ? strategy.twaReturnUrl || strategy.returnStrategy : "none";
1934
+ returnStrategy = isInTMA() ? strategy.twaReturnUrl || strategy.returnStrategy : "none";
1780
1935
  }
1781
1936
  const newUrl = addQueryParameter(url, "ret", returnStrategy);
1782
1937
  if (!isTelegramUrl(url)) {
@@ -1806,9 +1961,17 @@ function defineStylesRoot() {
1806
1961
  customElements.define(globalStylesTag, class TcRootElement extends HTMLElement {
1807
1962
  });
1808
1963
  }
1964
+ function createMacrotask(callback) {
1965
+ return __async(this, null, function* () {
1966
+ yield new Promise((resolve) => requestAnimationFrame(resolve));
1967
+ callback();
1968
+ });
1969
+ }
1809
1970
  function preloadImages(images) {
1810
1971
  if (document.readyState !== "complete") {
1811
- window.addEventListener("load", () => preloadImages(images), { once: true });
1972
+ window.addEventListener("load", () => createMacrotask(() => preloadImages(images)), {
1973
+ once: true
1974
+ });
1812
1975
  } else {
1813
1976
  images.forEach((img) => {
1814
1977
  const node = new window.Image();
@@ -1883,14 +2046,67 @@ function getUserAgent() {
1883
2046
  browser
1884
2047
  };
1885
2048
  }
2049
+ function isOS(...os) {
2050
+ return os.includes(getUserAgent().os);
2051
+ }
1886
2052
  function redirectToTelegram(universalLink, options) {
2053
+ options = __spreadValues({}, options);
2054
+ const directLink = convertToDirectLink(universalLink);
2055
+ const directLinkUrl = new URL(directLink);
2056
+ if (!directLinkUrl.searchParams.has("startapp")) {
2057
+ directLinkUrl.searchParams.append("startapp", "tonconnect");
2058
+ }
2059
+ if (isInTMA()) {
2060
+ if (isTmaPlatform("ios", "android")) {
2061
+ options.returnStrategy = "none";
2062
+ options.twaReturnUrl = void 0;
2063
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2064
+ } else if (isTmaPlatform("macos", "tdesktop")) {
2065
+ if (!options.twaReturnUrl) {
2066
+ throw new TonConnectUIError("`twaReturnUrl` is required for this platform");
2067
+ }
2068
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2069
+ } else if (isTmaPlatform("weba")) {
2070
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2071
+ } else if (isTmaPlatform("web")) {
2072
+ options.returnStrategy = "none";
2073
+ options.twaReturnUrl = void 0;
2074
+ sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
2075
+ } else {
2076
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
2077
+ }
2078
+ } else {
2079
+ if (isOS("ios", "android")) {
2080
+ options.returnStrategy = "back";
2081
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options.returnStrategy));
2082
+ } else if (isOS("macos", "windows", "linux")) {
2083
+ options.returnStrategy = "none";
2084
+ options.twaReturnUrl = void 0;
2085
+ if (options.forceRedirect) {
2086
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
2087
+ } else {
2088
+ const link = addReturnStrategy(directLinkUrl.toString(), options);
2089
+ const deepLink = convertToDeepLink(link);
2090
+ openIframeLink(deepLink, () => openLinkBlank(link));
2091
+ }
2092
+ } else {
2093
+ openLinkBlank(addReturnStrategy(directLinkUrl.toString(), options));
2094
+ }
2095
+ }
2096
+ }
2097
+ function convertToDirectLink(universalLink) {
1887
2098
  const url = new URL(universalLink);
1888
- url.searchParams.append("startattach", "tonconnect");
1889
- openLinkBlank(addReturnStrategy(url.toString(), options));
2099
+ if (url.searchParams.has("attach")) {
2100
+ url.searchParams.delete("attach");
2101
+ url.pathname += "/start";
2102
+ }
2103
+ return url.toString();
1890
2104
  }
1891
- function isInTWA() {
1892
- var _a2;
1893
- return !!((_a2 = getWindow$1()) == null ? void 0 : _a2.TelegramWebviewProxy);
2105
+ function convertToDeepLink(directLink) {
2106
+ const parsed = new URL(directLink);
2107
+ const [, domain, appname] = parsed.pathname.split("/");
2108
+ const startapp = parsed.searchParams.get("startapp");
2109
+ return `tg://resolve?domain=${domain}&appname=${appname}&startapp=${startapp}`;
1894
2110
  }
1895
2111
  class WalletInfoStorage {
1896
2112
  constructor() {
@@ -2009,8 +2225,8 @@ const walletModal$1 = {
2009
2225
  wallets: "Wallets",
2010
2226
  mobileUniversalModal: {
2011
2227
  connectYourWallet: "Connect your wallet",
2012
- openWalletOnTelegramOrSelect: "Open Wallet on Telegram or\xA0select your\xA0wallet\xA0to\xA0connect",
2013
- openWalletOnTelegram: "Open Wallet on Telegram",
2228
+ openWalletOnTelegramOrSelect: "Open Wallet in Telegram or select your wallet to connect",
2229
+ openWalletOnTelegram: "Open Wallet in Telegram",
2014
2230
  openLink: "Open Link",
2015
2231
  scan: "Scan with your mobile wallet"
2016
2232
  },
@@ -2031,7 +2247,7 @@ const walletModal$1 = {
2031
2247
  dontHaveExtension: "Seems you don't have installed {{ name }}\xA0browser\xA0extension",
2032
2248
  getWallet: "Get {{ name }}",
2033
2249
  continueOnDesktop: "Continue in\xA0{{ name }} on desktop\u2026",
2034
- openWalletOnTelegram: "Open Wallet on Telegram on desktop",
2250
+ openWalletOnTelegram: "Open Wallet in Telegram on desktop",
2035
2251
  connectionDeclined: "Connection declined"
2036
2252
  },
2037
2253
  infoModal: {
@@ -2620,6 +2836,9 @@ function isDevice(device) {
2620
2836
  if (!window2) {
2621
2837
  return device === "desktop";
2622
2838
  }
2839
+ if (isTmaPlatform("weba")) {
2840
+ return true;
2841
+ }
2623
2842
  const width = window2.innerWidth;
2624
2843
  switch (device) {
2625
2844
  case "desktop":
@@ -3073,7 +3292,7 @@ function androidBackHandler$1(_, config) {
3073
3292
  });
3074
3293
  onCleanup(() => {
3075
3294
  window.removeEventListener("popstate", popstateHandler);
3076
- new Promise((resolve) => requestAnimationFrame(resolve)).then(() => {
3295
+ createMacrotask(() => {
3077
3296
  var _a2;
3078
3297
  if (((_a2 = window.history.state) == null ? void 0 : _a2[ROUTE_STATE_KEY]) === true) {
3079
3298
  window.history.back();
@@ -3292,14 +3511,6 @@ const ModalFooterStyled = styled.div`
3292
3511
  const QuestionButtonStyled = styled(IconButton)`
3293
3512
  background-color: ${(props) => rgba(props.theme.colors.icon.secondary, 0.12)};
3294
3513
  `;
3295
- function logWarning(...args) {
3296
- {
3297
- try {
3298
- console.warn("[TON_CONNECT_UI]", ...args);
3299
- } catch (e2) {
3300
- }
3301
- }
3302
- }
3303
3514
  class AnimationTimelineNoop {
3304
3515
  constructor() {
3305
3516
  __publicField(this, "currentTime", 0);
@@ -5350,11 +5561,16 @@ var qrcode$1 = { exports: {} };
5350
5561
  })(qrcode$1);
5351
5562
  const qrcode = qrcode$1.exports;
5352
5563
  function copyToClipboard(text) {
5353
- if (navigator == null ? void 0 : navigator.clipboard) {
5354
- return navigator.clipboard.writeText(text);
5355
- }
5356
- fallbackCopyTextToClipboard(text);
5357
- return Promise.resolve();
5564
+ return __async(this, null, function* () {
5565
+ try {
5566
+ if (!(navigator == null ? void 0 : navigator.clipboard)) {
5567
+ throw new TonConnectUIError("Clipboard API not available");
5568
+ }
5569
+ return yield navigator.clipboard.writeText(text);
5570
+ } catch (e2) {
5571
+ }
5572
+ fallbackCopyTextToClipboard(text);
5573
+ });
5358
5574
  }
5359
5575
  function fallbackCopyTextToClipboard(text) {
5360
5576
  const textArea = document.createElement("textarea");
@@ -8096,6 +8312,7 @@ const DesktopConnectionModal = (props) => {
8096
8312
  const [mode, setMode] = createSignal("mobile");
8097
8313
  const [connectionErrored, setConnectionErrored] = createSignal(false);
8098
8314
  const [universalLink, setUniversalLink] = createSignal();
8315
+ const [firstClick, setFirstClick] = createSignal(true);
8099
8316
  const connector = useContext(ConnectorContext);
8100
8317
  const unsubscribe = connector.onStatusChange(() => {
8101
8318
  }, () => {
@@ -8137,13 +8354,16 @@ const DesktopConnectionModal = (props) => {
8137
8354
  openLinkBlank(addReturnStrategy(universalLink(), appState.returnStrategy));
8138
8355
  };
8139
8356
  const onClickTelegram = () => {
8357
+ const forceRedirect = !firstClick();
8358
+ setFirstClick(false);
8140
8359
  setLastSelectedWalletInfo(__spreadProps(__spreadValues({}, props.wallet), {
8141
8360
  openMethod: "universal-link"
8142
8361
  }));
8143
- openLinkBlank(addReturnStrategy(universalLink(), {
8362
+ redirectToTelegram(universalLink(), {
8144
8363
  returnStrategy: appState.returnStrategy,
8145
- twaReturnUrl: appState.twaReturnUrl
8146
- }));
8364
+ twaReturnUrl: appState.twaReturnUrl,
8365
+ forceRedirect
8366
+ });
8147
8367
  };
8148
8368
  const onClickExtension = () => {
8149
8369
  setConnectionErrored(false);
@@ -8409,7 +8629,7 @@ const DesktopConnectionModal = (props) => {
8409
8629
  get children() {
8410
8630
  return createComponent(Translation, {
8411
8631
  translationKey: "walletModal.desktopConnectionModal.openWalletOnTelegram",
8412
- children: "Open Wallet on Telegram on desktop"
8632
+ children: "Open Wallet in Telegram on desktop"
8413
8633
  });
8414
8634
  }
8415
8635
  });
@@ -9046,6 +9266,7 @@ const MobileUniversalQR = (props) => {
9046
9266
  const _tmpl$$1 = /* @__PURE__ */ template$1(`<li></li>`), _tmpl$2 = /* @__PURE__ */ template$1(`<div data-tc-wallets-modal-universal-mobile="true"></div>`);
9047
9267
  const MobileUniversalModal = (props) => {
9048
9268
  const [showQR, setShowQR] = createSignal(false);
9269
+ const [firstClick, setFirstClick] = createSignal(true);
9049
9270
  const connector = appState.connector;
9050
9271
  const walletsList = () => props.walletsList.filter((w) => supportsMobile(w) && w.appName !== AT_WALLET_APP_NAME);
9051
9272
  const shouldShowMoreButton = () => walletsList().length > 7;
@@ -9077,10 +9298,13 @@ const MobileUniversalModal = (props) => {
9077
9298
  bridgeUrl: atWallet.bridgeUrl,
9078
9299
  universalLink: atWallet.universalLink
9079
9300
  }, props.additionalRequest);
9080
- openLinkBlank(addReturnStrategy(walletLink, {
9301
+ const forceRedirect = !firstClick();
9302
+ setFirstClick(false);
9303
+ redirectToTelegram(walletLink, {
9081
9304
  returnStrategy: appState.returnStrategy,
9082
- twaReturnUrl: appState.twaReturnUrl
9083
- }));
9305
+ twaReturnUrl: appState.twaReturnUrl,
9306
+ forceRedirect
9307
+ });
9084
9308
  };
9085
9309
  const onOpenQR = () => {
9086
9310
  setShowQR(true);
@@ -9126,7 +9350,7 @@ const MobileUniversalModal = (props) => {
9126
9350
  children: "Connect your wallet"
9127
9351
  }), createComponent(H2Styled$2, {
9128
9352
  translationKey: "walletModal.mobileUniversalModal.openWalletOnTelegramOrSelect",
9129
- children: "Open Wallet on Telegram or select your wallet to connect"
9353
+ children: "Open Wallet in Telegram or select your wallet to connect"
9130
9354
  }), createComponent(TelegramButtonStyled, {
9131
9355
  get leftIcon() {
9132
9356
  return createComponent(AtWalletIcon, {});
@@ -9143,7 +9367,7 @@ const MobileUniversalModal = (props) => {
9143
9367
  get children() {
9144
9368
  return createComponent(Translation, {
9145
9369
  translationKey: "walletModal.mobileUniversalModal.openWalletOnTelegram",
9146
- children: "Open Wallet on Telegram"
9370
+ children: "Open Wallet in Telegram"
9147
9371
  });
9148
9372
  }
9149
9373
  }), createComponent(UlStyled, {
@@ -9580,17 +9804,21 @@ const ButtonStyled = styled(Button)`
9580
9804
  const ActionModal = (props) => {
9581
9805
  const dataAttrs = useDataAttributes(props);
9582
9806
  const tonConnectUI = useContext(TonConnectUiContext);
9807
+ const [firstClick, setFirstClick] = createSignal(true);
9583
9808
  let universalLink;
9584
- if ((tonConnectUI == null ? void 0 : tonConnectUI.wallet) && "universalLink" in tonConnectUI.wallet && (tonConnectUI.wallet.openMethod === "universal-link" || isTelegramUrl(tonConnectUI.wallet.universalLink) && isInTWA())) {
9809
+ if ((tonConnectUI == null ? void 0 : tonConnectUI.wallet) && "universalLink" in tonConnectUI.wallet && (tonConnectUI.wallet.openMethod === "universal-link" || isTelegramUrl(tonConnectUI.wallet.universalLink) && isInTMA())) {
9585
9810
  universalLink = tonConnectUI.wallet.universalLink;
9586
9811
  }
9587
9812
  const onOpenWallet = () => {
9588
9813
  const currentAction = action();
9589
9814
  const returnStrategy = "returnStrategy" in currentAction ? currentAction.returnStrategy : appState.returnStrategy;
9590
9815
  if (isTelegramUrl(universalLink)) {
9816
+ const forceRedirect = !firstClick();
9817
+ setFirstClick(false);
9591
9818
  redirectToTelegram(universalLink, {
9592
9819
  returnStrategy,
9593
- twaReturnUrl: "twaReturnUrl" in currentAction ? currentAction.twaReturnUrl : appState.twaReturnUrl
9820
+ twaReturnUrl: "twaReturnUrl" in currentAction ? currentAction.twaReturnUrl : appState.twaReturnUrl,
9821
+ forceRedirect
9594
9822
  });
9595
9823
  } else {
9596
9824
  openLinkBlank(addReturnStrategy(universalLink, returnStrategy));
@@ -9855,6 +10083,9 @@ class WalletsModalManager {
9855
10083
  }
9856
10084
  connectExternalWallet() {
9857
10085
  return __async(this, null, function* () {
10086
+ if (isInTMA()) {
10087
+ sendExpand();
10088
+ }
9858
10089
  widgetController.openWalletsModal();
9859
10090
  return new Promise((resolve) => {
9860
10091
  const unsubscribe = this.onStateChange((state) => {
@@ -10053,21 +10284,30 @@ class TonConnectUI {
10053
10284
  if (!this.connected) {
10054
10285
  throw new TonConnectUIError("Connect wallet to send a transaction.");
10055
10286
  }
10056
- const { notifications: notifications2, modals, returnStrategy, twaReturnUrl, skipRedirectToWallet } = this.getModalsAndNotificationsConfiguration(options);
10057
- const userOSIsIos = getUserAgent().os === "ios";
10058
- const shouldSkipRedirectToWallet = skipRedirectToWallet === "ios" && userOSIsIos || skipRedirectToWallet === "always";
10059
- if (this.walletInfo && "universalLink" in this.walletInfo && this.walletInfo.openMethod === "universal-link" && !shouldSkipRedirectToWallet) {
10060
- if (isTelegramUrl(this.walletInfo.universalLink)) {
10061
- redirectToTelegram(this.walletInfo.universalLink, { returnStrategy, twaReturnUrl });
10062
- } else {
10063
- openLinkBlank(addReturnStrategy(this.walletInfo.universalLink, returnStrategy));
10064
- }
10287
+ if (isInTMA()) {
10288
+ sendExpand();
10065
10289
  }
10290
+ const { notifications: notifications2, modals, returnStrategy, twaReturnUrl, skipRedirectToWallet } = this.getModalsAndNotificationsConfiguration(options);
10066
10291
  widgetController.setAction({
10067
10292
  name: "confirm-transaction",
10068
10293
  showNotification: notifications2.includes("before"),
10069
10294
  openModal: modals.includes("before")
10070
10295
  });
10296
+ const onRequestSent = () => {
10297
+ const userOSIsIos = getUserAgent().os === "ios";
10298
+ const shouldSkipRedirectToWallet = skipRedirectToWallet === "ios" && userOSIsIos || skipRedirectToWallet === "always";
10299
+ if (this.walletInfo && "universalLink" in this.walletInfo && this.walletInfo.openMethod === "universal-link" && !shouldSkipRedirectToWallet) {
10300
+ if (isTelegramUrl(this.walletInfo.universalLink)) {
10301
+ redirectToTelegram(this.walletInfo.universalLink, {
10302
+ returnStrategy,
10303
+ twaReturnUrl: twaReturnUrl || appState.twaReturnUrl,
10304
+ forceRedirect: false
10305
+ });
10306
+ } else {
10307
+ openLinkBlank(addReturnStrategy(this.walletInfo.universalLink, returnStrategy));
10308
+ }
10309
+ }
10310
+ };
10071
10311
  const abortController = new AbortController();
10072
10312
  const unsubscribe = this.onTransactionModalStateChange((action2) => {
10073
10313
  if (action2 == null ? void 0 : action2.openModal) {
@@ -10079,10 +10319,13 @@ class TonConnectUI {
10079
10319
  }
10080
10320
  });
10081
10321
  try {
10082
- const result = yield this.waitForSendTransaction({
10083
- transaction: tx,
10084
- abortSignal: abortController.signal
10085
- });
10322
+ const result = yield this.waitForSendTransaction(
10323
+ {
10324
+ transaction: tx,
10325
+ abortSignal: abortController.signal
10326
+ },
10327
+ onRequestSent
10328
+ );
10086
10329
  widgetController.setAction({
10087
10330
  name: "transaction-sent",
10088
10331
  showNotification: notifications2.includes("success"),
@@ -10182,7 +10425,7 @@ class TonConnectUI {
10182
10425
  });
10183
10426
  });
10184
10427
  }
10185
- waitForSendTransaction(options) {
10428
+ waitForSendTransaction(options, onRequestSent) {
10186
10429
  return __async(this, null, function* () {
10187
10430
  return new Promise((resolve, reject) => {
10188
10431
  const { transaction, abortSignal } = options;
@@ -10195,7 +10438,7 @@ class TonConnectUI {
10195
10438
  const onErrorsHandler = (reason) => {
10196
10439
  reject(reason);
10197
10440
  };
10198
- this.connector.sendTransaction(transaction).then((result) => onTransactionHandler(result)).catch((reason) => onErrorsHandler(reason));
10441
+ this.connector.sendTransaction(transaction, onRequestSent).then((result) => onTransactionHandler(result)).catch((reason) => onErrorsHandler(reason));
10199
10442
  abortSignal.addEventListener("abort", () => {
10200
10443
  reject(new TonConnectUIError("Transaction was not sent"));
10201
10444
  });
@@ -10315,7 +10558,10 @@ class TonConnectUI {
10315
10558
  }
10316
10559
  const returnStrategy = (options == null ? void 0 : options.returnStrategy) || ((_d = this.actionsConfiguration) == null ? void 0 : _d.returnStrategy) || "back";
10317
10560
  const twaReturnUrl = (options == null ? void 0 : options.twaReturnUrl) || ((_e = this.actionsConfiguration) == null ? void 0 : _e.twaReturnUrl);
10318
- const skipRedirectToWallet = (options == null ? void 0 : options.skipRedirectToWallet) || ((_f = this.actionsConfiguration) == null ? void 0 : _f.skipRedirectToWallet) || "ios";
10561
+ let skipRedirectToWallet = (options == null ? void 0 : options.skipRedirectToWallet) || ((_f = this.actionsConfiguration) == null ? void 0 : _f.skipRedirectToWallet) || "ios";
10562
+ if (isInTMA()) {
10563
+ skipRedirectToWallet = "never";
10564
+ }
10319
10565
  return {
10320
10566
  notifications: notifications2,
10321
10567
  modals,