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