@tonconnect/ui 2.0.2-beta.1 → 2.0.3-beta.0

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,6 +1,7 @@
1
1
  import { WalletInfoBase, WalletInfoInjectable, WalletInfoRemote, ITonConnect, Wallet, WalletInfo, Account, ConnectAdditionalRequest, TonConnectError, SendTransactionRequest, SendTransactionResponse } from '@tonconnect/sdk';
2
2
  export * from '@tonconnect/sdk';
3
3
  import { Property } from 'csstype';
4
+ import { ConnectItem } from '@tonconnect/protocol';
4
5
 
5
6
  declare type Locales = 'en' | 'ru';
6
7
 
@@ -307,6 +308,7 @@ declare class TonConnectUI {
307
308
  static getWallets(): Promise<WalletInfo[]>;
308
309
  private readonly walletInfoStorage;
309
310
  private readonly preferredWalletStorage;
311
+ private readonly tracker;
310
312
  private walletInfo;
311
313
  private systemThemeChangeUnsubscribe;
312
314
  private actionsConfiguration?;
@@ -474,10 +476,236 @@ declare class TonConnectUI {
474
476
  private getModalsAndNotificationsConfiguration;
475
477
  }
476
478
 
479
+ /**
480
+ * Requested authentication type: 'ton_addr' or 'ton_proof'.
481
+ */
482
+ declare type AuthType = ConnectItem['name'];
483
+ /**
484
+ * Information about a connected wallet.
485
+ */
486
+ declare type ConnectionInfo = {
487
+ /**
488
+ * Connected wallet address.
489
+ */
490
+ address: string | null;
491
+ /**
492
+ * Connected chain ID.
493
+ */
494
+ chainId: string | null;
495
+ /**
496
+ * Wallet provider.
497
+ */
498
+ provider: 'http' | 'injected' | null;
499
+ /**
500
+ * Wallet type: 'tonkeeper', 'tonhub', etc.
501
+ */
502
+ walletType: string | null;
503
+ /**
504
+ * Wallet version.
505
+ */
506
+ walletVersion: string | null;
507
+ /**
508
+ * Requested authentication types.
509
+ */
510
+ authType: AuthType | null;
511
+ };
512
+ /**
513
+ * Initial connection event when a user initiates a connection.
514
+ */
515
+ declare type ConnectionStartedEvent = {
516
+ /**
517
+ * Event type.
518
+ */
519
+ type: 'connection-started';
520
+ };
521
+ /**
522
+ * Successful connection event when a user successfully connected a wallet.
523
+ */
524
+ declare type ConnectionCompletedEvent = {
525
+ /**
526
+ * Event type.
527
+ */
528
+ type: 'connection-completed';
529
+ /**
530
+ * Wallet information.
531
+ */
532
+ connectionInfo: ConnectionInfo;
533
+ };
534
+ /**
535
+ * Connection error event when a user cancels a connection or there is an error during the connection process.
536
+ */
537
+ declare type ConnectionErrorEvent = {
538
+ /**
539
+ * Event type.
540
+ */
541
+ type: 'connection-error';
542
+ /**
543
+ * Reason for the error.
544
+ */
545
+ reason: string;
546
+ };
547
+ /**
548
+ * Connection events.
549
+ */
550
+ declare type ConnectionEvent = ConnectionStartedEvent | ConnectionCompletedEvent | ConnectionErrorEvent;
551
+ /**
552
+ * Connection restoring started event when initiates a connection restoring process.
553
+ */
554
+ declare type ConnectionRestoringStartedEvent = {
555
+ /**
556
+ * Event type.
557
+ */
558
+ type: 'connection-restoring-started';
559
+ };
560
+ /**
561
+ * Connection restoring completed event when successfully restored a connection.
562
+ */
563
+ declare type ConnectionRestoringCompletedEvent = {
564
+ /**
565
+ * Event type.
566
+ */
567
+ type: 'connection-restoring-completed';
568
+ /**
569
+ * Wallet information.
570
+ */
571
+ connectionInfo: ConnectionInfo;
572
+ };
573
+ /**
574
+ * Connection restoring error event when there is an error during the connection restoring process.
575
+ */
576
+ declare type ConnectionRestoringErrorEvent = {
577
+ /**
578
+ * Event type.
579
+ */
580
+ type: 'connection-restoring-error';
581
+ /**
582
+ * Reason for the error.
583
+ */
584
+ reason: string;
585
+ };
586
+ /**
587
+ * Connection restoring events.
588
+ */
589
+ declare type ConnectionRestoringEvent = ConnectionRestoringStartedEvent | ConnectionRestoringCompletedEvent | ConnectionRestoringErrorEvent;
590
+ /**
591
+ * Transaction message.
592
+ */
593
+ declare type TransactionMessage = {
594
+ /**
595
+ * Recipient address.
596
+ */
597
+ address: string | null;
598
+ /**
599
+ * Transfer amount.
600
+ */
601
+ amount: string | null;
602
+ };
603
+ /**
604
+ * Transaction information.
605
+ */
606
+ declare type TransactionInfo = {
607
+ /**
608
+ * Transaction validity time in unix timestamp.
609
+ */
610
+ validUntil: number | null;
611
+ /**
612
+ * Sender address.
613
+ */
614
+ from: string | null;
615
+ /**
616
+ * Transaction messages.
617
+ */
618
+ messages: TransactionMessage[];
619
+ };
620
+ /**
621
+ * Initial transaction event when a user initiates a transaction.
622
+ */
623
+ declare type TransactionSentForSignatureEvent = {
624
+ /**
625
+ * Event type.
626
+ */
627
+ type: 'transaction-sent-for-signature';
628
+ /**
629
+ * Wallet information.
630
+ */
631
+ connectionInfo: ConnectionInfo;
632
+ /**
633
+ * Transaction information.
634
+ */
635
+ transactionInfo: TransactionInfo;
636
+ };
637
+ /**
638
+ * Transaction signed event when a user successfully signed a transaction.
639
+ */
640
+ declare type TransactionSignedEvent = {
641
+ /**
642
+ * Event type.
643
+ */
644
+ type: 'transaction-signed';
645
+ /**
646
+ * Wallet information.
647
+ */
648
+ connectionInfo: ConnectionInfo;
649
+ /**
650
+ * Transaction information.
651
+ */
652
+ transactionInfo: TransactionInfo;
653
+ /**
654
+ * Signed transaction.
655
+ */
656
+ signedTransaction: string;
657
+ };
658
+ /**
659
+ * Transaction error event when a user cancels a transaction or there is an error during the transaction process.
660
+ */
661
+ declare type TransactionSigningFailedEvent = {
662
+ /**
663
+ * Event type.
664
+ */
665
+ type: 'transaction-signing-failed';
666
+ /**
667
+ * Wallet information.
668
+ */
669
+ connectionInfo: ConnectionInfo;
670
+ /**
671
+ * Transaction information.
672
+ */
673
+ transactionInfo: TransactionInfo;
674
+ /**
675
+ * Reason for the error.
676
+ */
677
+ reason: string;
678
+ };
679
+ /**
680
+ * Transaction events.
681
+ */
682
+ declare type TransactionSigningEvent = TransactionSentForSignatureEvent | TransactionSignedEvent | TransactionSigningFailedEvent;
683
+ /**
684
+ * Disconnect event when a user initiates a disconnection.
685
+ */
686
+ declare type DisconnectionEvent = {
687
+ /**
688
+ * Event type.
689
+ */
690
+ type: 'disconnection';
691
+ /**
692
+ * Wallet information.
693
+ */
694
+ connectionInfo: ConnectionInfo;
695
+ /**
696
+ * Disconnect scope: 'dapp' or 'wallet'.
697
+ */
698
+ scope: 'dapp' | 'wallet';
699
+ };
700
+ /**
701
+ * User action events.
702
+ */
703
+ declare type UserActionEvent = ConnectionEvent | ConnectionRestoringEvent | DisconnectionEvent | TransactionSigningEvent;
704
+
477
705
  declare type Color = Property.Color;
478
706
 
479
707
  declare class TonConnectUIError extends TonConnectError {
480
708
  constructor(...args: ConstructorParameters<typeof Error>);
481
709
  }
482
710
 
483
- export { ActionConfiguration, BorderRadius, Color, ColorsSet, ConnectedWallet, Loadable, LoadableLoading, LoadableReady, Locales, PartialColorsSet, ReturnStrategy, THEME, Theme, TonConnectUI, TonConnectUIError, TonConnectUiCreateOptions, TonConnectUiCreateOptionsBase, TonConnectUiOptions, TonConnectUiOptionsWithConnector, TonConnectUiOptionsWithManifest, UIPreferences, UIWallet, WalletInfoRemoteWithOpenMethod, WalletInfoWithOpenMethod, WalletModalClosed, WalletModalOpened, WalletOpenMethod, WalletsListConfiguration, WalletsModal, WalletsModalCloseReason, WalletsModalState };
711
+ export { ActionConfiguration, BorderRadius, Color, ColorsSet, ConnectedWallet, ConnectionCompletedEvent, ConnectionErrorEvent, ConnectionEvent, ConnectionRestoringCompletedEvent, ConnectionRestoringErrorEvent, ConnectionRestoringStartedEvent, ConnectionStartedEvent, DisconnectionEvent, Loadable, LoadableLoading, LoadableReady, Locales, PartialColorsSet, ReturnStrategy, THEME, Theme, TonConnectUI, TonConnectUIError, TonConnectUiCreateOptions, TonConnectUiCreateOptionsBase, TonConnectUiOptions, TonConnectUiOptionsWithConnector, TonConnectUiOptionsWithManifest, TransactionSentForSignatureEvent, TransactionSignedEvent, TransactionSigningEvent, TransactionSigningFailedEvent, UIPreferences, UIWallet, UserActionEvent, WalletInfoRemoteWithOpenMethod, WalletInfoWithOpenMethod, WalletModalClosed, WalletModalOpened, WalletOpenMethod, WalletsListConfiguration, WalletsModal, WalletsModalCloseReason, WalletsModalState };
package/lib/index.mjs CHANGED
@@ -10717,10 +10717,191 @@ class SingleWalletModalManager {
10717
10717
  });
