@movebridge/react 0.0.1

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/LICENSE ADDED
File without changes
@@ -0,0 +1,446 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { ReactNode } from 'react';
4
+ import { NetworkType, MovementError, Movement, WalletType, ContractInterface, BuildOptions, TransactionResponse } from '@movebridge/core';
5
+ export { ContractEvent, MovementError, NetworkType, TransactionResponse, WalletType } from '@movebridge/core';
6
+
7
+ /**
8
+ * Movement context value
9
+ */
10
+ interface MovementContextValue {
11
+ /** Movement SDK instance */
12
+ movement: Movement | null;
13
+ /** Current network */
14
+ network: NetworkType;
15
+ /** Wallet state */
16
+ address: string | null;
17
+ connected: boolean;
18
+ connecting: boolean;
19
+ /** Available wallets */
20
+ wallets: WalletType[];
21
+ /** Currently connected wallet */
22
+ wallet: WalletType | null;
23
+ /** Connect to a wallet */
24
+ connect: (wallet: WalletType) => Promise<void>;
25
+ /** Disconnect from wallet */
26
+ disconnect: () => Promise<void>;
27
+ /** Error handler */
28
+ onError?: (error: MovementError) => void;
29
+ }
30
+ /**
31
+ * Movement context
32
+ */
33
+ declare const MovementContext: react.Context<MovementContextValue | null>;
34
+ /**
35
+ * Provider props
36
+ */
37
+ interface MovementProviderProps {
38
+ /** Network to connect to */
39
+ network: NetworkType;
40
+ /** Auto-connect to previously connected wallet */
41
+ autoConnect?: boolean;
42
+ /** Error callback */
43
+ onError?: (error: MovementError) => void;
44
+ /** Children */
45
+ children: ReactNode;
46
+ }
47
+ /**
48
+ * Movement Provider
49
+ * Provides Movement SDK context to child components
50
+ *
51
+ * @example
52
+ * ```tsx
53
+ * import { MovementProvider } from '@movebridge/react';
54
+ *
55
+ * function App() {
56
+ * return (
57
+ * <MovementProvider network="testnet" autoConnect>
58
+ * <YourApp />
59
+ * </MovementProvider>
60
+ * );
61
+ * }
62
+ * ```
63
+ */
64
+ declare function MovementProvider({ network, autoConnect, onError, children, }: MovementProviderProps): react_jsx_runtime.JSX.Element;
65
+ /**
66
+ * Hook to access Movement context
67
+ * @throws Error if used outside MovementProvider
68
+ */
69
+ declare function useMovementContext(): MovementContextValue;
70
+
71
+ /**
72
+ * @movebridge/react - useMovement hook
73
+ * Hook for wallet connection state
74
+ */
75
+
76
+ /**
77
+ * Return type for useMovement hook
78
+ */
79
+ interface UseMovementReturn {
80
+ /** Movement SDK instance */
81
+ movement: Movement | null;
82
+ /** Current network */
83
+ network: NetworkType;
84
+ /** Connected wallet address */
85
+ address: string | null;
86
+ /** Whether a wallet is connected */
87
+ connected: boolean;
88
+ /** Whether a connection is in progress */
89
+ connecting: boolean;
90
+ /** Connect to a wallet */
91
+ connect: (wallet: WalletType) => Promise<void>;
92
+ /** Disconnect from wallet */
93
+ disconnect: () => Promise<void>;
94
+ /** Available wallets */
95
+ wallets: WalletType[];
96
+ /** Currently connected wallet */
97
+ wallet: WalletType | null;
98
+ }
99
+ /**
100
+ * Hook for wallet connection state
101
+ *
102
+ * @example
103
+ * ```tsx
104
+ * function WalletButton() {
105
+ * const { address, connected, connect, disconnect, wallets } = useMovement();
106
+ *
107
+ * if (connected) {
108
+ * return (
109
+ * <button onClick={disconnect}>
110
+ * {address?.slice(0, 6)}...{address?.slice(-4)}
111
+ * </button>
112
+ * );
113
+ * }
114
+ *
115
+ * return (
116
+ * <button onClick={() => connect(wallets[0])}>
117
+ * Connect Wallet
118
+ * </button>
119
+ * );
120
+ * }
121
+ * ```
122
+ */
123
+ declare function useMovement(): UseMovementReturn;
124
+
125
+ /**
126
+ * @movebridge/react - useBalance hook
127
+ * Hook for fetching account balance
128
+ */
129
+
130
+ /**
131
+ * Return type for useBalance hook
132
+ */
133
+ interface UseBalanceReturn {
134
+ /** Account balance in smallest unit */
135
+ balance: string | null;
136
+ /** Whether balance is loading */
137
+ loading: boolean;
138
+ /** Error if fetch failed */
139
+ error: MovementError | null;
140
+ /** Refetch balance */
141
+ refetch: () => Promise<void>;
142
+ }
143
+ /**
144
+ * Hook for fetching account balance
145
+ *
146
+ * @param address - Account address to fetch balance for (defaults to connected address)
147
+ *
148
+ * @example
149
+ * ```tsx
150
+ * function BalanceDisplay() {
151
+ * const { address } = useMovement();
152
+ * const { balance, loading, error, refetch } = useBalance(address);
153
+ *
154
+ * if (loading) return <div>Loading...</div>;
155
+ * if (error) return <div>Error: {error.message}</div>;
156
+ *
157
+ * return (
158
+ * <div>
159
+ * Balance: {balance} octas
160
+ * <button onClick={refetch}>Refresh</button>
161
+ * </div>
162
+ * );
163
+ * }
164
+ * ```
165
+ */
166
+ declare function useBalance(address?: string | null): UseBalanceReturn;
167
+
168
+ /**
169
+ * @movebridge/react - useContract hook
170
+ * Hook for contract interactions
171
+ */
172
+
173
+ /**
174
+ * Return type for useContract hook
175
+ */
176
+ interface UseContractReturn<T = unknown> {
177
+ /** Last operation result */
178
+ data: T | null;
179
+ /** Whether an operation is in progress */
180
+ loading: boolean;
181
+ /** Error if operation failed */
182
+ error: MovementError | null;
183
+ /** Call a view function */
184
+ read: <R = unknown>(functionName: string, args: unknown[], typeArgs?: string[]) => Promise<R>;
185
+ /** Call an entry function */
186
+ write: (functionName: string, args: unknown[], typeArgs?: string[]) => Promise<string>;
187
+ /** Contract interface instance */
188
+ contract: ContractInterface | null;
189
+ }
190
+ /**
191
+ * Options for useContract hook
192
+ */
193
+ interface UseContractOptions {
194
+ /** Contract address */
195
+ address: string;
196
+ /** Module name */
197
+ module: string;
198
+ }
199
+ /**
200
+ * Hook for contract interactions
201
+ *
202
+ * @param options - Contract options
203
+ *
204
+ * @example
205
+ * ```tsx
206
+ * function Counter() {
207
+ * const { data, loading, error, read, write } = useContract({
208
+ * address: '0x123',
209
+ * module: 'counter',
210
+ * });
211
+ *
212
+ * const fetchCount = async () => {
213
+ * const count = await read('get_count', []);
214
+ * console.log('Count:', count);
215
+ * };
216
+ *
217
+ * const increment = async () => {
218
+ * const txHash = await write('increment', []);
219
+ * console.log('Transaction:', txHash);
220
+ * };
221
+ *
222
+ * return (
223
+ * <div>
224
+ * <p>Count: {data}</p>
225
+ * <button onClick={fetchCount}>Fetch</button>
226
+ * <button onClick={increment}>Increment</button>
227
+ * </div>
228
+ * );
229
+ * }
230
+ * ```
231
+ */
232
+ declare function useContract<T = unknown>(options: UseContractOptions): UseContractReturn<T>;
233
+
234
+ /**
235
+ * @movebridge/react - useTransaction hook
236
+ * Hook for transaction submission
237
+ */
238
+
239
+ /**
240
+ * Return type for useTransaction hook
241
+ */
242
+ interface UseTransactionReturn {
243
+ /** Send a transaction */
244
+ send: (options: BuildOptions) => Promise<string>;
245
+ /** Last transaction hash */
246
+ data: string | null;
247
+ /** Whether transaction is in progress */
248
+ loading: boolean;
249
+ /** Error if transaction failed */
250
+ error: MovementError | null;
251
+ /** Reset state */
252
+ reset: () => void;
253
+ }
254
+ /**
255
+ * Hook for transaction submission
256
+ *
257
+ * @example
258
+ * ```tsx
259
+ * function TransferForm() {
260
+ * const { send, data, loading, error, reset } = useTransaction();
261
+ *
262
+ * const handleTransfer = async () => {
263
+ * try {
264
+ * const hash = await send({
265
+ * function: '0x1::coin::transfer',
266
+ * typeArguments: ['0x1::aptos_coin::AptosCoin'],
267
+ * arguments: ['0x123...', '1000000'],
268
+ * });
269
+ * console.log('Transaction hash:', hash);
270
+ * } catch (err) {
271
+ * console.error('Transaction failed:', err);
272
+ * }
273
+ * };
274
+ *
275
+ * return (
276
+ * <div>
277
+ * <button onClick={handleTransfer} disabled={loading}>
278
+ * {loading ? 'Sending...' : 'Send'}
279
+ * </button>
280
+ * {data && <p>Transaction: {data}</p>}
281
+ * {error && <p>Error: {error.message}</p>}
282
+ * <button onClick={reset}>Reset</button>
283
+ * </div>
284
+ * );
285
+ * }
286
+ * ```
287
+ */
288
+ declare function useTransaction(): UseTransactionReturn;
289
+
290
+ /**
291
+ * @movebridge/react - useWaitForTransaction hook
292
+ * Hook for waiting for transaction confirmation
293
+ */
294
+
295
+ /**
296
+ * Return type for useWaitForTransaction hook
297
+ */
298
+ interface UseWaitForTransactionReturn {
299
+ /** Transaction response */
300
+ data: TransactionResponse | null;
301
+ /** Whether waiting for confirmation */
302
+ loading: boolean;
303
+ /** Error if confirmation failed */
304
+ error: MovementError | null;
305
+ }
306
+ /**
307
+ * Options for useWaitForTransaction hook
308
+ */
309
+ interface UseWaitForTransactionOptions {
310
+ /** Timeout in milliseconds */
311
+ timeoutMs?: number;
312
+ /** Check interval in milliseconds */
313
+ checkIntervalMs?: number;
314
+ }
315
+ /**
316
+ * Hook for waiting for transaction confirmation
317
+ *
318
+ * @param hash - Transaction hash to wait for
319
+ * @param options - Wait options
320
+ *
321
+ * @example
322
+ * ```tsx
323
+ * function TransactionStatus({ hash }: { hash: string }) {
324
+ * const { data, loading, error } = useWaitForTransaction(hash);
325
+ *
326
+ * if (loading) return <div>Waiting for confirmation...</div>;
327
+ * if (error) return <div>Error: {error.message}</div>;
328
+ * if (!data) return null;
329
+ *
330
+ * return (
331
+ * <div>
332
+ * <p>Status: {data.success ? 'Success' : 'Failed'}</p>
333
+ * <p>Gas used: {data.gasUsed}</p>
334
+ * </div>
335
+ * );
336
+ * }
337
+ * ```
338
+ */
339
+ declare function useWaitForTransaction(hash: string | null | undefined, options?: UseWaitForTransactionOptions): UseWaitForTransactionReturn;
340
+
341
+ /**
342
+ * @movebridge/react - WalletButton component
343
+ * Drop-in wallet connect button
344
+ */
345
+ /**
346
+ * Props for WalletButton component
347
+ */
348
+ interface WalletButtonProps {
349
+ /** Additional CSS class */
350
+ className?: string;
351
+ /** Text to show when disconnected */
352
+ connectText?: string;
353
+ }
354
+ /**
355
+ * WalletButton component
356
+ * Shows connect button when disconnected, address when connected
357
+ *
358
+ * @example
359
+ * ```tsx
360
+ * <WalletButton />
361
+ * <WalletButton connectText="Connect" className="my-button" />
362
+ * ```
363
+ */
364
+ declare function WalletButton({ className, connectText }: WalletButtonProps): react_jsx_runtime.JSX.Element;
365
+
366
+ /**
367
+ * @movebridge/react - WalletModal component
368
+ * Modal for wallet selection
369
+ */
370
+ /**
371
+ * Props for WalletModal component
372
+ */
373
+ interface WalletModalProps {
374
+ /** Whether modal is open */
375
+ open: boolean;
376
+ /** Callback when modal should close */
377
+ onClose: () => void;
378
+ }
379
+ /**
380
+ * WalletModal component
381
+ * Displays available wallets for selection
382
+ *
383
+ * @example
384
+ * ```tsx
385
+ * const [open, setOpen] = useState(false);
386
+ *
387
+ * <button onClick={() => setOpen(true)}>Connect</button>
388
+ * <WalletModal open={open} onClose={() => setOpen(false)} />
389
+ * ```
390
+ */
391
+ declare function WalletModal({ open, onClose }: WalletModalProps): react_jsx_runtime.JSX.Element | null;
392
+
393
+ /**
394
+ * @movebridge/react - AddressDisplay component
395
+ * Displays an address with truncation and copy functionality
396
+ */
397
+ /**
398
+ * Props for AddressDisplay component
399
+ */
400
+ interface AddressDisplayProps {
401
+ /** Address to display */
402
+ address: string;
403
+ /** Whether to truncate the address */
404
+ truncate?: boolean;
405
+ /** Whether to show copy button */
406
+ copyable?: boolean;
407
+ /** Additional CSS class */
408
+ className?: string;
409
+ }
410
+ /**
411
+ * AddressDisplay component
412
+ * Shows an address with optional truncation and copy-to-clipboard
413
+ *
414
+ * @example
415
+ * ```tsx
416
+ * <AddressDisplay address="0x123..." />
417
+ * <AddressDisplay address="0x123..." truncate copyable />
418
+ * ```
419
+ */
420
+ declare function AddressDisplay({ address, truncate, copyable, className, }: AddressDisplayProps): react_jsx_runtime.JSX.Element;
421
+
422
+ /**
423
+ * Props for NetworkSwitcher component
424
+ */
425
+ interface NetworkSwitcherProps {
426
+ /** Additional CSS class */
427
+ className?: string;
428
+ /** Callback when network change is requested */
429
+ onNetworkChange?: (network: NetworkType) => void;
430
+ }
431
+ /**
432
+ * NetworkSwitcher component
433
+ * Displays current network with option to switch
434
+ *
435
+ * Note: Switching networks requires re-initializing the provider.
436
+ * This component shows the current network and can trigger a callback
437
+ * for the parent to handle network switching.
438
+ *
439
+ * @example
440
+ * ```tsx
441
+ * <NetworkSwitcher onNetworkChange={(network) => setNetwork(network)} />
442
+ * ```
443
+ */
444
+ declare function NetworkSwitcher({ className, onNetworkChange }: NetworkSwitcherProps): react_jsx_runtime.JSX.Element;
445
+
446
+ export { AddressDisplay, type AddressDisplayProps, MovementContext, type MovementContextValue, MovementProvider, type MovementProviderProps, NetworkSwitcher, type NetworkSwitcherProps, type UseBalanceReturn, type UseContractOptions, type UseContractReturn, type UseMovementReturn, type UseTransactionReturn, type UseWaitForTransactionOptions, type UseWaitForTransactionReturn, WalletButton, type WalletButtonProps, WalletModal, type WalletModalProps, useBalance, useContract, useMovement, useMovementContext, useTransaction, useWaitForTransaction };