@meshconnect/uwc-ton-connector 0.6.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ton-connect-connector.d.ts +13 -1
- package/dist/ton-connect-connector.d.ts.map +1 -1
- package/dist/ton-connect-connector.js +46 -2
- package/dist/ton-connect-connector.js.map +1 -1
- package/package.json +3 -3
- package/src/ton-connect-connector.test.ts +97 -1
- package/src/ton-connect-connector.ts +58 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Network, Connector, ConnectorResult, SwitchNetworkResult, TonConnectConfig, TonConnectWalletProvider, TransactionRequest, TransactionResult, SignatureType } from '@meshconnect/uwc-types';
|
|
1
|
+
import type { Network, Connector, ConnectorResult, SwitchNetworkResult, TonConnectConfig, TonConnectWalletProvider, TransactionRequest, TransactionResult, SignatureType, WalletLifecycleEvent, WalletLifecycleContext } from '@meshconnect/uwc-types';
|
|
2
2
|
export declare class TonConnectConnector implements Connector {
|
|
3
3
|
private config;
|
|
4
4
|
private sdk;
|
|
@@ -26,6 +26,18 @@ export declare class TonConnectConnector implements Connector {
|
|
|
26
26
|
switchNetwork(network: Network): Promise<SwitchNetworkResult>;
|
|
27
27
|
/** Disconnect from the wallet and clean up resources. */
|
|
28
28
|
disconnect(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Observe post-connect lifecycle via the TON Connect SDK's `onStatusChange`.
|
|
31
|
+
* The SDK runs in this context (its own HTTP bridge / JS bridge, not the iframe
|
|
32
|
+
* Comlink bridge), so this works in the production iframe too.
|
|
33
|
+
*
|
|
34
|
+
* Only the disconnect signal is forwarded: a `null` / address-less status means
|
|
35
|
+
* the wallet ended the session from its side. A non-null status is the
|
|
36
|
+
* (re)connect — already covered by the connect handoff — and is skipped to avoid
|
|
37
|
+
* a spurious event from the state replay the SDK does on a fresh subscription.
|
|
38
|
+
* Returns undefined before a session exists. No address is ever forwarded.
|
|
39
|
+
*/
|
|
40
|
+
onLifecycleEvent(listener: (event: WalletLifecycleEvent) => void, _context: WalletLifecycleContext): (() => void) | undefined;
|
|
29
41
|
/** Tear down SDK, event listeners, and pending timeouts. */
|
|
30
42
|
destroy(): Promise<void>;
|
|
31
43
|
private waitForWalletApproval;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ton-connect-connector.d.ts","sourceRoot":"","sources":["../src/ton-connect-connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EAExB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,
|
|
1
|
+
{"version":3,"file":"ton-connect-connector.d.ts","sourceRoot":"","sources":["../src/ton-connect-connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EAExB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EAEb,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,wBAAwB,CAAA;AAkC/B,qBAAa,mBAAoB,YAAW,SAAS;IACnD,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,GAAG,CAA2B;IACtC,OAAO,CAAC,aAAa,CAAoB;IACzC,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,OAAO,CAAC,kBAAkB,CAAyB;IACnD,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,uBAAuB,CAEhB;IACf,OAAO,CAAC,qBAAqB,CAAiD;IAC9E,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,mBAAmB,CAA4B;IACvD,OAAO,CAAC,qBAAqB,CAAwC;IACrE,OAAO,CAAC,iBAAiB,CAAI;gBAEjB,MAAM,EAAE,gBAAgB;IAIpC,oEAAoE;IAC9D,OAAO,CACX,OAAO,EAAE,OAAO,EAChB,QAAQ,CAAC,EAAE,wBAAwB,GAClC,OAAO,CAAC,eAAe,CAAC;YA6Bb,cAAc;IAqG5B,sEAAsE;IACtE,gBAAgB,IAAI,MAAM;IAO1B,iDAAiD;IAC3C,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAyB1D,uDAAuD;IACjD,eAAe,CACnB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC;IA8B7B,qEAAqE;IAC/D,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAOnE,yDAAyD;IACnD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBjC;;;;;;;;;;OAUG;IACH,gBAAgB,CACd,QAAQ,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,EAG/C,QAAQ,EAAE,sBAAsB,GAC/B,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS;IAiB3B,4DAA4D;IACtD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAIhB,qBAAqB;IA2FnC,OAAO,CAAC,sBAAsB;YAWhB,UAAU;IAWxB,OAAO,CAAC,mBAAmB;CAM5B"}
|
|
@@ -196,6 +196,35 @@ export class TonConnectConnector {
|
|
|
196
196
|
this.connectInFlight = false;
|
|
197
197
|
this.clearConnectTimeout();
|
|
198
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Observe post-connect lifecycle via the TON Connect SDK's `onStatusChange`.
|
|
201
|
+
* The SDK runs in this context (its own HTTP bridge / JS bridge, not the iframe
|
|
202
|
+
* Comlink bridge), so this works in the production iframe too.
|
|
203
|
+
*
|
|
204
|
+
* Only the disconnect signal is forwarded: a `null` / address-less status means
|
|
205
|
+
* the wallet ended the session from its side. A non-null status is the
|
|
206
|
+
* (re)connect — already covered by the connect handoff — and is skipped to avoid
|
|
207
|
+
* a spurious event from the state replay the SDK does on a fresh subscription.
|
|
208
|
+
* Returns undefined before a session exists. No address is ever forwarded.
|
|
209
|
+
*/
|
|
210
|
+
onLifecycleEvent(listener,
|
|
211
|
+
// TON has a single namespace and one SDK session — the context is accepted
|
|
212
|
+
// for contract parity and unused.
|
|
213
|
+
_context) {
|
|
214
|
+
const sdk = this.sdk;
|
|
215
|
+
if (!sdk)
|
|
216
|
+
return undefined;
|
|
217
|
+
// Coexists safely with the connect-time subscription: the SDK keeps an
|
|
218
|
+
// ARRAY of status callbacks with identity-filtered unsubscribe
|
|
219
|
+
// (@tonconnect/sdk `onStatusChange` → `statusChangeSubscriptions.push`).
|
|
220
|
+
return sdk.onStatusChange(wallet => {
|
|
221
|
+
if (!wallet?.account?.address)
|
|
222
|
+
listener({ type: 'disconnect' });
|
|
223
|
+
}, () => {
|
|
224
|
+
// errorsHandler is required by the signature; lifecycle errors are not
|
|
225
|
+
// actionable here (the connect handoff owns connection-error reporting).
|
|
226
|
+
});
|
|
227
|
+
}
|
|
199
228
|
/** Tear down SDK, event listeners, and pending timeouts. */
|
|
200
229
|
async destroy() {
|
|
201
230
|
await this.disconnect();
|
|
@@ -241,9 +270,21 @@ export class TonConnectConnector {
|
|
|
241
270
|
: {})
|
|
242
271
|
});
|
|
243
272
|
}
|
|
273
|
+
else if (wallet === null) {
|
|
274
|
+
cleanup();
|
|
275
|
+
// Null wallet = the user declined in the wallet. Typed like the
|
|
276
|
+
// sign/send rejection paths so the core classifies it
|
|
277
|
+
// `user_rejected`/`walletRejected`, not `unknown`/`walletFailed`.
|
|
278
|
+
reject(new WalletConnectorError({
|
|
279
|
+
type: 'rejected',
|
|
280
|
+
message: 'TON wallet connection was rejected'
|
|
281
|
+
}));
|
|
282
|
+
}
|
|
244
283
|
else {
|
|
245
284
|
cleanup();
|
|
246
|
-
|
|
285
|
+
// Truthy wallet with a malformed/missing account is a wallet bug,
|
|
286
|
+
// not a decline — keep it out of the rejection funnel.
|
|
287
|
+
reject(new Error('TON wallet returned no account address on connect'));
|
|
247
288
|
}
|
|
248
289
|
}, error => {
|
|
249
290
|
if (settled)
|
|
@@ -255,7 +296,10 @@ export class TonConnectConnector {
|
|
|
255
296
|
this.extractSdkErrorMessage(error) ||
|
|
256
297
|
'TON wallet connection was rejected';
|
|
257
298
|
cleanup();
|
|
258
|
-
reject(
|
|
299
|
+
reject(this.UserRejectsErrorClass &&
|
|
300
|
+
error instanceof this.UserRejectsErrorClass
|
|
301
|
+
? new WalletConnectorError({ type: 'rejected', message })
|
|
302
|
+
: new Error(message));
|
|
259
303
|
});
|
|
260
304
|
this.connectionURI = sdk.connect({ universalLink, bridgeUrl });
|
|
261
305
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ton-connect-connector.js","sourceRoot":"","sources":["../src/ton-connect-connector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ton-connect-connector.js","sourceRoot":"","sources":["../src/ton-connect-connector.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAM7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,SAAS,EACT,SAAS,EACV,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,EACxB,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,+BAA+B,CAAA;AAEtC,6EAA6E;AAC7E,8BAA8B;AAC9B,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA;AASxC,MAAM,OAAO,mBAAmB;IACtB,MAAM,CAAkB;IACxB,GAAG,GAAuB,IAAI,CAAA;IAC9B,aAAa,CAAoB;IACjC,gBAAgB,GAAkB,IAAI,CAAA;IACtC,kBAAkB,GAAqB,IAAI,CAAA;IAC3C,cAAc,GAAyC,IAAI,CAAA;IAC3D,uBAAuB,GAEpB,IAAI,CAAA;IACP,qBAAqB,GAA6C,IAAI,CAAA;IACtE,eAAe,GAA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A;YAClD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAC7B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrB,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;YAChC,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAEO,KAAK,CAAC,UAAU,CAAC,GAAgB;QACvC,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,UAAU,EAAE,CAAA;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,iBAAiB;QACnB,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;YACrB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAA;QACjB,CAAC;IACH,CAAC;IAEO,mBAAmB;QACzB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;YACjC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA;QAC5B,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshconnect/uwc-ton-connector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "TON Connect connector for Universal Wallet Connector — mobile QR/URI wallet connections",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@ton/core": "^0.63.1",
|
|
20
20
|
"@tonconnect/sdk": "^3.0.5",
|
|
21
|
-
"@meshconnect/uwc-constants": "0.6.
|
|
22
|
-
"@meshconnect/uwc-types": "0.
|
|
21
|
+
"@meshconnect/uwc-constants": "0.6.8",
|
|
22
|
+
"@meshconnect/uwc-types": "0.17.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"typescript": "^5.9.3"
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Network,
|
|
4
|
+
TonConnectWalletProvider,
|
|
5
|
+
WalletLifecycleEvent
|
|
6
|
+
} from '@meshconnect/uwc-types'
|
|
3
7
|
import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
4
8
|
|
|
5
9
|
const {
|
|
@@ -347,6 +351,67 @@ describe('TonConnectConnector', () => {
|
|
|
347
351
|
)
|
|
348
352
|
})
|
|
349
353
|
|
|
354
|
+
it('classifies a null-wallet status change as a typed user rejection', async () => {
|
|
355
|
+
mockSdkConnect.mockReturnValue('tc://uri')
|
|
356
|
+
mockDisconnect.mockResolvedValue(undefined)
|
|
357
|
+
mockOnStatusChange.mockImplementation(callback => {
|
|
358
|
+
setTimeout(() => callback(null), 10)
|
|
359
|
+
return vi.fn()
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
const error = await connector
|
|
363
|
+
.connect(TON_NETWORK, PROVIDER)
|
|
364
|
+
.then(() => null)
|
|
365
|
+
.catch((e: unknown) => e)
|
|
366
|
+
// Typed so the core funnel counts walletRejected, not walletFailed.
|
|
367
|
+
expect(error).toBeInstanceOf(WalletConnectorError)
|
|
368
|
+
expect((error as WalletConnectorError).type).toBe('rejected')
|
|
369
|
+
expect((error as WalletConnectorError).message).toBe(
|
|
370
|
+
'TON wallet connection was rejected'
|
|
371
|
+
)
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
it('classifies a truthy wallet with a malformed account as a failure, NOT a rejection', async () => {
|
|
375
|
+
mockSdkConnect.mockReturnValue('tc://uri')
|
|
376
|
+
mockDisconnect.mockResolvedValue(undefined)
|
|
377
|
+
mockOnStatusChange.mockImplementation(callback => {
|
|
378
|
+
// Wallet bug: status change fired with a wallet but no account address.
|
|
379
|
+
setTimeout(() => callback({ account: { address: '' } }), 10)
|
|
380
|
+
return vi.fn()
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
const error = await connector
|
|
384
|
+
.connect(TON_NETWORK, PROVIDER)
|
|
385
|
+
.then(() => null)
|
|
386
|
+
.catch((e: unknown) => e)
|
|
387
|
+
// Untyped so the core funnel counts walletFailed — this is not a decline.
|
|
388
|
+
expect(error).toBeInstanceOf(Error)
|
|
389
|
+
expect(error).not.toBeInstanceOf(WalletConnectorError)
|
|
390
|
+
expect((error as Error).message).toBe(
|
|
391
|
+
'TON wallet returned no account address on connect'
|
|
392
|
+
)
|
|
393
|
+
expect(mockDisconnect).toHaveBeenCalled()
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
it('classifies a UserRejectsError from the SDK error callback as a typed user rejection', async () => {
|
|
397
|
+
mockSdkConnect.mockReturnValue('tc://uri')
|
|
398
|
+
mockDisconnect.mockResolvedValue(undefined)
|
|
399
|
+
mockOnStatusChange.mockImplementation((_callback, errorCallback) => {
|
|
400
|
+
setTimeout(
|
|
401
|
+
() => errorCallback(new MockUserRejectsError('User rejected')),
|
|
402
|
+
10
|
|
403
|
+
)
|
|
404
|
+
return vi.fn()
|
|
405
|
+
})
|
|
406
|
+
|
|
407
|
+
const error = await connector
|
|
408
|
+
.connect(TON_NETWORK, PROVIDER)
|
|
409
|
+
.then(() => null)
|
|
410
|
+
.catch((e: unknown) => e)
|
|
411
|
+
expect(error).toBeInstanceOf(WalletConnectorError)
|
|
412
|
+
expect((error as WalletConnectorError).type).toBe('rejected')
|
|
413
|
+
})
|
|
414
|
+
|
|
350
415
|
it('falls back to default message when error has no payload or message', async () => {
|
|
351
416
|
mockSdkConnect.mockReturnValue('tc://uri')
|
|
352
417
|
mockDisconnect.mockResolvedValue(undefined)
|
|
@@ -1192,4 +1257,35 @@ describe('TonConnectConnector', () => {
|
|
|
1192
1257
|
expect(firstResult.networkId).toBe(secondResult.networkId)
|
|
1193
1258
|
})
|
|
1194
1259
|
})
|
|
1260
|
+
|
|
1261
|
+
describe('onLifecycleEvent (P2)', () => {
|
|
1262
|
+
it('returns undefined before the SDK exists', () => {
|
|
1263
|
+
expect(
|
|
1264
|
+
connector.onLifecycleEvent(() => {}, { connectionMode: 'tonConnect' })
|
|
1265
|
+
).toBeUndefined()
|
|
1266
|
+
})
|
|
1267
|
+
|
|
1268
|
+
it('forwards a null status as disconnect and skips the (re)connect replay', () => {
|
|
1269
|
+
let statusCb: ((w: unknown) => void) | undefined
|
|
1270
|
+
const unsub = vi.fn()
|
|
1271
|
+
;(connector as unknown as { sdk: unknown }).sdk = {
|
|
1272
|
+
onStatusChange: (cb: (w: unknown) => void) => {
|
|
1273
|
+
statusCb = cb
|
|
1274
|
+
return unsub
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
const events: WalletLifecycleEvent[] = []
|
|
1278
|
+
const stop = connector.onLifecycleEvent(e => events.push(e), {
|
|
1279
|
+
connectionMode: 'tonConnect'
|
|
1280
|
+
})
|
|
1281
|
+
expect(typeof stop).toBe('function')
|
|
1282
|
+
|
|
1283
|
+
statusCb?.({ account: { address: '0:abc' } }) // (re)connect → skipped
|
|
1284
|
+
statusCb?.(null) // wallet ended the session from its side
|
|
1285
|
+
expect(events).toEqual([{ type: 'disconnect' }])
|
|
1286
|
+
|
|
1287
|
+
stop!()
|
|
1288
|
+
expect(unsub).toHaveBeenCalled()
|
|
1289
|
+
})
|
|
1290
|
+
})
|
|
1195
1291
|
})
|
|
@@ -9,7 +9,9 @@ import type {
|
|
|
9
9
|
TransactionRequest,
|
|
10
10
|
TransactionResult,
|
|
11
11
|
SignatureType,
|
|
12
|
-
NetworkId
|
|
12
|
+
NetworkId,
|
|
13
|
+
WalletLifecycleEvent,
|
|
14
|
+
WalletLifecycleContext
|
|
13
15
|
} from '@meshconnect/uwc-types'
|
|
14
16
|
import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
15
17
|
import type {
|
|
@@ -296,6 +298,39 @@ export class TonConnectConnector implements Connector {
|
|
|
296
298
|
this.clearConnectTimeout()
|
|
297
299
|
}
|
|
298
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Observe post-connect lifecycle via the TON Connect SDK's `onStatusChange`.
|
|
303
|
+
* The SDK runs in this context (its own HTTP bridge / JS bridge, not the iframe
|
|
304
|
+
* Comlink bridge), so this works in the production iframe too.
|
|
305
|
+
*
|
|
306
|
+
* Only the disconnect signal is forwarded: a `null` / address-less status means
|
|
307
|
+
* the wallet ended the session from its side. A non-null status is the
|
|
308
|
+
* (re)connect — already covered by the connect handoff — and is skipped to avoid
|
|
309
|
+
* a spurious event from the state replay the SDK does on a fresh subscription.
|
|
310
|
+
* Returns undefined before a session exists. No address is ever forwarded.
|
|
311
|
+
*/
|
|
312
|
+
onLifecycleEvent(
|
|
313
|
+
listener: (event: WalletLifecycleEvent) => void,
|
|
314
|
+
// TON has a single namespace and one SDK session — the context is accepted
|
|
315
|
+
// for contract parity and unused.
|
|
316
|
+
_context: WalletLifecycleContext
|
|
317
|
+
): (() => void) | undefined {
|
|
318
|
+
const sdk = this.sdk
|
|
319
|
+
if (!sdk) return undefined
|
|
320
|
+
// Coexists safely with the connect-time subscription: the SDK keeps an
|
|
321
|
+
// ARRAY of status callbacks with identity-filtered unsubscribe
|
|
322
|
+
// (@tonconnect/sdk `onStatusChange` → `statusChangeSubscriptions.push`).
|
|
323
|
+
return sdk.onStatusChange(
|
|
324
|
+
wallet => {
|
|
325
|
+
if (!wallet?.account?.address) listener({ type: 'disconnect' })
|
|
326
|
+
},
|
|
327
|
+
() => {
|
|
328
|
+
// errorsHandler is required by the signature; lifecycle errors are not
|
|
329
|
+
// actionable here (the connect handoff owns connection-error reporting).
|
|
330
|
+
}
|
|
331
|
+
)
|
|
332
|
+
}
|
|
333
|
+
|
|
299
334
|
/** Tear down SDK, event listeners, and pending timeouts. */
|
|
300
335
|
async destroy(): Promise<void> {
|
|
301
336
|
await this.disconnect()
|
|
@@ -348,9 +383,24 @@ export class TonConnectConnector implements Connector {
|
|
|
348
383
|
? { publicKey: wallet.account.publicKey }
|
|
349
384
|
: {})
|
|
350
385
|
})
|
|
386
|
+
} else if (wallet === null) {
|
|
387
|
+
cleanup()
|
|
388
|
+
// Null wallet = the user declined in the wallet. Typed like the
|
|
389
|
+
// sign/send rejection paths so the core classifies it
|
|
390
|
+
// `user_rejected`/`walletRejected`, not `unknown`/`walletFailed`.
|
|
391
|
+
reject(
|
|
392
|
+
new WalletConnectorError({
|
|
393
|
+
type: 'rejected',
|
|
394
|
+
message: 'TON wallet connection was rejected'
|
|
395
|
+
})
|
|
396
|
+
)
|
|
351
397
|
} else {
|
|
352
398
|
cleanup()
|
|
353
|
-
|
|
399
|
+
// Truthy wallet with a malformed/missing account is a wallet bug,
|
|
400
|
+
// not a decline — keep it out of the rejection funnel.
|
|
401
|
+
reject(
|
|
402
|
+
new Error('TON wallet returned no account address on connect')
|
|
403
|
+
)
|
|
354
404
|
}
|
|
355
405
|
},
|
|
356
406
|
error => {
|
|
@@ -363,7 +413,12 @@ export class TonConnectConnector implements Connector {
|
|
|
363
413
|
this.extractSdkErrorMessage(error) ||
|
|
364
414
|
'TON wallet connection was rejected'
|
|
365
415
|
cleanup()
|
|
366
|
-
reject(
|
|
416
|
+
reject(
|
|
417
|
+
this.UserRejectsErrorClass &&
|
|
418
|
+
error instanceof this.UserRejectsErrorClass
|
|
419
|
+
? new WalletConnectorError({ type: 'rejected', message })
|
|
420
|
+
: new Error(message)
|
|
421
|
+
)
|
|
367
422
|
}
|
|
368
423
|
)
|
|
369
424
|
|