10718
10718
  }
10719
10719
  }
10720
+ function createConnnectionInfo(wallet) {
10721
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
10722
+ let authType = null;
10723
+ if ((_a2 = wallet == null ? void 0 : wallet.connectItems) == null ? void 0 : _a2.tonProof) {
10724
+ authType = "proof" in wallet.connectItems.tonProof ? "ton_proof" : null;
10725
+ } else if (wallet == null ? void 0 : wallet.connectItems) {
10726
+ authType = "ton_addr";
10727
+ }
10728
+ return {
10729
+ address: (_c2 = (_b2 = wallet == null ? void 0 : wallet.account) == null ? void 0 : _b2.address) != null ? _c2 : null,
10730
+ chainId: (_e2 = (_d2 = wallet == null ? void 0 : wallet.account) == null ? void 0 : _d2.chain) != null ? _e2 : null,
10731
+ provider: (_f2 = wallet == null ? void 0 : wallet.provider) != null ? _f2 : null,
10732
+ walletType: (_g2 = wallet == null ? void 0 : wallet.device.appName) != null ? _g2 : null,
10733
+ walletVersion: (_h2 = wallet == null ? void 0 : wallet.device.appVersion) != null ? _h2 : null,
10734
+ authType
10735
+ };
10736
+ }
10737
+ function createConnectionStartedEvent() {
10738
+ return {
10739
+ type: "connection-started"
10740
+ };
10741
+ }
10742
+ function createConnectionCompletedEvent(wallet) {
10743
+ return {
10744
+ type: "connection-completed",
10745
+ connectionInfo: createConnnectionInfo(wallet)
10746
+ };
10747
+ }
10748
+ function createConnectionErrorEvent(reason) {
10749
+ return {
10750
+ type: "connection-error",
10751
+ reason
10752
+ };
10753
+ }
10754
+ function createConnectionRestoringStartedEvent() {
10755
+ return {
10756
+ type: "connection-restoring-started"
10757
+ };
10758
+ }
10759
+ function createConnectionRestoringCompletedEvent(wallet) {
10760
+ return {
10761
+ type: "connection-restoring-completed",
10762
+ connectionInfo: createConnnectionInfo(wallet)
10763
+ };
10764
+ }
10765
+ function createConnectionRestoringErrorEvent(reason) {
10766
+ return {
10767
+ type: "connection-restoring-error",
10768
+ reason
10769
+ };
10770
+ }
10771
+ function createTransactionInfo(transaction) {
10772
+ var _a2, _b2;
10773
+ return {
10774
+ validUntil: (_a2 = transaction.validUntil) != null ? _a2 : null,
10775
+ from: (_b2 = transaction.from) != null ? _b2 : null,
10776
+ messages: transaction.messages.map((message) => {
10777
+ var _a3, _b3;
10778
+ return {
10779
+ address: (_a3 = message.address) != null ? _a3 : null,
10780
+ amount: (_b3 = message.amount) != null ? _b3 : null
10781
+ };
10782
+ })
10783
+ };
10784
+ }
10785
+ function createTransactionSentForSignatureEvent(wallet, transaction) {
10786
+ return {
10787
+ type: "transaction-sent-for-signature",
10788
+ connectionInfo: createConnnectionInfo(wallet),
10789
+ transactionInfo: createTransactionInfo(transaction)
10790
+ };
10791
+ }
10792
+ function createTransactionSignedEvent(wallet, transaction, signedTransaction) {
10793
+ return {
10794
+ type: "transaction-signed",
10795
+ connectionInfo: createConnnectionInfo(wallet),
10796
+ transactionInfo: createTransactionInfo(transaction),
10797
+ signedTransaction: signedTransaction.boc
10798
+ };
10799
+ }
10800
+ function createTransactionSigningFailedEvent(wallet, transaction, reason) {
10801
+ return {
10802
+ type: "transaction-signing-failed",
10803
+ connectionInfo: createConnnectionInfo(wallet),
10804
+ transactionInfo: createTransactionInfo(transaction),
10805
+ reason
10806
+ };
10807
+ }
10808
+ function createDisconnectionEvent(wallet, scope) {
10809
+ return {
10810
+ type: "disconnection",
10811
+ connectionInfo: createConnnectionInfo(wallet),
10812
+ scope
10813
+ };
10814
+ }
10815
+ class TonConnectTracker {
10816
+ constructor() {
10817
+ __publicField(this, "eventPrefix", "ton-connect-ui-");
10818
+ __publicField(this, "window", getWindow$1());
10819
+ }
10820
+ dispatchUserActionEvent(eventDetails) {
10821
+ var _a2;
10822
+ try {
10823
+ const eventName = `${this.eventPrefix}${eventDetails.type}`;
10824
+ const event = new CustomEvent(eventName, { detail: eventDetails });
10825
+ (_a2 = this.window) == null ? void 0 : _a2.dispatchEvent(event);
10826
+ } catch (e2) {
10827
+ }
10828
+ }
10829
+ trackConnectionStarted(...args) {
10830
+ try {
10831
+ const event = createConnectionStartedEvent(...args);
10832
+ this.dispatchUserActionEvent(event);
10833
+ } catch (e2) {
10834
+ }
10835
+ }
10836
+ trackConnectionCompleted(...args) {
10837
+ try {
10838
+ const event = createConnectionCompletedEvent(...args);
10839
+ this.dispatchUserActionEvent(event);
10840
+ } catch (e2) {
10841
+ }
10842
+ }
10843
+ trackConnectionError(...args) {
10844
+ try {
10845
+ const event = createConnectionErrorEvent(...args);
10846
+ this.dispatchUserActionEvent(event);
10847
+ } catch (e2) {
10848
+ }
10849
+ }
10850
+ trackConnectionRestoringStarted(...args) {
10851
+ try {
10852
+ const event = createConnectionRestoringStartedEvent(...args);
10853
+ this.dispatchUserActionEvent(event);
10854
+ } catch (e2) {
10855
+ }
10856
+ }
10857
+ trackConnectionRestoringCompleted(...args) {
10858
+ try {
10859
+ const event = createConnectionRestoringCompletedEvent(...args);
10860
+ this.dispatchUserActionEvent(event);
10861
+ } catch (e2) {
10862
+ }
10863
+ }
10864
+ trackConnectionRestoringError(...args) {
10865
+ try {
10866
+ const event = createConnectionRestoringErrorEvent(...args);
10867
+ this.dispatchUserActionEvent(event);
10868
+ } catch (e2) {
10869
+ }
10870
+ }
10871
+ trackDisconnection(...args) {
10872
+ try {
10873
+ const event = createDisconnectionEvent(...args);
10874
+ this.dispatchUserActionEvent(event);
10875
+ } catch (e2) {
10876
+ }
10877
+ }
10878
+ trackTransactionSentForSignature(...args) {
10879
+ try {
10880
+ const event = createTransactionSentForSignatureEvent(...args);
10881
+ this.dispatchUserActionEvent(event);
10882
+ } catch (e2) {
10883
+ }
10884
+ }
10885
+ trackTransactionSigned(...args) {
10886
+ try {
10887
+ const event = createTransactionSignedEvent(...args);
10888
+ this.dispatchUserActionEvent(event);
10889
+ } catch (e2) {
10890
+ }
10891
+ }
10892
+ trackTransactionSigningFailed(...args) {
10893
+ try {
10894
+ const event = createTransactionSigningFailedEvent(...args);
10895
+ this.dispatchUserActionEvent(event);
10896
+ } catch (e2) {
10897
+ }
10898
+ }
10899
+ }
10720
10900
  class TonConnectUI {
10721
10901
  constructor(options) {
10722
10902
  __publicField(this, "walletInfoStorage", new WalletInfoStorage());
10723
10903
  __publicField(this, "preferredWalletStorage", new PreferredWalletStorage());
10904
+ __publicField(this, "tracker", new TonConnectTracker());
10724
10905
  __publicField(this, "walletInfo", null);
10725
10906
  __publicField(this, "systemThemeChangeUnsubscribe", null);
10726
10907
  __publicField(this, "actionsConfiguration");
@@ -10760,10 +10941,14 @@ class TonConnectUI {
10760
10941
  const rootId = this.normalizeWidgetRoot(options == null ? void 0 : options.widgetRootId);
10761
10942
  this.subscribeToWalletChange();
10762
10943
  if ((options == null ? void 0 : options.restoreConnection) !== false) {
10944
+ this.tracker.trackConnectionRestoringStarted();
10763
10945
  this.connectionRestored = new Promise((resolve) => __async(this, null, function* () {
10764
10946
  yield this.connector.restoreConnection();
10765
10947
  if (!this.connector.connected) {
10948
+ this.tracker.trackConnectionRestoringError("Connection was not restored");
10766
10949
  this.walletInfoStorage.removeWalletInfo();
10950
+ } else {
10951
+ this.tracker.trackConnectionRestoringCompleted(this.wallet);
10767
10952
  }
10768
10953
  resolve(this.connector.connected);
10769
10954
  }));
@@ -10858,10 +11043,12 @@ class TonConnectUI {
10858
11043
  }
10859
11044
  openModal() {
10860
11045
  return __async(this, null, function* () {
11046
+ this.tracker.trackConnectionStarted();
10861
11047
  return this.modal.open();
10862
11048
  });
10863
11049
  }
10864
11050
  closeModal() {
11051
+ this.tracker.trackConnectionError("Connection was cancelled");
10865
11052
  this.modal.close();
10866
11053
  }
10867
11054
  onModalStateChange(onChange) {
@@ -10872,10 +11059,12 @@ class TonConnectUI {
10872
11059
  }
10873
11060
  openSingleWalletModal(wallet) {
10874
11061
  return __async(this, null, function* () {
11062
+ this.tracker.trackConnectionStarted();
10875
11063
  return this.singleWalletModal.open(wallet);
10876
11064
  });
10877
11065
  }
10878
11066
  closeSingleWalletModal() {
11067
+ this.tracker.trackConnectionError("Connection was cancelled");
10879
11068
  this.singleWalletModal.close();
10880
11069
  }
10881
11070
  onSingleWalletModalStateChange(onChange) {
@@ -10896,6 +11085,7 @@ class TonConnectUI {
10896
11085
  });
10897
11086
  }
10898
11087
  disconnect() {
11088
+ this.tracker.trackDisconnection(this.wallet, "dapp");
10899
11089
  widgetController.clearAction();
10900
11090
  widgetController.removeSelectedWalletInfo();
10901
11091
  this.walletInfoStorage.removeWalletInfo();
@@ -10903,7 +11093,9 @@ class TonConnectUI {
10903
11093
  }
10904
11094
  sendTransaction(tx, options) {
10905
11095
  return __async(this, null, function* () {
11096
+ this.tracker.trackTransactionSentForSignature(this.wallet, tx);
10906
11097
  if (!this.connected) {
11098
+ this.tracker.trackTransactionSigningFailed(this.wallet, tx, "Wallet was not connected");
10907
11099
  throw new TonConnectUIError("Connect wallet to send a transaction.");
10908
11100
  }
10909
11101
  if (isInTMA()) {
@@ -10965,6 +11157,7 @@ class TonConnectUI {
10965
11157
  },
10966
11158
  onRequestSent
10967
11159
  );
11160
+ this.tracker.trackTransactionSigned(this.wallet, tx, result);
10968
11161
  widgetController.setAction({
10969
11162
  name: "transaction-sent",
10970
11163
  showNotification: notifications2.includes("success"),
@@ -10972,6 +11165,7 @@ class TonConnectUI {
10972
11165
  });
10973
11166
  return result;
10974
11167
  } catch (e2) {
11168
+ this.tracker.trackTransactionSigningFailed(this.wallet, tx, e2.message);
10975
11169
  widgetController.setAction({
10976
11170
  name: "transaction-canceled",
10977
11171
  showNotification: notifications2.includes("error"),
@@ -11028,23 +11222,28 @@ class TonConnectUI {
11028
11222
  waitForWalletConnection(options) {
11029
11223
  return __async(this, null, function* () {
11030
11224
  return new Promise((resolve, reject) => {
11225
+ this.tracker.trackConnectionStarted();
11031
11226
  const { ignoreErrors = false, signal = null } = options;
11032
11227
  if (signal && signal.aborted) {
11228
+ this.tracker.trackConnectionError("Connection was cancelled");
11033
11229
  return reject(new TonConnectUIError("Wallet was not connected"));
11034
11230
  }
11035
11231
  const onStatusChangeHandler = (wallet) => __async(this, null, function* () {
11036
11232
  if (!wallet) {
11233
+ this.tracker.trackConnectionError("Connection was cancelled");
11037
11234
  if (ignoreErrors) {
11038
11235
  return;
11039
11236
  }
11040
11237
  unsubscribe();
11041
11238
  reject(new TonConnectUIError("Wallet was not connected"));
11042
11239
  } else {
11240
+ this.tracker.trackConnectionCompleted(wallet);
11043
11241
  unsubscribe();
11044
11242
  resolve(wallet);
11045
11243
  }
11046
11244
  });
11047
11245
  const onErrorsHandler = (reason) => {
11246
+ this.tracker.trackConnectionError(reason.message);
11048
11247
  if (ignoreErrors) {
11049
11248
  return;
11050
11249
  }