@blazium/ton-connect-mobile 1.1.5 → 1.2.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/README.md +424 -145
- package/dist/index.d.ts +10 -2
- package/dist/index.js +31 -5
- package/dist/react/TonConnectUIProvider.js +8 -3
- package/dist/react/WalletSelectionModal.d.ts +20 -0
- package/dist/react/WalletSelectionModal.js +213 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +3 -1
- package/dist/utils/retry.d.ts +31 -0
- package/dist/utils/retry.js +67 -0
- package/dist/utils/transactionBuilder.d.ts +67 -0
- package/dist/utils/transactionBuilder.js +131 -0
- package/package.json +1 -1
- package/src/index.ts +47 -5
- package/src/react/TonConnectUIProvider.tsx +15 -3
- package/src/react/WalletSelectionModal.tsx +292 -0
- package/src/react/index.ts +2 -0
- package/src/utils/retry.ts +101 -0
- package/src/utils/transactionBuilder.ts +153 -0
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ import { type WalletDefinition } from './core/wallets';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class TonConnectError extends Error {
|
|
11
11
|
code?: string | undefined;
|
|
12
|
-
|
|
12
|
+
recoverySuggestion?: string | undefined;
|
|
13
|
+
constructor(message: string, code?: string | undefined, recoverySuggestion?: string | undefined);
|
|
13
14
|
}
|
|
14
15
|
export declare class ConnectionTimeoutError extends TonConnectError {
|
|
15
16
|
constructor();
|
|
@@ -18,7 +19,7 @@ export declare class TransactionTimeoutError extends TonConnectError {
|
|
|
18
19
|
constructor();
|
|
19
20
|
}
|
|
20
21
|
export declare class UserRejectedError extends TonConnectError {
|
|
21
|
-
constructor();
|
|
22
|
+
constructor(message?: string);
|
|
22
23
|
}
|
|
23
24
|
export declare class ConnectionInProgressError extends TonConnectError {
|
|
24
25
|
constructor();
|
|
@@ -99,6 +100,11 @@ export declare class TonConnectMobile {
|
|
|
99
100
|
* Get current wallet being used
|
|
100
101
|
*/
|
|
101
102
|
getCurrentWallet(): WalletDefinition;
|
|
103
|
+
/**
|
|
104
|
+
* Check if a wallet is available on the current platform
|
|
105
|
+
* Note: This is a best-effort check and may not be 100% accurate
|
|
106
|
+
*/
|
|
107
|
+
isWalletAvailable(walletName?: string): Promise<boolean>;
|
|
102
108
|
/**
|
|
103
109
|
* Set preferred wallet for connections
|
|
104
110
|
*/
|
|
@@ -135,3 +141,5 @@ export declare class TonConnectMobile {
|
|
|
135
141
|
export * from './types';
|
|
136
142
|
export type { WalletDefinition } from './core/wallets';
|
|
137
143
|
export { SUPPORTED_WALLETS, getWalletByName, getDefaultWallet, getWalletsForPlatform } from './core/wallets';
|
|
144
|
+
export * from './utils/transactionBuilder';
|
|
145
|
+
export * from './utils/retry';
|
package/dist/index.js
CHANGED
|
@@ -29,30 +29,31 @@ const wallets_1 = require("./core/wallets");
|
|
|
29
29
|
* Custom error classes
|
|
30
30
|
*/
|
|
31
31
|
class TonConnectError extends Error {
|
|
32
|
-
constructor(message, code) {
|
|
32
|
+
constructor(message, code, recoverySuggestion) {
|
|
33
33
|
super(message);
|
|
34
34
|
this.code = code;
|
|
35
|
+
this.recoverySuggestion = recoverySuggestion;
|
|
35
36
|
this.name = 'TonConnectError';
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
exports.TonConnectError = TonConnectError;
|
|
39
40
|
class ConnectionTimeoutError extends TonConnectError {
|
|
40
41
|
constructor() {
|
|
41
|
-
super('Connection request timed out', 'CONNECTION_TIMEOUT');
|
|
42
|
+
super('Connection request timed out. The wallet did not respond in time.', 'CONNECTION_TIMEOUT', 'Please make sure the wallet app is installed and try again. If the issue persists, check your internet connection.');
|
|
42
43
|
this.name = 'ConnectionTimeoutError';
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
exports.ConnectionTimeoutError = ConnectionTimeoutError;
|
|
46
47
|
class TransactionTimeoutError extends TonConnectError {
|
|
47
48
|
constructor() {
|
|
48
|
-
super('Transaction request timed out', 'TRANSACTION_TIMEOUT');
|
|
49
|
+
super('Transaction request timed out. The wallet did not respond in time.', 'TRANSACTION_TIMEOUT', 'Please check the wallet app and try again. Make sure you approve or reject the transaction in the wallet.');
|
|
49
50
|
this.name = 'TransactionTimeoutError';
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
exports.TransactionTimeoutError = TransactionTimeoutError;
|
|
53
54
|
class UserRejectedError extends TonConnectError {
|
|
54
|
-
constructor() {
|
|
55
|
-
super('User rejected the request', 'USER_REJECTED');
|
|
55
|
+
constructor(message) {
|
|
56
|
+
super(message || 'User rejected the request', 'USER_REJECTED', 'The user cancelled the operation in the wallet app.');
|
|
56
57
|
this.name = 'UserRejectedError';
|
|
57
58
|
}
|
|
58
59
|
}
|
|
@@ -645,6 +646,28 @@ class TonConnectMobile {
|
|
|
645
646
|
getCurrentWallet() {
|
|
646
647
|
return this.currentWallet;
|
|
647
648
|
}
|
|
649
|
+
/**
|
|
650
|
+
* Check if a wallet is available on the current platform
|
|
651
|
+
* Note: This is a best-effort check and may not be 100% accurate
|
|
652
|
+
*/
|
|
653
|
+
async isWalletAvailable(walletName) {
|
|
654
|
+
const wallet = walletName ? (0, wallets_1.getWalletByName)(walletName) : this.currentWallet;
|
|
655
|
+
if (!wallet) {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
// On web, check if wallet supports web platform
|
|
659
|
+
// eslint-disable-next-line no-undef
|
|
660
|
+
if (typeof globalThis !== 'undefined' && globalThis.window) {
|
|
661
|
+
return wallet.platforms.includes('web');
|
|
662
|
+
}
|
|
663
|
+
// On mobile, we can't reliably check if wallet is installed
|
|
664
|
+
// Return true if wallet supports the current platform
|
|
665
|
+
// eslint-disable-next-line no-undef
|
|
666
|
+
const platform = typeof globalThis !== 'undefined' && globalThis.Platform
|
|
667
|
+
? globalThis.Platform.OS === 'ios' ? 'ios' : 'android'
|
|
668
|
+
: 'android';
|
|
669
|
+
return wallet.platforms.includes(platform);
|
|
670
|
+
}
|
|
648
671
|
/**
|
|
649
672
|
* Set preferred wallet for connections
|
|
650
673
|
*/
|
|
@@ -805,3 +828,6 @@ Object.defineProperty(exports, "SUPPORTED_WALLETS", { enumerable: true, get: fun
|
|
|
805
828
|
Object.defineProperty(exports, "getWalletByName", { enumerable: true, get: function () { return wallets_2.getWalletByName; } });
|
|
806
829
|
Object.defineProperty(exports, "getDefaultWallet", { enumerable: true, get: function () { return wallets_2.getDefaultWallet; } });
|
|
807
830
|
Object.defineProperty(exports, "getWalletsForPlatform", { enumerable: true, get: function () { return wallets_2.getWalletsForPlatform; } });
|
|
831
|
+
// Export utilities
|
|
832
|
+
__exportStar(require("./utils/transactionBuilder"), exports);
|
|
833
|
+
__exportStar(require("./utils/retry"), exports);
|
|
@@ -44,6 +44,7 @@ exports.useTonConnectModal = useTonConnectModal;
|
|
|
44
44
|
exports.useTonConnectSDK = useTonConnectSDK;
|
|
45
45
|
const react_1 = __importStar(require("react"));
|
|
46
46
|
const index_1 = require("../index");
|
|
47
|
+
const WalletSelectionModal_1 = require("./WalletSelectionModal");
|
|
47
48
|
const TonConnectUIContext = (0, react_1.createContext)(null);
|
|
48
49
|
/**
|
|
49
50
|
* TonConnectUIProvider - React context provider for TON Connect
|
|
@@ -98,8 +99,10 @@ function TonConnectUIProvider({ config, children, sdkInstance, }) {
|
|
|
98
99
|
}, [sdk, updateWalletState]);
|
|
99
100
|
// Open modal
|
|
100
101
|
const openModal = (0, react_1.useCallback)(async () => {
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
if (!walletState?.connected) {
|
|
103
|
+
setModalOpen(true);
|
|
104
|
+
}
|
|
105
|
+
}, [walletState?.connected]);
|
|
103
106
|
// Close modal
|
|
104
107
|
const closeModal = (0, react_1.useCallback)(() => {
|
|
105
108
|
setModalOpen(false);
|
|
@@ -164,7 +167,9 @@ function TonConnectUIProvider({ config, children, sdkInstance, }) {
|
|
|
164
167
|
tonConnectUI,
|
|
165
168
|
sdk,
|
|
166
169
|
};
|
|
167
|
-
return react_1.default.createElement(TonConnectUIContext.Provider, { value: contextValue },
|
|
170
|
+
return (react_1.default.createElement(TonConnectUIContext.Provider, { value: contextValue },
|
|
171
|
+
children,
|
|
172
|
+
react_1.default.createElement(WalletSelectionModal_1.WalletSelectionModal, { visible: modalOpen && !walletState?.connected, onClose: closeModal })));
|
|
168
173
|
}
|
|
169
174
|
/**
|
|
170
175
|
* Hook to access TonConnectUI instance
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WalletSelectionModal component
|
|
3
|
+
* Provides a beautiful wallet selection UI compatible with @tonconnect/ui-react
|
|
4
|
+
*/
|
|
5
|
+
import type { WalletDefinition } from '../index';
|
|
6
|
+
export interface WalletSelectionModalProps {
|
|
7
|
+
/** Whether the modal is visible */
|
|
8
|
+
visible: boolean;
|
|
9
|
+
/** Callback when modal should close */
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
/** Custom wallet list (optional, uses SDK's supported wallets by default) */
|
|
12
|
+
wallets?: WalletDefinition[];
|
|
13
|
+
/** Custom styles */
|
|
14
|
+
style?: any;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* WalletSelectionModal - Beautiful wallet selection modal
|
|
18
|
+
* Compatible with @tonconnect/ui-react modal behavior
|
|
19
|
+
*/
|
|
20
|
+
export declare function WalletSelectionModal({ visible, onClose, wallets: customWallets, style, }: WalletSelectionModalProps): JSX.Element;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* WalletSelectionModal component
|
|
4
|
+
* Provides a beautiful wallet selection UI compatible with @tonconnect/ui-react
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.WalletSelectionModal = WalletSelectionModal;
|
|
11
|
+
const react_1 = __importDefault(require("react"));
|
|
12
|
+
const react_native_1 = require("react-native");
|
|
13
|
+
const index_1 = require("./index");
|
|
14
|
+
/**
|
|
15
|
+
* WalletSelectionModal - Beautiful wallet selection modal
|
|
16
|
+
* Compatible with @tonconnect/ui-react modal behavior
|
|
17
|
+
*/
|
|
18
|
+
function WalletSelectionModal({ visible, onClose, wallets: customWallets, style, }) {
|
|
19
|
+
const tonConnectUI = (0, index_1.useTonConnectUI)();
|
|
20
|
+
const sdk = (0, index_1.useTonConnectSDK)();
|
|
21
|
+
const [wallets, setWallets] = react_1.default.useState([]);
|
|
22
|
+
const [connectingWallet, setConnectingWallet] = react_1.default.useState(null);
|
|
23
|
+
// Load wallets
|
|
24
|
+
react_1.default.useEffect(() => {
|
|
25
|
+
if (customWallets) {
|
|
26
|
+
setWallets(customWallets);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const supportedWallets = sdk.getSupportedWallets();
|
|
30
|
+
// Filter wallets for current platform
|
|
31
|
+
const platform = react_native_1.Platform.OS === 'ios' ? 'ios' : react_native_1.Platform.OS === 'android' ? 'android' : 'web';
|
|
32
|
+
const platformWallets = supportedWallets.filter((w) => w.platforms.includes(platform));
|
|
33
|
+
setWallets(platformWallets);
|
|
34
|
+
}
|
|
35
|
+
}, [sdk, customWallets]);
|
|
36
|
+
// Handle wallet selection
|
|
37
|
+
const handleSelectWallet = async (wallet) => {
|
|
38
|
+
try {
|
|
39
|
+
setConnectingWallet(wallet.name);
|
|
40
|
+
// Set preferred wallet
|
|
41
|
+
sdk.setPreferredWallet(wallet.name);
|
|
42
|
+
// Close modal
|
|
43
|
+
onClose();
|
|
44
|
+
// Small delay to ensure modal closes
|
|
45
|
+
await new Promise((resolve) => setTimeout(() => resolve(), 100));
|
|
46
|
+
// Connect
|
|
47
|
+
await tonConnectUI.connectWallet();
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error('Wallet connection error:', error);
|
|
51
|
+
setConnectingWallet(null);
|
|
52
|
+
// Re-open modal on error
|
|
53
|
+
onClose();
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
// Modal will be re-opened by parent if needed
|
|
56
|
+
}, 500);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return (react_1.default.createElement(react_native_1.Modal, { visible: visible, animationType: "slide", transparent: true, onRequestClose: onClose },
|
|
60
|
+
react_1.default.createElement(react_native_1.View, { style: [styles.overlay, style] },
|
|
61
|
+
react_1.default.createElement(react_native_1.View, { style: styles.modalContainer },
|
|
62
|
+
react_1.default.createElement(react_native_1.View, { style: styles.header },
|
|
63
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.title }, "Connect your TON wallet"),
|
|
64
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.subtitle }, "Choose a wallet to connect to this app"),
|
|
65
|
+
react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.closeButton, onPress: onClose },
|
|
66
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.closeButtonText }, "\u2715"))),
|
|
67
|
+
react_1.default.createElement(react_native_1.ScrollView, { style: styles.walletList, showsVerticalScrollIndicator: false }, wallets.length === 0 ? (react_1.default.createElement(react_native_1.View, { style: styles.emptyState },
|
|
68
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.emptyStateText }, "No wallets available"),
|
|
69
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.emptyStateSubtext }, "Please install a TON wallet app to continue"))) : (wallets.map((wallet) => {
|
|
70
|
+
const isConnecting = connectingWallet === wallet.name;
|
|
71
|
+
return (react_1.default.createElement(react_native_1.TouchableOpacity, { key: wallet.name, style: [styles.walletItem, isConnecting && styles.walletItemConnecting], onPress: () => handleSelectWallet(wallet), disabled: isConnecting },
|
|
72
|
+
react_1.default.createElement(react_native_1.View, { style: styles.walletIconContainer }, wallet.iconUrl ? (react_1.default.createElement(react_native_1.Image, { source: { uri: wallet.iconUrl }, style: styles.walletIcon })) : (react_1.default.createElement(react_native_1.View, { style: styles.walletIconPlaceholder },
|
|
73
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.walletIconText }, wallet.name.charAt(0).toUpperCase())))),
|
|
74
|
+
react_1.default.createElement(react_native_1.View, { style: styles.walletInfo },
|
|
75
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.walletName }, wallet.name),
|
|
76
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.walletAppName }, wallet.appName)),
|
|
77
|
+
isConnecting && (react_1.default.createElement(react_native_1.View, { style: styles.connectingIndicator },
|
|
78
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.connectingText }, "Connecting...")))));
|
|
79
|
+
}))),
|
|
80
|
+
react_1.default.createElement(react_native_1.View, { style: styles.footer },
|
|
81
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.footerText }, "By connecting, you agree to the app's Terms of Service and Privacy Policy"))))));
|
|
82
|
+
}
|
|
83
|
+
const styles = react_native_1.StyleSheet.create({
|
|
84
|
+
overlay: {
|
|
85
|
+
flex: 1,
|
|
86
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
87
|
+
justifyContent: 'flex-end',
|
|
88
|
+
},
|
|
89
|
+
modalContainer: {
|
|
90
|
+
backgroundColor: '#1a1a1a',
|
|
91
|
+
borderTopLeftRadius: 24,
|
|
92
|
+
borderTopRightRadius: 24,
|
|
93
|
+
maxHeight: '85%',
|
|
94
|
+
paddingBottom: react_native_1.Platform.OS === 'ios' ? 34 : 20,
|
|
95
|
+
},
|
|
96
|
+
header: {
|
|
97
|
+
padding: 24,
|
|
98
|
+
borderBottomWidth: 1,
|
|
99
|
+
borderBottomColor: '#2a2a2a',
|
|
100
|
+
position: 'relative',
|
|
101
|
+
},
|
|
102
|
+
title: {
|
|
103
|
+
fontSize: 28,
|
|
104
|
+
fontWeight: 'bold',
|
|
105
|
+
color: '#ffffff',
|
|
106
|
+
marginBottom: 8,
|
|
107
|
+
},
|
|
108
|
+
subtitle: {
|
|
109
|
+
fontSize: 15,
|
|
110
|
+
color: '#999999',
|
|
111
|
+
lineHeight: 20,
|
|
112
|
+
},
|
|
113
|
+
closeButton: {
|
|
114
|
+
position: 'absolute',
|
|
115
|
+
top: 24,
|
|
116
|
+
right: 24,
|
|
117
|
+
width: 32,
|
|
118
|
+
height: 32,
|
|
119
|
+
borderRadius: 16,
|
|
120
|
+
backgroundColor: '#2a2a2a',
|
|
121
|
+
justifyContent: 'center',
|
|
122
|
+
alignItems: 'center',
|
|
123
|
+
},
|
|
124
|
+
closeButtonText: {
|
|
125
|
+
color: '#ffffff',
|
|
126
|
+
fontSize: 18,
|
|
127
|
+
fontWeight: '600',
|
|
128
|
+
},
|
|
129
|
+
walletList: {
|
|
130
|
+
padding: 16,
|
|
131
|
+
maxHeight: 400,
|
|
132
|
+
},
|
|
133
|
+
walletItem: {
|
|
134
|
+
flexDirection: 'row',
|
|
135
|
+
alignItems: 'center',
|
|
136
|
+
padding: 16,
|
|
137
|
+
backgroundColor: '#2a2a2a',
|
|
138
|
+
borderRadius: 16,
|
|
139
|
+
marginBottom: 12,
|
|
140
|
+
minHeight: 72,
|
|
141
|
+
},
|
|
142
|
+
walletItemConnecting: {
|
|
143
|
+
opacity: 0.7,
|
|
144
|
+
},
|
|
145
|
+
walletIconContainer: {
|
|
146
|
+
marginRight: 16,
|
|
147
|
+
},
|
|
148
|
+
walletIcon: {
|
|
149
|
+
width: 48,
|
|
150
|
+
height: 48,
|
|
151
|
+
borderRadius: 12,
|
|
152
|
+
},
|
|
153
|
+
walletIconPlaceholder: {
|
|
154
|
+
width: 48,
|
|
155
|
+
height: 48,
|
|
156
|
+
borderRadius: 12,
|
|
157
|
+
backgroundColor: '#3a3a3a',
|
|
158
|
+
justifyContent: 'center',
|
|
159
|
+
alignItems: 'center',
|
|
160
|
+
},
|
|
161
|
+
walletIconText: {
|
|
162
|
+
color: '#ffffff',
|
|
163
|
+
fontSize: 20,
|
|
164
|
+
fontWeight: 'bold',
|
|
165
|
+
},
|
|
166
|
+
walletInfo: {
|
|
167
|
+
flex: 1,
|
|
168
|
+
},
|
|
169
|
+
walletName: {
|
|
170
|
+
fontSize: 17,
|
|
171
|
+
fontWeight: '600',
|
|
172
|
+
color: '#ffffff',
|
|
173
|
+
marginBottom: 4,
|
|
174
|
+
},
|
|
175
|
+
walletAppName: {
|
|
176
|
+
fontSize: 14,
|
|
177
|
+
color: '#999999',
|
|
178
|
+
},
|
|
179
|
+
connectingIndicator: {
|
|
180
|
+
marginLeft: 12,
|
|
181
|
+
},
|
|
182
|
+
connectingText: {
|
|
183
|
+
fontSize: 14,
|
|
184
|
+
color: '#0088cc',
|
|
185
|
+
fontWeight: '500',
|
|
186
|
+
},
|
|
187
|
+
emptyState: {
|
|
188
|
+
padding: 40,
|
|
189
|
+
alignItems: 'center',
|
|
190
|
+
},
|
|
191
|
+
emptyStateText: {
|
|
192
|
+
fontSize: 18,
|
|
193
|
+
fontWeight: '600',
|
|
194
|
+
color: '#ffffff',
|
|
195
|
+
marginBottom: 8,
|
|
196
|
+
},
|
|
197
|
+
emptyStateSubtext: {
|
|
198
|
+
fontSize: 14,
|
|
199
|
+
color: '#999999',
|
|
200
|
+
textAlign: 'center',
|
|
201
|
+
},
|
|
202
|
+
footer: {
|
|
203
|
+
padding: 16,
|
|
204
|
+
borderTopWidth: 1,
|
|
205
|
+
borderTopColor: '#2a2a2a',
|
|
206
|
+
},
|
|
207
|
+
footerText: {
|
|
208
|
+
fontSize: 12,
|
|
209
|
+
color: '#666666',
|
|
210
|
+
textAlign: 'center',
|
|
211
|
+
lineHeight: 16,
|
|
212
|
+
},
|
|
213
|
+
});
|
package/dist/react/index.d.ts
CHANGED
|
@@ -6,3 +6,5 @@ export { TonConnectUIProvider, useTonConnectUI, useTonWallet, useTonConnectModal
|
|
|
6
6
|
export type { TonConnectUIProviderProps, TonConnectUI, WalletState, Account, TransactionResponse, SignDataRequest, SignDataResponse, } from './TonConnectUIProvider';
|
|
7
7
|
export { TonConnectButton } from './TonConnectButton';
|
|
8
8
|
export type { TonConnectButtonProps } from './TonConnectButton';
|
|
9
|
+
export { WalletSelectionModal } from './WalletSelectionModal';
|
|
10
|
+
export type { WalletSelectionModalProps } from './WalletSelectionModal';
|
package/dist/react/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Re-export all React components and hooks
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.TonConnectButton = exports.useTonConnectSDK = exports.useTonConnectModal = exports.useTonWallet = exports.useTonConnectUI = exports.TonConnectUIProvider = void 0;
|
|
7
|
+
exports.WalletSelectionModal = exports.TonConnectButton = exports.useTonConnectSDK = exports.useTonConnectModal = exports.useTonWallet = exports.useTonConnectUI = exports.TonConnectUIProvider = void 0;
|
|
8
8
|
var TonConnectUIProvider_1 = require("./TonConnectUIProvider");
|
|
9
9
|
Object.defineProperty(exports, "TonConnectUIProvider", { enumerable: true, get: function () { return TonConnectUIProvider_1.TonConnectUIProvider; } });
|
|
10
10
|
Object.defineProperty(exports, "useTonConnectUI", { enumerable: true, get: function () { return TonConnectUIProvider_1.useTonConnectUI; } });
|
|
@@ -13,3 +13,5 @@ Object.defineProperty(exports, "useTonConnectModal", { enumerable: true, get: fu
|
|
|
13
13
|
Object.defineProperty(exports, "useTonConnectSDK", { enumerable: true, get: function () { return TonConnectUIProvider_1.useTonConnectSDK; } });
|
|
14
14
|
var TonConnectButton_1 = require("./TonConnectButton");
|
|
15
15
|
Object.defineProperty(exports, "TonConnectButton", { enumerable: true, get: function () { return TonConnectButton_1.TonConnectButton; } });
|
|
16
|
+
var WalletSelectionModal_1 = require("./WalletSelectionModal");
|
|
17
|
+
Object.defineProperty(exports, "WalletSelectionModal", { enumerable: true, get: function () { return WalletSelectionModal_1.WalletSelectionModal; } });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry Utilities
|
|
3
|
+
* Helper functions for retrying operations with exponential backoff
|
|
4
|
+
*/
|
|
5
|
+
export interface RetryOptions {
|
|
6
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
7
|
+
maxAttempts?: number;
|
|
8
|
+
/** Initial delay in milliseconds (default: 1000) */
|
|
9
|
+
initialDelay?: number;
|
|
10
|
+
/** Maximum delay in milliseconds (default: 10000) */
|
|
11
|
+
maxDelay?: number;
|
|
12
|
+
/** Multiplier for exponential backoff (default: 2) */
|
|
13
|
+
multiplier?: number;
|
|
14
|
+
/** Function to determine if error should be retried (default: retry all errors) */
|
|
15
|
+
shouldRetry?: (error: Error) => boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retry a function with exponential backoff
|
|
19
|
+
* @param fn - Function to retry
|
|
20
|
+
* @param options - Retry options
|
|
21
|
+
* @returns Promise that resolves with the function result
|
|
22
|
+
*/
|
|
23
|
+
export declare function retry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Retry with custom delay function
|
|
26
|
+
* @param fn - Function to retry
|
|
27
|
+
* @param getDelay - Function that returns delay for each attempt (attempt number, last error)
|
|
28
|
+
* @param maxAttempts - Maximum number of attempts
|
|
29
|
+
* @returns Promise that resolves with the function result
|
|
30
|
+
*/
|
|
31
|
+
export declare function retryWithCustomDelay<T>(fn: () => Promise<T>, getDelay: (attempt: number, error: Error | null) => number, maxAttempts?: number): Promise<T>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Retry Utilities
|
|
4
|
+
* Helper functions for retrying operations with exponential backoff
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.retry = retry;
|
|
8
|
+
exports.retryWithCustomDelay = retryWithCustomDelay;
|
|
9
|
+
/**
|
|
10
|
+
* Retry a function with exponential backoff
|
|
11
|
+
* @param fn - Function to retry
|
|
12
|
+
* @param options - Retry options
|
|
13
|
+
* @returns Promise that resolves with the function result
|
|
14
|
+
*/
|
|
15
|
+
async function retry(fn, options = {}) {
|
|
16
|
+
const { maxAttempts = 3, initialDelay = 1000, maxDelay = 10000, multiplier = 2, shouldRetry = () => true, } = options;
|
|
17
|
+
let lastError = null;
|
|
18
|
+
let delay = initialDelay;
|
|
19
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
20
|
+
try {
|
|
21
|
+
return await fn();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
25
|
+
// Don't retry if shouldRetry returns false
|
|
26
|
+
if (!shouldRetry(lastError)) {
|
|
27
|
+
throw lastError;
|
|
28
|
+
}
|
|
29
|
+
// Don't retry on last attempt
|
|
30
|
+
if (attempt === maxAttempts) {
|
|
31
|
+
throw lastError;
|
|
32
|
+
}
|
|
33
|
+
// Wait before retrying
|
|
34
|
+
await new Promise((resolve) => setTimeout(() => resolve(), delay));
|
|
35
|
+
// Increase delay for next attempt (exponential backoff)
|
|
36
|
+
delay = Math.min(delay * multiplier, maxDelay);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// This should never be reached, but TypeScript needs it
|
|
40
|
+
throw lastError || new Error('Retry failed');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retry with custom delay function
|
|
44
|
+
* @param fn - Function to retry
|
|
45
|
+
* @param getDelay - Function that returns delay for each attempt (attempt number, last error)
|
|
46
|
+
* @param maxAttempts - Maximum number of attempts
|
|
47
|
+
* @returns Promise that resolves with the function result
|
|
48
|
+
*/
|
|
49
|
+
async function retryWithCustomDelay(fn, getDelay, maxAttempts = 3) {
|
|
50
|
+
let lastError = null;
|
|
51
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
52
|
+
try {
|
|
53
|
+
return await fn();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
57
|
+
// Don't retry on last attempt
|
|
58
|
+
if (attempt === maxAttempts) {
|
|
59
|
+
throw lastError;
|
|
60
|
+
}
|
|
61
|
+
// Wait before retrying
|
|
62
|
+
const delay = getDelay(attempt, lastError);
|
|
63
|
+
await new Promise((resolve) => setTimeout(() => resolve(), delay));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw lastError || new Error('Retry failed');
|
|
67
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction Builder Utilities
|
|
3
|
+
* Helper functions for building TON Connect transaction requests
|
|
4
|
+
*/
|
|
5
|
+
import type { SendTransactionRequest } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Convert TON amount to nanotons
|
|
8
|
+
* @param tonAmount - Amount in TON (e.g., 1.5 for 1.5 TON)
|
|
9
|
+
* @returns Amount in nanotons as string
|
|
10
|
+
*/
|
|
11
|
+
export declare function tonToNano(tonAmount: number | string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Convert nanotons to TON
|
|
14
|
+
* @param nanotons - Amount in nanotons as string
|
|
15
|
+
* @returns Amount in TON as number
|
|
16
|
+
*/
|
|
17
|
+
export declare function nanoToTon(nanotons: string): number;
|
|
18
|
+
/**
|
|
19
|
+
* Build a simple TON transfer transaction
|
|
20
|
+
* @param to - Recipient address (EQ... format)
|
|
21
|
+
* @param amount - Amount in TON (will be converted to nanotons)
|
|
22
|
+
* @param validUntil - Optional expiration timestamp (default: 5 minutes from now)
|
|
23
|
+
* @returns Transaction request
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildTransferTransaction(to: string, amount: number | string, validUntil?: number): SendTransactionRequest;
|
|
26
|
+
/**
|
|
27
|
+
* Build a transaction with multiple recipients
|
|
28
|
+
* @param transfers - Array of {to, amount} transfers
|
|
29
|
+
* @param validUntil - Optional expiration timestamp (default: 5 minutes from now)
|
|
30
|
+
* @returns Transaction request
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildMultiTransferTransaction(transfers: Array<{
|
|
33
|
+
to: string;
|
|
34
|
+
amount: number | string;
|
|
35
|
+
}>, validUntil?: number): SendTransactionRequest;
|
|
36
|
+
/**
|
|
37
|
+
* Build a transaction with custom payload
|
|
38
|
+
* @param to - Recipient address
|
|
39
|
+
* @param amount - Amount in TON
|
|
40
|
+
* @param payload - Base64 encoded payload
|
|
41
|
+
* @param validUntil - Optional expiration timestamp
|
|
42
|
+
* @returns Transaction request
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildTransactionWithPayload(to: string, amount: number | string, payload: string, validUntil?: number): SendTransactionRequest;
|
|
45
|
+
/**
|
|
46
|
+
* Build a transaction with state init (for contract deployment)
|
|
47
|
+
* @param to - Recipient address
|
|
48
|
+
* @param amount - Amount in TON
|
|
49
|
+
* @param stateInit - Base64 encoded state init
|
|
50
|
+
* @param validUntil - Optional expiration timestamp
|
|
51
|
+
* @returns Transaction request
|
|
52
|
+
*/
|
|
53
|
+
export declare function buildTransactionWithStateInit(to: string, amount: number | string, stateInit: string, validUntil?: number): SendTransactionRequest;
|
|
54
|
+
/**
|
|
55
|
+
* Validate TON address format
|
|
56
|
+
* @param address - Address to validate
|
|
57
|
+
* @returns true if address is valid
|
|
58
|
+
*/
|
|
59
|
+
export declare function isValidTonAddress(address: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Format TON address for display (with ellipsis)
|
|
62
|
+
* @param address - Full address
|
|
63
|
+
* @param startLength - Characters to show at start (default: 6)
|
|
64
|
+
* @param endLength - Characters to show at end (default: 4)
|
|
65
|
+
* @returns Formatted address
|
|
66
|
+
*/
|
|
67
|
+
export declare function formatTonAddress(address: string, startLength?: number, endLength?: number): string;
|