@blazium/ton-connect-mobile 1.1.1 → 1.1.3

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.
@@ -17,14 +17,14 @@ export declare function decodeBase64URL<T>(encoded: string): T;
17
17
  * Or universal link: https://app.tonkeeper.com/ton-connect?<base64_encoded_payload>
18
18
  * Or custom wallet universal link
19
19
  */
20
- export declare function buildConnectionRequest(manifestUrl: string, returnScheme: string, walletUniversalLink?: string): string;
20
+ export declare function buildConnectionRequest(manifestUrl: string, returnScheme: string, walletUniversalLink?: string, returnStrategy?: 'back' | 'post_redirect' | 'none', requiresReturnScheme?: boolean): string;
21
21
  /**
22
22
  * Build transaction request URL
23
23
  * Format: tonconnect://send-transaction?<base64_encoded_payload>
24
24
  * Or universal link: https://app.tonkeeper.com/ton-connect/send-transaction?<base64_encoded_payload>
25
25
  * Or custom wallet universal link
26
26
  */
27
- export declare function buildTransactionRequest(manifestUrl: string, request: SendTransactionRequest, returnScheme: string, walletUniversalLink?: string): string;
27
+ export declare function buildTransactionRequest(manifestUrl: string, request: SendTransactionRequest, returnScheme: string, walletUniversalLink?: string, returnStrategy?: 'back' | 'post_redirect' | 'none', requiresReturnScheme?: boolean): string;
28
28
  /**
29
29
  * Parse callback URL
30
30
  * Format: <scheme>://tonconnect?<base64_encoded_response>
@@ -105,17 +105,20 @@ function decodeBase64URL(encoded) {
105
105
  * Or universal link: https://app.tonkeeper.com/ton-connect?<base64_encoded_payload>
106
106
  * Or custom wallet universal link
107
107
  */
