@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/dist/tonconnect-ui.min.js +32 -32
- package/dist/tonconnect-ui.min.js.map +1 -1
- package/lib/index.cjs +199 -0
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +229 -1
- package/lib/index.mjs +199 -0
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -10722,10 +10722,191 @@ class SingleWalletModalManager {
|
|
|
10722
10722
|
});
|
|
10723
10723
|
}
|
|
10724
10724
|
}
|
|
10725
|
+
function createConnnectionInfo(wallet) {
|
|
10726
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
10727
|
+
let authType = null;
|
|
10728
|
+
if ((_a2 = wallet == null ? void 0 : wallet.connectItems) == null ? void 0 : _a2.tonProof) {
|
|
10729
|
+
authType = "proof" in wallet.connectItems.tonProof ? "ton_proof" : null;
|
|
10730
|
+
} else if (wallet == null ? void 0 : wallet.connectItems) {
|
|
10731
|
+
authType = "ton_addr";
|
|
10732
|
+
}
|
|
10733
|
+
return {
|
|
10734
|
+
address: (_c2 = (_b2 = wallet == null ? void 0 : wallet.account) == null ? void 0 : _b2.address) != null ? _c2 : null,
|
|
10735
|
+
chainId: (_e2 = (_d2 = wallet == null ? void 0 : wallet.account) == null ? void 0 : _d2.chain) != null ? _e2 : null,
|
|
10736
|
+
provider: (_f2 = wallet == null ? void 0 : wallet.provider) != null ? _f2 : null,
|
|
10737
|
+
walletType: (_g2 = wallet == null ? void 0 : wallet.device.appName) != null ? _g2 : null,
|
|
10738
|
+
walletVersion: (_h2 = wallet == null ? void 0 : wallet.device.appVersion) != null ? _h2 : null,
|
|
10739
|
+
authType
|
|
10740
|
+
};
|
|
10741
|
+
}
|
|
10742
|
+
function createConnectionStartedEvent() {
|
|
10743
|
+
return {
|
|
10744
|
+
type: "connection-started"
|
|
10745
|
+
};
|
|
10746
|
+
}
|
|
10747
|
+
function createConnectionCompletedEvent(wallet) {
|
|
10748
|
+
return {
|
|
10749
|
+
type: "connection-completed",
|
|
10750
|
+
connectionInfo: createConnnectionInfo(wallet)
|
|
10751
|
+
};
|
|
10752
|
+
}
|
|
10753
|
+
function createConnectionErrorEvent(reason) {
|
|
10754
|
+
return {
|
|
10755
|
+
type: "connection-error",
|
|
10756
|
+
reason
|
|
10757
|
+
};
|
|
10758
|
+
}
|
|
10759
|
+
function createConnectionRestoringStartedEvent() {
|
|
10760
|
+
return {
|
|
10761
|
+
type: "connection-restoring-started"
|
|
10762
|
+
};
|
|
10763
|
+
}
|
|
10764
|
+
function createConnectionRestoringCompletedEvent(wallet) {
|
|
10765
|
+
return {
|
|
10766
|
+
type: "connection-restoring-completed",
|
|
10767
|
+
connectionInfo: createConnnectionInfo(wallet)
|
|
10768
|
+
};
|
|
10769
|
+
}
|
|
10770
|
+
function createConnectionRestoringErrorEvent(reason) {
|
|
10771
|
+
return {
|
|
10772
|
+
type: "connection-restoring-error",
|
|
10773
|
+
reason
|
|
10774
|
+
};
|
|
10775
|
+
}
|
|
10776
|
+
function createTransactionInfo(transaction) {
|
|
10777
|
+
var _a2, _b2;
|
|
10778
|
+
return {
|
|
10779
|
+
validUntil: (_a2 = transaction.validUntil) != null ? _a2 : null,
|
|
10780
|
+
from: (_b2 = transaction.from) != null ? _b2 : null,
|
|
10781
|
+
messages: transaction.messages.map((message) => {
|
|
10782
|
+
var _a3, _b3;
|
|
10783
|
+
return {
|
|
10784
|
+
address: (_a3 = message.address) != null ? _a3 : null,
|
|
10785
|
+
amount: (_b3 = message.amount) != null ? _b3 : null
|
|
10786
|
+
};
|
|
10787
|
+
})
|
|
10788
|
+
};
|
|
10789
|
+
}
|
|
10790
|
+
function createTransactionSentForSignatureEvent(wallet, transaction) {
|
|
10791
|
+
return {
|
|
10792
|
+
type: "transaction-sent-for-signature",
|
|
10793
|
+
connectionInfo: createConnnectionInfo(wallet),
|
|
10794
|
+
transactionInfo: createTransactionInfo(transaction)
|
|
10795
|
+
};
|
|
10796
|
+
}
|
|
10797
|
+
function createTransactionSignedEvent(wallet, transaction, signedTransaction) {
|
|
10798
|
+
return {
|
|
10799
|
+
type: "transaction-signed",
|
|
10800
|
+
connectionInfo: createConnnectionInfo(wallet),
|
|
10801
|
+
transactionInfo: createTransactionInfo(transaction),
|
|
10802
|
+
signedTransaction: signedTransaction.boc
|
|
10803
|
+
};
|
|
10804
|
+
}
|
|
10805
|
+
function createTransactionSigningFailedEvent(wallet, transaction, reason) {
|
|
10806
|
+
return {
|
|
10807
|
+
type: "transaction-signing-failed",
|
|
10808
|
+
connectionInfo: createConnnectionInfo(wallet),
|
|
10809
|
+
transactionInfo: createTransactionInfo(transaction),
|
|
10810
|
+
reason
|
|
10811
|
+
};
|
|
10812
|
+
}
|
|
10813
|
+
function createDisconnectionEvent(wallet, scope) {
|
|
10814
|
+
return {
|
|
10815
|
+
type: "disconnection",
|
|
10816
|
+
connectionInfo: createConnnectionInfo(wallet),
|
|
10817
|
+
scope
|
|
10818
|
+
};
|
|
10819
|
+
}
|
|
10820
|
+
class TonConnectTracker {
|
|
10821
|
+
constructor() {
|
|
10822
|
+
__publicField(this, "eventPrefix", "ton-connect-ui-");
|
|
10823
|
+
__publicField(this, "window", getWindow$1());
|
|
10824
|
+
}
|
|
10825
|
+
dispatchUserActionEvent(eventDetails) {
|
|
10826
|
+
var _a2;
|
|
10827
|
+
try {
|
|
10828
|
+
const eventName = `${this.eventPrefix}${eventDetails.type}`;
|
|
10829
|
+
const event = new CustomEvent(eventName, { detail: eventDetails });
|
|
10830
|
+
(_a2 = this.window) == null ? void 0 : _a2.dispatchEvent(event);
|
|
10831
|
+
} catch (e2) {
|
|
10832
|
+
}
|
|
10833
|
+
}
|
|
10834
|
+
trackConnectionStarted(...args) {
|
|
10835
|
+
try {
|
|
10836
|
+
const event = createConnectionStartedEvent(...args);
|
|
10837
|
+
this.dispatchUserActionEvent(event);
|
|
10838
|
+
} catch (e2) {
|
|
10839
|
+
}
|
|
10840
|
+
}
|
|
10841
|
+
trackConnectionCompleted(...args) {
|
|
10842
|
+
try {
|
|
10843
|
+
const event = createConnectionCompletedEvent(...args);
|
|
10844
|
+
this.dispatchUserActionEvent(event);
|
|
10845
|
+
} catch (e2) {
|
|
10846
|
+
}
|
|
10847
|
+
}
|
|
10848
|
+
trackConnectionError(...args) {
|
|
10849
|
+
try {
|
|
10850
|
+
const event = createConnectionErrorEvent(...args);
|
|
10851
|
+
this.dispatchUserActionEvent(event);
|
|
10852
|
+
} catch (e2) {
|
|
10853
|
+
}
|
|
10854
|
+
}
|
|
10855
|
+
trackConnectionRestoringStarted(...args) {
|
|
10856
|
+
try {
|
|
10857
|
+
const event = createConnectionRestoringStartedEvent(...args);
|
|
10858
|
+
this.dispatchUserActionEvent(event);
|
|
10859
|
+
} catch (e2) {
|
|
10860
|
+
}
|
|
10861
|
+
}
|
|
10862
|
+
trackConnectionRestoringCompleted(...args) {
|
|
10863
|
+
try {
|
|
10864
|
+
const event = createConnectionRestoringCompletedEvent(...args);
|
|
10865
|
+
this.dispatchUserActionEvent(event);
|
|
10866
|
+
} catch (e2) {
|
|
10867
|
+
}
|
|
10868
|
+
}
|
|
10869
|
+
trackConnectionRestoringError(...args) {
|
|
10870
|
+
try {
|
|
10871
|
+
const event = createConnectionRestoringErrorEvent(...args);
|
|
10872
|
+
this.dispatchUserActionEvent(event);
|
|
10873
|
+
} catch (e2) {
|
|
10874
|
+
}
|
|
10875
|
+
}
|
|
10876
|
+
trackDisconnection(...args) {
|
|
10877
|
+
try {
|
|
10878
|
+
const event = createDisconnectionEvent(...args);
|
|
10879
|
+
this.dispatchUserActionEvent(event);
|
|
10880
|
+
} catch (e2) {
|
|
10881
|
+
}
|
|
10882
|
+
}
|
|
10883
|
+
trackTransactionSentForSignature(...args) {
|
|
10884
|
+
try {
|
|
10885
|
+
const event = createTransactionSentForSignatureEvent(...args);
|
|
10886
|
+
this.dispatchUserActionEvent(event);
|
|
10887
|
+
} catch (e2) {
|
|
10888
|
+
}
|
|
10889
|
+
}
|
|
10890
|
+
trackTransactionSigned(...args) {
|
|
10891
|
+
try {
|
|
10892
|
+
const event = createTransactionSignedEvent(...args);
|
|
10893
|
+
this.dispatchUserActionEvent(event);
|
|
10894
|
+
} catch (e2) {
|
|
10895
|
+
}
|
|
10896
|
+
}
|
|
10897
|
+
trackTransactionSigningFailed(...args) {
|
|
10898
|
+
try {
|
|
10899
|
+
const event = createTransactionSigningFailedEvent(...args);
|
|
10900
|
+
this.dispatchUserActionEvent(event);
|
|
10901
|
+
} catch (e2) {
|
|
10902
|
+
}
|
|
10903
|
+
}
|
|
10904
|
+
}
|
|
10725
10905
|
class TonConnectUI {
|
|
10726
10906
|
constructor(options) {
|
|
10727
10907
|
__publicField(this, "walletInfoStorage", new WalletInfoStorage());
|
|
10728
10908
|
__publicField(this, "preferredWalletStorage", new PreferredWalletStorage());
|
|
10909
|
+
__publicField(this, "tracker", new TonConnectTracker());
|
|
10729
10910
|
__publicField(this, "walletInfo", null);
|
|
10730
10911
|
__publicField(this, "systemThemeChangeUnsubscribe", null);
|
|
10731
10912
|
__publicField(this, "actionsConfiguration");
|
|
@@ -10765,10 +10946,14 @@ class TonConnectUI {
|
|
|
10765
10946
|
const rootId = this.normalizeWidgetRoot(options == null ? void 0 : options.widgetRootId);
|
|
10766
10947
|
this.subscribeToWalletChange();
|
|
10767
10948
|
if ((options == null ? void 0 : options.restoreConnection) !== false) {
|
|
10949
|
+
this.tracker.trackConnectionRestoringStarted();
|
|
10768
10950
|
this.connectionRestored = new Promise((resolve) => __async(this, null, function* () {
|
|
10769
10951
|
yield this.connector.restoreConnection();
|
|
10770
10952
|
if (!this.connector.connected) {
|
|
10953
|
+
this.tracker.trackConnectionRestoringError("Connection was not restored");
|
|
10771
10954
|
this.walletInfoStorage.removeWalletInfo();
|
|
10955
|
+
} else {
|
|
10956
|
+
this.tracker.trackConnectionRestoringCompleted(this.wallet);
|
|
10772
10957
|
}
|
|
10773
10958
|
resolve(this.connector.connected);
|
|
10774
10959
|
}));
|
|
@@ -10863,10 +11048,12 @@ class TonConnectUI {
|
|
|
10863
11048
|
}
|
|
10864
11049
|
openModal() {
|
|
10865
11050
|
return __async(this, null, function* () {
|
|
11051
|
+
this.tracker.trackConnectionStarted();
|
|
10866
11052
|
return this.modal.open();
|
|
10867
11053
|
});
|
|
10868
11054
|
}
|
|
10869
11055
|
closeModal() {
|
|
11056
|
+
this.tracker.trackConnectionError("Connection was cancelled");
|
|
10870
11057
|
this.modal.close();
|
|
10871
11058
|
}
|
|
10872
11059
|
onModalStateChange(onChange) {
|
|
@@ -10877,10 +11064,12 @@ class TonConnectUI {
|
|
|
10877
11064
|
}
|
|
10878
11065
|
openSingleWalletModal(wallet) {
|
|
10879
11066
|
return __async(this, null, function* () {
|
|
11067
|
+
this.tracker.trackConnectionStarted();
|
|
10880
11068
|
return this.singleWalletModal.open(wallet);
|
|
10881
11069
|
});
|
|
10882
11070
|
}
|
|
10883
11071
|
closeSingleWalletModal() {
|
|
11072
|
+
this.tracker.trackConnectionError("Connection was cancelled");
|
|
10884
11073
|
this.singleWalletModal.close();
|
|
10885
11074
|
}
|
|
10886
11075
|
onSingleWalletModalStateChange(onChange) {
|
|
@@ -10901,6 +11090,7 @@ class TonConnectUI {
|
|
|
10901
11090
|
});
|
|
10902
11091
|
}
|
|
10903
11092
|
disconnect() {
|
|
11093
|
+
this.tracker.trackDisconnection(this.wallet, "dapp");
|
|
10904
11094
|
widgetController.clearAction();
|
|
10905
11095
|
widgetController.removeSelectedWalletInfo();
|
|
10906
11096
|
this.walletInfoStorage.removeWalletInfo();
|
|
@@ -10908,7 +11098,9 @@ class TonConnectUI {
|
|
|
10908
11098
|
}
|
|
10909
11099
|
sendTransaction(tx, options) {
|
|
10910
11100
|
return __async(this, null, function* () {
|
|
11101
|
+
this.tracker.trackTransactionSentForSignature(this.wallet, tx);
|
|
10911
11102
|
if (!this.connected) {
|
|
11103
|
+
this.tracker.trackTransactionSigningFailed(this.wallet, tx, "Wallet was not connected");
|
|
10912
11104
|
throw new TonConnectUIError("Connect wallet to send a transaction.");
|
|
10913
11105
|
}
|
|
10914
11106
|
if (isInTMA()) {
|
|
@@ -10970,6 +11162,7 @@ class TonConnectUI {
|
|
|
10970
11162
|
},
|
|
10971
11163
|
onRequestSent
|
|
10972
11164
|
);
|
|
11165
|
+
this.tracker.trackTransactionSigned(this.wallet, tx, result);
|
|
10973
11166
|
widgetController.setAction({
|
|
10974
11167
|
name: "transaction-sent",
|
|
10975
11168
|
showNotification: notifications2.includes("success"),
|
|
@@ -10977,6 +11170,7 @@ class TonConnectUI {
|
|
|
10977
11170
|
});
|
|
10978
11171
|
return result;
|
|
10979
11172
|
} catch (e2) {
|
|
11173
|
+
this.tracker.trackTransactionSigningFailed(this.wallet, tx, e2.message);
|
|
10980
11174
|
widgetController.setAction({
|
|
10981
11175
|
name: "transaction-canceled",
|
|
10982
11176
|
showNotification: notifications2.includes("error"),
|
|
@@ -11033,23 +11227,28 @@ class TonConnectUI {
|
|
|
11033
11227
|
waitForWalletConnection(options) {
|
|
11034
11228
|
return __async(this, null, function* () {
|
|
11035
11229
|
return new Promise((resolve, reject) => {
|
|
11230
|
+
this.tracker.trackConnectionStarted();
|
|
11036
11231
|
const { ignoreErrors = false, signal = null } = options;
|
|
11037
11232
|
if (signal && signal.aborted) {
|
|
11233
|
+
this.tracker.trackConnectionError("Connection was cancelled");
|
|
11038
11234
|
return reject(new TonConnectUIError("Wallet was not connected"));
|
|
11039
11235
|
}
|
|
11040
11236
|
const onStatusChangeHandler = (wallet) => __async(this, null, function* () {
|
|
11041
11237
|
if (!wallet) {
|
|
11238
|
+
this.tracker.trackConnectionError("Connection was cancelled");
|
|
11042
11239
|
if (ignoreErrors) {
|
|
11043
11240
|
return;
|
|
11044
11241
|
}
|
|
11045
11242
|
unsubscribe();
|
|
11046
11243
|
reject(new TonConnectUIError("Wallet was not connected"));
|
|
11047
11244
|
} else {
|
|
11245
|
+
this.tracker.trackConnectionCompleted(wallet);
|
|
11048
11246
|
unsubscribe();
|
|
11049
11247
|
resolve(wallet);
|
|
11050
11248
|
}
|
|
11051
11249
|
});
|
|
11052
11250
|
const onErrorsHandler = (reason) => {
|
|
11251
|
+
this.tracker.trackConnectionError(reason.message);
|
|
11053
11252
|
if (ignoreErrors) {
|
|
11054
11253
|
return;
|
|
11055
11254
|
}
|