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