@hardkas/react 0.7.13-alpha → 0.8.1-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 +62 -7
- package/dist/index.d.ts +23 -4902
- package/dist/index.js +80 -1536
- package/package.json +2 -7
package/README.md
CHANGED
|
@@ -1,13 +1,68 @@
|
|
|
1
1
|
# @hardkas/react
|
|
2
2
|
|
|
3
|
-
React hooks
|
|
3
|
+
Zero-dependency React hooks for HardKAS.
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
9
|
+
## Installation
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
```bash
|
|
12
|
+
npm install @hardkas/react @hardkas/client
|
|
13
|
+
```
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
```
|