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