@tonconnect/sdk 3.0.2 → 3.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/README.md +48 -0
- package/dist/tonconnect-sdk.min.js +1 -1
- package/dist/tonconnect-sdk.min.js.map +1 -1
- package/lib/cjs/index.cjs +358 -13
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/index.mjs +341 -15
- package/lib/esm/index.mjs.map +1 -1
- package/lib/types/index.d.ts +355 -0
- package/package.json +1 -1
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,7 +489,10 @@ function createResource(createFn, disposeFn) {
|
|
|
489
489
|
currentResource = null;
|
|
490
490
|
const promise = currentPromise;
|
|
491
491
|
currentPromise = null;
|
|
492
|
-
|
|
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()
|
|
@@ -1267,12 +1270,10 @@ class BridgeProvider {
|
|
|
1267
1270
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1268
1271
|
if (Array.isArray(this.walletConnectionSource)) {
|
|
1269
1272
|
// close all gateways before opening new ones
|
|
1270
|
-
this.pendingGateways.map(bridge => bridge.close().catch(
|
|
1273
|
+
this.pendingGateways.map(bridge => bridge.close().catch());
|
|
1271
1274
|
// open new gateways
|
|
1272
1275
|
this.pendingGateways = this.walletConnectionSource.map(source => {
|
|
1273
|
-
const gateway = new BridgeGateway(this.storage, source.bridgeUrl, sessionCrypto.sessionId, () => { },
|
|
1274
|
-
console.error(e);
|
|
1275
|
-
});
|
|
1276
|
+
const gateway = new BridgeGateway(this.storage, source.bridgeUrl, sessionCrypto.sessionId, () => { }, () => { });
|
|
1276
1277
|
gateway.setListener(message => this.pendingGatewaysListener(gateway, source.bridgeUrl, message));
|
|
1277
1278
|
return gateway;
|
|
1278
1279
|
});
|
|
@@ -2005,6 +2006,307 @@ function checkSendTransactionSupport(features, options) {
|
|
|
2005
2006
|
logWarning("Connected wallet didn't provide information about max allowed messages in the SendTransaction request. Request may be rejected by the wallet.");
|
|
2006
2007
|
}
|
|
2007
2008
|
|
|
2009
|
+
function createConnectionInfo(wallet) {
|
|
2010
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2011
|
+
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;
|
|
2012
|
+
const authType = isTonProof ? 'ton_proof' : 'ton_addr';
|
|
2013
|
+
return {
|
|
2014
|
+
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,
|
|
2015
|
+
wallet_type: (_d = wallet === null || wallet === void 0 ? void 0 : wallet.device.appName) !== null && _d !== void 0 ? _d : null,
|
|
2016
|
+
wallet_version: (_e = wallet === null || wallet === void 0 ? void 0 : wallet.device.appVersion) !== null && _e !== void 0 ? _e : null,
|
|
2017
|
+
auth_type: authType,
|
|
2018
|
+
custom_data: {
|
|
2019
|
+
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,
|
|
2020
|
+
provider: (_h = wallet === null || wallet === void 0 ? void 0 : wallet.provider) !== null && _h !== void 0 ? _h : null
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
2024
|
+
/**
|
|
2025
|
+
* Create a connection init event.
|
|
2026
|
+
*/
|
|
2027
|
+
function createConnectionStartedEvent() {
|
|
2028
|
+
return {
|
|
2029
|
+
type: 'connection-started'
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
/**
|
|
2033
|
+
* Create a connection completed event.
|
|
2034
|
+
* @param wallet
|
|
2035
|
+
*/
|
|
2036
|
+
function createConnectionCompletedEvent(wallet) {
|
|
2037
|
+
return Object.assign({ type: 'connection-completed' }, createConnectionInfo(wallet));
|
|
2038
|
+
}
|
|
2039
|
+
/**
|
|
2040
|
+
* Create a connection error event.
|
|
2041
|
+
* @param error_message
|
|
2042
|
+
* @param errorCode
|
|
2043
|
+
*/
|
|
2044
|
+
function createConnectionErrorEvent(error_message, errorCode) {
|
|
2045
|
+
return {
|
|
2046
|
+
type: 'connection-error',
|
|
2047
|
+
error_message: error_message,
|
|
2048
|
+
error_code: errorCode !== null && errorCode !== void 0 ? errorCode : null
|
|
2049
|
+
};
|
|
2050
|
+
}
|
|
2051
|
+
/**
|
|
2052
|
+
* Create a connection restoring started event.
|
|
2053
|
+
*/
|
|
2054
|
+
function createConnectionRestoringStartedEvent() {
|
|
2055
|
+
return {
|
|
2056
|
+
type: 'connection-restoring-started'
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
/**
|
|
2060
|
+
* Create a connection restoring completed event.
|
|
2061
|
+
* @param wallet
|
|
2062
|
+
*/
|
|
2063
|
+
function createConnectionRestoringCompletedEvent(wallet) {
|
|
2064
|
+
return Object.assign({ type: 'connection-restoring-completed' }, createConnectionInfo(wallet));
|
|
2065
|
+
}
|
|
2066
|
+
/**
|
|
2067
|
+
* Create a connection restoring error event.
|
|
2068
|
+
* @param errorMessage
|
|
2069
|
+
*/
|
|
2070
|
+
function createConnectionRestoringErrorEvent(errorMessage) {
|
|
2071
|
+
return {
|
|
2072
|
+
type: 'connection-restoring-error',
|
|
2073
|
+
error_message: errorMessage
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
function createTransactionInfo(wallet, transaction) {
|
|
2077
|
+
var _a, _b, _c, _d;
|
|
2078
|
+
return {
|
|
2079
|
+
valid_until: (_a = String(transaction.validUntil)) !== null && _a !== void 0 ? _a : null,
|
|
2080
|
+
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,
|
|
2081
|
+
messages: transaction.messages.map(message => {
|
|
2082
|
+
var _a, _b;
|
|
2083
|
+
return ({
|
|
2084
|
+
address: (_a = message.address) !== null && _a !== void 0 ? _a : null,
|
|
2085
|
+
amount: (_b = message.amount) !== null && _b !== void 0 ? _b : null
|
|
2086
|
+
});
|
|
2087
|
+
})
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
2091
|
+
* Create a transaction init event.
|
|
2092
|
+
* @param wallet
|
|
2093
|
+
* @param transaction
|
|
2094
|
+
*/
|
|
2095
|
+
function createTransactionSentForSignatureEvent(wallet, transaction) {
|
|
2096
|
+
return Object.assign(Object.assign({ type: 'transaction-sent-for-signature' }, createConnectionInfo(wallet)), createTransactionInfo(wallet, transaction));
|
|
2097
|
+
}
|
|
2098
|
+
/**
|
|
2099
|
+
* Create a transaction signed event.
|
|
2100
|
+
* @param wallet
|
|
2101
|
+
* @param transaction
|
|
2102
|
+
* @param signedTransaction
|
|
2103
|
+
*/
|
|
2104
|
+
function createTransactionSignedEvent(wallet, transaction, signedTransaction) {
|
|
2105
|
+
return Object.assign(Object.assign({ type: 'transaction-signed', signed_transaction: signedTransaction.boc }, createConnectionInfo(wallet)), createTransactionInfo(wallet, transaction));
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* Create a transaction error event.
|
|
2109
|
+
* @param wallet
|
|
2110
|
+
* @param transaction
|
|
2111
|
+
* @param errorMessage
|
|
2112
|
+
* @param errorCode
|
|
2113
|
+
*/
|
|
2114
|
+
function createTransactionSigningFailedEvent(wallet, transaction, errorMessage, errorCode) {
|
|
2115
|
+
return Object.assign(Object.assign({ type: 'transaction-signing-failed', error_message: errorMessage, error_code: errorCode !== null && errorCode !== void 0 ? errorCode : null }, createConnectionInfo(wallet)), createTransactionInfo(wallet, transaction));
|
|
2116
|
+
}
|
|
2117
|
+
/**
|
|
2118
|
+
* Create a disconnect event.
|
|
2119
|
+
* @param wallet
|
|
2120
|
+
* @param scope
|
|
2121
|
+
* @returns
|
|
2122
|
+
*/
|
|
2123
|
+
function createDisconnectionEvent(wallet, scope) {
|
|
2124
|
+
return Object.assign({ type: 'disconnection', scope: scope }, createConnectionInfo(wallet));
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
/**
|
|
2128
|
+
* A concrete implementation of EventDispatcher that dispatches events to the browser window.
|
|
2129
|
+
*/
|
|
2130
|
+
class BrowserEventDispatcher {
|
|
2131
|
+
constructor() {
|
|
2132
|
+
/**
|
|
2133
|
+
* The window object, possibly undefined in a server environment.
|
|
2134
|
+
* @private
|
|
2135
|
+
*/
|
|
2136
|
+
this.window = getWindow();
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Dispatches an event with the given name and details to the browser window.
|
|
2140
|
+
* @param eventName - The name of the event to dispatch.
|
|
2141
|
+
* @param eventDetails - The details of the event to dispatch.
|
|
2142
|
+
* @returns A promise that resolves when the event has been dispatched.
|
|
2143
|
+
*/
|
|
2144
|
+
dispatchEvent(eventName, eventDetails) {
|
|
2145
|
+
var _a;
|
|
2146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2147
|
+
const event = new CustomEvent(eventName, { detail: eventDetails });
|
|
2148
|
+
(_a = this.window) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
/**
|
|
2154
|
+
* Tracker for TonConnect user actions, such as transaction signing, connection, etc.
|
|
2155
|
+
*
|
|
2156
|
+
* List of events:
|
|
2157
|
+
* * `connection-started`: when a user starts connecting a wallet.
|
|
2158
|
+
* * `connection-completed`: when a user successfully connected a wallet.
|
|
2159
|
+
* * `connection-error`: when a user cancels a connection or there is an error during the connection process.
|
|
2160
|
+
* * `connection-restoring-started`: when the dApp starts restoring a connection.
|
|
2161
|
+
* * `connection-restoring-completed`: when the dApp successfully restores a connection.
|
|
2162
|
+
* * `connection-restoring-error`: when the dApp fails to restore a connection.
|
|
2163
|
+
* * `disconnection`: when a user starts disconnecting a wallet.
|
|
2164
|
+
* * `transaction-sent-for-signature`: when a user sends a transaction for signature.
|
|
2165
|
+
* * `transaction-signed`: when a user successfully signs a transaction.
|
|
2166
|
+
* * `transaction-signing-failed`: when a user cancels transaction signing or there is an error during the signing process.
|
|
2167
|
+
*
|
|
2168
|
+
* If you want to track user actions, you can subscribe to the window events with prefix `ton-connect-`:
|
|
2169
|
+
*
|
|
2170
|
+
* @example
|
|
2171
|
+
* window.addEventListener('ton-connect-transaction-sent-for-signature', (event) => {
|
|
2172
|
+
* console.log('Transaction init', event.detail);
|
|
2173
|
+
* });
|
|
2174
|
+
*
|
|
2175
|
+
* @internal
|
|
2176
|
+
*/
|
|
2177
|
+
class TonConnectTracker {
|
|
2178
|
+
constructor(eventDispatcher) {
|
|
2179
|
+
/**
|
|
2180
|
+
* Event prefix for user actions.
|
|
2181
|
+
* @private
|
|
2182
|
+
*/
|
|
2183
|
+
this.eventPrefix = 'ton-connect-';
|
|
2184
|
+
this.eventDispatcher = eventDispatcher !== null && eventDispatcher !== void 0 ? eventDispatcher : new BrowserEventDispatcher();
|
|
2185
|
+
}
|
|
2186
|
+
/**
|
|
2187
|
+
* Emit user action event to the window.
|
|
2188
|
+
* @param eventDetails
|
|
2189
|
+
* @private
|
|
2190
|
+
*/
|
|
2191
|
+
dispatchUserActionEvent(eventDetails) {
|
|
2192
|
+
try {
|
|
2193
|
+
const eventName = `${this.eventPrefix}${eventDetails.type}`;
|
|
2194
|
+
this.eventDispatcher.dispatchEvent(eventName, eventDetails).catch();
|
|
2195
|
+
}
|
|
2196
|
+
catch (e) { }
|
|
2197
|
+
}
|
|
2198
|
+
/**
|
|
2199
|
+
* Track connection init event.
|
|
2200
|
+
* @param args
|
|
2201
|
+
*/
|
|
2202
|
+
trackConnectionStarted(...args) {
|
|
2203
|
+
try {
|
|
2204
|
+
const event = createConnectionStartedEvent(...args);
|
|
2205
|
+
this.dispatchUserActionEvent(event);
|
|
2206
|
+
}
|
|
2207
|
+
catch (e) { }
|
|
2208
|
+
}
|
|
2209
|
+
/**
|
|
2210
|
+
* Track connection success event.
|
|
2211
|
+
* @param args
|
|
2212
|
+
*/
|
|
2213
|
+
trackConnectionCompleted(...args) {
|
|
2214
|
+
try {
|
|
2215
|
+
const event = createConnectionCompletedEvent(...args);
|
|
2216
|
+
this.dispatchUserActionEvent(event);
|
|
2217
|
+
}
|
|
2218
|
+
catch (e) { }
|
|
2219
|
+
}
|
|
2220
|
+
/**
|
|
2221
|
+
* Track connection error event.
|
|
2222
|
+
* @param args
|
|
2223
|
+
*/
|
|
2224
|
+
trackConnectionError(...args) {
|
|
2225
|
+
try {
|
|
2226
|
+
const event = createConnectionErrorEvent(...args);
|
|
2227
|
+
this.dispatchUserActionEvent(event);
|
|
2228
|
+
}
|
|
2229
|
+
catch (e) { }
|
|
2230
|
+
}
|
|
2231
|
+
/**
|
|
2232
|
+
* Track connection restoring init event.
|
|
2233
|
+
* @param args
|
|
2234
|
+
*/
|
|
2235
|
+
trackConnectionRestoringStarted(...args) {
|
|
2236
|
+
try {
|
|
2237
|
+
const event = createConnectionRestoringStartedEvent(...args);
|
|
2238
|
+
this.dispatchUserActionEvent(event);
|
|
2239
|
+
}
|
|
2240
|
+
catch (e) { }
|
|
2241
|
+
}
|
|
2242
|
+
/**
|
|
2243
|
+
* Track connection restoring success event.
|
|
2244
|
+
* @param args
|
|
2245
|
+
*/
|
|
2246
|
+
trackConnectionRestoringCompleted(...args) {
|
|
2247
|
+
try {
|
|
2248
|
+
const event = createConnectionRestoringCompletedEvent(...args);
|
|
2249
|
+
this.dispatchUserActionEvent(event);
|
|
2250
|
+
}
|
|
2251
|
+
catch (e) { }
|
|
2252
|
+
}
|
|
2253
|
+
/**
|
|
2254
|
+
* Track connection restoring error event.
|
|
2255
|
+
* @param args
|
|
2256
|
+
*/
|
|
2257
|
+
trackConnectionRestoringError(...args) {
|
|
2258
|
+
try {
|
|
2259
|
+
const event = createConnectionRestoringErrorEvent(...args);
|
|
2260
|
+
this.dispatchUserActionEvent(event);
|
|
2261
|
+
}
|
|
2262
|
+
catch (e) { }
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* Track disconnect event.
|
|
2266
|
+
* @param args
|
|
2267
|
+
*/
|
|
2268
|
+
trackDisconnection(...args) {
|
|
2269
|
+
try {
|
|
2270
|
+
const event = createDisconnectionEvent(...args);
|
|
2271
|
+
this.dispatchUserActionEvent(event);
|
|
2272
|
+
}
|
|
2273
|
+
catch (e) { }
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* Track transaction init event.
|
|
2277
|
+
* @param args
|
|
2278
|
+
*/
|
|
2279
|
+
trackTransactionSentForSignature(...args) {
|
|
2280
|
+
try {
|
|
2281
|
+
const event = createTransactionSentForSignatureEvent(...args);
|
|
2282
|
+
this.dispatchUserActionEvent(event);
|
|
2283
|
+
}
|
|
2284
|
+
catch (e) { }
|
|
2285
|
+
}
|
|
2286
|
+
/**
|
|
2287
|
+
* Track transaction signed event.
|
|
2288
|
+
* @param args
|
|
2289
|
+
*/
|
|
2290
|
+
trackTransactionSigned(...args) {
|
|
2291
|
+
try {
|
|
2292
|
+
const event = createTransactionSignedEvent(...args);
|
|
2293
|
+
this.dispatchUserActionEvent(event);
|
|
2294
|
+
}
|
|
2295
|
+
catch (e) { }
|
|
2296
|
+
}
|
|
2297
|
+
/**
|
|
2298
|
+
* Track transaction error event.
|
|
2299
|
+
* @param args
|
|
2300
|
+
*/
|
|
2301
|
+
trackTransactionSigningFailed(...args) {
|
|
2302
|
+
try {
|
|
2303
|
+
const event = createTransactionSigningFailedEvent(...args);
|
|
2304
|
+
this.dispatchUserActionEvent(event);
|
|
2305
|
+
}
|
|
2306
|
+
catch (e) { }
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
|
|
2008
2310
|
class TonConnect {
|
|
2009
2311
|
constructor(options) {
|
|
2010
2312
|
this.walletsList = new WalletsListManager();
|
|
@@ -2020,6 +2322,7 @@ class TonConnect {
|
|
|
2020
2322
|
walletsListSource: options === null || options === void 0 ? void 0 : options.walletsListSource,
|
|
2021
2323
|
cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs
|
|
2022
2324
|
});
|
|
2325
|
+
this.tracker = new TonConnectTracker(options === null || options === void 0 ? void 0 : options.eventDispatcher);
|
|
2023
2326
|
if (!this.dappSettings.manifestUrl) {
|
|
2024
2327
|
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
2328
|
}
|
|
@@ -2112,6 +2415,7 @@ class TonConnect {
|
|
|
2112
2415
|
(_a = this.provider) === null || _a === void 0 ? void 0 : _a.closeConnection();
|
|
2113
2416
|
this.provider = null;
|
|
2114
2417
|
});
|
|
2418
|
+
this.tracker.trackConnectionStarted();
|
|
2115
2419
|
return this.provider.connect(this.createConnectRequest(options === null || options === void 0 ? void 0 : options.request), {
|
|
2116
2420
|
openingDeadlineMS: options === null || options === void 0 ? void 0 : options.openingDeadlineMS,
|
|
2117
2421
|
signal: abortController.signal
|
|
@@ -2123,10 +2427,12 @@ class TonConnect {
|
|
|
2123
2427
|
restoreConnection(options) {
|
|
2124
2428
|
var _a, _b;
|
|
2125
2429
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2430
|
+
this.tracker.trackConnectionRestoringStarted();
|
|
2126
2431
|
const abortController = createAbortController(options === null || options === void 0 ? void 0 : options.signal);
|
|
2127
2432
|
(_a = this.abortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
2128
2433
|
this.abortController = abortController;
|
|
2129
2434
|
if (abortController.signal.aborted) {
|
|
2435
|
+
this.tracker.trackConnectionRestoringError('Connection restoring was aborted');
|
|
2130
2436
|
return;
|
|
2131
2437
|
}
|
|
2132
2438
|
// TODO: potentially race condition here
|
|
@@ -2135,6 +2441,7 @@ class TonConnect {
|
|
|
2135
2441
|
this.walletsList.getEmbeddedWallet()
|
|
2136
2442
|
]);
|
|
2137
2443
|
if (abortController.signal.aborted) {
|
|
2444
|
+
this.tracker.trackConnectionRestoringError('Connection restoring was aborted');
|
|
2138
2445
|
return;
|
|
2139
2446
|
}
|
|
2140
2447
|
let provider = null;
|
|
@@ -2156,6 +2463,7 @@ class TonConnect {
|
|
|
2156
2463
|
}
|
|
2157
2464
|
}
|
|
2158
2465
|
catch (_c) {
|
|
2466
|
+
this.tracker.trackConnectionRestoringError('Provider is not restored');
|
|
2159
2467
|
yield this.bridgeConnectionStorage.removeConnection();
|
|
2160
2468
|
provider === null || provider === void 0 ? void 0 : provider.closeConnection();
|
|
2161
2469
|
provider = null;
|
|
@@ -2163,24 +2471,35 @@ class TonConnect {
|
|
|
2163
2471
|
}
|
|
2164
2472
|
if (abortController.signal.aborted) {
|
|
2165
2473
|
provider === null || provider === void 0 ? void 0 : provider.closeConnection();
|
|
2474
|
+
this.tracker.trackConnectionRestoringError('Connection restoring was aborted');
|
|
2166
2475
|
return;
|
|
2167
2476
|
}
|
|
2168
2477
|
if (!provider) {
|
|
2169
2478
|
logError('Provider is not restored');
|
|
2479
|
+
this.tracker.trackConnectionRestoringError('Provider is not restored');
|
|
2170
2480
|
return;
|
|
2171
2481
|
}
|
|
2172
2482
|
(_b = this.provider) === null || _b === void 0 ? void 0 : _b.closeConnection();
|
|
2173
2483
|
this.provider = provider;
|
|
2174
2484
|
provider.listen(this.walletEventsListener.bind(this));
|
|
2175
|
-
|
|
2485
|
+
const onAbortRestore = () => {
|
|
2486
|
+
this.tracker.trackConnectionRestoringError('Connection restoring was aborted');
|
|
2176
2487
|
provider === null || provider === void 0 ? void 0 : provider.closeConnection();
|
|
2177
2488
|
provider = null;
|
|
2178
|
-
}
|
|
2489
|
+
};
|
|
2490
|
+
abortController.signal.addEventListener('abort', onAbortRestore);
|
|
2179
2491
|
return yield callForSuccess((_options) => __awaiter(this, void 0, void 0, function* () {
|
|
2180
|
-
|
|
2492
|
+
yield (provider === null || provider === void 0 ? void 0 : provider.restoreConnection({
|
|
2181
2493
|
openingDeadlineMS: options === null || options === void 0 ? void 0 : options.openingDeadlineMS,
|
|
2182
2494
|
signal: _options.signal
|
|
2183
|
-
});
|
|
2495
|
+
}));
|
|
2496
|
+
abortController.signal.removeEventListener('abort', onAbortRestore);
|
|
2497
|
+
if (this.connected) {
|
|
2498
|
+
this.tracker.trackConnectionRestoringCompleted(this.wallet);
|
|
2499
|
+
}
|
|
2500
|
+
else {
|
|
2501
|
+
this.tracker.trackConnectionRestoringError('Connection restoring failed');
|
|
2502
|
+
}
|
|
2184
2503
|
}), {
|
|
2185
2504
|
attempts: Number.MAX_SAFE_INTEGER,
|
|
2186
2505
|
delayMs: 5000,
|
|
@@ -2207,15 +2526,19 @@ class TonConnect {
|
|
|
2207
2526
|
checkSendTransactionSupport(this.wallet.device.features, {
|
|
2208
2527
|
requiredMessagesNumber: transaction.messages.length
|
|
2209
2528
|
});
|
|
2529
|
+
this.tracker.trackTransactionSentForSignature(this.wallet, transaction);
|
|
2210
2530
|
const { validUntil } = transaction, tx = __rest(transaction, ["validUntil"]);
|
|
2211
2531
|
const from = transaction.from || this.account.address;
|
|
2212
2532
|
const network = transaction.network || this.account.chain;
|
|
2213
2533
|
const response = yield this.provider.sendRequest(sendTransactionParser.convertToRpcRequest(Object.assign(Object.assign({}, tx), { valid_until: validUntil, from,
|
|
2214
2534
|
network })), { onRequestSent: options.onRequestSent, signal: abortController.signal });
|
|
2215
2535
|
if (sendTransactionParser.isError(response)) {
|
|
2536
|
+
this.tracker.trackTransactionSigningFailed(this.wallet, transaction, response.error.message, response.error.code);
|
|
2216
2537
|
return sendTransactionParser.parseAndThrowError(response);
|
|
2217
2538
|
}
|
|
2218
|
-
|
|
2539
|
+
const result = sendTransactionParser.convertFromRpcResponse(response);
|
|
2540
|
+
this.tracker.trackTransactionSigned(this.wallet, transaction, result);
|
|
2541
|
+
return result;
|
|
2219
2542
|
});
|
|
2220
2543
|
}
|
|
2221
2544
|
/**
|
|
@@ -2233,7 +2556,7 @@ class TonConnect {
|
|
|
2233
2556
|
if (abortController.signal.aborted) {
|
|
2234
2557
|
throw new TonConnectError('Disconnect was aborted');
|
|
2235
2558
|
}
|
|
2236
|
-
this.onWalletDisconnected();
|
|
2559
|
+
this.onWalletDisconnected('dapp');
|
|
2237
2560
|
yield ((_a = this.provider) === null || _a === void 0 ? void 0 : _a.disconnect({
|
|
2238
2561
|
signal: abortController.signal
|
|
2239
2562
|
}));
|
|
@@ -2300,7 +2623,7 @@ class TonConnect {
|
|
|
2300
2623
|
this.onWalletConnectError(e.payload);
|
|
2301
2624
|
break;
|
|
2302
2625
|
case 'disconnect':
|
|
2303
|
-
this.onWalletDisconnected();
|
|
2626
|
+
this.onWalletDisconnected('wallet');
|
|
2304
2627
|
}
|
|
2305
2628
|
}
|
|
2306
2629
|
onWalletConnected(connectEvent) {
|
|
@@ -2325,17 +2648,20 @@ class TonConnect {
|
|
|
2325
2648
|
};
|
|
2326
2649
|
}
|
|
2327
2650
|
this.wallet = wallet;
|
|
2651
|
+
this.tracker.trackConnectionCompleted(wallet);
|
|
2328
2652
|
}
|
|
2329
2653
|
onWalletConnectError(connectEventError) {
|
|
2330
2654
|
const error = connectErrorsParser.parseError(connectEventError);
|
|
2331
2655
|
this.statusChangeErrorSubscriptions.forEach(errorsHandler => errorsHandler(error));
|
|
2332
2656
|
console.debug(error);
|
|
2657
|
+
this.tracker.trackConnectionError(connectEventError.message, connectEventError.code);
|
|
2333
2658
|
if (error instanceof ManifestNotFoundError || error instanceof ManifestContentErrorError) {
|
|
2334
2659
|
console.error(error);
|
|
2335
2660
|
throw error;
|
|
2336
2661
|
}
|
|
2337
2662
|
}
|
|
2338
|
-
onWalletDisconnected() {
|
|
2663
|
+
onWalletDisconnected(scope) {
|
|
2664
|
+
this.tracker.trackDisconnection(this.wallet, scope);
|
|
2339
2665
|
this.wallet = null;
|
|
2340
2666
|
}
|
|
2341
2667
|
checkConnection() {
|
|
@@ -2465,5 +2791,5 @@ function hexToBytes(hex) {
|
|
|
2465
2791
|
return result;
|
|
2466
2792
|
}
|
|
2467
2793
|
|
|
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 };
|
|
2794
|
+
export { BadRequestError, BrowserEventDispatcher, FetchWalletsError, LocalstorageNotFoundError, ParseHexError, TonConnect, TonConnectError, UnknownAppError, UnknownError, UserRejectsError, WalletAlreadyConnectedError, WalletNotConnectedError, WalletNotInjectedError, WalletsListManager, WrongAddressError, createConnectionCompletedEvent, createConnectionErrorEvent, createConnectionRestoringCompletedEvent, createConnectionRestoringErrorEvent, createConnectionRestoringStartedEvent, createConnectionStartedEvent, createDisconnectionEvent, createTransactionSentForSignatureEvent, createTransactionSignedEvent, createTransactionSigningFailedEvent, TonConnect as default, encodeTelegramUrlParameters, isTelegramUrl, isWalletInfoCurrentlyEmbedded, isWalletInfoCurrentlyInjected, isWalletInfoInjectable, isWalletInfoInjected, isWalletInfoRemote, toUserFriendlyAddress };
|
|
2469
2795
|
//# sourceMappingURL=index.mjs.map
|