@blazium/ton-connect-mobile 1.1.2 → 1.1.4
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/adapters/expo.js +16 -2
- package/dist/core/wallets.js +1 -1
- package/dist/index.js +14 -4
- package/dist/react/TonConnectButton.js +5 -1
- package/dist/react/package.json +4 -0
- package/package.json +4 -2
- package/src/adapters/expo.ts +15 -2
- package/src/core/wallets.ts +1 -1
- package/src/index.ts +16 -5
- package/src/react/TonConnectButton.tsx +5 -1
package/dist/adapters/expo.js
CHANGED
|
@@ -32,12 +32,22 @@ class ExpoAdapter {
|
|
|
32
32
|
}
|
|
33
33
|
setupURLListener() {
|
|
34
34
|
if (!Linking) {
|
|
35
|
+
console.warn('[ExpoAdapter] Linking not available, URL listener not set up');
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
// Listen for deep links when app is already open
|
|
38
39
|
this.subscription = Linking.addEventListener('url', (event) => {
|
|
39
|
-
|
|
40
|
+
console.log('[ExpoAdapter] URL event received:', event.url);
|
|
41
|
+
this.urlListeners.forEach((listener) => {
|
|
42
|
+
try {
|
|
43
|
+
listener(event.url);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error('[ExpoAdapter] Error in URL listener:', error);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
40
49
|
});
|
|
50
|
+
console.log('[ExpoAdapter] URL listener set up successfully');
|
|
41
51
|
}
|
|
42
52
|
async openURL(url, skipCanOpenURLCheck = true) {
|
|
43
53
|
if (!Linking) {
|
|
@@ -75,12 +85,16 @@ class ExpoAdapter {
|
|
|
75
85
|
}
|
|
76
86
|
async getInitialURL() {
|
|
77
87
|
if (!Linking) {
|
|
88
|
+
console.warn('[ExpoAdapter] Linking not available, cannot get initial URL');
|
|
78
89
|
return null;
|
|
79
90
|
}
|
|
80
91
|
try {
|
|
81
|
-
|
|
92
|
+
const url = await Linking.getInitialURL();
|
|
93
|
+
console.log('[ExpoAdapter] getInitialURL result:', url);
|
|
94
|
+
return url;
|
|
82
95
|
}
|
|
83
96
|
catch (error) {
|
|
97
|
+
console.error('[ExpoAdapter] Error getting initial URL:', error);
|
|
84
98
|
return null;
|
|
85
99
|
}
|
|
86
100
|
}
|
package/dist/core/wallets.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.SUPPORTED_WALLETS = [
|
|
|
19
19
|
deepLink: 'tonkeeper://',
|
|
20
20
|
platforms: ['ios', 'android'],
|
|
21
21
|
preferredReturnStrategy: 'back',
|
|
22
|
-
requiresReturnScheme:
|
|
22
|
+
requiresReturnScheme: true, // CRITICAL FIX: Mobile apps need returnScheme for proper callback handling
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
name: 'MyTonWallet',
|
package/dist/index.js
CHANGED
|
@@ -182,9 +182,16 @@ class TonConnectMobile {
|
|
|
182
182
|
*/
|
|
183
183
|
handleCallback(url) {
|
|
184
184
|
console.log('[TON Connect] handleCallback called with URL:', url);
|
|
185
|
+
console.log('[TON Connect] Expected scheme:', this.config.scheme);
|
|
186
|
+
console.log('[TON Connect] URL starts with scheme?', url?.startsWith(`${this.config.scheme}://`));
|
|
185
187
|
// CRITICAL FIX: Check if URL matches our scheme
|
|
186
|
-
if (!url ||
|
|
188
|
+
if (!url || typeof url !== 'string') {
|
|
189
|
+
console.log('[TON Connect] Invalid URL, ignoring:', url);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (!url.startsWith(`${this.config.scheme}://`)) {
|
|
187
193
|
console.log('[TON Connect] Callback URL does not match scheme, ignoring:', url);
|
|
194
|
+
console.log('[TON Connect] Expected prefix:', `${this.config.scheme}://`);
|
|
188
195
|
return;
|
|
189
196
|
}
|
|
190
197
|
const parsed = (0, protocol_1.parseCallbackURL)(url, this.config.scheme);
|
|
@@ -349,13 +356,16 @@ class TonConnectMobile {
|
|
|
349
356
|
const urlParts = url.split('?');
|
|
350
357
|
if (urlParts.length > 1) {
|
|
351
358
|
const payload = urlParts[1];
|
|
352
|
-
|
|
359
|
+
// CRITICAL FIX: Handle URL encoding - payload might have additional encoding
|
|
360
|
+
const cleanPayload = decodeURIComponent(payload);
|
|
361
|
+
const decoded = (0, protocol_1.decodeBase64URL)(cleanPayload);
|
|
353
362
|
console.log('[TON Connect] Connection request payload:', JSON.stringify(decoded, null, 2));
|
|
354
363
|
}
|
|
355
364
|
}
|
|
356
365
|
catch (e) {
|
|
357
|
-
//
|
|
358
|
-
console.log('[TON Connect] Could not decode payload for logging:', e);
|
|
366
|
+
// Log decode errors for debugging but don't fail
|
|
367
|
+
console.log('[TON Connect] Could not decode payload for logging:', e?.message || e);
|
|
368
|
+
// This is just for logging, the actual URL is correct
|
|
359
369
|
}
|
|
360
370
|
console.log('[TON Connect] Built URL:', url.substring(0, 100) + '...');
|
|
361
371
|
console.log('[TON Connect] Full URL:', url);
|
|
@@ -65,8 +65,12 @@ function TonConnectButton({ text = 'Connect Wallet', connectedText = 'Disconnect
|
|
|
65
65
|
await tonConnectUI.disconnect();
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
|
+
// CRITICAL FIX: Only open modal, don't auto-connect
|
|
69
|
+
// The modal should handle wallet selection and connection
|
|
70
|
+
// This allows users to choose which wallet to connect
|
|
68
71
|
await tonConnectUI.openModal();
|
|
69
|
-
|
|
72
|
+
// Note: connectWallet() should be called by the modal/wallet selection UI
|
|
73
|
+
// Not automatically here, to allow wallet selection
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blazium/ton-connect-mobile",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Production-ready TON Connect Mobile SDK for React Native and Expo. Implements the real TonConnect protocol for mobile applications using deep links and callbacks.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"./react": {
|
|
13
13
|
"types": "./dist/react/index.d.ts",
|
|
14
|
-
"default": "./dist/react/index.js"
|
|
14
|
+
"default": "./dist/react/index.js",
|
|
15
|
+
"react-native": "./dist/react/index.js"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
"repository": {
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
|
22
23
|
"build": "tsc",
|
|
24
|
+
"postbuild": "node scripts/postbuild.js",
|
|
23
25
|
"prepublishOnly": "npm run build",
|
|
24
26
|
"example": "cd example && npm start"
|
|
25
27
|
},
|
package/src/adapters/expo.ts
CHANGED
|
@@ -40,12 +40,21 @@ export class ExpoAdapter implements PlatformAdapter {
|
|
|
40
40
|
|
|
41
41
|
private setupURLListener(): void {
|
|
42
42
|
if (!Linking) {
|
|
43
|
+
console.warn('[ExpoAdapter] Linking not available, URL listener not set up');
|
|
43
44
|
return;
|
|
44
45
|
}
|
|
45
46
|
// Listen for deep links when app is already open
|
|
46
47
|
this.subscription = Linking.addEventListener('url', (event: { url: string }) => {
|
|
47
|
-
|
|
48
|
+
console.log('[ExpoAdapter] URL event received:', event.url);
|
|
49
|
+
this.urlListeners.forEach((listener) => {
|
|
50
|
+
try {
|
|
51
|
+
listener(event.url);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('[ExpoAdapter] Error in URL listener:', error);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
48
56
|
});
|
|
57
|
+
console.log('[ExpoAdapter] URL listener set up successfully');
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
async openURL(url: string, skipCanOpenURLCheck: boolean = true): Promise<boolean> {
|
|
@@ -89,11 +98,15 @@ export class ExpoAdapter implements PlatformAdapter {
|
|
|
89
98
|
|
|
90
99
|
async getInitialURL(): Promise<string | null> {
|
|
91
100
|
if (!Linking) {
|
|
101
|
+
console.warn('[ExpoAdapter] Linking not available, cannot get initial URL');
|
|
92
102
|
return null;
|
|
93
103
|
}
|
|
94
104
|
try {
|
|
95
|
-
|
|
105
|
+
const url = await Linking.getInitialURL();
|
|
106
|
+
console.log('[ExpoAdapter] getInitialURL result:', url);
|
|
107
|
+
return url;
|
|
96
108
|
} catch (error) {
|
|
109
|
+
console.error('[ExpoAdapter] Error getting initial URL:', error);
|
|
97
110
|
return null;
|
|
98
111
|
}
|
|
99
112
|
}
|
package/src/core/wallets.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const SUPPORTED_WALLETS: WalletDefinition[] = [
|
|
|
33
33
|
deepLink: 'tonkeeper://',
|
|
34
34
|
platforms: ['ios', 'android'],
|
|
35
35
|
preferredReturnStrategy: 'back',
|
|
36
|
-
requiresReturnScheme:
|
|
36
|
+
requiresReturnScheme: true, // CRITICAL FIX: Mobile apps need returnScheme for proper callback handling
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
39
|
name: 'MyTonWallet',
|
package/src/index.ts
CHANGED
|
@@ -216,10 +216,18 @@ export class TonConnectMobile {
|
|
|
216
216
|
*/
|
|
217
217
|
private handleCallback(url: string): void {
|
|
218
218
|
console.log('[TON Connect] handleCallback called with URL:', url);
|
|
219
|
+
console.log('[TON Connect] Expected scheme:', this.config.scheme);
|
|
220
|
+
console.log('[TON Connect] URL starts with scheme?', url?.startsWith(`${this.config.scheme}://`));
|
|
219
221
|
|
|
220
222
|
// CRITICAL FIX: Check if URL matches our scheme
|
|
221
|
-
if (!url ||
|
|
223
|
+
if (!url || typeof url !== 'string') {
|
|
224
|
+
console.log('[TON Connect] Invalid URL, ignoring:', url);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!url.startsWith(`${this.config.scheme}://`)) {
|
|
222
229
|
console.log('[TON Connect] Callback URL does not match scheme, ignoring:', url);
|
|
230
|
+
console.log('[TON Connect] Expected prefix:', `${this.config.scheme}://`);
|
|
223
231
|
return;
|
|
224
232
|
}
|
|
225
233
|
|
|
@@ -407,12 +415,15 @@ export class TonConnectMobile {
|
|
|
407
415
|
const urlParts = url.split('?');
|
|
408
416
|
if (urlParts.length > 1) {
|
|
409
417
|
const payload = urlParts[1];
|
|
410
|
-
|
|
418
|
+
// CRITICAL FIX: Handle URL encoding - payload might have additional encoding
|
|
419
|
+
const cleanPayload = decodeURIComponent(payload);
|
|
420
|
+
const decoded = decodeBase64URL<ConnectionRequestPayload>(cleanPayload);
|
|
411
421
|
console.log('[TON Connect] Connection request payload:', JSON.stringify(decoded, null, 2));
|
|
412
422
|
}
|
|
413
|
-
} catch (e) {
|
|
414
|
-
//
|
|
415
|
-
console.log('[TON Connect] Could not decode payload for logging:', e);
|
|
423
|
+
} catch (e: any) {
|
|
424
|
+
// Log decode errors for debugging but don't fail
|
|
425
|
+
console.log('[TON Connect] Could not decode payload for logging:', e?.message || e);
|
|
426
|
+
// This is just for logging, the actual URL is correct
|
|
416
427
|
}
|
|
417
428
|
|
|
418
429
|
console.log('[TON Connect] Built URL:', url.substring(0, 100) + '...');
|
|
@@ -52,8 +52,12 @@ export function TonConnectButton({
|
|
|
52
52
|
if (isConnected) {
|
|
53
53
|
await tonConnectUI.disconnect();
|
|
54
54
|
} else {
|
|
55
|
+
// CRITICAL FIX: Only open modal, don't auto-connect
|
|
56
|
+
// The modal should handle wallet selection and connection
|
|
57
|
+
// This allows users to choose which wallet to connect
|
|
55
58
|
await tonConnectUI.openModal();
|
|
56
|
-
|
|
59
|
+
// Note: connectWallet() should be called by the modal/wallet selection UI
|
|
60
|
+
// Not automatically here, to allow wallet selection
|
|
57
61
|
}
|
|
58
62
|
} catch (error) {
|
|
59
63
|
// CRITICAL FIX: Handle errors gracefully
|