@tonconnect/ui 2.3.0-beta.2 → 2.3.0-beta.4

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
@@ -475,6 +475,11 @@ declare class TonConnectUI {
475
475
  signData(data: SignDataPayload, options?: {
476
476
  onRequestSent?: (redirectToWallet: () => void) => void;
477
477
  }): Promise<SignDataResponse>;
478
+ /**
479
+ * Gets the current session ID if available.
480
+ * @returns session ID string or null if not available.
481
+ */
482
+ private getSessionId;
478
483
  private redirectAfterRequestSent;
479
484
  /**
480
485
  * TODO: remove in the next major version.
package/lib/index.mjs CHANGED
@@ -50,7 +50,7 @@ var __async = (__this, __arguments, generator) => {
50
50
  });
51
51
  };
52
52
  var _a, _b, _c, _d, _e, _f, _g, _h;
53
- import { TonConnectError, isWalletInfoCurrentlyInjected, toUserFriendlyAddress, CHAIN, TonConnect, isTelegramUrl, encodeTelegramUrlParameters, WalletMissingRequiredFeaturesError, isWalletInfoRemote, checkRequiredWalletFeatures, isWalletInfoCurrentlyEmbedded, BrowserEventDispatcher, createVersionInfo, createResponseVersionEvent, createRequestVersionEvent, createConnectionStartedEvent, createConnectionCompletedEvent, createConnectionErrorEvent, createConnectionRestoringStartedEvent, createConnectionRestoringCompletedEvent, createConnectionRestoringErrorEvent, createDisconnectionEvent, createTransactionSentForSignatureEvent, createTransactionSignedEvent, createTransactionSigningFailedEvent, createDataSentForSignatureEvent, createDataSignedEvent, createDataSigningFailedEvent, WalletNotSupportFeatureError } from "@tonconnect/sdk";
53
+ import { TonConnectError, isWalletInfoCurrentlyInjected, toUserFriendlyAddress, CHAIN, TonConnect, isTelegramUrl, encodeTelegramUrlParameters, WalletMissingRequiredFeaturesError, isWalletInfoRemote, checkRequiredWalletFeatures, isWalletInfoCurrentlyEmbedded, BrowserEventDispatcher, createVersionInfo, createResponseVersionEvent, createRequestVersionEvent, createConnectionStartedEvent, createConnectionCompletedEvent, createConnectionErrorEvent, createConnectionRestoringStartedEvent, createConnectionRestoringCompletedEvent, createConnectionRestoringErrorEvent, createDisconnectionEvent, createTransactionSentForSignatureEvent, createTransactionSignedEvent, createTransactionSigningFailedEvent, createDataSentForSignatureEvent, createDataSignedEvent, createDataSigningFailedEvent, WalletNotSupportFeatureError, SessionCrypto } from "@tonconnect/sdk";
54
54
  export * from "@tonconnect/sdk";
55
55
  import UAParser from "ua-parser-js";
56
56
  import deepmerge from "deepmerge";
@@ -1753,6 +1753,9 @@ function disableScroll() {
1753
1753
  document.body.classList.add(disableScrollClass);
1754
1754
  }
1755
1755
  function enableScroll() {
1756
+ if (!document.body.classList.contains(disableScrollClass)) {
1757
+ return;
1758
+ }
1756
1759
  document.body.classList.remove(disableScrollClass);
1757
1760
  document.documentElement.scrollTo({ top: -parseFloat(getComputedStyle(document.body).top) });
1758
1761
  document.body.style.top = "auto";
@@ -5679,7 +5682,6 @@ const WalletItemStyled = styled.button`
5679
5682
  border: none;
5680
5683
  background-color: unset;
5681
5684
  padding: 8px 4px;
5682
- width: 100%;
5683
5685
  min-width: 78px;
5684
5686
  display: flex;
5685
5687
  flex-direction: column;
@@ -8942,16 +8944,19 @@ function redirectToTelegram(universalLink, options) {
8942
8944
  }
8943
8945
  if (isInTelegramBrowser()) {
8944
8946
  options.returnStrategy = "back";
8945
- const linkWitStrategy = addReturnStrategy(directLinkUrl.toString(), options.returnStrategy);
8946
- openLinkBlank(linkWitStrategy);
8947
+ const linkWithStrategy = addReturnStrategy(
8948
+ directLinkUrl.toString(),
8949
+ options.returnStrategy
8950
+ );
8951
+ openLinkBlank(linkWithStrategy);
8947
8952
  } else if (isInTMA()) {
8948
8953
  if (isTmaPlatform("ios", "android", "macos", "tdesktop", "web")) {
8949
8954
  options.returnStrategy = "back";
8950
- const linkWitStrategy = addReturnStrategy(
8955
+ const linkWithStrategy = addReturnStrategy(
8951
8956
  directLinkUrl.toString(),
8952
8957
  options.returnStrategy
8953
8958
  );
8954
- sendOpenTelegramLink(linkWitStrategy);
8959
+ sendOpenTelegramLink(linkWithStrategy);
8955
8960
  } else if (isTmaPlatform("weba")) {
8956
8961
  sendOpenTelegramLink(addReturnStrategy(directLinkUrl.toString(), options));
8957
8962
  } else {
@@ -9064,8 +9069,8 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
9064
9069
  openLink(addReturnStrategy(universalLink, options.returnStrategy), "_self");
9065
9070
  } else {
9066
9071
  setOpenMethod("universal-link");
9067
- const linkWitStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9068
- openLinkBlank(linkWitStrategy);
9072
+ const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9073
+ openLinkBlank(linkWithStrategy);
9069
9074
  }
9070
9075
  } else if (isInTMA()) {
9071
9076
  if (isTmaPlatform("ios", "android")) {
@@ -9073,26 +9078,26 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
9073
9078
  options.returnStrategy = "tg://resolve";
9074
9079
  }
9075
9080
  setOpenMethod("universal-link");
9076
- const linkWitStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9077
- sendOpenTelegramLink(linkWitStrategy, () => {
9081
+ const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9082
+ sendOpenTelegramLink(linkWithStrategy, () => {
9078
9083
  setOpenMethod("universal-link");
9079
- openLinkBlank(linkWitStrategy);
9084
+ openLinkBlank(linkWithStrategy);
9080
9085
  });
9081
9086
  } else if (isTmaPlatform("macos", "tdesktop")) {
9082
9087
  if (options.returnStrategy === "back") {
9083
9088
  options.returnStrategy = "tg://resolve";
9084
9089
  }
9085
- const linkWitStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9090
+ const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9086
9091
  const useDeepLink = !!deepLink && !options.forceRedirect;
9087
9092
  if (useDeepLink) {
9088
9093
  setOpenMethod("custom-deeplink");
9089
- openDeeplinkWithFallback(toDeeplink(linkWitStrategy, deepLink), () => {
9094
+ openDeeplinkWithFallback(toDeeplink(linkWithStrategy, deepLink), () => {
9090
9095
  setOpenMethod("universal-link");
9091
- openLinkBlank(linkWitStrategy);
9096
+ openLinkBlank(linkWithStrategy);
9092
9097
  });
9093
9098
  } else {
9094
9099
  setOpenMethod("universal-link");
9095
- openLinkBlank(linkWitStrategy);
9100
+ openLinkBlank(linkWithStrategy);
9096
9101
  }
9097
9102
  } else if (isTmaPlatform("weba")) {
9098
9103
  if (options.returnStrategy === "back") {
@@ -9108,17 +9113,17 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
9108
9113
  options.returnStrategy = location.href;
9109
9114
  }
9110
9115
  }
9111
- const linkWitStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9116
+ const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9112
9117
  const useDeepLink = !!deepLink && !options.forceRedirect;
9113
9118
  if (useDeepLink) {
9114
9119
  setOpenMethod("custom-deeplink");
9115
- openDeeplinkWithFallback(toDeeplink(linkWitStrategy, deepLink), () => {
9120
+ openDeeplinkWithFallback(toDeeplink(linkWithStrategy, deepLink), () => {
9116
9121
  setOpenMethod("universal-link");
9117
- openLinkBlank(linkWitStrategy);
9122
+ openLinkBlank(linkWithStrategy);
9118
9123
  });
9119
9124
  } else {
9120
9125
  setOpenMethod("universal-link");
9121
- openLinkBlank(linkWitStrategy);
9126
+ openLinkBlank(linkWithStrategy);
9122
9127
  }
9123
9128
  } else if (isTmaPlatform("web")) {
9124
9129
  if (options.returnStrategy === "back") {
@@ -9134,22 +9139,22 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
9134
9139
  options.returnStrategy = location.href;
9135
9140
  }
9136
9141
  }
9137
- const linkWitStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9142
+ const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9138
9143
  const useDeepLink = !!deepLink && !options.forceRedirect;
9139
9144
  if (useDeepLink) {
9140
9145
  setOpenMethod("custom-deeplink");
9141
- openDeeplinkWithFallback(toDeeplink(linkWitStrategy, deepLink), () => {
9146
+ openDeeplinkWithFallback(toDeeplink(linkWithStrategy, deepLink), () => {
9142
9147
  setOpenMethod("universal-link");
9143
- openLinkBlank(linkWitStrategy);
9148
+ openLinkBlank(linkWithStrategy);
9144
9149
  });
9145
9150
  } else {
9146
9151
  setOpenMethod("universal-link");
9147
- openLinkBlank(linkWitStrategy);
9152
+ openLinkBlank(linkWithStrategy);
9148
9153
  }
9149
9154
  } else {
9150
9155
  setOpenMethod("universal-link");
9151
- const linkWitStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9152
- openLinkBlank(linkWitStrategy);
9156
+ const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9157
+ openLinkBlank(linkWithStrategy);
9153
9158
  }
9154
9159
  } else {
9155
9160
  if (isOS("ios")) {
@@ -9222,17 +9227,17 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
9222
9227
  options.returnStrategy = "none";
9223
9228
  }
9224
9229
  }
9225
- const linkWitStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9230
+ const linkWithStrategy = addReturnStrategy(universalLink, options.returnStrategy);
9226
9231
  const useDeepLink = !!deepLink && !options.forceRedirect;
9227
9232
  if (useDeepLink) {
9228
9233
  setOpenMethod("custom-deeplink");
9229
- openDeeplinkWithFallback(toDeeplink(linkWitStrategy, deepLink), () => {
9234
+ openDeeplinkWithFallback(toDeeplink(linkWithStrategy, deepLink), () => {
9230
9235
  setOpenMethod("universal-link");
9231
- openLinkBlank(linkWitStrategy);
9236
+ openLinkBlank(linkWithStrategy);
9232
9237
  });
9233
9238
  } else {
9234
9239
  setOpenMethod("universal-link");
9235
- openLinkBlank(linkWitStrategy);
9240
+ openLinkBlank(linkWithStrategy);
9236
9241
  }
9237
9242
  } else {
9238
9243
  setOpenMethod("universal-link");
@@ -9240,6 +9245,23 @@ function redirectToWallet(universalLink, deepLink, options, setOpenMethod) {
9240
9245
  }
9241
9246
  }
9242
9247
  }
9248
+ function addSessionIdToUniversalLink(universalLink, sessionId) {
9249
+ if (!sessionId) {
9250
+ return universalLink;
9251
+ }
9252
+ if (!isTelegramUrl(universalLink)) {
9253
+ const newUrl2 = addQueryParameter(universalLink, "id", sessionId);
9254
+ return newUrl2;
9255
+ }
9256
+ const directLink = convertToTGDirectLink(universalLink);
9257
+ const directLinkUrl = new URL(directLink);
9258
+ if (!directLinkUrl.searchParams.has("startapp")) {
9259
+ directLinkUrl.searchParams.append("startapp", "tonconnect");
9260
+ }
9261
+ const newUrl = addQueryParameter(directLinkUrl.toString(), "id", sessionId);
9262
+ const lastParam = newUrl.slice(newUrl.lastIndexOf("&") + 1);
9263
+ return newUrl.slice(0, newUrl.lastIndexOf("&")) + "-v__2-" + encodeTelegramUrlParameters(lastParam);
9264
+ }
9243
9265
  function addQueryParameter(url, key, value) {
9244
9266
  const parsed = new URL(url);
9245
9267
  parsed.searchParams.append(key, value);
@@ -11307,6 +11329,7 @@ const WalletsModal = () => {
11307
11329
  createEffect(() => {
11308
11330
  if (getWalletsModalIsOpened()) {
11309
11331
  updateIsMobile();
11332
+ refetchWallets();
11310
11333
  } else {
11311
11334
  setSelectedWalletInfo(null);
11312
11335
  setSelectedTab("universal");
@@ -11315,7 +11338,11 @@ const WalletsModal = () => {
11315
11338
  });
11316
11339
  const connector = useContext(ConnectorContext);
11317
11340
  const tonConnectUI = useContext(TonConnectUiContext);
11318
- const [fetchedWalletsList] = createResource(() => tonConnectUI.getWallets());
11341
+ const [fetchedWalletsList, {
11342
+ refetch: refetchWallets
11343
+ }] = createResource(() => {
11344
+ return tonConnectUI.getWallets();
11345
+ });
11319
11346
  const [selectedWalletInfo, setSelectedWalletInfo] = createSignal(null);
11320
11347
  const [selectedWalletError, setSelectedWalletError] = createSignal(null);
11321
11348
  const [selectedTab, setSelectedTab] = createSignal("universal");
@@ -11598,14 +11625,15 @@ const ActionModal = (props) => {
11598
11625
  const returnStrategy = "returnStrategy" in currentAction ? currentAction.returnStrategy : appState.returnStrategy;
11599
11626
  const forceRedirect = !firstClick();
11600
11627
  setFirstClick(false);
11628
+ const linkWithSessionId = addSessionIdToUniversalLink(universalLink, currentAction.sessionId);
11601
11629
  if (isTelegramUrl(universalLink)) {
11602
- redirectToTelegram(universalLink, {
11630
+ redirectToTelegram(linkWithSessionId, {
11603
11631
  returnStrategy,
11604
11632
  twaReturnUrl: "twaReturnUrl" in currentAction ? currentAction.twaReturnUrl : appState.twaReturnUrl,
11605
11633
  forceRedirect
11606
11634
  });
11607
11635
  } else {
11608
- redirectToWallet(universalLink, deepLink, {
11636
+ redirectToWallet(linkWithSessionId, deepLink, {
11609
11637
  returnStrategy,
11610
11638
  forceRedirect
11611
11639
  }, () => {
@@ -12468,7 +12496,7 @@ class TonConnectUITracker {
12468
12496
  }
12469
12497
  }
12470
12498
  }
12471
- const tonConnectUiVersion = "2.3.0-beta.2";
12499
+ const tonConnectUiVersion = "2.3.0-beta.4";
12472
12500
  class TonConnectUI {
12473
12501
  // TODO: `actionsConfiguration.twaReturnUrl` is used only in `connectWallet` method, but it's not used in `sendTransaction` method, NEED TO FIX IT
12474
12502
  constructor(options) {
@@ -12755,11 +12783,13 @@ class TonConnectUI {
12755
12783
  sendExpand();
12756
12784
  }
12757
12785
  const { notifications: notifications2, modals, returnStrategy, twaReturnUrl } = this.getModalsAndNotificationsConfiguration(options);
12786
+ const sessionId = yield this.getSessionId();
12758
12787
  widgetController.setAction({
12759
12788
  name: "confirm-transaction",
12760
12789
  showNotification: notifications2.includes("before"),
12761
12790
  openModal: modals.includes("before"),
12762
- sent: false
12791
+ sent: false,
12792
+ sessionId: sessionId || void 0
12763
12793
  });
12764
12794
  const abortController = new AbortController();
12765
12795
  const onRequestSent = () => {
@@ -12771,25 +12801,28 @@ class TonConnectUI {
12771
12801
  name: "confirm-transaction",
12772
12802
  showNotification: notifications2.includes("before"),
12773
12803
  openModal: modals.includes("before"),
12774
- sent: true
12804
+ sent: true,
12805
+ sessionId: sessionId || void 0
12775
12806
  });
12776
12807
  this.redirectAfterRequestSent({
12777
12808
  returnStrategy,
12778
- twaReturnUrl
12809
+ twaReturnUrl,
12810
+ sessionId: sessionId || void 0
12779
12811
  });
12780
12812
  let firstClick = true;
12781
- const redirectToWallet2 = () => {
12813
+ const redirectToWallet2 = () => __async(this, null, function* () {
12782
12814
  if (abortController.signal.aborted) {
12783
12815
  return;
12784
12816
  }
12785
12817
  const forceRedirect = !firstClick;
12786
12818
  firstClick = false;
12787
- this.redirectAfterRequestSent({
12819
+ yield this.redirectAfterRequestSent({
12788
12820
  returnStrategy,
12789
12821
  twaReturnUrl,
12790
- forceRedirect
12822
+ forceRedirect,
12823
+ sessionId: sessionId || void 0
12791
12824
  });
12792
- };
12825
+ });
12793
12826
  (_a2 = options == null ? void 0 : options.onRequestSent) == null ? void 0 : _a2.call(options, redirectToWallet2);
12794
12827
  };
12795
12828
  const unsubscribe = this.onTransactionModalStateChange((action2) => {
@@ -12853,11 +12886,13 @@ class TonConnectUI {
12853
12886
  sendExpand();
12854
12887
  }
12855
12888
  const { notifications: notifications2, modals, returnStrategy, twaReturnUrl } = this.getModalsAndNotificationsConfiguration();
12889
+ const sessionId = yield this.getSessionId();
12856
12890
  widgetController.setAction({
12857
12891
  name: "confirm-sign-data",
12858
12892
  showNotification: notifications2.includes("before"),
12859
12893
  openModal: modals.includes("before"),
12860
- signed: false
12894
+ signed: false,
12895
+ sessionId: sessionId || void 0
12861
12896
  });
12862
12897
  const abortController = new AbortController();
12863
12898
  const onRequestSent = () => {
@@ -12869,11 +12904,13 @@ class TonConnectUI {
12869
12904
  name: "confirm-sign-data",
12870
12905
  showNotification: notifications2.includes("before"),
12871
12906
  openModal: modals.includes("before"),
12872
- signed: true
12907
+ signed: true,
12908
+ sessionId: sessionId || void 0
12873
12909
  });
12874
12910
  this.redirectAfterRequestSent({
12875
12911
  returnStrategy,
12876
- twaReturnUrl
12912
+ twaReturnUrl,
12913
+ sessionId: sessionId || void 0
12877
12914
  });
12878
12915
  let firstClick = true;
12879
12916
  const redirectToWallet2 = () => {
@@ -12885,7 +12922,8 @@ class TonConnectUI {
12885
12922
  this.redirectAfterRequestSent({
12886
12923
  returnStrategy,
12887
12924
  twaReturnUrl,
12888
- forceRedirect
12925
+ forceRedirect,
12926
+ sessionId: sessionId || void 0
12889
12927
  });
12890
12928
  };
12891
12929
  (_a2 = options == null ? void 0 : options.onRequestSent) == null ? void 0 : _a2.call(options, redirectToWallet2);
@@ -12936,21 +12974,58 @@ class TonConnectUI {
12936
12974
  }
12937
12975
  });
12938
12976
  }
12977
+ /**
12978
+ * Gets the current session ID if available.
12979
+ * @returns session ID string or null if not available.
12980
+ */
12981
+ getSessionId() {
12982
+ return __async(this, null, function* () {
12983
+ var _a2, _b2;
12984
+ if (!this.connected) {
12985
+ return null;
12986
+ }
12987
+ try {
12988
+ const storage = (_a2 = this.connector.dappSettings) == null ? void 0 : _a2.storage;
12989
+ if (storage) {
12990
+ const stored = yield storage.getItem("ton-connect-storage_bridge-connection");
12991
+ if (stored) {
12992
+ const connection = JSON.parse(stored);
12993
+ if (connection.type === "http" && connection.sessionCrypto) {
12994
+ const sessionCrypto = new SessionCrypto(connection.sessionCrypto);
12995
+ const sessionId = sessionCrypto.sessionId;
12996
+ return sessionId;
12997
+ } else if (connection.type === "http" && ((_b2 = connection.session) == null ? void 0 : _b2.sessionKeyPair)) {
12998
+ const sessionCrypto = new SessionCrypto(connection.session.sessionKeyPair);
12999
+ const sessionId = sessionCrypto.sessionId;
13000
+ return sessionId;
13001
+ }
13002
+ }
13003
+ }
13004
+ } catch (e2) {
13005
+ }
13006
+ return null;
13007
+ });
13008
+ }
12939
13009
  redirectAfterRequestSent({
12940
13010
  returnStrategy,
12941
13011
  twaReturnUrl,
12942
- forceRedirect
13012
+ forceRedirect,
13013
+ sessionId
12943
13014
  }) {
12944
13015
  if (this.walletInfo && "universalLink" in this.walletInfo && (this.walletInfo.openMethod === "universal-link" || this.walletInfo.openMethod === "custom-deeplink")) {
13016
+ const linkWithSessionId = addSessionIdToUniversalLink(
13017
+ this.walletInfo.universalLink,
13018
+ sessionId
13019
+ );
12945
13020
  if (isTelegramUrl(this.walletInfo.universalLink)) {
12946
- redirectToTelegram(this.walletInfo.universalLink, {
13021
+ redirectToTelegram(linkWithSessionId, {
12947
13022
  returnStrategy,
12948
13023
  twaReturnUrl: twaReturnUrl || appState.twaReturnUrl,
12949
13024
  forceRedirect: forceRedirect || false
12950
13025
  });
12951
13026
  } else {
12952
13027
  redirectToWallet(
12953
- this.walletInfo.universalLink,
13028
+ linkWithSessionId,
12954
13029
  this.walletInfo.deepLink,
12955
13030
  {
12956
13031
  returnStrategy,