@hardkas/react 0.7.12-alpha → 0.8.0-alpha

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 CHANGED
@@ -1,13 +1,68 @@
1
1
  # @hardkas/react
2
2
 
3
- React hooks and provider context for integrating with the HardKAS deterministic local developer runtime.
3
+ Zero-dependency React hooks for HardKAS.
4
4
 
5
- ## ⚠️ Alpha-Only Local-Runtime Coupling Warning
5
+ > [!WARNING]
6
+ > **DO NOT import `@hardkas/sdk` in the browser!**
7
+ > The main SDK package contains Node.js specific libraries. Use `@hardkas/react` for your web UI.
6
8
 
7
- Please note that in the `v0.5.4-alpha` release, this package has direct dependencies on the **`@hardkas/bridge-local`** package to facilitate local bridge payload planning and prefix-mining simulations directly within hooks like `useBridgeLocalPlan` and `useBridgeLocalSimulation`.
9
+ ## Installation
8
10
 
9
- ### 🛡️ Production & Browser Safety
11
+ ```bash
12
+ npm install @hardkas/react @hardkas/client
13
+ ```
10
14
 
11
- - **Local Developer Context Only**: The current coupling is designed strictly for local developer preview, ZK/bridge research, and sandbox cockpit operations.
12
- - **Not Safe for Production Web Browsers**: Do not use the bridge simulation hooks in a public-facing production environment, as they contain node/local-first filesystem assumptions and heavy CPU simulation logic.
13
- - **Future Separation Roadmap**: We plan to decouple this local simulation code from `@hardkas/react` into a dedicated local testing library (`@hardkas/react-local`) in a post-alpha release.
15
+ ## Setup Provider
16
+
17
+ Wrap your application in the `HardKASProvider`. This initializes the underlying `@hardkas/client` instance.
18
+
19
+ ```tsx
20
+ import { HardKASProvider } from '@hardkas/react';
21
+
22
+ function App() {
23
+ return (
24
+ <HardKASProvider baseUrl="http://127.0.0.1:7420" timeout={10000}>
25
+ <MyDApp />
26
+ </HardKASProvider>
27
+ );
28
+ }
29
+ ```
30
+
31
+ ## Hooks
32
+
33
+ ### `useWallet`
34
+
35
+ Fetch wallet details.
36
+
37
+ ```tsx
38
+ import { useWallet } from '@hardkas/react';
39
+
40
+ function WalletView() {
41
+ const { data, loading, error } = useWallet('alice');
42
+
43
+ if (loading) return <p>Loading...</p>;
44
+ if (error) return <p>Error: {error.message}</p>;
45
+
46
+ return <pre>{JSON.stringify(data, null, 2)}</pre>;
47
+ }
48
+ ```
49
+
50
+ ### `useMutation`
51
+
52
+ Generic hook for executing state-changing transactions against the Dev API.
53
+
54
+ ```tsx
55
+ import { useMutation } from '@hardkas/react';
56
+
57
+ function SendKas() {
58
+ const { execute, loading } = useMutation((client, vars: { to: string, amount: number }) => {
59
+ return client.txSimulate({ ...vars });
60
+ });
61
+
62
+ return (
63
+ <button onClick={() => execute({ to: 'bob', amount: 100 })} disabled={loading}>
64
+ {loading ? 'Sending...' : 'Send to Bob'}
65
+ </button>
66
+ );
67
+ }
68
+ ```