@blazium/ton-connect-mobile 1.2.0 → 1.2.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.
- package/README.md +316 -18
- package/dist/adapters/expo.js +3 -3
- package/dist/adapters/react-native.js +3 -3
- package/dist/core/protocol.d.ts +1 -0
- package/dist/core/protocol.js +69 -9
- package/dist/core/wallets.js +5 -1
- package/dist/index.d.ts +40 -1
- package/dist/index.js +309 -13
- package/dist/react/TonConnectUIProvider.d.ts +21 -2
- package/dist/react/TonConnectUIProvider.js +118 -14
- package/dist/react/WalletSelectionModal.d.ts +1 -0
- package/dist/react/WalletSelectionModal.js +153 -80
- package/dist/react/index.d.ts +1 -0
- package/dist/types/index.d.ts +46 -0
- package/dist/utils/transactionBuilder.js +50 -7
- package/package.json +1 -1
- package/src/adapters/expo.ts +3 -3
- package/src/adapters/react-native.ts +3 -3
- package/src/core/protocol.ts +76 -9
- package/src/core/wallets.ts +5 -1
- package/src/index.ts +381 -15
- package/src/react/TonConnectUIProvider.tsx +154 -15
- package/src/react/WalletSelectionModal.tsx +180 -90
- package/src/react/index.ts +1 -0
- package/src/types/index.ts +52 -0
- package/src/utils/transactionBuilder.ts +56 -7
package/src/types/index.ts
CHANGED
|
@@ -187,6 +187,11 @@ export interface PlatformAdapter {
|
|
|
187
187
|
randomBytes(length: number): Promise<Uint8Array>;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Network type
|
|
192
|
+
*/
|
|
193
|
+
export type Network = 'mainnet' | 'testnet';
|
|
194
|
+
|
|
190
195
|
/**
|
|
191
196
|
* SDK configuration
|
|
192
197
|
*/
|
|
@@ -211,6 +216,12 @@ export interface TonConnectMobileConfig {
|
|
|
211
216
|
* Available: 'Tonkeeper', 'MyTonWallet', 'Wallet in Telegram', 'Tonhub'
|
|
212
217
|
*/
|
|
213
218
|
preferredWallet?: string;
|
|
219
|
+
/** Network (mainnet/testnet) - default: 'mainnet' */
|
|
220
|
+
network?: Network;
|
|
221
|
+
/** TON API endpoint for balance checking (optional)
|
|
222
|
+
* Default: 'https://toncenter.com/api/v2' for mainnet, 'https://testnet.toncenter.com/api/v2' for testnet
|
|
223
|
+
*/
|
|
224
|
+
tonApiEndpoint?: string;
|
|
214
225
|
}
|
|
215
226
|
|
|
216
227
|
/**
|
|
@@ -218,3 +229,44 @@ export interface TonConnectMobileConfig {
|
|
|
218
229
|
*/
|
|
219
230
|
export type StatusChangeCallback = (status: ConnectionStatus) => void;
|
|
220
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Event types for TonConnectMobile
|
|
234
|
+
*/
|
|
235
|
+
export type TonConnectEventType = 'connect' | 'disconnect' | 'transaction' | 'error' | 'statusChange';
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Event listener callback
|
|
239
|
+
*/
|
|
240
|
+
export type TonConnectEventListener<T = any> = (data: T) => void;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Transaction status
|
|
244
|
+
*/
|
|
245
|
+
export type TransactionStatus = 'pending' | 'confirmed' | 'failed' | 'unknown';
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Transaction status response
|
|
249
|
+
*/
|
|
250
|
+
export interface TransactionStatusResponse {
|
|
251
|
+
/** Transaction status */
|
|
252
|
+
status: TransactionStatus;
|
|
253
|
+
/** Transaction hash (if available) */
|
|
254
|
+
hash?: string;
|
|
255
|
+
/** Block number (if confirmed) */
|
|
256
|
+
blockNumber?: number;
|
|
257
|
+
/** Error message (if failed) */
|
|
258
|
+
error?: string;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Balance response
|
|
263
|
+
*/
|
|
264
|
+
export interface BalanceResponse {
|
|
265
|
+
/** Balance in nanotons */
|
|
266
|
+
balance: string;
|
|
267
|
+
/** Balance in TON (formatted) */
|
|
268
|
+
balanceTon: string;
|
|
269
|
+
/** Network */
|
|
270
|
+
network: Network;
|
|
271
|
+
}
|
|
272
|
+
|
|
@@ -41,12 +41,32 @@ export function buildTransferTransaction(
|
|
|
41
41
|
amount: number | string,
|
|
42
42
|
validUntil?: number
|
|
43
43
|
): SendTransactionRequest {
|
|
44
|
+
// Validate address
|
|
45
|
+
if (!to || typeof to !== 'string') {
|
|
46
|
+
throw new Error('Recipient address is required');
|
|
47
|
+
}
|
|
48
|
+
if (!isValidTonAddress(to)) {
|
|
49
|
+
throw new Error(`Invalid TON address format: ${to}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Validate amount
|
|
53
|
+
const nanoAmount = tonToNano(amount);
|
|
54
|
+
if (BigInt(nanoAmount) <= 0n) {
|
|
55
|
+
throw new Error('Transaction amount must be greater than 0');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Validate validUntil
|
|
59
|
+
const expiration = validUntil || Date.now() + 5 * 60 * 1000; // 5 minutes default
|
|
60
|
+
if (expiration <= Date.now()) {
|
|
61
|
+
throw new Error('Transaction expiration must be in the future');
|
|
62
|
+
}
|
|
63
|
+
|
|
44
64
|
return {
|
|
45
|
-
validUntil:
|
|
65
|
+
validUntil: expiration,
|
|
46
66
|
messages: [
|
|
47
67
|
{
|
|
48
68
|
address: to,
|
|
49
|
-
amount:
|
|
69
|
+
amount: nanoAmount,
|
|
50
70
|
},
|
|
51
71
|
],
|
|
52
72
|
};
|
|
@@ -62,12 +82,41 @@ export function buildMultiTransferTransaction(
|
|
|
62
82
|
transfers: Array<{ to: string; amount: number | string }>,
|
|
63
83
|
validUntil?: number
|
|
64
84
|
): SendTransactionRequest {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
// Validate transfers array
|
|
86
|
+
if (!transfers || !Array.isArray(transfers) || transfers.length === 0) {
|
|
87
|
+
throw new Error('Transfers array is required and cannot be empty');
|
|
88
|
+
}
|
|
89
|
+
if (transfers.length > 255) {
|
|
90
|
+
throw new Error('Maximum 255 transfers allowed per transaction');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Validate each transfer
|
|
94
|
+
const messages = transfers.map((transfer, index) => {
|
|
95
|
+
if (!transfer.to || typeof transfer.to !== 'string') {
|
|
96
|
+
throw new Error(`Transfer ${index + 1}: Recipient address is required`);
|
|
97
|
+
}
|
|
98
|
+
if (!isValidTonAddress(transfer.to)) {
|
|
99
|
+
throw new Error(`Transfer ${index + 1}: Invalid TON address format: ${transfer.to}`);
|
|
100
|
+
}
|
|
101
|
+
const nanoAmount = tonToNano(transfer.amount);
|
|
102
|
+
if (BigInt(nanoAmount) <= 0n) {
|
|
103
|
+
throw new Error(`Transfer ${index + 1}: Amount must be greater than 0`);
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
68
106
|
address: transfer.to,
|
|
69
|
-
amount:
|
|
70
|
-
}
|
|
107
|
+
amount: nanoAmount,
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Validate validUntil
|
|
112
|
+
const expiration = validUntil || Date.now() + 5 * 60 * 1000;
|
|
113
|
+
if (expiration <= Date.now()) {
|
|
114
|
+
throw new Error('Transaction expiration must be in the future');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
validUntil: expiration,
|
|
119
|
+
messages,
|
|
71
120
|
};
|
|
72
121
|
}
|
|
73
122
|
|