@tonconnect/sdk 3.0.2 → 3.0.3-beta.1

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/esm/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CONNECT_EVENT_ERROR_CODES, SEND_TRANSACTION_ERROR_CODES, Base64, SessionCrypto, hexToByteArray } from '@tonconnect/protocol';
2
- export { CHAIN, CONNECT_ITEM_ERROR_CODES } from '@tonconnect/protocol';
2
+ export { CHAIN, CONNECT_EVENT_ERROR_CODES, CONNECT_ITEM_ERROR_CODES, SEND_TRANSACTION_ERROR_CODES } from '@tonconnect/protocol';
3
3
  import '@tonconnect/isomorphic-eventsource';
4
4
  import '@tonconnect/isomorphic-fetch';
5
5
 
@@ -489,15 +489,16 @@ function createResource(createFn, disposeFn) {
489
489
  currentResource = null;
490
490
  const promise = currentPromise;
491
491
  currentPromise = null;
492
- abortController === null || abortController === void 0 ? void 0 : abortController.abort();
492
+ try {
493
+ abortController === null || abortController === void 0 ? void 0 : abortController.abort();
494
+ }
495
+ catch (e) { }
493
496
  yield Promise.allSettled([
494
497
  resource ? disposeFn(resource) : Promise.resolve(),
495
498
  promise ? disposeFn(yield promise) : Promise.resolve()
496
499
  ]);
497
500
  }
498
- catch (e) {
499
- logError('Failed to dispose the resource', e);
500
- }
501
+ catch (e) { }
501
502
  });
502
503
  // recreate the current resource
