@tonconnect/ui 2.0.3-beta.1 → 2.0.3-beta.3

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
@@ -1,4 +1,4 @@
1
- import { WalletInfoBase, WalletInfoInjectable, WalletInfoRemote, ConnectionEvent, ConnectionRestoringEvent, DisconnectionEvent, TransactionSigningEvent, ITonConnect, EventDispatcher, SdkActionEvent, Wallet, WalletInfo, Account, ConnectAdditionalRequest, TonConnectError, SendTransactionRequest, SendTransactionResponse } from '@tonconnect/sdk';
1
+ import { WalletInfoBase, WalletInfoInjectable, WalletInfoRemote, VersionEvent, ConnectionEvent, ConnectionRestoringEvent, DisconnectionEvent, TransactionSigningEvent, ITonConnect, EventDispatcher, SdkActionEvent, Wallet, WalletInfo, Account, ConnectAdditionalRequest, TonConnectError, SendTransactionRequest, SendTransactionResponse } from '@tonconnect/sdk';
2
2
  export * from '@tonconnect/sdk';
3
3
  import { Property } from 'csstype';
4
4
 
@@ -171,7 +171,7 @@ interface TonConnectUiOptions {
171
171
  /**
172
172
  * User action events.
173
173
  */
174
- declare type UserActionEvent = ConnectionEvent | ConnectionRestoringEvent | DisconnectionEvent | TransactionSigningEvent;
174
+ declare type UserActionEvent = VersionEvent | ConnectionEvent | ConnectionRestoringEvent | DisconnectionEvent | TransactionSigningEvent;
175
175
 
176
176
  declare type TonConnectUiCreateOptions = TonConnectUiOptionsWithConnector | TonConnectUiOptionsWithManifest;
177
177
  interface TonConnectUiOptionsWithManifest extends TonConnectUiCreateOptionsBase {
package/lib/index.mjs CHANGED
@@ -42,7 +42,7 @@ var __async = (__this, __arguments, generator) => {
42
42
  });
43
43
  };
44
44
  var _a, _b, _c, _d, _e, _f, _g, _h;
45
- import { TonConnectError, isWalletInfoCurrentlyInjected, toUserFriendlyAddress, CHAIN, TonConnect, isTelegramUrl, encodeTelegramUrlParameters, isWalletInfoRemote, isWalletInfoCurrentlyEmbedded, BrowserEventDispatcher, createConnectionStartedEvent, createConnectionCompletedEvent, createConnectionErrorEvent, createConnectionRestoringStartedEvent, createConnectionRestoringCompletedEvent, createConnectionRestoringErrorEvent, createDisconnectionEvent, createTransactionSentForSignatureEvent, createTransactionSignedEvent, createTransactionSigningFailedEvent } from "@tonconnect/sdk";
45
+ import { TonConnectError, isWalletInfoCurrentlyInjected, toUserFriendlyAddress, CHAIN, TonConnect, isTelegramUrl, encodeTelegramUrlParameters, isWalletInfoRemote, isWalletInfoCurrentlyEmbedded, createVersionInfo, BrowserEventDispatcher, createResponseVersionEvent, createRequestVersionEvent, createConnectionStartedEvent, createConnectionCompletedEvent, createConnectionErrorEvent, createConnectionRestoringStartedEvent, createConnectionRestoringCompletedEvent, createConnectionRestoringErrorEvent, createDisconnectionEvent, createTransactionSentForSignatureEvent, createTransactionSignedEvent, createTransactionSigningFailedEvent } from "@tonconnect/sdk";
46
46
  export * from "@tonconnect/sdk";
47
47
  import UAParser from "ua-parser-js";
48
48
  import deepmerge from "deepmerge";
@@ -1829,6 +1829,12 @@ function createMacrotask(callback) {
1829
1829
  callback();
1830
1830
  });
1831
1831
  }
