@tonconnect/ui 2.0.3-beta.2 → 2.0.3-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
@@ -1834,6 +1834,12 @@ function createMacrotask(callback) {
1834
1834
  callback();
1835
1835
  });
1836
1836
  }
1837
+ function createMacrotaskAsync(callback) {
1838
+ return __async(this, null, function* () {
1839
+ yield new Promise((resolve) => requestAnimationFrame(resolve));
1840
+ return callback();
1841
+ });
1842
+ }
1837
1843
  function preloadImages(images) {
1838
1844
  if (document.readyState !== "complete") {
1839
1845
  window.addEventListener("load", () => createMacrotask(() => preloadImages(images)), {
@@ -7164,7 +7170,7 @@ const computePosition$1 = (reference, floating, config) => __async(exports, null
7164
7170
  } = config;
7165
7171
  const validMiddleware = middleware.filter(Boolean);
7166
7172
  const rtl = yield platform2.isRTL == null ? void 0 : platform2.isRTL(floating);
7167
- if ({}.NODE_ENV !== "production") {
7173
+ if (process.env.NODE_ENV !== "production") {
7168
7174
  if (platform2 == null) {
7169
7175
  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(" "));
7170
7176
  }
@@ -7221,7 +7227,7 @@ const computePosition$1 = (reference, floating, config) => __async(exports, null
7221
7227
  middlewareData = __spreadProps(__spreadValues({}, middlewareData), {
7222
7228
  [name]: __spreadValues(__spreadValues({}, middlewareData[name]), data)
7223
7229
  });
7224
- if ({}.NODE_ENV !== "production") {
7230
+ if (process.env.NODE_ENV !== "production") {
7225
7231
  if (resetCount > 50) {
7226
7232
  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(" "));
7227
7233
  }
@@ -8648,10 +8654,14 @@ const DesktopConnectionModal = (props) => {
8648
8654
  });
8649
8655
  onCleanup(unsubscribe);
8650
8656
  const generateUniversalLink = () => {
8651
- setUniversalLink(connector.connect({
8652
- universalLink: props.wallet.universalLink,
8653
- bridgeUrl: props.wallet.bridgeUrl
8654
- }, props.additionalRequest));
8657
+ try {
8658
+ const universalLink2 = connector.connect({
8659
+ universalLink: props.wallet.universalLink,
8660
+ bridgeUrl: props.wallet.bridgeUrl
8661
+ }, props.additionalRequest);
8662
+ setUniversalLink(universalLink2);
8663
+ } catch (e2) {
8664
+ }
8655
8665
  };
8656
8666
  createEffect(() => {
8657
8667
  if (untrack(mode) !== "extension" && (supportsMobile(props.wallet) || supportsDesktop(props.wallet))) {
@@ -9631,6 +9641,17 @@ const MobileUniversalQR = (props) => {
9631
9641
  }
9632
9642
  })];
9633
9643
  };
9644
+ function getUniqueBridges(walletsList) {
9645
+ const uniqueBridges = new Set(
9646
+ walletsList.filter(sdk.isWalletInfoRemote).map((item) => item.bridgeUrl)
9647
+ );
9648
+ return Array.from(uniqueBridges).map((bridgeUrl) => ({ bridgeUrl }));
9649
+ }
9650
+ function bridgesIsEqual(left, right) {
9651
+ const leftSet = new Set(left == null ? void 0 : left.map((i2) => i2.bridgeUrl));
9652
+ const rightSet = new Set(right == null ? void 0 : right.map((i2) => i2.bridgeUrl));
9653
+ return leftSet.size === rightSet.size && [...leftSet].every((value) => rightSet.has(value));
9654
+ }
9634
9655
  const _tmpl$$1 = /* @__PURE__ */ template$1(`<li></li>`), _tmpl$2 = /* @__PURE__ */ template$1(`<div data-tc-wallets-modal-universal-mobile="true"></div>`);
9635
9656
  const MobileUniversalModal = (props) => {
9636
9657
  const [showQR, setShowQR] = createSignal(false);
@@ -9638,10 +9659,10 @@ const MobileUniversalModal = (props) => {
9638
9659
  const connector = appState.connector;
9639
9660
  const walletsList = () => props.walletsList.filter((w) => supportsMobile(w) && w.appName !== AT_WALLET_APP_NAME);
9640
9661
  const shouldShowMoreButton = () => walletsList().length > 7;
9641
- const walletsBridges = () => [...new Set(props.walletsList.filter(sdk.isWalletInfoRemote).map((item) => item.bridgeUrl)).values()].map((bridgeUrl) => ({
9642
- bridgeUrl
9643
- }));
9644
- const getUniversalLink = () => connector.connect(walletsBridges(), props.additionalRequest);
9662
+ const walletsBridges = createMemo(() => getUniqueBridges(props.walletsList), null, {
9663
+ equals: bridgesIsEqual
9664
+ });
9665
+ const getUniversalLink = createMemo(() => connector.connect(walletsBridges(), props.additionalRequest));
9645
9666
  setLastSelectedWalletInfo({
9646
9667
  openMethod: "universal-link"
9647
9668
  });
@@ -9929,9 +9950,9 @@ const _tmpl$ = /* @__PURE__ */ template$1(`<li></li>`);
9929
9950
  const DesktopUniversalModal = (props) => {
9930
9951
  const [popupOpened, setPopupOpened] = createSignal(false);
9931
9952
  const connector = appState.connector;
9932
- const walletsBridges = () => [...new Set(props.walletsList.filter(sdk.isWalletInfoRemote).map((item) => item.bridgeUrl)).values()].map((bridgeUrl) => ({
9933
- bridgeUrl
9934
- }));
9953
+ const walletsBridges = createMemo(() => getUniqueBridges(props.walletsList), null, {
9954
+ equals: bridgesIsEqual
9955
+ });
9935
9956
  setLastSelectedWalletInfo({
9936
9957
  openMethod: "qrcode"
9937
9958
  });
@@ -9994,6 +10015,10 @@ const WalletsModal = () => {
9994
10015
  createEffect(() => {
9995
10016
  if (getWalletsModalIsOpened()) {
9996
10017
  updateIsMobile();
10018
+ } else {
10019
+ setSelectedWalletInfo(null);
10020
+ setSelectedTab("universal");
10021
+ setInfoTab(false);
9997
10022
  }
9998
10023
  });
9999
10024
  const connector = useContext(ConnectorContext);
@@ -10745,90 +10770,141 @@ class SingleWalletModalManager {
10745
10770
  }
10746
10771
  }
10747
10772
  class TonConnectUITracker {
10748
- constructor(eventDispatcher) {
10773
+ constructor(options) {
10749
10774
  __publicField(this, "eventPrefix", "ton-connect-ui-");
10775
+ __publicField(this, "tonConnectUiVersion");
10776
+ __publicField(this, "tonConnectSdkVersion", null);
10750
10777
  __publicField(this, "eventDispatcher");
10751
- this.eventDispatcher = eventDispatcher != null ? eventDispatcher : new sdk.BrowserEventDispatcher();
10778
+ var _a2;
10779
+ this.eventDispatcher = (_a2 = options == null ? void 0 : options.eventDispatcher) != null ? _a2 : new sdk.BrowserEventDispatcher();
10780
+ this.tonConnectUiVersion = options.tonConnectUiVersion;
10781
+ this.init().catch();
10782
+ }
10783
+ get version() {
10784
+ return sdk.createVersionInfo({
10785
+ ton_connect_sdk_lib: this.tonConnectSdkVersion,
10786
+ ton_connect_ui_lib: this.tonConnectUiVersion
10787
+ });
10788
+ }
10789
+ init() {
10790
+ return __async(this, null, function* () {
10791
+ try {
10792
+ yield this.setRequestVersionHandler();
10793
+ this.tonConnectSdkVersion = yield this.requestTonConnectSdkVersion();
10794
+ } catch (e2) {
10795
+ }
10796
+ });
10797
+ }
10798
+ setRequestVersionHandler() {
10799
+ return __async(this, null, function* () {
10800
+ yield this.eventDispatcher.addEventListener("ton-connect-ui-request-version", () => __async(this, null, function* () {
10801
+ yield this.eventDispatcher.dispatchEvent(
10802
+ "ton-connect-ui-response-version",
10803
+ sdk.createResponseVersionEvent(this.tonConnectUiVersion)
10804
+ );
10805
+ }));
10806
+ });
10807
+ }
10808
+ requestTonConnectSdkVersion() {
10809
+ return __async(this, null, function* () {
10810
+ return new Promise((resolve, reject) => __async(this, null, function* () {
10811
+ try {
10812
+ yield this.eventDispatcher.addEventListener(
10813
+ "ton-connect-response-version",
10814
+ (event) => {
10815
+ resolve(event.detail.version);
10816
+ },
10817
+ { once: true }
10818
+ );
10819
+ yield this.eventDispatcher.dispatchEvent(
10820
+ "ton-connect-request-version",
10821
+ sdk.createRequestVersionEvent()
10822
+ );
10823
+ } catch (e2) {
10824
+ reject(e2);
10825
+ }
10826
+ }));
10827
+ });
10752
10828
  }
10753
10829
  dispatchUserActionEvent(eventDetails) {
10754
10830
  var _a2;
10755
10831
  try {
10756
- const eventName = `${this.eventPrefix}${eventDetails.type}`;
10757
- (_a2 = this.eventDispatcher) == null ? void 0 : _a2.dispatchEvent(eventName, eventDetails).catch();
10832
+ (_a2 = this.eventDispatcher) == null ? void 0 : _a2.dispatchEvent(`${this.eventPrefix}${eventDetails.type}`, eventDetails).catch();
10758
10833
  } catch (e2) {
10759
10834
  }
10760
10835
  }
10761
10836
  trackConnectionStarted(...args) {
10762
10837
  try {
10763
- const event = sdk.createConnectionStartedEvent(...args);
10838
+ const event = sdk.createConnectionStartedEvent(this.version, ...args);
10764
10839
  this.dispatchUserActionEvent(event);
10765
10840
  } catch (e2) {
10766
10841
  }
10767
10842
  }
10768
10843
  trackConnectionCompleted(...args) {
10769
10844
  try {
10770
- const event = sdk.createConnectionCompletedEvent(...args);
10845
+ const event = sdk.createConnectionCompletedEvent(this.version, ...args);
10771
10846
  this.dispatchUserActionEvent(event);
10772
10847
  } catch (e2) {
10773
10848
  }
10774
10849
  }
10775
10850
  trackConnectionError(...args) {
10776
10851
  try {
10777
- const event = sdk.createConnectionErrorEvent(...args);
10852
+ const event = sdk.createConnectionErrorEvent(this.version, ...args);
10778
10853
  this.dispatchUserActionEvent(event);
10779
10854
  } catch (e2) {
10780
10855
  }
10781
10856
  }
10782
10857
  trackConnectionRestoringStarted(...args) {
10783
10858
  try {
10784
- const event = sdk.createConnectionRestoringStartedEvent(...args);
10859
+ const event = sdk.createConnectionRestoringStartedEvent(this.version, ...args);
10785
10860
  this.dispatchUserActionEvent(event);
10786
10861
  } catch (e2) {
10787
10862
  }
10788
10863
  }
10789
10864
  trackConnectionRestoringCompleted(...args) {
10790
10865
  try {
10791
- const event = sdk.createConnectionRestoringCompletedEvent(...args);
10866
+ const event = sdk.createConnectionRestoringCompletedEvent(this.version, ...args);
10792
10867
  this.dispatchUserActionEvent(event);
10793
10868
  } catch (e2) {
10794
10869
  }
10795
10870
  }
10796
10871
  trackConnectionRestoringError(...args) {
10797
10872
  try {
10798
- const event = sdk.createConnectionRestoringErrorEvent(...args);
10873
+ const event = sdk.createConnectionRestoringErrorEvent(this.version, ...args);
10799
10874
  this.dispatchUserActionEvent(event);
10800
10875
  } catch (e2) {
10801
10876
  }
10802
10877
  }
10803
10878
  trackDisconnection(...args) {
10804
10879
  try {
10805
- const event = sdk.createDisconnectionEvent(...args);
10880
+ const event = sdk.createDisconnectionEvent(this.version, ...args);
10806
10881
  this.dispatchUserActionEvent(event);
10807
10882
  } catch (e2) {
10808
10883
  }
10809
10884
  }
10810
10885
  trackTransactionSentForSignature(...args) {
10811
10886
  try {
10812
- const event = sdk.createTransactionSentForSignatureEvent(...args);
10887
+ const event = sdk.createTransactionSentForSignatureEvent(this.version, ...args);
10813
10888
  this.dispatchUserActionEvent(event);
10814
10889
  } catch (e2) {
10815
10890
  }
10816
10891
  }
10817
10892
  trackTransactionSigned(...args) {
10818
10893
  try {
10819
- const event = sdk.createTransactionSignedEvent(...args);
10894
+ const event = sdk.createTransactionSignedEvent(this.version, ...args);
10820
10895
  this.dispatchUserActionEvent(event);
10821
10896
  } catch (e2) {
10822
10897
  }
10823
10898
  }
10824
10899
  trackTransactionSigningFailed(...args) {
10825
10900
  try {
10826
- const event = sdk.createTransactionSigningFailedEvent(...args);
10901
+ const event = sdk.createTransactionSigningFailedEvent(this.version, ...args);
10827
10902
  this.dispatchUserActionEvent(event);
10828
10903
  } catch (e2) {
10829
10904
  }
10830
10905
  }
10831
10906
  }
10907
+ const tonConnectUiVersion = "2.0.3-beta.4";
10832
10908
  class TonConnectUI {
10833
10909
  constructor(options) {
10834
10910
  __publicField(this, "walletInfoStorage", new WalletInfoStorage());
@@ -10856,7 +10932,10 @@ class TonConnectUI {
10856
10932
  "You have to specify a `manifestUrl` or a `connector` in the options."
10857
10933
  );
10858
10934
  }
10859
- this.tracker = new TonConnectUITracker(options == null ? void 0 : options.eventDispatcher);
10935
+ this.tracker = new TonConnectUITracker({
10936
+ eventDispatcher: options == null ? void 0 : options.eventDispatcher,
10937
+ tonConnectUiVersion
10938
+ });
10860
10939
  this.modal = new WalletsModalManager({
10861
10940
  connector: this.connector,
10862
10941
  tracker: this.tracker,
@@ -10879,8 +10958,8 @@ class TonConnectUI {
10879
10958
  const rootId = this.normalizeWidgetRoot(options == null ? void 0 : options.widgetRootId);
10880
10959
  this.subscribeToWalletChange();
10881
10960
  if ((options == null ? void 0 : options.restoreConnection) !== false) {
10882
- this.tracker.trackConnectionRestoringStarted();
10883
- this.connectionRestored = new Promise((resolve) => __async(this, null, function* () {
10961
+ this.connectionRestored = createMacrotaskAsync(() => __async(this, null, function* () {
10962
+ this.tracker.trackConnectionRestoringStarted();
10884
10963
  yield this.connector.restoreConnection();
10885
10964
  if (!this.connector.connected) {
10886
10965
  this.tracker.trackConnectionRestoringError("Connection was not restored");
@@ -10888,7 +10967,7 @@ class TonConnectUI {
10888
10967
  } else {
10889
10968
  this.tracker.trackConnectionRestoringCompleted(this.wallet);
10890
10969
  }
10891
- resolve(this.connector.connected);
10970
+ return this.connector.connected;
10892
10971
  }));
10893
10972
  }
10894
10973
  this.uiOptions = mergeOptions(options, { uiPreferences: { theme: "SYSTEM" } });
@@ -11205,7 +11284,11 @@ class TonConnectUI {
11205
11284
  return new Promise((resolve, reject) => {
11206
11285
  const { transaction, signal } = options;
11207
11286
  if (signal.aborted) {
11208
- this.tracker.trackTransactionSigningFailed(this.wallet, transaction, "Transaction was cancelled");
11287
+ this.tracker.trackTransactionSigningFailed(
11288
+ this.wallet,
11289
+ transaction,
11290
+ "Transaction was cancelled"
11291
+ );
11209
11292
  return reject(new TonConnectUIError("Transaction was not sent"));
11210
11293
  }
11211
11294
  const onTransactionHandler = (transaction2) => __async(this, null, function* () {
@@ -11215,7 +11298,11 @@ class TonConnectUI {
11215
11298
  reject(reason);
11216
11299
  };
11217
11300
  const onCanceledHandler = () => {
11218
- this.tracker.trackTransactionSigningFailed(this.wallet, transaction, "Transaction was cancelled");
11301
+ this.tracker.trackTransactionSigningFailed(
11302
+ this.wallet,
11303
+ transaction,
11304
+ "Transaction was cancelled"
11305
+ );
11219
11306
  reject(new TonConnectUIError("Transaction was not sent"));
11220
11307
  };
11221
11308
  signal.addEventListener("abort", onCanceledHandler, { once: true });