@c7-digital/react 0.0.3 → 0.0.4
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 +22 -36
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @c7
|
|
1
|
+
# @c7/react
|
|
2
2
|
|
|
3
3
|
React hooks for Daml ledger integration using Canton JSON API v2
|
|
4
4
|
|
|
@@ -12,11 +12,11 @@ React hooks for Daml ledger integration using Canton JSON API v2
|
|
|
12
12
|
|
|
13
13
|
## Versioning
|
|
14
14
|
|
|
15
|
-
This package follows the Canton SDK versioning scheme, matching the `@c7
|
|
15
|
+
This package follows the Canton SDK versioning scheme, matching the `@c7/ledger` package it depends on.
|
|
16
16
|
|
|
17
17
|
**Current version**: `3.3.0-snapshot.20250507.0`
|
|
18
18
|
|
|
19
|
-
- Versioned to match the Canton SDK and `@c7
|
|
19
|
+
- Versioned to match the Canton SDK and `@c7/ledger` package
|
|
20
20
|
- Ensures compatibility with the specific Canton OpenAPI types
|
|
21
21
|
- When Canton releases a new version, both packages will be updated together
|
|
22
22
|
|
|
@@ -25,7 +25,7 @@ This package follows the Canton SDK versioning scheme, matching the `@c7-digital
|
|
|
25
25
|
## Installation
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
pnpm install @c7
|
|
28
|
+
pnpm install @c7/react @c7/ledger
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
## Build Output
|
|
@@ -43,8 +43,8 @@ The library builds to the `dist/` folder with:
|
|
|
43
43
|
Wrap your app with `DamlLedger` provider:
|
|
44
44
|
|
|
45
45
|
```tsx
|
|
46
|
-
import { DamlLedger } from "@c7
|
|
47
|
-
import { Ledger } from "@c7
|
|
46
|
+
import { DamlLedger } from "@c7/react";
|
|
47
|
+
import { Ledger } from "@c7/ledger";
|
|
48
48
|
|
|
49
49
|
const ledger = new Ledger({
|
|
50
50
|
baseUrl: "http://localhost:7575",
|
|
@@ -66,7 +66,7 @@ function App() {
|
|
|
66
66
|
Use `useQuery` to fetch active contracts:
|
|
67
67
|
|
|
68
68
|
```tsx
|
|
69
|
-
import { useQuery } from "@c7
|
|
69
|
+
import { useQuery } from "@c7/react";
|
|
70
70
|
|
|
71
71
|
function MyComponent() {
|
|
72
72
|
const { contracts, loading, error, reload } = useQuery(
|
|
@@ -77,9 +77,7 @@ function MyComponent() {
|
|
|
77
77
|
if (error) return <div>Error: {error.message}</div>;
|
|
78
78
|
|
|
79
79
|
// Filter contracts at the application level
|
|
80
|
-
const exampleContracts = contracts.filter(
|
|
81
|
-
(contract) => contract.domain === "example.com"
|
|
82
|
-
);
|
|
80
|
+
const exampleContracts = contracts.filter(contract => contract.domain === "example.com");
|
|
83
81
|
|
|
84
82
|
return (
|
|
85
83
|
<div>
|
|
@@ -98,7 +96,7 @@ function MyComponent() {
|
|
|
98
96
|
Use `useLedger` to get the ledger instance and `useUser` for the current user information:
|
|
99
97
|
|
|
100
98
|
```tsx
|
|
101
|
-
import { useLedger, useUser } from "@c7
|
|
99
|
+
import { useLedger, useUser } from "@c7/react";
|
|
102
100
|
|
|
103
101
|
function ApprovalComponent({ contractId }: { contractId: string }) {
|
|
104
102
|
const ledger = useLedger();
|
|
@@ -107,8 +105,7 @@ function ApprovalComponent({ contractId }: { contractId: string }) {
|
|
|
107
105
|
const handleApprove = async () => {
|
|
108
106
|
try {
|
|
109
107
|
await ledger.exercise({
|
|
110
|
-
templateId:
|
|
111
|
-
"#domain-verification-model:InternetDomainName:VerificationRequest",
|
|
108
|
+
templateId: "#domain-verification-model:InternetDomainName:VerificationRequest",
|
|
112
109
|
contractId,
|
|
113
110
|
choice: "AcceptRequest",
|
|
114
111
|
choiceArgument: {
|
|
@@ -123,9 +120,7 @@ function ApprovalComponent({ contractId }: { contractId: string }) {
|
|
|
123
120
|
if (loading) return <div>Loading user...</div>;
|
|
124
121
|
if (error) return <div>Error: {error.message}</div>;
|
|
125
122
|
|
|
126
|
-
return (
|
|
127
|
-
<button onClick={handleApprove}>Approve Request (as {user?.userId})</button>
|
|
128
|
-
);
|
|
123
|
+
return <button onClick={handleApprove}>Approve Request (as {user?.userId})</button>;
|
|
129
124
|
}
|
|
130
125
|
```
|
|
131
126
|
|
|
@@ -134,7 +129,7 @@ function ApprovalComponent({ contractId }: { contractId: string }) {
|
|
|
134
129
|
Use `useStreamQuery` for live updates:
|
|
135
130
|
|
|
136
131
|
```tsx
|
|
137
|
-
import { useStreamQuery } from "@c7
|
|
132
|
+
import { useStreamQuery } from "@c7/react";
|
|
138
133
|
|
|
139
134
|
function LiveContracts() {
|
|
140
135
|
const { contracts, loading, connected, error } = useStreamQuery(
|
|
@@ -176,10 +171,7 @@ interface DamlLedgerProps {
|
|
|
176
171
|
Query active contracts for a template.
|
|
177
172
|
|
|
178
173
|
```tsx
|
|
179
|
-
function useQuery<T>(
|
|
180
|
-
templateId: string,
|
|
181
|
-
options?: QueryOptions
|
|
182
|
-
): QueryResult<T>;
|
|
174
|
+
function useQuery<T>(templateId: string, options?: QueryOptions): QueryResult<T>;
|
|
183
175
|
|
|
184
176
|
interface QueryOptions {
|
|
185
177
|
autoReload?: boolean;
|
|
@@ -220,10 +212,7 @@ interface UserResult {
|
|
|
220
212
|
Stream active contracts with real-time updates.
|
|
221
213
|
|
|
222
214
|
```tsx
|
|
223
|
-
function useStreamQuery<T>(
|
|
224
|
-
templateId: string,
|
|
225
|
-
options?: QueryOptions
|
|
226
|
-
): StreamQueryResult<T>;
|
|
215
|
+
function useStreamQuery<T>(templateId: string, options?: QueryOptions): StreamQueryResult<T>;
|
|
227
216
|
|
|
228
217
|
interface StreamQueryResult<T> extends QueryResult<T> {
|
|
229
218
|
connected: boolean;
|
|
@@ -235,10 +224,7 @@ interface StreamQueryResult<T> extends QueryResult<T> {
|
|
|
235
224
|
Stream multiple templates simultaneously.
|
|
236
225
|
|
|
237
226
|
```tsx
|
|
238
|
-
function useStreamQueries<T>(
|
|
239
|
-
templateIds: string[],
|
|
240
|
-
options?: QueryOptions
|
|
241
|
-
): StreamQueryResult<T>;
|
|
227
|
+
function useStreamQueries<T>(templateIds: string[], options?: QueryOptions): StreamQueryResult<T>;
|
|
242
228
|
```
|
|
243
229
|
|
|
244
230
|
#### `useReload()`
|
|
@@ -253,13 +239,13 @@ function useReload(): () => void;
|
|
|
253
239
|
|
|
254
240
|
This package provides a compatible API with `@daml/react` but uses the newer Canton JSON API v2:
|
|
255
241
|
|
|
256
|
-
| @daml/react | @c7
|
|
257
|
-
| ------------------ |
|
|
258
|
-
| `DamlLedger` | `DamlLedger`
|
|
259
|
-
| `useParty()` | `useParty()`
|
|
260
|
-
| `useLedger()` | `useLedger()`
|
|
261
|
-
| `useQuery()` | `useQuery()`
|
|
262
|
-
| `useStreamQuery()` | `useStreamQuery()`
|
|
242
|
+
| @daml/react | @c7/react | Notes |
|
|
243
|
+
| ------------------ | -------------------- | ------------------------------ |
|
|
244
|
+
| `DamlLedger` | `DamlLedger` | Same API, different backend |
|
|
245
|
+
| `useParty()` | `useParty()` | Identical |
|
|
246
|
+
| `useLedger()` | `useLedger()` | Enhanced with typed operations |
|
|
247
|
+
| `useQuery()` | `useQuery()` | Improved filtering and caching |
|
|
248
|
+
| `useStreamQuery()` | `useStreamQuery()` | Real-time WebSocket updates |
|
|
263
249
|
|
|
264
250
|
## License
|
|
265
251
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c7-digital/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "React hooks for Daml ledger integration using Canton JSON API v2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"author": "",
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@c7
|
|
28
|
+
"@c7/ledger": "^0.0.4",
|
|
29
29
|
"react": "^18.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|