108
- function buildConnectionRequest(manifestUrl, returnScheme, walletUniversalLink) {
109
- // TON Connect protocol: payload should only contain manifestUrl, items, and returnStrategy
110
- // returnScheme is NOT part of the official protocol payload
111
- // For mobile apps, wallets should infer the callback scheme from the manifest or use a default
108
+ function buildConnectionRequest(manifestUrl, returnScheme, walletUniversalLink, returnStrategy, requiresReturnScheme) {
109
+ // Build payload with required fields
112
110
  const payload = {
113
111
  manifestUrl,
114
112
  items: [{ name: 'ton_addr' }],
115
- returnStrategy: 'back',
116
- // NOTE: returnScheme is NOT in the official TON Connect protocol
117
- // Wallets should handle mobile app callbacks differently
113
+ returnStrategy: returnStrategy || 'back',
118
114
  };
115
+ // CRITICAL FIX: Many wallets (Tonhub, MyTonWallet, Telegram Wallet) require returnScheme
116
+ // in the payload to properly handle mobile app callbacks. While not in the official
117
+ // protocol spec, it's a de-facto requirement for mobile apps.
118
+ if (requiresReturnScheme !== false) {
119
+ // Default to true if not specified - safer to include it
120
+ payload.returnScheme = returnScheme;
121
+ }
119
122
  const encoded = encodeBase64URL(payload);
120
123
  // Use custom wallet universal link if provided
121
124
  if (walletUniversalLink) {
@@ -130,7 +133,7 @@ function buildConnectionRequest(manifestUrl, returnScheme, walletUniversalLink)
130
133
  * Or universal link: https://app.tonkeeper.com/ton-connect/send-transaction?<base64_encoded_payload>
131
134
  * Or custom wallet universal link
132
135
  */
133
- function buildTransactionRequest(manifestUrl, request, returnScheme, walletUniversalLink) {
136
+ function buildTransactionRequest(manifestUrl, request, returnScheme, walletUniversalLink, returnStrategy, requiresReturnScheme) {
134
137
  const payload = {
135
138
  manifestUrl,
136
139
  request: {
@@ -144,10 +147,12 @@ function buildTransactionRequest(manifestUrl, request, returnScheme, walletUnive
144
147
  network: request.network,
145
148
  from: request.from,
146
149
  },
147
- returnStrategy: 'back',
148
- // NOTE: returnScheme is NOT in the official TON Connect protocol
149
- // Wallets should handle mobile app callbacks differently
150
+ returnStrategy: returnStrategy || 'back',
150
151
  };
152
+ // CRITICAL FIX: Include returnScheme for mobile wallets that require it
153
+ if (requiresReturnScheme !== false) {
154
+ payload.returnScheme = returnScheme;
155
+ }
151
156
  const encoded = encodeBase64URL(payload);
152
157
  // Use custom wallet universal link if provided
153
158
  if (walletUniversalLink) {
@@ -15,6 +15,10 @@ export interface WalletDefinition {
15
15
  iconUrl?: string;
16
16
  /** Platform support */
17
17
  platforms: ('ios' | 'android' | 'web')[];
18
+ /** Preferred return strategy for this wallet */
19
+ preferredReturnStrategy?: 'back' | 'post_redirect' | 'none';
20
+ /** Whether this wallet requires returnScheme in payload */
21
+ requiresReturnScheme?: boolean;
18
22
  }
19
23
  /**
20
24
  * List of supported TON Connect wallets
@@ -18,6 +18,8 @@ exports.SUPPORTED_WALLETS = [
18
18
  universalLink: 'https://app.tonkeeper.com/ton-connect',
19
19
  deepLink: 'tonkeeper://',
20
20
  platforms: ['ios', 'android'],
21
+ preferredReturnStrategy: 'back',
22
+ requiresReturnScheme: true, // CRITICAL FIX: Mobile apps need returnScheme for proper callback handling
21
23
  },
22
24
  {
23
25
  name: 'MyTonWallet',
@@ -25,6 +27,8 @@ exports.SUPPORTED_WALLETS = [
25
27
  universalLink: 'https://connect.mytonwallet.org',
26
28
  deepLink: 'mytonwallet://',
27
29
  platforms: ['ios', 'android', 'web'],
30
+ preferredReturnStrategy: 'post_redirect',
31
+ requiresReturnScheme: true, // MyTonWallet requires explicit returnScheme
28
32
  },
29
33
  {
30
34
  name: 'Wallet in Telegram',
@@ -32,6 +36,8 @@ exports.SUPPORTED_WALLETS = [
32
36
  universalLink: 'https://wallet.tonapi.io/ton-connect',
33
37
  deepLink: 'tg://',
34
38
  platforms: ['ios', 'android'],
39
+ preferredReturnStrategy: 'post_redirect',
40
+ requiresReturnScheme: true, // Telegram Wallet requires explicit returnScheme
35
41
  },
36
42
  {
37
43
  name: 'Tonhub',
@@ -39,6 +45,8 @@ exports.SUPPORTED_WALLETS = [
39
45
  universalLink: 'https://tonhub.com/ton-connect',
40
46
  deepLink: 'tonhub://',
41
47
  platforms: ['ios', 'android'],
48
+ preferredReturnStrategy: 'post_redirect',
49
+ requiresReturnScheme: true, // Tonhub requires explicit returnScheme for proper callback
42
50
  },
43
51
  ];
44
52
  /**
package/dist/index.d.ts CHANGED
@@ -38,6 +38,7 @@ export declare class TonConnectMobile {
38
38
  private currentWallet;
39
39
  private connectionPromise;
40
40
  private transactionPromise;
41
+ private signDataPromise;
41
42
  constructor(config: TonConnectMobileConfig);
42
43
  /**
43
44
  * Create platform adapter based on available modules
@@ -74,6 +75,14 @@ export declare class TonConnectMobile {
74
75
  boc: string;
75
76
  signature: string;
76
77
  }>;
78
+ /**
79
+ * Sign data (for authentication, etc.)
80
+ * Note: Not all wallets support signData. This is a TON Connect extension.
81
+ */
82
+ signData(data: string | Uint8Array, version?: string): Promise<{
83
+ signature: string;
84
+ timestamp: number;
85
+ }>;
77
86
  /**
78
87
  * Disconnect from wallet
79
88
  */
package/dist/index.js CHANGED
@@ -81,6 +81,7 @@ class TonConnectMobile {
81
81
  this.urlUnsubscribe = null;
82
82
  this.connectionPromise = null;
83
83
  this.transactionPromise = null;
84
+ this.signDataPromise = null;
84
85
  // Validate config
85
86
  if (!config.manifestUrl) {
86
87
  throw new TonConnectError('manifestUrl is required');
@@ -188,6 +189,40 @@ class TonConnectMobile {
188
189
  }
189
190
  const parsed = (0, protocol_1.parseCallbackURL)(url, this.config.scheme);
190
191
  console.log('[TON Connect] Parsed callback:', parsed.type, parsed.data ? 'has data' : 'no data');
192
+ // CRITICAL FIX: Check for sign data response first (before other handlers)
193
+ if (this.signDataPromise && !this.signDataPromise.timeout) {
194
+ // Sign data request is pending
195
+ if (parsed.type === 'error' && parsed.data) {
196
+ const errorData = parsed.data;
197
+ if (errorData?.error) {
198
+ const promise = this.signDataPromise;
199
+ this.signDataPromise = null;
200
+ if (errorData.error.code === 300) {
201
+ promise.reject(new UserRejectedError());
202
+ }
203
+ else {
204
+ promise.reject(new TonConnectError(errorData.error.message || 'Sign data failed'));
205
+ }
206
+ return;
207
+ }
208
+ }
209
+ // Check for sign data response format
210
+ // Note: TON Connect protocol may return sign data in different format
211
+ // We check for signature field in the response
212
+ if (parsed.data && typeof parsed.data === 'object') {
213
+ const data = parsed.data;
214
+ if (data.signature && typeof data.signature === 'string') {
215
+ const promise = this.signDataPromise;
216
+ this.signDataPromise = null;
217
+ promise.resolve({
218
+ signature: data.signature,
219
+ timestamp: data.timestamp || Date.now(),
220
+ });
221
+ return;
222
+ }
223
+ }
224
+ }
225
+ // Handle connection responses
191
226
  if (parsed.type === 'connect' && parsed.data) {
192
227
  this.handleConnectionResponse(parsed.data);
193
228
  }
@@ -306,10 +341,27 @@ class TonConnectMobile {
306
341
  // Build connection request URL (use wallet's universal link)
307
342
  console.log('[TON Connect] Building connection request URL for wallet:', this.currentWallet.name);
308
343
  console.log('[TON Connect] Using universal link:', this.currentWallet.universalLink);
309
- const url = (0, protocol_1.buildConnectionRequest)(this.config.manifestUrl, this.config.scheme, this.currentWallet.universalLink);
344
+ console.log('[TON Connect] Wallet return strategy:', this.currentWallet.preferredReturnStrategy || 'back');
345
+ console.log('[TON Connect] Wallet requires returnScheme:', this.currentWallet.requiresReturnScheme !== false);
346
+ const url = (0, protocol_1.buildConnectionRequest)(this.config.manifestUrl, this.config.scheme, this.currentWallet.universalLink, this.currentWallet.preferredReturnStrategy, this.currentWallet.requiresReturnScheme);
347
+ // DEBUG: Decode and log the payload for debugging
348
+ try {
349
+ const urlParts = url.split('?');
350
+ if (urlParts.length > 1) {
351
+ const payload = urlParts[1];
352
+ // CRITICAL FIX: Handle URL encoding - payload might have additional encoding
353
+ const cleanPayload = decodeURIComponent(payload);
354
+ const decoded = (0, protocol_1.decodeBase64URL)(cleanPayload);
355
+ console.log('[TON Connect] Connection request payload:', JSON.stringify(decoded, null, 2));
356
+ }
357
+ }
358
+ catch (e) {
359
+ // Log decode errors for debugging but don't fail
360
+ console.log('[TON Connect] Could not decode payload for logging:', e?.message || e);
361
+ // This is just for logging, the actual URL is correct
362
+ }
310
363
  console.log('[TON Connect] Built URL:', url.substring(0, 100) + '...');
311
- // DEBUG: Log the URL being opened
312
- console.log('[TON Connect] Opening URL:', url);
364
+ console.log('[TON Connect] Full URL:', url);
313
365
  console.log('[TON Connect] Manifest URL:', this.config.manifestUrl);
314
366
  console.log('[TON Connect] Return scheme:', this.config.scheme);
315
367
  console.log('[TON Connect] Adapter type:', this.adapter.constructor.name);
@@ -381,7 +433,7 @@ class TonConnectMobile {
381
433
  throw new TransactionInProgressError();
382
434
  }
383
435
  // Build transaction request URL (use universal link for Android compatibility)
384
- const url = (0, protocol_1.buildTransactionRequest)(this.config.manifestUrl, request, this.config.scheme, this.currentWallet.universalLink);
436
+ const url = (0, protocol_1.buildTransactionRequest)(this.config.manifestUrl, request, this.config.scheme, this.currentWallet.universalLink, this.currentWallet.preferredReturnStrategy, this.currentWallet.requiresReturnScheme);
385
437
  // Create promise for transaction
386
438
  return new Promise((resolve, reject) => {
387
439
  let timeout = null;
@@ -424,6 +476,140 @@ class TonConnectMobile {
424
476
  });
425
477
  });
426
478
  }
479
+ /**
480
+ * Sign data (for authentication, etc.)
481
+ * Note: Not all wallets support signData. This is a TON Connect extension.
482
+ */
483
+ async signData(data, version = '1.0') {
484
+ // Check if connected
485
+ if (!this.currentStatus.connected || !this.currentStatus.wallet) {
486
+ throw new TonConnectError('Not connected to wallet. Call connect() first.');
487
+ }
488
+ // Helper function to encode bytes to base64
489
+ const base64EncodeBytes = (bytes) => {
490
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
491
+ let result = '';
492
+ let i = 0;
493
+ while (i < bytes.length) {
494
+ const a = bytes[i++];
495
+ const b = i < bytes.length ? bytes[i++] : 0;
496
+ const c = i < bytes.length ? bytes[i++] : 0;
497
+ const bitmap = (a << 16) | (b << 8) | c;
498
+ result += chars.charAt((bitmap >> 18) & 63);
499
+ result += chars.charAt((bitmap >> 12) & 63);
500
+ result += i - 2 < bytes.length ? chars.charAt((bitmap >> 6) & 63) : '=';
501
+ result += i - 1 < bytes.length ? chars.charAt(bitmap & 63) : '=';
502
+ }
503
+ return result;
504
+ };
505
+ // Helper function to get TextEncoder
506
+ const getTextEncoder = () => {
507
+ // eslint-disable-next-line no-undef
508
+ if (typeof globalThis !== 'undefined' && globalThis.TextEncoder) {
509
+ // eslint-disable-next-line no-undef
510
+ return new globalThis.TextEncoder();
511
+ }
512
+ // Fallback: manual encoding
513
+ return {
514
+ encode(input) {
515
+ const bytes = new Uint8Array(input.length);
516
+ for (let i = 0; i < input.length; i++) {
517
+ bytes[i] = input.charCodeAt(i);
518
+ }
519
+ return bytes;
520
+ },
521
+ };
522
+ };
523
+ // Convert data to base64
524
+ let dataBase64;
525
+ if (typeof data === 'string') {
526
+ // Check if it's already base64
527
+ const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
528
+ if (base64Regex.test(data) && data.length % 4 === 0) {
529
+ // Likely base64, use as-is
530
+ dataBase64 = data;
531
+ }
532
+ else {
533
+ // Not base64, encode it
534
+ const encoder = getTextEncoder();
535
+ const bytes = encoder.encode(data);
536
+ dataBase64 = base64EncodeBytes(bytes);
537
+ }
538
+ }
539
+ else {
540
+ // Uint8Array - convert to base64
541
+ dataBase64 = base64EncodeBytes(data);
542
+ }
543
+ // Build sign data request
544
+ const payload = {
545
+ manifestUrl: this.config.manifestUrl,
546
+ data: dataBase64,
547
+ version,
548
+ returnStrategy: this.currentWallet.preferredReturnStrategy || 'back',
549
+ returnScheme: this.currentWallet.requiresReturnScheme !== false ? this.config.scheme : undefined,
550
+ };
551
+ // Encode payload
552
+ const { encodeBase64URL } = require('./core/protocol');
553
+ const encoded = encodeBase64URL(payload);
554
+ // Build URL
555
+ const baseUrl = this.currentWallet.universalLink.endsWith('/ton-connect')
556
+ ? this.currentWallet.universalLink
557
+ : `${this.currentWallet.universalLink}/ton-connect`;
558
+ const url = `${baseUrl}/sign-data?${encoded}`;
559
+ // Open wallet app and wait for response
560
+ return new Promise((resolve, reject) => {
561
+ let timeout = null;
562
+ let resolved = false;
563
+ // CRITICAL FIX: Check if sign data is already in progress
564
+ if (this.signDataPromise) {
565
+ throw new TonConnectError('Sign data request already in progress');
566
+ }
567
+ // Create promise for sign data
568
+ const signDataPromise = {
569
+ resolve: (response) => {
570
+ if (timeout !== null) {
571
+ clearTimeout(timeout);
572
+ }
573
+ resolved = true;
574
+ if (this.signDataPromise === signDataPromise) {
575
+ this.signDataPromise = null;
576
+ }
577
+ resolve(response);
578
+ },
579
+ reject: (error) => {
580
+ if (timeout !== null) {
581
+ clearTimeout(timeout);
582
+ }
583
+ resolved = true;
584
+ if (this.signDataPromise === signDataPromise) {
585
+ this.signDataPromise = null;
586
+ }
587
+ reject(error);
588
+ },
589
+ timeout: null,
590
+ };
591
+ // Set timeout
592
+ timeout = setTimeout(() => {
593
+ if (!resolved && this.signDataPromise === signDataPromise) {
594
+ this.signDataPromise = null;
595
+ signDataPromise.reject(new TonConnectError('Sign data request timed out'));
596
+ }
597
+ }, this.config.transactionTimeout);
598
+ signDataPromise.timeout = timeout;
599
+ // Store promise for callback handling
600
+ // CRITICAL FIX: Don't mutate handleCallback method - use a separate tracking mechanism
601
+ this.signDataPromise = signDataPromise;
602
+ // Open URL
603
+ this.adapter.openURL(url, this.config.skipCanOpenURLCheck).then(() => {
604
+ // URL opened, wait for callback
605
+ // Callback will be handled by handleCallback method checking signDataPromise
606
+ }).catch((error) => {
607
+ // Clear promise on error
608
+ this.signDataPromise = null;
609
+ signDataPromise.reject(new TonConnectError(`Failed to open wallet: ${error?.message || String(error)}`));
610
+ });
611
+ });
612
+ }
427
613
  /**
428
614
  * Disconnect from wallet
429
615
  */
@@ -601,6 +787,7 @@ class TonConnectMobile {
601
787
  this.statusChangeCallbacks.clear();
602
788
  this.connectionPromise = null;
603
789
  this.transactionPromise = null;
790
+ this.signDataPromise = null;
604
791
  }
605
792
  }
606
793
  exports.TonConnectMobile = TonConnectMobile;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * TonConnectButton component
3
+ * Compatible with @tonconnect/ui-react TonConnectButton
4
+ */
5
+ import { ViewStyle, TextStyle } from 'react-native';
6
+ export interface TonConnectButtonProps {
7
+ /** Button text when disconnected */
8
+ text?: string;
9
+ /** Button text when connected */
10
+ connectedText?: string;
11
+ /** Custom styles */
12
+ style?: ViewStyle;
13
+ /** Custom text styles */
14
+ textStyle?: TextStyle;
15
+ /** Callback when button is pressed */
16
+ onPress?: () => void;
17
+ }
18
+ /**
19
+ * TonConnectButton - Button component for connecting/disconnecting wallet
20
+ * Compatible with @tonconnect/ui-react TonConnectButton
21
+ */
22
+ export declare function TonConnectButton({ text, connectedText, style, textStyle, onPress, }: TonConnectButtonProps): JSX.Element;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ /**
3
+ * TonConnectButton component
4
+ * Compatible with @tonconnect/ui-react TonConnectButton
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.TonConnectButton = TonConnectButton;
41
+ const react_1 = __importStar(require("react"));
42
+ const react_native_1 = require("react-native");
43
+ const index_1 = require("./index");
44
+ /**
45
+ * TonConnectButton - Button component for connecting/disconnecting wallet
46
+ * Compatible with @tonconnect/ui-react TonConnectButton
47
+ */
48
+ function TonConnectButton({ text = 'Connect Wallet', connectedText = 'Disconnect', style, textStyle, onPress, }) {
49
+ const tonConnectUI = (0, index_1.useTonConnectUI)();
50
+ const wallet = (0, index_1.useTonWallet)();
51
+ const isConnected = wallet?.connected || false;
52
+ const [isLoading, setIsLoading] = (0, react_1.useState)(false);
53
+ const handlePress = async () => {
54
+ // CRITICAL FIX: Prevent multiple simultaneous presses
55
+ if (isLoading) {
56
+ return;
57
+ }
58
+ if (onPress) {
59
+ onPress();
60
+ return;
61
+ }
62
+ setIsLoading(true);
63
+ try {
64
+ if (isConnected) {
65
+ await tonConnectUI.disconnect();
66
+ }
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
71
+ await tonConnectUI.openModal();
72
+ // Note: connectWallet() should be called by the modal/wallet selection UI
73
+ // Not automatically here, to allow wallet selection
74
+ }
75
+ }
76
+ catch (error) {
77
+ // CRITICAL FIX: Handle errors gracefully
78
+ console.error('TonConnectButton error:', error);
79
+ // Error is already handled by the SDK/UI, just reset loading state
80
+ }
81
+ finally {
82
+ setIsLoading(false);
83
+ }
84
+ };
85
+ return (react_1.default.createElement(react_native_1.TouchableOpacity, { style: [styles.button, style, isLoading && styles.buttonDisabled], onPress: handlePress, disabled: isLoading }, isLoading ? (react_1.default.createElement(react_native_1.ActivityIndicator, { color: "#ffffff" })) : (react_1.default.createElement(react_native_1.Text, { style: [styles.buttonText, textStyle] }, isConnected ? connectedText : text))));
86
+ }
87
+ const styles = react_native_1.StyleSheet.create({
88
+ button: {
89
+ backgroundColor: '#0088cc',
90
+ paddingHorizontal: 24,
91
+ paddingVertical: 12,
92
+ borderRadius: 8,
93
+ alignItems: 'center',
94
+ justifyContent: 'center',
95
+ minHeight: 44,
96
+ },
97
+ buttonDisabled: {
98
+ opacity: 0.6,
99
+ },
100
+ buttonText: {
101
+ color: '#ffffff',
102
+ fontSize: 16,
103
+ fontWeight: '600',
104
+ },
105
+ });
@@ -0,0 +1,110 @@
1
+ /**
2
+ * React integration layer for @tonconnect/ui-react compatibility
3
+ * Provides TonConnectUIProvider, hooks, and components compatible with @tonconnect/ui-react API
4
+ */
5
+ import { ReactNode } from 'react';
6
+ import { TonConnectMobile, WalletInfo, SendTransactionRequest } from '../index';
7
+ import type { TonConnectMobileConfig } from '../types';
8
+ /**
9
+ * Account information (compatible with @tonconnect/ui-react)
10
+ */
11
+ export interface Account {
12
+ address: string;
13
+ chain: number;
14
+ publicKey?: string;
15
+ }
16
+ /**
17
+ * Wallet state (compatible with @tonconnect/ui-react)
18
+ */
19
+ export interface WalletState {
20
+ account: Account | null;
21
+ wallet: WalletInfo | null;
22
+ connected: boolean;
23
+ }
24
+ /**
25
+ * Transaction response (compatible with @tonconnect/ui-react)
26
+ */
27
+ export interface TransactionResponse {
28
+ boc: string;
29
+ signature: string;
30
+ }
31
+ /**
32
+ * Sign data request
33
+ */
34
+ export interface SignDataRequest {
35
+ /** Data to sign (will be base64 encoded) */
36
+ data: string | Uint8Array;
37
+ /** Optional version */
38
+ version?: string;
39
+ }
40
+ /**
41
+ * Sign data response
42
+ */
43
+ export interface SignDataResponse {
44
+ signature: string;
45
+ timestamp: number;
46
+ }
47
+ /**
48
+ * TonConnect UI instance interface (compatible with @tonconnect/ui-react)
49
+ */
50
+ export interface TonConnectUI {
51
+ /** Open connection modal */
52
+ openModal: () => Promise<void>;
53
+ /** Close connection modal */
54
+ closeModal: () => void;
55
+ /** Connect to wallet */
56
+ connectWallet: () => Promise<void>;
57
+ /** Disconnect from wallet */
58
+ disconnect: () => Promise<void>;
59
+ /** Send transaction */
60
+ sendTransaction: (transaction: SendTransactionRequest) => Promise<TransactionResponse>;
61
+ /** Sign data */
62
+ signData: (request: SignDataRequest) => Promise<SignDataResponse>;
63
+ /** Current wallet state */
64
+ wallet: WalletState | null;
65
+ /** Modal open state */
66
+ modalState: {
67
+ open: boolean;
68
+ };
69
+ /** UI kit version */
70
+ uiVersion: string;
71
+ }
72
+ /**
73
+ * TonConnectUIProvider props
74
+ */
75
+ export interface TonConnectUIProviderProps {
76
+ /** SDK configuration */
77
+ config: TonConnectMobileConfig;
78
+ /** Children */
79
+ children: ReactNode;
80
+ /** Optional SDK instance (for testing or custom instances) */
81
+ sdkInstance?: TonConnectMobile;
82
+ }
83
+ /**
84
+ * TonConnectUIProvider - React context provider for TON Connect
85
+ * Compatible with @tonconnect/ui-react API
86
+ */
87
+ export declare function TonConnectUIProvider({ config, children, sdkInstance, }: TonConnectUIProviderProps): JSX.Element;
88
+ /**
89
+ * Hook to access TonConnectUI instance
90
+ * Compatible with @tonconnect/ui-react useTonConnectUI hook
91
+ */
92
+ export declare function useTonConnectUI(): TonConnectUI;
93
+ /**
94
+ * Hook to access wallet state
95
+ * Compatible with @tonconnect/ui-react useTonWallet hook
96
+ */
97
+ export declare function useTonWallet(): WalletState | null;
98
+ /**
99
+ * Hook to access modal state
100
+ * Compatible with @tonconnect/ui-react useTonConnectModal hook
101
+ */
102
+ export declare function useTonConnectModal(): {
103
+ open: boolean;
104
+ close: () => void;
105
+ openModal: () => Promise<void>;
106
+ };
107
+ /**
108
+ * Hook to access SDK instance (for advanced usage)
109
+ */
110
+ export declare function useTonConnectSDK(): TonConnectMobile;