1832
+ function createMacrotaskAsync(callback) {
1833
+ return __async(this, null, function* () {
1834
+ yield new Promise((resolve) => requestAnimationFrame(resolve));
1835
+ return callback();
1836
+ });
1837
+ }
1832
1838
  function preloadImages(images) {
1833
1839
  if (document.readyState !== "complete") {
1834
1840
  window.addEventListener("load", () => createMacrotask(() => preloadImages(images)), {
@@ -7159,7 +7165,7 @@ const computePosition$1 = (reference, floating, config) => __async(void 0, null,
7159
7165
  } = config;
7160
7166
  const validMiddleware = middleware.filter(Boolean);
7161
7167
  const rtl = yield platform2.isRTL == null ? void 0 : platform2.isRTL(floating);
7162
- if ({}.NODE_ENV !== "production") {
7168
+ if (process.env.NODE_ENV !== "production") {
7163
7169
  if (platform2 == null) {
7164
7170
  console.error(["Floating UI: `platform` property was not passed to config. If you", "want to use Floating UI on the web, install @floating-ui/dom", "instead of the /core package. Otherwise, you can create your own", "`platform`: https://floating-ui.com/docs/platform"].join(" "));
7165
7171
  }
@@ -7216,7 +7222,7 @@ const computePosition$1 = (reference, floating, config) => __async(void 0, null,
7216
7222
  middlewareData = __spreadProps(__spreadValues({}, middlewareData), {
7217
7223
  [name]: __spreadValues(__spreadValues({}, middlewareData[name]), data)
7218
7224
  });
7219
- if ({}.NODE_ENV !== "production") {
7225
+ if (process.env.NODE_ENV !== "production") {
7220
7226
  if (resetCount > 50) {
7221
7227
  console.warn(["Floating UI: The middleware lifecycle appears to be running in an", "infinite loop. This is usually caused by a `reset` continually", "being returned without a break condition."].join(" "));
7222
7228
  }
@@ -8643,10 +8649,14 @@ const DesktopConnectionModal = (props) => {
8643
8649
  });
8644
8650
  onCleanup(unsubscribe);
8645
8651
  const generateUniversalLink = () => {
8646
- setUniversalLink(connector.connect({
8647
- universalLink: props.wallet.universalLink,
8648
- bridgeUrl: props.wallet.bridgeUrl
8649
- }, props.additionalRequest));
8652
+ try {
8653
+ const universalLink2 = connector.connect({
8654
+ universalLink: props.wallet.universalLink,
8655
+ bridgeUrl: props.wallet.bridgeUrl
8656
+ }, props.additionalRequest);
8657
+ setUniversalLink(universalLink2);
8658
+ } catch (e2) {
8659
+ }
8650
8660
  };
8651
8661
  createEffect(() => {
8652
8662
  if (untrack(mode) !== "extension" && (supportsMobile(props.wallet) || supportsDesktop(props.wallet))) {
@@ -9626,6 +9636,17 @@ const MobileUniversalQR = (props) => {
9626
9636
  }
9627
9637
  })];
9628
9638
  };
9639
+ function getUniqueBridges(walletsList) {
9640
+ const uniqueBridges = new Set(
9641
+ walletsList.filter(isWalletInfoRemote).map((item) => item.bridgeUrl)
9642
+ );
9643
+ return Array.from(uniqueBridges).map((bridgeUrl) => ({ bridgeUrl }));
9644
+ }
9645
+ function bridgesIsEqual(left, right) {
9646
+ const leftSet = new Set(left == null ? void 0 : left.map((i2) => i2.bridgeUrl));
9647
+ const rightSet = new Set(right == null ? void 0 : right.map((i2) => i2.bridgeUrl));
9648
+ return leftSet.size === rightSet.size && [...leftSet].every((value) => rightSet.has(value));
9649
+ }
9629
9650
  const _tmpl$$1 = /* @__PURE__ */ template$1(`<li></li>`), _tmpl$2 = /* @__PURE__ */ template$1(`<div data-tc-wallets-modal-universal-mobile="true"></div>`);
9630
9651
  const MobileUniversalModal = (props) => {
9631
9652
  const [showQR, setShowQR] = createSignal(false);
@@ -9633,10 +9654,10 @@ const MobileUniversalModal = (props) => {
9633
9654
  const connector = appState.connector;
9634
9655
  const walletsList = () => props.walletsList.filter((w) => supportsMobile(w) && w.appName !== AT_WALLET_APP_NAME);
9635
9656
  const shouldShowMoreButton = () => walletsList().length > 7;
9636
- const walletsBridges = () => [...new Set(props.walletsList.filter(isWalletInfoRemote).map((item) => item.bridgeUrl)).values()].map((bridgeUrl) => ({
9637
- bridgeUrl
9638
- }));
9639
- const getUniversalLink = () => connector.connect(walletsBridges(), props.additionalRequest);
9657
+ const walletsBridges = createMemo(() => getUniqueBridges(props.walletsList), null, {
9658
+ equals: bridgesIsEqual
9659
+ });
9660
+ const getUniversalLink = createMemo(() => connector.connect(walletsBridges(), props.additionalRequest));
9640
9661
  setLastSelectedWalletInfo({
9641
9662
  openMethod: "universal-link"
9642
9663
  });
@@ -9924,9 +9945,9 @@ const _tmpl$ = /* @__PURE__ */ template$1(`<li></li>`);
9924
9945
  const DesktopUniversalModal = (props) => {
9925
9946
  const [popupOpened, setPopupOpened] = createSignal(false);
9926
9947
  const connector = appState.connector;
9927
- const walletsBridges = () => [...new Set(props.walletsList.filter(isWalletInfoRemote).map((item) => item.bridgeUrl)).values()].map((bridgeUrl) => ({
9928
- bridgeUrl
9929
- }));
9948
+ const walletsBridges = createMemo(() => getUniqueBridges(props.walletsList), null, {
9949
+ equals: bridgesIsEqual
9950
+ });
9930
9951
  setLastSelectedWalletInfo({
9931
9952
  openMethod: "qrcode"
9932
9953
  });
@@ -9988,6 +10009,9 @@ const WalletsModal = () => {
9988
10009
  createEffect(() => locale(appState.language));
9989
10010
  createEffect(() => {
9990
10011
  if (getWalletsModalIsOpened()) {
10012
+ setSelectedWalletInfo(null);
10013
+ setSelectedTab("universal");
10014
+ setInfoTab(false);
9991
10015
  updateIsMobile();
9992
10016
  }
9993
10017
  });
@@ -10740,90 +10764,141 @@ class SingleWalletModalManager {
10740
10764
  }
10741
10765
  }
10742
10766
  class TonConnectUITracker {
10743
- constructor(eventDispatcher) {
10767
+ constructor(options) {
10744
10768
  __publicField(this, "eventPrefix", "ton-connect-ui-");
10769
+ __publicField(this, "tonConnectUiVersion");
10770
+ __publicField(this, "tonConnectSdkVersion", null);
10745
10771
  __publicField(this, "eventDispatcher");
10746
- this.eventDispatcher = eventDispatcher != null ? eventDispatcher : new BrowserEventDispatcher();
10772
+ var _a2;
10773
+ this.eventDispatcher = (_a2 = options == null ? void 0 : options.eventDispatcher) != null ? _a2 : new BrowserEventDispatcher();
10774
+ this.tonConnectUiVersion = options.tonConnectUiVersion;
10775
+ this.init().catch();
10776
+ }
10777
+ get version() {
10778
+ return createVersionInfo({
10779
+ ton_connect_sdk_lib: this.tonConnectSdkVersion,
10780
+ ton_connect_ui_lib: this.tonConnectUiVersion
10781
+ });
10782
+ }
10783
+ init() {
10784
+ return __async(this, null, function* () {
10785
+ try {
10786
+ yield this.setRequestVersionHandler();
10787
+ this.tonConnectSdkVersion = yield this.requestTonConnectSdkVersion();
10788
+ } catch (e2) {
10789
+ }
10790
+ });
10791
+ }
10792
+ setRequestVersionHandler() {
10793
+ return __async(this, null, function* () {
10794
+ yield this.eventDispatcher.addEventListener("ton-connect-ui-request-version", () => __async(this, null, function* () {
10795
+ yield this.eventDispatcher.dispatchEvent(
10796
+ "ton-connect-ui-response-version",
10797
+ createResponseVersionEvent(this.tonConnectUiVersion)
10798
+ );
10799
+ }));
10800
+ });
10801
+ }
10802
+ requestTonConnectSdkVersion() {
10803
+ return __async(this, null, function* () {
10804
+ return new Promise((resolve, reject) => __async(this, null, function* () {
10805
+ try {
10806
+ yield this.eventDispatcher.addEventListener(
10807
+ "ton-connect-response-version",
10808
+ (event) => {
10809
+ resolve(event.detail.version);
10810
+ },
10811
+ { once: true }
10812
+ );
10813
+ yield this.eventDispatcher.dispatchEvent(
10814
+ "ton-connect-request-version",
10815
+ createRequestVersionEvent()
10816
+ );
10817
+ } catch (e2) {
10818
+ reject(e2);
10819
+ }
10820
+ }));
10821
+ });
10747
10822
  }
10748
10823
  dispatchUserActionEvent(eventDetails) {
10749
10824
  var _a2;
10750
10825
  try {
10751
- const eventName = `${this.eventPrefix}${eventDetails.type}`;
10752
- (_a2 = this.eventDispatcher) == null ? void 0 : _a2.dispatchEvent(eventName, eventDetails).catch();
10826
+ (_a2 = this.eventDispatcher) == null ? void 0 : _a2.dispatchEvent(`${this.eventPrefix}${eventDetails.type}`, eventDetails).catch();
10753
10827
  } catch (e2) {
10754
10828
  }
10755
10829
  }
10756
10830
  trackConnectionStarted(...args) {
10757
10831
  try {
10758
- const event = createConnectionStartedEvent(...args);
10832
+ const event = createConnectionStartedEvent(this.version, ...args);
10759
10833
  this.dispatchUserActionEvent(event);
10760
10834
  } catch (e2) {
10761
10835
  }
10762
10836
  }
10763
10837
  trackConnectionCompleted(...args) {
10764
10838
  try {
10765
- const event = createConnectionCompletedEvent(...args);
10839
+ const event = createConnectionCompletedEvent(this.version, ...args);
10766
10840
  this.dispatchUserActionEvent(event);
10767
10841
  } catch (e2) {
10768
10842
  }
10769
10843
  }
10770
10844
  trackConnectionError(...args) {
10771
10845
  try {
10772
- const event = createConnectionErrorEvent(...args);
10846
+ const event = createConnectionErrorEvent(this.version, ...args);
10773
10847
  this.dispatchUserActionEvent(event);
10774
10848
  } catch (e2) {
10775
10849
  }
10776
10850
  }
10777
10851
  trackConnectionRestoringStarted(...args) {
10778
10852
  try {
10779
- const event = createConnectionRestoringStartedEvent(...args);
10853
+ const event = createConnectionRestoringStartedEvent(this.version, ...args);
10780
10854
  this.dispatchUserActionEvent(event);
10781
10855
  } catch (e2) {
10782
10856
  }
10783
10857
  }
10784
10858
  trackConnectionRestoringCompleted(...args) {
10785
10859
  try {
10786
- const event = createConnectionRestoringCompletedEvent(...args);
10860
+ const event = createConnectionRestoringCompletedEvent(this.version, ...args);
10787
10861
  this.dispatchUserActionEvent(event);
10788
10862
  } catch (e2) {
10789
10863
  }
10790
10864
  }
10791
10865
  trackConnectionRestoringError(...args) {
10792
10866
  try {
10793
- const event = createConnectionRestoringErrorEvent(...args);
10867
+ const event = createConnectionRestoringErrorEvent(this.version, ...args);
10794
10868
  this.dispatchUserActionEvent(event);
10795
10869
  } catch (e2) {
10796
10870
  }
10797
10871
  }
10798
10872
  trackDisconnection(...args) {
10799
10873
  try {
10800
- const event = createDisconnectionEvent(...args);
10874
+ const event = createDisconnectionEvent(this.version, ...args);
10801
10875
  this.dispatchUserActionEvent(event);
10802
10876
  } catch (e2) {
10803
10877
  }
10804
10878
  }
10805
10879
  trackTransactionSentForSignature(...args) {
10806
10880
  try {
10807
- const event = createTransactionSentForSignatureEvent(...args);
10881
+ const event = createTransactionSentForSignatureEvent(this.version, ...args);
10808
10882
  this.dispatchUserActionEvent(event);
10809
10883
  } catch (e2) {
10810
10884
  }
10811
10885
  }
10812
10886
  trackTransactionSigned(...args) {
10813
10887
  try {
10814
- const event = createTransactionSignedEvent(...args);
10888
+ const event = createTransactionSignedEvent(this.version, ...args);
10815
10889
  this.dispatchUserActionEvent(event);
10816
10890
  } catch (e2) {
10817
10891
  }
10818
10892
  }
10819
10893
  trackTransactionSigningFailed(...args) {
10820
10894
  try {
10821
- const event = createTransactionSigningFailedEvent(...args);
10895
+ const event = createTransactionSigningFailedEvent(this.version, ...args);
10822
10896
  this.dispatchUserActionEvent(event);
10823
10897
  } catch (e2) {
10824
10898
  }
10825
10899
  }
10826
10900
  }
10901
+ const tonConnectUiVersion = "2.0.3-beta.3";
10827
10902
  class TonConnectUI {
10828
10903
  constructor(options) {
10829
10904
  __publicField(this, "walletInfoStorage", new WalletInfoStorage());
@@ -10851,7 +10926,10 @@ class TonConnectUI {
10851
10926
  "You have to specify a `manifestUrl` or a `connector` in the options."
10852
10927
  );
10853
10928
  }
10854
- this.tracker = new TonConnectUITracker(options == null ? void 0 : options.eventDispatcher);
10929
+ this.tracker = new TonConnectUITracker({
10930
+ eventDispatcher: options == null ? void 0 : options.eventDispatcher,
10931
+ tonConnectUiVersion
10932
+ });
10855
10933
  this.modal = new WalletsModalManager({
10856
10934
  connector: this.connector,
10857
10935
  tracker: this.tracker,
@@ -10874,8 +10952,8 @@ class TonConnectUI {
10874
10952
  const rootId = this.normalizeWidgetRoot(options == null ? void 0 : options.widgetRootId);
10875
10953
  this.subscribeToWalletChange();
10876
10954
  if ((options == null ? void 0 : options.restoreConnection) !== false) {
10877
- this.tracker.trackConnectionRestoringStarted();
10878
- this.connectionRestored = new Promise((resolve) => __async(this, null, function* () {
10955
+ this.connectionRestored = createMacrotaskAsync(() => __async(this, null, function* () {
10956
+ this.tracker.trackConnectionRestoringStarted();
10879
10957
  yield this.connector.restoreConnection();
10880
10958
  if (!this.connector.connected) {
10881
10959
  this.tracker.trackConnectionRestoringError("Connection was not restored");
@@ -10883,7 +10961,7 @@ class TonConnectUI {
10883
10961
  } else {
10884
10962
  this.tracker.trackConnectionRestoringCompleted(this.wallet);
10885
10963
  }
10886
- resolve(this.connector.connected);
10964
+ return this.connector.connected;
10887
10965
  }));
10888
10966
  }
10889
10967
  this.uiOptions = mergeOptions(options, { uiPreferences: { theme: "SYSTEM" } });
@@ -11094,7 +11172,6 @@ class TonConnectUI {
11094
11172
  });
11095
11173
  return result;
11096
11174
  } catch (e2) {
11097
- this.tracker.trackTransactionSigningFailed(this.wallet, tx, e2.message);
11098
11175
  widgetController.setAction({
11099
11176
  name: "transaction-canceled",
11100
11177
  showNotification: notifications2.includes("error"),
@@ -11201,6 +11278,11 @@ class TonConnectUI {
11201
11278
  return new Promise((resolve, reject) => {
11202
11279
  const { transaction, signal } = options;
11203
11280
  if (signal.aborted) {
11281
+ this.tracker.trackTransactionSigningFailed(
11282
+ this.wallet,
11283
+ transaction,
11284
+ "Transaction was cancelled"
11285
+ );
11204
11286
  return reject(new TonConnectUIError("Transaction was not sent"));
11205
11287
  }
11206
11288
  const onTransactionHandler = (transaction2) => __async(this, null, function* () {
@@ -11209,14 +11291,22 @@ class TonConnectUI {
11209
11291
  const onErrorsHandler = (reason) => {
11210
11292
  reject(reason);
11211
11293
  };
11212
- this.connector.sendTransaction(transaction, { onRequestSent, signal }).then((result) => onTransactionHandler(result)).catch((reason) => onErrorsHandler(reason));
11213
- signal.addEventListener(
11214
- "abort",
11215
- () => {
11216
- reject(new TonConnectUIError("Transaction was not sent"));
11217
- },
11218
- { once: true }
11219
- );
11294
+ const onCanceledHandler = () => {
11295
+ this.tracker.trackTransactionSigningFailed(
11296
+ this.wallet,
11297
+ transaction,
11298
+ "Transaction was cancelled"
11299
+ );
11300
+ reject(new TonConnectUIError("Transaction was not sent"));
11301
+ };
11302
+ signal.addEventListener("abort", onCanceledHandler, { once: true });
11303
+ this.connector.sendTransaction(transaction, { onRequestSent, signal }).then((result) => {
11304
+ signal.removeEventListener("abort", onCanceledHandler);
11305
+ return onTransactionHandler(result);
11306
+ }).catch((reason) => {
11307
+ signal.removeEventListener("abort", onCanceledHandler);
11308
+ return onErrorsHandler(reason);
11309
+ });
11220
11310
  });
11221
11311
  });
11222
11312
  }