503
504
  const recreate = (delayMs) => __awaiter(this, void 0, void 0, function* () {
@@ -1267,12 +1268,10 @@ class BridgeProvider {
1267
1268
  return __awaiter(this, void 0, void 0, function* () {
1268
1269
  if (Array.isArray(this.walletConnectionSource)) {
1269
1270
  // close all gateways before opening new ones
1270
- this.pendingGateways.map(bridge => bridge.close().catch(e => console.error(e)));
1271
+ this.pendingGateways.map(bridge => bridge.close().catch());
1271
1272
  // open new gateways
1272
1273
  this.pendingGateways = this.walletConnectionSource.map(source => {
1273
- const gateway = new BridgeGateway(this.storage, source.bridgeUrl, sessionCrypto.sessionId, () => { }, e => {
1274
- console.error(e);
1275
- });
1274
+ const gateway = new BridgeGateway(this.storage, source.bridgeUrl, sessionCrypto.sessionId, () => { }, () => { });
1276
1275
  gateway.setListener(message => this.pendingGatewaysListener(gateway, source.bridgeUrl, message));
1277
1276
  return gateway;
1278
1277
  });
@@ -2005,6 +2004,424 @@ function checkSendTransactionSupport(features, options) {
2005
2004
  logWarning("Connected wallet didn't provide information about max allowed messages in the SendTransaction request. Request may be rejected by the wallet.");
2006
2005
  }
2007
2006
 
2007
+ /**
2008
+ * Create a request version event.
2009
+ */
2010
+ function createRequestVersionEvent() {
2011
+ return {
2012
+ type: 'request-version'
2013
+ };
2014
+ }
2015
+ /**
2016
+ * Create a response version event.
2017
+ * @param version
2018
+ */
2019
+ function createResponseVersionEvent(version) {
2020
+ return {
2021
+ type: 'response-version',
2022
+ version: version
2023
+ };
2024
+ }
2025
+ /**
2026
+ * Create a version info.
2027
+ * @param version
2028
+ */
2029
+ function createVersionInfo(version) {
2030
+ return {
2031
+ ton_connect_sdk_lib: version.ton_connect_sdk_lib,
2032
+ ton_connect_ui_lib: version.ton_connect_ui_lib
2033
+ };
2034
+ }
2035
+ function createConnectionInfo(version, wallet) {
2036
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2037
+ const isTonProof = ((_a = wallet === null || wallet === void 0 ? void 0 : wallet.connectItems) === null || _a === void 0 ? void 0 : _a.tonProof) && 'proof' in wallet.connectItems.tonProof;
2038
+ const authType = isTonProof ? 'ton_proof' : 'ton_addr';
2039
+ return {
2040
+ wallet_address: (_c = (_b = wallet === null || wallet === void 0 ? void 0 : wallet.account) === null || _b === void 0 ? void 0 : _b.address) !== null && _c !== void 0 ? _c : null,
2041
+ wallet_type: (_d = wallet === null || wallet === void 0 ? void 0 : wallet.device.appName) !== null && _d !== void 0 ? _d : null,
2042
+ wallet_version: (_e = wallet === null || wallet === void 0 ? void 0 : wallet.device.appVersion) !== null && _e !== void 0 ? _e : null,
2043
+ auth_type: authType,
2044
+ custom_data: Object.assign({ chain_id: (_g = (_f = wallet === null || wallet === void 0 ? void 0 : wallet.account) === null || _f === void 0 ? void 0 : _f.chain) !== null && _g !== void 0 ? _g : null, provider: (_h = wallet === null || wallet === void 0 ? void 0 : wallet.provider) !== null && _h !== void 0 ? _h : null }, createVersionInfo(version))
2045
+ };
2046
+ }
2047
+ /**
2048
+ * Create a connection init event.
2049
+ */
2050
+ function createConnectionStartedEvent(version) {
2051
+ return {
2052
+ type: 'connection-started',
2053
+ custom_data: createVersionInfo(version)
2054
+ };
2055
+ }
2056
+ /**
2057
+ * Create a connection completed event.
2058
+ * @param version
2059
+ * @param wallet
2060
+ */
2061
+ function createConnectionCompletedEvent(version, wallet) {
2062
+ return Object.assign({ type: 'connection-completed', is_success: true }, createConnectionInfo(version, wallet));
2063
+ }
2064
+ /**
2065
+ * Create a connection error event.
2066
+ * @param version
2067
+ * @param error_message
2068
+ * @param errorCode
2069
+ */
2070
+ function createConnectionErrorEvent(version, error_message, errorCode) {
2071
+ return {
2072
+ type: 'connection-error',
2073
+ is_success: false,
2074
+ error_message: error_message,
2075
+ error_code: errorCode !== null && errorCode !== void 0 ? errorCode : null,
2076
+ custom_data: createVersionInfo(version)
2077
+ };
2078
+ }
2079
+ /**
2080
+ * Create a connection restoring started event.
2081
+ */
2082
+ function createConnectionRestoringStartedEvent(version) {
2083
+ return {
2084
+ type: 'connection-restoring-started',
2085
+ custom_data: createVersionInfo(version)
2086
+ };
2087
+ }
2088
+ /**
2089
+ * Create a connection restoring completed event.
2090
+ * @param version
2091
+ * @param wallet
2092
+ */
2093
+ function createConnectionRestoringCompletedEvent(version, wallet) {
2094
+ return Object.assign({ type: 'connection-restoring-completed', is_success: true }, createConnectionInfo(version, wallet));
2095
+ }
2096
+ /**
2097
+ * Create a connection restoring error event.
2098
+ * @param version
2099
+ * @param errorMessage
2100
+ */
2101
+ function createConnectionRestoringErrorEvent(version, errorMessage) {
2102
+ return {
2103
+ type: 'connection-restoring-error',
2104
+ is_success: false,
2105
+ error_message: errorMessage,
2106
+ custom_data: createVersionInfo(version)
2107
+ };
2108
+ }
2109
+ function createTransactionInfo(wallet, transaction) {
2110
+ var _a, _b, _c, _d;
2111
+ return {
2112
+ valid_until: (_a = String(transaction.validUntil)) !== null && _a !== void 0 ? _a : null,
2113
+ from: (_d = (_b = transaction.from) !== null && _b !== void 0 ? _b : (_c = wallet === null || wallet === void 0 ? void 0 : wallet.account) === null || _c === void 0 ? void 0 : _c.address) !== null && _d !== void 0 ? _d : null,
2114
+ messages: transaction.messages.map(message => {
2115
+ var _a, _b;
2116
+ return ({
2117
+ address: (_a = message.address) !== null && _a !== void 0 ? _a : null,
2118
+ amount: (_b = message.amount) !== null && _b !== void 0 ? _b : null
2119
+ });
2120
+ })
2121
+ };
2122
+ }
2123
+ /**
2124
+ * Create a transaction init event.
2125
+ * @param version
2126
+ * @param wallet
2127
+ * @param transaction
2128
+ */
2129
+ function createTransactionSentForSignatureEvent(version, wallet, transaction) {
2130
+ return Object.assign(Object.assign({ type: 'transaction-sent-for-signature' }, createConnectionInfo(version, wallet)), createTransactionInfo(wallet, transaction));
2131
+ }
2132
+ /**
2133
+ * Create a transaction signed event.
2134
+ * @param version
2135
+ * @param wallet
2136
+ * @param transaction
2137
+ * @param signedTransaction
2138
+ */
2139
+ function createTransactionSignedEvent(version, wallet, transaction, signedTransaction) {
2140
+ return Object.assign(Object.assign({ type: 'transaction-signed', is_success: true, signed_transaction: signedTransaction.boc }, createConnectionInfo(version, wallet)), createTransactionInfo(wallet, transaction));
2141
+ }
2142
+ /**
2143
+ * Create a transaction error event.
2144
+ * @param version
2145
+ * @param wallet
2146
+ * @param transaction
2147
+ * @param errorMessage
2148
+ * @param errorCode
2149
+ */
2150
+ function createTransactionSigningFailedEvent(version, wallet, transaction, errorMessage, errorCode) {
2151
+ return Object.assign(Object.assign({ type: 'transaction-signing-failed', is_success: false, error_message: errorMessage, error_code: errorCode !== null && errorCode !== void 0 ? errorCode : null }, createConnectionInfo(version, wallet)), createTransactionInfo(wallet, transaction));
2152
+ }
2153
+ /**
2154
+ * Create a disconnect event.
2155
+ * @param version
2156
+ * @param wallet
2157
+ * @param scope
2158
+ * @returns
2159
+ */
2160
+ function createDisconnectionEvent(version, wallet, scope) {
2161
+ return Object.assign({ type: 'disconnection', scope: scope }, createConnectionInfo(version, wallet));
2162
+ }
2163
+
2164
+ /**
2165
+ * A concrete implementation of EventDispatcher that dispatches events to the browser window.
2166
+ */
2167
+ class BrowserEventDispatcher {
2168
+ constructor() {
2169
+ /**
2170
+ * The window object, possibly undefined in a server environment.
2171
+ * @private
2172
+ */
2173
+ this.window = getWindow();
2174
+ }
2175
+ /**
2176
+ * Dispatches an event with the given name and details to the browser window.
2177
+ * @param eventName - The name of the event to dispatch.
2178
+ * @param eventDetails - The details of the event to dispatch.
2179
+ * @returns A promise that resolves when the event has been dispatched.
2180
+ */
2181
+ dispatchEvent(eventName, eventDetails) {
2182
+ var _a;
2183
+ return __awaiter(this, void 0, void 0, function* () {
2184
+ const event = new CustomEvent(eventName, { detail: eventDetails });
2185
+ (_a = this.window) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
2186
+ });
2187
+ }
2188
+ /**
2189
+ * Adds an event listener to the browser window.
2190
+ * @param eventName - The name of the event to listen for.
2191
+ * @param listener - The listener to add.
2192
+ * @param options - The options for the listener.
2193
+ * @returns A function that removes the listener.
2194
+ */
2195
+ addEventListener(eventName, listener, options) {
2196
+ var _a;
2197
+ return __awaiter(this, void 0, void 0, function* () {
2198
+ (_a = this.window) === null || _a === void 0 ? void 0 : _a.addEventListener(eventName, listener, options);
2199
+ return () => {
2200
+ var _a;
2201
+ return (_a = this.window) === null || _a === void 0 ? void 0 : _a.removeEventListener(eventName, listener);
2202
+ };
2203
+ });
2204
+ }
2205
+ }
2206
+
2207
+ /**
2208
+ * Tracker for TonConnect user actions, such as transaction signing, connection, etc.
2209
+ *
2210
+ * List of events:
2211
+ * * `connection-started`: when a user starts connecting a wallet.
2212
+ * * `connection-completed`: when a user successfully connected a wallet.
2213
+ * * `connection-error`: when a user cancels a connection or there is an error during the connection process.
2214
+ * * `connection-restoring-started`: when the dApp starts restoring a connection.
2215
+ * * `connection-restoring-completed`: when the dApp successfully restores a connection.
2216
+ * * `connection-restoring-error`: when the dApp fails to restore a connection.
2217
+ * * `disconnection`: when a user starts disconnecting a wallet.
2218
+ * * `transaction-sent-for-signature`: when a user sends a transaction for signature.
2219
+ * * `transaction-signed`: when a user successfully signs a transaction.
2220
+ * * `transaction-signing-failed`: when a user cancels transaction signing or there is an error during the signing process.
2221
+ *
2222
+ * If you want to track user actions, you can subscribe to the window events with prefix `ton-connect-`:
2223
+ *
2224
+ * @example
2225
+ * window.addEventListener('ton-connect-transaction-sent-for-signature', (event) => {
2226
+ * console.log('Transaction init', event.detail);
2227
+ * });
2228
+ *
2229
+ * @internal
2230
+ */
2231
+ class TonConnectTracker {
2232
+ constructor(options) {
2233
+ var _a;
2234
+ /**
2235
+ * Event prefix for user actions.
2236
+ * @private
2237
+ */
2238
+ this.eventPrefix = 'ton-connect-';
2239
+ /**
2240
+ * TonConnect UI version.
2241
+ */
2242
+ this.tonConnectUiVersion = null;
2243
+ this.eventDispatcher = (_a = options === null || options === void 0 ? void 0 : options.eventDispatcher) !== null && _a !== void 0 ? _a : new BrowserEventDispatcher();
2244
+ this.tonConnectSdkVersion = options.tonConnectSdkVersion;
2245
+ this.init().catch();
2246
+ }
2247
+ /**
2248
+ * Version of the library.
2249
+ */
2250
+ get version() {
2251
+ return createVersionInfo({
2252
+ ton_connect_sdk_lib: this.tonConnectSdkVersion,
2253
+ ton_connect_ui_lib: this.tonConnectUiVersion
2254
+ });
2255
+ }
2256
+ /**
2257
+ * Called once when the tracker is created and request version other libraries.
2258
+ */
2259
+ init() {
2260
+ return __awaiter(this, void 0, void 0, function* () {
2261
+ try {
2262
+ yield this.setRequestVersionHandler();
2263
+ this.tonConnectUiVersion = yield this.requestTonConnectUiVersion();
2264
+ }
2265
+ catch (e) { }
2266
+ });
2267
+ }
2268
+ /**
2269
+ * Set request version handler.
2270
+ * @private
2271
+ */
2272
+ setRequestVersionHandler() {
2273
+ return __awaiter(this, void 0, void 0, function* () {
2274
+ yield this.eventDispatcher.addEventListener('ton-connect-request-version', () => __awaiter(this, void 0, void 0, function* () {
2275
+ yield this.eventDispatcher.dispatchEvent('ton-connect-response-version', createResponseVersionEvent(this.tonConnectSdkVersion));
2276
+ }));
2277
+ });
2278
+ }
2279
+ /**
2280
+ * Request TonConnect UI version.
2281
+ * @private
2282
+ */
2283
+ requestTonConnectUiVersion() {
2284
+ return __awaiter(this, void 0, void 0, function* () {
2285
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
2286
+ try {
2287
+ yield this.eventDispatcher.addEventListener('ton-connect-ui-response-version', (event) => {
2288
+ resolve(event.detail.version);
2289
+ }, { once: true });
2290
+ yield this.eventDispatcher.dispatchEvent('ton-connect-ui-request-version', createRequestVersionEvent());
2291
+ }
2292
+ catch (e) {
2293
+ reject(e);
2294
+ }
2295
+ }));
2296
+ });
2297
+ }
2298
+ /**
2299
+ * Emit user action event to the window.
2300
+ * @param eventDetails
2301
+ * @private
2302
+ */
2303
+ dispatchUserActionEvent(eventDetails) {
2304
+ try {
2305
+ this.eventDispatcher
2306
+ .dispatchEvent(`${this.eventPrefix}${eventDetails.type}`, eventDetails)
2307
+ .catch();
2308
+ }
2309
+ catch (e) { }
2310
+ }
2311
+ /**
2312
+ * Track connection init event.
2313
+ * @param args
2314
+ */
2315
+ trackConnectionStarted(...args) {
2316
+ try {
2317
+ const event = createConnectionStartedEvent(this.version, ...args);
2318
+ this.dispatchUserActionEvent(event);
2319
+ }
2320
+ catch (e) { }
2321
+ }
2322
+ /**
2323
+ * Track connection success event.
2324
+ * @param args
2325
+ */
2326
+ trackConnectionCompleted(...args) {
2327
+ try {
2328
+ const event = createConnectionCompletedEvent(this.version, ...args);
2329
+ this.dispatchUserActionEvent(event);
2330
+ }
2331
+ catch (e) { }
2332
+ }
2333
+ /**
2334
+ * Track connection error event.
2335
+ * @param args
2336
+ */
2337
+ trackConnectionError(...args) {
2338
+ try {
2339
+ const event = createConnectionErrorEvent(this.version, ...args);
2340
+ this.dispatchUserActionEvent(event);
2341
+ }
2342
+ catch (e) { }
2343
+ }
2344
+ /**
2345
+ * Track connection restoring init event.
2346
+ * @param args
2347
+ */
2348
+ trackConnectionRestoringStarted(...args) {
2349
+ try {
2350
+ const event = createConnectionRestoringStartedEvent(this.version, ...args);
2351
+ this.dispatchUserActionEvent(event);
2352
+ }
2353
+ catch (e) { }
2354
+ }
2355
+ /**
2356
+ * Track connection restoring success event.
2357
+ * @param args
2358
+ */
2359
+ trackConnectionRestoringCompleted(...args) {
2360
+ try {
2361
+ const event = createConnectionRestoringCompletedEvent(this.version, ...args);
2362
+ this.dispatchUserActionEvent(event);
2363
+ }
2364
+ catch (e) { }
2365
+ }
2366
+ /**
2367
+ * Track connection restoring error event.
2368
+ * @param args
2369
+ */
2370
+ trackConnectionRestoringError(...args) {
2371
+ try {
2372
+ const event = createConnectionRestoringErrorEvent(this.version, ...args);
2373
+ this.dispatchUserActionEvent(event);
2374
+ }
2375
+ catch (e) { }
2376
+ }
2377
+ /**
2378
+ * Track disconnect event.
2379
+ * @param args
2380
+ */
2381
+ trackDisconnection(...args) {
2382
+ try {
2383
+ const event = createDisconnectionEvent(this.version, ...args);
2384
+ this.dispatchUserActionEvent(event);
2385
+ }
2386
+ catch (e) { }
2387
+ }
2388
+ /**
2389
+ * Track transaction init event.
2390
+ * @param args
2391
+ */
2392
+ trackTransactionSentForSignature(...args) {
2393
+ try {
2394
+ const event = createTransactionSentForSignatureEvent(this.version, ...args);
2395
+ this.dispatchUserActionEvent(event);
2396
+ }
2397
+ catch (e) { }
2398
+ }
2399
+ /**
2400
+ * Track transaction signed event.
2401
+ * @param args
2402
+ */
2403
+ trackTransactionSigned(...args) {
2404
+ try {
2405
+ const event = createTransactionSignedEvent(this.version, ...args);
2406
+ this.dispatchUserActionEvent(event);
2407
+ }
2408
+ catch (e) { }
2409
+ }
2410
+ /**
2411
+ * Track transaction error event.
2412
+ * @param args
2413
+ */
2414
+ trackTransactionSigningFailed(...args) {
2415
+ try {
2416
+ const event = createTransactionSigningFailedEvent(this.version, ...args);
2417
+ this.dispatchUserActionEvent(event);
2418
+ }
2419
+ catch (e) { }
2420
+ }
2421
+ }
2422
+
2423
+ const tonConnectSdkVersion = "3.0.3-beta.1";
2424
+
2008
2425
  class TonConnect {
2009
2426
  constructor(options) {
2010
2427
  this.walletsList = new WalletsListManager();
@@ -2020,6 +2437,10 @@ class TonConnect {
2020
2437
  walletsListSource: options === null || options === void 0 ? void 0 : options.walletsListSource,
2021
2438
  cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs
2022
2439
  });
2440
+ this.tracker = new TonConnectTracker({
2441
+ eventDispatcher: options === null || options === void 0 ? void 0 : options.eventDispatcher,
2442
+ tonConnectSdkVersion: tonConnectSdkVersion
2443
+ });
2023
2444
  if (!this.dappSettings.manifestUrl) {
2024
2445
  throw new DappMetadataError('Dapp tonconnect-manifest.json must be specified if window.location.origin is undefined. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest');
2025
2446
  }
@@ -2112,6 +2533,7 @@ class TonConnect {
2112
2533
  (_a = this.provider) === null || _a === void 0 ? void 0 : _a.closeConnection();
2113
2534
  this.provider = null;
2114
2535
  });
2536
+ this.tracker.trackConnectionStarted();
2115
2537
  return this.provider.connect(this.createConnectRequest(options === null || options === void 0 ? void 0 : options.request), {
2116
2538
  openingDeadlineMS: options === null || options === void 0 ? void 0 : options.openingDeadlineMS,
2117
2539
  signal: abortController.signal
@@ -2123,10 +2545,12 @@ class TonConnect {
2123
2545
  restoreConnection(options) {
2124
2546
  var _a, _b;
2125
2547
  return __awaiter(this, void 0, void 0, function* () {
2548
+ this.tracker.trackConnectionRestoringStarted();
2126
2549
  const abortController = createAbortController(options === null || options === void 0 ? void 0 : options.signal);
2127
2550
  (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.abort();
2128
2551
  this.abortController = abortController;
2129
2552
  if (abortController.signal.aborted) {
2553
+ this.tracker.trackConnectionRestoringError('Connection restoring was aborted');
2130
2554
  return;
2131
2555
  }
2132
2556
  // TODO: potentially race condition here
@@ -2135,6 +2559,7 @@ class TonConnect {
2135
2559
  this.walletsList.getEmbeddedWallet()
2136
2560
  ]);
2137
2561
  if (abortController.signal.aborted) {
2562
+ this.tracker.trackConnectionRestoringError('Connection restoring was aborted');
2138
2563
  return;
2139
2564
  }
2140
2565
  let provider = null;
@@ -2156,6 +2581,7 @@ class TonConnect {
2156
2581
  }
2157
2582
  }
2158
2583
  catch (_c) {
2584
+ this.tracker.trackConnectionRestoringError('Provider is not restored');
2159
2585
  yield this.bridgeConnectionStorage.removeConnection();
2160
2586
  provider === null || provider === void 0 ? void 0 : provider.closeConnection();
2161
2587
  provider = null;
@@ -2163,24 +2589,35 @@ class TonConnect {
2163
2589
  }
2164
2590
  if (abortController.signal.aborted) {
2165
2591
  provider === null || provider === void 0 ? void 0 : provider.closeConnection();
2592
+ this.tracker.trackConnectionRestoringError('Connection restoring was aborted');
2166
2593
  return;
2167
2594
  }
2168
2595
  if (!provider) {
2169
2596
  logError('Provider is not restored');
2597
+ this.tracker.trackConnectionRestoringError('Provider is not restored');
2170
2598
  return;
2171
2599
  }
2172
2600
  (_b = this.provider) === null || _b === void 0 ? void 0 : _b.closeConnection();
2173
2601
  this.provider = provider;
2174
2602
  provider.listen(this.walletEventsListener.bind(this));
2175
- abortController.signal.addEventListener('abort', () => {
2603
+ const onAbortRestore = () => {
2604
+ this.tracker.trackConnectionRestoringError('Connection restoring was aborted');
2176
2605
  provider === null || provider === void 0 ? void 0 : provider.closeConnection();
2177
2606
  provider = null;
2178
- });
2607
+ };
2608
+ abortController.signal.addEventListener('abort', onAbortRestore);
2179
2609
  return yield callForSuccess((_options) => __awaiter(this, void 0, void 0, function* () {
2180
- return provider === null || provider === void 0 ? void 0 : provider.restoreConnection({
2610
+ yield (provider === null || provider === void 0 ? void 0 : provider.restoreConnection({
2181
2611
  openingDeadlineMS: options === null || options === void 0 ? void 0 : options.openingDeadlineMS,
2182
2612
  signal: _options.signal
2183
- });
2613
+ }));
2614
+ abortController.signal.removeEventListener('abort', onAbortRestore);
2615
+ if (this.connected) {
2616
+ this.tracker.trackConnectionRestoringCompleted(this.wallet);
2617
+ }
2618
+ else {
2619
+ this.tracker.trackConnectionRestoringError('Connection restoring failed');
2620
+ }
2184
2621
  }), {
2185
2622
  attempts: Number.MAX_SAFE_INTEGER,
2186
2623
  delayMs: 5000,
@@ -2207,15 +2644,19 @@ class TonConnect {
2207
2644
  checkSendTransactionSupport(this.wallet.device.features, {
2208
2645
  requiredMessagesNumber: transaction.messages.length
2209
2646
  });
2647
+ this.tracker.trackTransactionSentForSignature(this.wallet, transaction);
2210
2648
  const { validUntil } = transaction, tx = __rest(transaction, ["validUntil"]);
2211
2649
  const from = transaction.from || this.account.address;
2212
2650
  const network = transaction.network || this.account.chain;
2213
2651
  const response = yield this.provider.sendRequest(sendTransactionParser.convertToRpcRequest(Object.assign(Object.assign({}, tx), { valid_until: validUntil, from,
2214
2652
  network })), { onRequestSent: options.onRequestSent, signal: abortController.signal });
2215
2653
  if (sendTransactionParser.isError(response)) {
2654
+ this.tracker.trackTransactionSigningFailed(this.wallet, transaction, response.error.message, response.error.code);
2216
2655
  return sendTransactionParser.parseAndThrowError(response);
2217
2656
  }
2218
- return sendTransactionParser.convertFromRpcResponse(response);
2657
+ const result = sendTransactionParser.convertFromRpcResponse(response);
2658
+ this.tracker.trackTransactionSigned(this.wallet, transaction, result);
2659
+ return result;
2219
2660
  });
2220
2661
  }
2221
2662
  /**
@@ -2233,7 +2674,7 @@ class TonConnect {
2233
2674
  if (abortController.signal.aborted) {
2234
2675
  throw new TonConnectError('Disconnect was aborted');
2235
2676
  }
2236
- this.onWalletDisconnected();
2677
+ this.onWalletDisconnected('dapp');
2237
2678
  yield ((_a = this.provider) === null || _a === void 0 ? void 0 : _a.disconnect({
2238
2679
  signal: abortController.signal
2239
2680
  }));
@@ -2272,7 +2713,7 @@ class TonConnect {
2272
2713
  this.pauseConnection();
2273
2714
  }
2274
2715
  else {
2275
- this.unPauseConnection().catch(e => logError('Cannot unpause connection', e));
2716
+ this.unPauseConnection().catch();
2276
2717
  }
2277
2718
  });
2278
2719
  }
@@ -2300,7 +2741,7 @@ class TonConnect {
2300
2741
  this.onWalletConnectError(e.payload);
2301
2742
  break;
2302
2743
  case 'disconnect':
2303
- this.onWalletDisconnected();
2744
+ this.onWalletDisconnected('wallet');
2304
2745
  }
2305
2746
  }
2306
2747
  onWalletConnected(connectEvent) {
@@ -2325,17 +2766,20 @@ class TonConnect {
2325
2766
  };
2326
2767
  }
2327
2768
  this.wallet = wallet;
2769
+ this.tracker.trackConnectionCompleted(wallet);
2328
2770
  }
2329
2771
  onWalletConnectError(connectEventError) {
2330
2772
  const error = connectErrorsParser.parseError(connectEventError);
2331
2773
  this.statusChangeErrorSubscriptions.forEach(errorsHandler => errorsHandler(error));
2332
- console.debug(error);
2774
+ logDebug(error);
2775
+ this.tracker.trackConnectionError(connectEventError.message, connectEventError.code);
2333
2776
  if (error instanceof ManifestNotFoundError || error instanceof ManifestContentErrorError) {
2334
- console.error(error);
2777
+ logError(error);
2335
2778
  throw error;
2336
2779
  }
2337
2780
  }
2338
- onWalletDisconnected() {
2781
+ onWalletDisconnected(scope) {
2782
+ this.tracker.trackDisconnection(this.wallet, scope);
2339
2783
  this.wallet = null;
2340
2784
  }
2341
2785
  checkConnection() {
@@ -2465,5 +2909,5 @@ function hexToBytes(hex) {
2465
2909
  return result;
2466
2910
  }
2467
2911
 
2468
- export { BadRequestError, FetchWalletsError, LocalstorageNotFoundError, ParseHexError, TonConnect, TonConnectError, UnknownAppError, UnknownError, UserRejectsError, WalletAlreadyConnectedError, WalletNotConnectedError, WalletNotInjectedError, WalletsListManager, WrongAddressError, TonConnect as default, encodeTelegramUrlParameters, isTelegramUrl, isWalletInfoCurrentlyEmbedded, isWalletInfoCurrentlyInjected, isWalletInfoInjectable, isWalletInfoInjected, isWalletInfoRemote, toUserFriendlyAddress };
2912
+ export { BadRequestError, BrowserEventDispatcher, FetchWalletsError, LocalstorageNotFoundError, ParseHexError, TonConnect, TonConnectError, UnknownAppError, UnknownError, UserRejectsError, WalletAlreadyConnectedError, WalletNotConnectedError, WalletNotInjectedError, WalletsListManager, WrongAddressError, createConnectionCompletedEvent, createConnectionErrorEvent, createConnectionRestoringCompletedEvent, createConnectionRestoringErrorEvent, createConnectionRestoringStartedEvent, createConnectionStartedEvent, createDisconnectionEvent, createRequestVersionEvent, createResponseVersionEvent, createTransactionSentForSignatureEvent, createTransactionSignedEvent, createTransactionSigningFailedEvent, createVersionInfo, TonConnect as default, encodeTelegramUrlParameters, isTelegramUrl, isWalletInfoCurrentlyEmbedded, isWalletInfoCurrentlyInjected, isWalletInfoInjectable, isWalletInfoInjected, isWalletInfoRemote, toUserFriendlyAddress };
2469
2913
  //# sourceMappingURL=index.mjs.map