@trustless-work/blocks 0.0.6 → 0.0.7
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 +39 -13
- package/bin/index.js +1128 -1137
- package/package.json +44 -44
- package/templates/escrows/details/EscrowDetailDialog.tsx +3 -3
- package/templates/escrows/details/GeneralInformation.tsx +2 -2
- package/templates/escrows/details/SuccessReleaseDialog.tsx +2 -3
- package/templates/escrows/details/useDetailsEscrow.ts +2 -2
- package/templates/escrows/escrows-by-role/cards/EscrowsCards.tsx +32 -16
- package/templates/escrows/escrows-by-role/table/EscrowsTable.tsx +34 -18
- package/templates/escrows/escrows-by-role/useEscrowsByRole.shared.ts +33 -25
- package/templates/escrows/escrows-by-signer/cards/EscrowsCards.tsx +22 -16
- package/templates/escrows/escrows-by-signer/table/EscrowsTable.tsx +23 -17
- package/templates/escrows/escrows-by-signer/useEscrowsBySigner.shared.ts +32 -25
- package/templates/escrows/single-release/approve-milestone/button/ApproveMilestone.tsx +1 -1
- package/templates/escrows/single-release/approve-milestone/dialog/ApproveMilestone.tsx +1 -1
- package/templates/escrows/single-release/approve-milestone/form/ApproveMilestone.tsx +1 -1
- package/templates/escrows/single-release/approve-milestone/shared/useApproveMilestone.ts +1 -1
- package/templates/escrows/single-release/change-milestone-status/button/ChangeMilestoneStatus.tsx +1 -1
- package/templates/escrows/single-release/change-milestone-status/dialog/ChangeMilestoneStatus.tsx +1 -1
- package/templates/escrows/single-release/change-milestone-status/form/ChangeMilestoneStatus.tsx +1 -1
- package/templates/escrows/single-release/change-milestone-status/shared/useChangeMilestoneStatus.ts +1 -1
- package/templates/escrows/single-release/dispute-escrow/button/DisputeEscrow.tsx +1 -1
- package/templates/escrows/single-release/fund-escrow/button/FundEscrow.tsx +1 -1
- package/templates/escrows/single-release/fund-escrow/shared/useFundEscrow.ts +1 -1
- package/templates/escrows/single-release/initialize-escrow/shared/useInitializeEscrow.ts +1 -1
- package/templates/escrows/single-release/release-escrow/button/ReleaseEscrow.tsx +3 -3
- package/templates/escrows/single-release/resolve-dispute/button/ResolveDispute.tsx +1 -1
- package/templates/escrows/single-release/resolve-dispute/dialog/ResolveDispute.tsx +1 -1
- package/templates/escrows/single-release/resolve-dispute/shared/useResolveDispute.ts +1 -1
- package/templates/escrows/single-release/update-escrow/shared/useUpdateEscrow.ts +224 -224
- package/templates/providers/ReactQueryClientProvider.tsx +3 -1
- /package/templates/{escrows/escrow-context → providers}/EscrowAmountProvider.tsx +0 -0
- /package/templates/{escrows/escrow-context → providers}/EscrowDialogsProvider.tsx +0 -0
- /package/templates/{escrows/escrow-context → providers}/EscrowProvider.tsx +0 -0
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Trustless Work <a href="https://www.npmjs.com/package/@trustless-work/blocks" target="_blank">React Library</a>
|
|
4
4
|
|
|
5
5
|
A production-ready set of React blocks for integrating Trustless Work's escrow and dispute resolution flows. It ships:
|
|
6
|
+
|
|
6
7
|
- UI blocks (cards/tables/dialogs/forms) to list and manage escrows
|
|
7
8
|
- Providers for API config, wallet context, dialogs and amounts
|
|
8
9
|
- TanStack Query hooks for fetching and mutating escrows
|
|
@@ -20,12 +21,14 @@ npx trustless-work init
|
|
|
20
21
|
```
|
|
21
22
|
|
|
22
23
|
What init does:
|
|
24
|
+
|
|
23
25
|
- Installs shadcn/ui components (prompted)
|
|
24
26
|
- Installs required deps: @tanstack/react-query, @trustless-work/escrow, axios, zod, react-hook-form, @creit.tech/stellar-wallets-kit, react-day-picker, etc.
|
|
25
27
|
- Creates .twblocks.json with your UI base alias (default: "@/components/ui")
|
|
26
28
|
- Optionally wires providers into Next.js `app/layout.tsx`
|
|
27
29
|
|
|
28
30
|
Environment:
|
|
31
|
+
|
|
29
32
|
- Create `NEXT_PUBLIC_API_KEY` in your env. The library uses `TrustlessWorkProvider` with `development` base URL by default.
|
|
30
33
|
|
|
31
34
|
Tutorial at <a href="https://dapp.trustlesswork.com" target="_blank">backoffice's landing</a>
|
|
@@ -33,33 +36,41 @@ Tutorial at <a href="https://dapp.trustlesswork.com" target="_blank">backoffice'
|
|
|
33
36
|
## Quick Start
|
|
34
37
|
|
|
35
38
|
1. Initialize
|
|
39
|
+
|
|
36
40
|
```bash
|
|
37
41
|
npx trustless-work init
|
|
38
42
|
```
|
|
39
43
|
|
|
40
44
|
2. Add providers (if you skipped wiring during init)
|
|
45
|
+
|
|
41
46
|
```bash
|
|
42
47
|
npx trustless-work add providers
|
|
43
48
|
```
|
|
44
49
|
|
|
45
50
|
3. Wrap your Next.js layout
|
|
51
|
+
|
|
46
52
|
```tsx
|
|
47
53
|
// app/layout.tsx
|
|
48
54
|
import { ReactQueryClientProvider } from "@/components/tw-blocks/providers/ReactQueryClientProvider";
|
|
49
|
-
import {
|
|
55
|
+
import {
|
|
56
|
+
TrustlessWorkProvider,
|
|
57
|
+
ReactQueryClientProvider,
|
|
58
|
+
EscrowProvider,
|
|
59
|
+
} from "@/components/tw-blocks/providers/TrustlessWork";
|
|
50
60
|
import { WalletProvider } from "@/components/tw-blocks/wallet-kit/WalletProvider";
|
|
51
|
-
import { EscrowProvider } from "@/components/tw-blocks/escrows/escrow-context/EscrowProvider";
|
|
52
61
|
|
|
53
|
-
export default function RootLayout({
|
|
62
|
+
export default function RootLayout({
|
|
63
|
+
children,
|
|
64
|
+
}: {
|
|
65
|
+
children: React.ReactNode;
|
|
66
|
+
}) {
|
|
54
67
|
return (
|
|
55
68
|
<html lang="en">
|
|
56
69
|
<body>
|
|
57
70
|
<ReactQueryClientProvider>
|
|
58
71
|
<TrustlessWorkProvider>
|
|
59
72
|
<WalletProvider>
|
|
60
|
-
<EscrowProvider>
|
|
61
|
-
{children}
|
|
62
|
-
</EscrowProvider>
|
|
73
|
+
<EscrowProvider>{children}</EscrowProvider>
|
|
63
74
|
</WalletProvider>
|
|
64
75
|
</TrustlessWorkProvider>
|
|
65
76
|
</ReactQueryClientProvider>
|
|
@@ -70,9 +81,11 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
70
81
|
```
|
|
71
82
|
|
|
72
83
|
4. Add a wallet button to your header
|
|
84
|
+
|
|
73
85
|
```bash
|
|
74
86
|
npx trustless-work add wallet-kit
|
|
75
87
|
```
|
|
88
|
+
|
|
76
89
|
```tsx
|
|
77
90
|
// Example usage
|
|
78
91
|
import { WalletButton } from "@/components/tw-blocks/wallet-kit/WalletButtons";
|
|
@@ -87,16 +100,18 @@ export function Header() {
|
|
|
87
100
|
```
|
|
88
101
|
|
|
89
102
|
5. List escrows quickly
|
|
103
|
+
|
|
90
104
|
```bash
|
|
91
105
|
# By role
|
|
92
106
|
npx trustless-work add escrows/escrows-by-role/cards
|
|
93
107
|
# Or table view
|
|
94
108
|
npx trustless-work add escrows/escrows-by-role/table
|
|
95
109
|
```
|
|
110
|
+
|
|
96
111
|
```tsx
|
|
97
112
|
// app/escrows/page.tsx
|
|
98
113
|
import { EscrowsByRoleCards } from "@/components/tw-blocks/escrows/escrows-by-role/cards/EscrowsCards";
|
|
99
|
-
import { EscrowDialogsProvider } from "@/components/tw-blocks/
|
|
114
|
+
import { EscrowDialogsProvider } from "@/components/tw-blocks/providers/EscrowDialogsProvider";
|
|
100
115
|
|
|
101
116
|
export default function Page() {
|
|
102
117
|
return (
|
|
@@ -142,7 +157,9 @@ export function DeployButton({ address }: { address: string }) {
|
|
|
142
157
|
<button
|
|
143
158
|
onClick={() =>
|
|
144
159
|
deployEscrow.mutate({
|
|
145
|
-
payload: {
|
|
160
|
+
payload: {
|
|
161
|
+
/* InitializeSingleReleaseEscrowPayload */
|
|
162
|
+
},
|
|
146
163
|
type: "single-release",
|
|
147
164
|
address,
|
|
148
165
|
})
|
|
@@ -170,9 +187,6 @@ npx trustless-work add helpers
|
|
|
170
187
|
npx trustless-work add tanstack
|
|
171
188
|
npx trustless-work add escrows
|
|
172
189
|
|
|
173
|
-
# Escrow context providers
|
|
174
|
-
npx trustless-work add escrows/escrow-context
|
|
175
|
-
|
|
176
190
|
# Escrows by role
|
|
177
191
|
npx trustless-work add escrows/escrows-by-role
|
|
178
192
|
npx trustless-work add escrows/escrows-by-role/table
|
|
@@ -199,13 +213,15 @@ npx trustless-work add escrows/single-release/update-escrow
|
|
|
199
213
|
```
|
|
200
214
|
|
|
201
215
|
### Escrows
|
|
216
|
+
|
|
202
217
|
- Cards and tables to browse escrows (by role or by signer) with filters, pagination, and sort
|
|
203
218
|
- Detail dialog with actions gated by roles and escrow flags
|
|
204
219
|
- Dialogs/forms for single-release lifecycle (initialize, fund, approve, change status, release, dispute, resolve, update)
|
|
205
220
|
|
|
206
221
|
Using cards (by role):
|
|
222
|
+
|
|
207
223
|
```tsx
|
|
208
|
-
import { EscrowDialogsProvider } from "@/components/tw-blocks/
|
|
224
|
+
import { EscrowDialogsProvider } from "@/components/tw-blocks/providers/EscrowDialogsProvider";
|
|
209
225
|
import { EscrowsByRoleCards } from "@/components/tw-blocks/escrows/escrows-by-role/cards/EscrowsCards";
|
|
210
226
|
|
|
211
227
|
export default function Screen() {
|
|
@@ -218,6 +234,7 @@ export default function Screen() {
|
|
|
218
234
|
```
|
|
219
235
|
|
|
220
236
|
Make sure to:
|
|
237
|
+
|
|
221
238
|
1. Set `NEXT_PUBLIC_API_KEY` and run the app against the correct environment (the provider defaults to `development`).
|
|
222
239
|
2. Configure your UI base imports. CLI uses `.twblocks.json` `uiBase` to replace `__UI_BASE__`. If your UI alias differs, pass `--ui-base`:
|
|
223
240
|
```bash
|
|
@@ -228,6 +245,7 @@ Make sure to:
|
|
|
228
245
|
## Best Practices
|
|
229
246
|
|
|
230
247
|
1. Providers
|
|
248
|
+
|
|
231
249
|
- `ReactQueryClientProvider`: global query cache and devtools.
|
|
232
250
|
- `TrustlessWorkProvider`: sets API `baseURL` and `apiKey` via `TrustlessWorkConfig` from `@trustless-work/escrow`.
|
|
233
251
|
- `WalletProvider`: minimal wallet state (address/name) persisted in localStorage; used by wallet button and mutations.
|
|
@@ -236,17 +254,25 @@ Make sure to:
|
|
|
236
254
|
- `EscrowAmountProvider`: computes receiver/platform/fee splits for releases.
|
|
237
255
|
|
|
238
256
|
2. Queries and caching
|
|
257
|
+
|
|
239
258
|
- Use provided queries: `useEscrowsByRoleQuery`, `useEscrowsBySignerQuery`.
|
|
240
259
|
- All mutations invalidate `['escrows']` automatically.
|
|
241
260
|
|
|
242
261
|
3. Error handling
|
|
262
|
+
|
|
243
263
|
- Use `handleError(error)` from `handle-errors/handle.ts` to map Axios and wallet errors to normalized types (`ApiErrorTypes`).
|
|
264
|
+
|
|
244
265
|
```ts
|
|
245
266
|
import { handleError } from "@/components/tw-blocks/handle-errors/handle";
|
|
246
|
-
try {
|
|
267
|
+
try {
|
|
268
|
+
/* ... */
|
|
269
|
+
} catch (e) {
|
|
270
|
+
const err = handleError(e as any); /* show toast */
|
|
271
|
+
}
|
|
247
272
|
```
|
|
248
273
|
|
|
249
274
|
4. Wallet-kit
|
|
275
|
+
|
|
250
276
|
- `WalletButton` opens a modal using `@creit.tech/stellar-wallets-kit` and stores address/name in `WalletProvider`.
|
|
251
277
|
- `signTransaction({ unsignedTransaction, address })` signs and returns XDR used by mutations.
|
|
252
278
|
- `trustlines` and `trustlineOptions` include common assets for testnet/mainnet.
|