@bsv/create-dpp-app 0.0.0-stage → 0.1.0-beta.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 +203 -0
- package/README.md +73 -2
- package/dist/index.js +97 -0
- package/package.json +53 -4
- package/template/Dockerfile +35 -0
- package/template/README.md +134 -0
- package/template/_dockerignore +6 -0
- package/template/_env.example +53 -0
- package/template/_github/workflows/ci.yml +23 -0
- package/template/_gitignore +8 -0
- package/template/_prettierrc +6 -0
- package/template/apps/api/API.md +49 -0
- package/template/apps/api/package.json +34 -0
- package/template/apps/api/src/auth.ts +55 -0
- package/template/apps/api/src/claims.ts +85 -0
- package/template/apps/api/src/cli.ts +42 -0
- package/template/apps/api/src/config.ts +66 -0
- package/template/apps/api/src/custody.ts +186 -0
- package/template/apps/api/src/dev-index.ts +71 -0
- package/template/apps/api/src/env.ts +14 -0
- package/template/apps/api/src/identifiers.ts +57 -0
- package/template/apps/api/src/index-client.ts +136 -0
- package/template/apps/api/src/main.ts +50 -0
- package/template/apps/api/src/parties.ts +68 -0
- package/template/apps/api/src/platform.ts +121 -0
- package/template/apps/api/src/profiles.ts +100 -0
- package/template/apps/api/src/reader.ts +96 -0
- package/template/apps/api/src/server.ts +420 -0
- package/template/apps/api/src/store.ts +249 -0
- package/template/apps/api/src/wallet.ts +346 -0
- package/template/apps/api/src/worker.ts +106 -0
- package/template/apps/api/src/writer.ts +351 -0
- package/template/apps/api/test/config.test.ts +15 -0
- package/template/apps/api/test/external-index.test.ts +31 -0
- package/template/apps/api/test/lifecycle.test.ts +136 -0
- package/template/apps/api/tsconfig.json +9 -0
- package/template/apps/api/vitest.config.ts +9 -0
- package/template/apps/web/components.json +21 -0
- package/template/apps/web/index.html +12 -0
- package/template/apps/web/package.json +33 -0
- package/template/apps/web/src/app.tsx +51 -0
- package/template/apps/web/src/components/bits.tsx +188 -0
- package/template/apps/web/src/components/layout.tsx +118 -0
- package/template/apps/web/src/components/passport-form.tsx +244 -0
- package/template/apps/web/src/components/read-passport.tsx +48 -0
- package/template/apps/web/src/components/reading.tsx +157 -0
- package/template/apps/web/src/components/ui/alert.tsx +65 -0
- package/template/apps/web/src/components/ui/badge.tsx +47 -0
- package/template/apps/web/src/components/ui/button.tsx +63 -0
- package/template/apps/web/src/components/ui/card.tsx +91 -0
- package/template/apps/web/src/components/ui/dialog.tsx +156 -0
- package/template/apps/web/src/components/ui/input.tsx +20 -0
- package/template/apps/web/src/components/ui/label.tsx +21 -0
- package/template/apps/web/src/components/ui/select.tsx +189 -0
- package/template/apps/web/src/components/ui/separator.tsx +25 -0
- package/template/apps/web/src/components/ui/table.tsx +115 -0
- package/template/apps/web/src/components/ui/tabs.tsx +90 -0
- package/template/apps/web/src/components/ui/textarea.tsx +17 -0
- package/template/apps/web/src/index.css +81 -0
- package/template/apps/web/src/lib/api.ts +286 -0
- package/template/apps/web/src/lib/auth.ts +10 -0
- package/template/apps/web/src/lib/format.ts +64 -0
- package/template/apps/web/src/lib/session.tsx +92 -0
- package/template/apps/web/src/lib/use-load.ts +46 -0
- package/template/apps/web/src/main.tsx +18 -0
- package/template/apps/web/src/pages/accept.tsx +108 -0
- package/template/apps/web/src/pages/brand.tsx +94 -0
- package/template/apps/web/src/pages/brands.tsx +104 -0
- package/template/apps/web/src/pages/home.tsx +51 -0
- package/template/apps/web/src/pages/new-passport.tsx +114 -0
- package/template/apps/web/src/pages/operations.tsx +150 -0
- package/template/apps/web/src/pages/passport.tsx +568 -0
- package/template/apps/web/src/pages/public-passport.tsx +24 -0
- package/template/apps/web/src/pages/sign-in.tsx +93 -0
- package/template/apps/web/src/pages/verify.tsx +30 -0
- package/template/apps/web/src/pages/wallet.tsx +141 -0
- package/template/apps/web/tsconfig.json +29 -0
- package/template/apps/web/vite.config.ts +15 -0
- package/template/deploy/compose.yml +26 -0
- package/template/package.json +42 -0
- package/template/tsconfig.base.json +13 -0
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
// The brand's view of one passport: what is in the journal, and every action
|
|
2
|
+
// on it in a dialog. A passport that was handed on is held by a recipient,
|
|
3
|
+
// and every action then needs the claim code they accepted with.
|
|
4
|
+
import { useState, type FormEvent, type ReactNode } from 'react'
|
|
5
|
+
import { Link, useParams } from 'react-router'
|
|
6
|
+
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
7
|
+
import { Button } from '@/components/ui/button'
|
|
8
|
+
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
|
9
|
+
import { Input } from '@/components/ui/input'
|
|
10
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
|
11
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
|
12
|
+
import { Textarea } from '@/components/ui/textarea'
|
|
13
|
+
import { CopyButton, DefinitionList, ErrorNotice, Field, Loading, Mono, PageTitle, Section, ToneBadge, YesNo, entriesOf, indexTone, networkTone, statusTone } from '@/components/bits'
|
|
14
|
+
import { RequireAccount } from '@/components/layout'
|
|
15
|
+
import { PassportForm, type PassportFormValues } from '@/components/passport-form'
|
|
16
|
+
import { EVENT_TYPES, api, type ClaimView, type EventType, type OfferView, type PassportView } from '@/lib/api'
|
|
17
|
+
import { formatTime, holderLabel, humanise, isRecord, parseIdentifier, passportIdFromRef, publicPathOf, shortKey, shortTxid } from '@/lib/format'
|
|
18
|
+
import { useLoad } from '@/lib/use-load'
|
|
19
|
+
|
|
20
|
+
type DialogKind = 'update' | 'offer' | 'retire' | 'claim'
|
|
21
|
+
|
|
22
|
+
export function Passport() {
|
|
23
|
+
return (
|
|
24
|
+
<RequireAccount>
|
|
25
|
+
<PassportPage />
|
|
26
|
+
</RequireAccount>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function PassportPage() {
|
|
31
|
+
const { ref = '' } = useParams()
|
|
32
|
+
const passportId = passportIdFromRef(ref)
|
|
33
|
+
const passport = useLoad(() => api.passport(passportId), [passportId])
|
|
34
|
+
const offers = useLoad(() => api.passportOffers(passportId), [passportId])
|
|
35
|
+
const claims = useLoad(() => api.passportClaims(passportId), [passportId])
|
|
36
|
+
const [dialog, setDialog] = useState<DialogKind>()
|
|
37
|
+
|
|
38
|
+
if (passport.loading) return <Loading what="Loading the passport" />
|
|
39
|
+
if (passport.error != null || passport.data == null) return <ErrorNotice error={passport.error ?? new Error('no answer')} title="Could not load the passport" />
|
|
40
|
+
|
|
41
|
+
const view = passport.data
|
|
42
|
+
const needsClaimCode = view.holder.party.startsWith('recipient:')
|
|
43
|
+
const retired = view.status === 'retired'
|
|
44
|
+
const ident = parseIdentifier(view.passportId)
|
|
45
|
+
const publicPath = publicPathOf(view.passportId)
|
|
46
|
+
const close = () => setDialog(undefined)
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div className="space-y-10">
|
|
50
|
+
<PageTitle
|
|
51
|
+
title={ident == null ? view.passportId : `Serial ${ident.serial}`}
|
|
52
|
+
description={
|
|
53
|
+
<span className="flex flex-wrap items-center gap-2">
|
|
54
|
+
{ident == null ? null : <span>GTIN {ident.gtin}</span>}
|
|
55
|
+
<Mono>{view.passportId}</Mono>
|
|
56
|
+
<CopyButton text={view.passportId} label="Copy the identifier" />
|
|
57
|
+
</span>
|
|
58
|
+
}
|
|
59
|
+
action={
|
|
60
|
+
publicPath == null ? null : (
|
|
61
|
+
<Button asChild variant="outline">
|
|
62
|
+
<Link to={publicPath}>Public page</Link>
|
|
63
|
+
</Button>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 text-sm">
|
|
69
|
+
<ToneBadge tone={statusTone(view.status)}>{view.status}</ToneBadge>
|
|
70
|
+
{view.demonstration ? <ToneBadge tone="warn">Demonstration</ToneBadge> : null}
|
|
71
|
+
<span className="text-muted-foreground">Profile {view.profile}</span>
|
|
72
|
+
<span className="text-muted-foreground">
|
|
73
|
+
Held by {holderLabel(view.holder.party)} <Mono className="text-muted-foreground">{shortKey(view.holder.controllerKey)}</Mono>
|
|
74
|
+
</span>
|
|
75
|
+
<span className="text-muted-foreground">Issued {formatTime(view.createdAt)}</span>
|
|
76
|
+
<span className="text-muted-foreground">
|
|
77
|
+
Brand{' '}
|
|
78
|
+
<Link to={`/brands/${encodeURIComponent(view.brandId)}`} className="underline underline-offset-4">
|
|
79
|
+
{view.brandId}
|
|
80
|
+
</Link>
|
|
81
|
+
</span>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
{needsClaimCode ? (
|
|
85
|
+
<Alert>
|
|
86
|
+
<AlertTitle>Held by a recipient</AlertTitle>
|
|
87
|
+
<AlertDescription>
|
|
88
|
+
<p>This passport was handed on. Every action on it now needs the claim code the recipient accepted with.</p>
|
|
89
|
+
</AlertDescription>
|
|
90
|
+
</Alert>
|
|
91
|
+
) : null}
|
|
92
|
+
|
|
93
|
+
<div className="flex flex-wrap gap-2">
|
|
94
|
+
<Button onClick={() => setDialog('update')} disabled={retired}>
|
|
95
|
+
Update
|
|
96
|
+
</Button>
|
|
97
|
+
<Button variant="outline" onClick={() => setDialog('offer')} disabled={retired}>
|
|
98
|
+
Hand on
|
|
99
|
+
</Button>
|
|
100
|
+
<Button variant="outline" onClick={() => setDialog('retire')} disabled={retired}>
|
|
101
|
+
Retire
|
|
102
|
+
</Button>
|
|
103
|
+
<Button variant="outline" onClick={() => setDialog('claim')}>
|
|
104
|
+
Add a claim
|
|
105
|
+
</Button>
|
|
106
|
+
{retired ? <span className="self-center text-sm text-muted-foreground">Retired: no further state can be written.</span> : null}
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<Section title="Public payload">
|
|
110
|
+
<DefinitionList entries={entriesOf(view.payload, new Set(), humanise)} />
|
|
111
|
+
</Section>
|
|
112
|
+
|
|
113
|
+
<Section title="Journal">
|
|
114
|
+
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
|
|
115
|
+
<Stat label="States" value={view.journal.states} />
|
|
116
|
+
<Stat label="Proven" value={view.journal.proven} />
|
|
117
|
+
<Stat label="Pending" value={view.journal.pending} />
|
|
118
|
+
<Stat label="Status" value={view.journal.status} />
|
|
119
|
+
</div>
|
|
120
|
+
</Section>
|
|
121
|
+
|
|
122
|
+
<Section title="States">
|
|
123
|
+
<Table>
|
|
124
|
+
<TableHeader>
|
|
125
|
+
<TableRow>
|
|
126
|
+
<TableHead>Op</TableHead>
|
|
127
|
+
<TableHead>Time</TableHead>
|
|
128
|
+
<TableHead>Actor</TableHead>
|
|
129
|
+
<TableHead>Index</TableHead>
|
|
130
|
+
<TableHead>Network</TableHead>
|
|
131
|
+
<TableHead>Proven</TableHead>
|
|
132
|
+
<TableHead>Proof pushed</TableHead>
|
|
133
|
+
<TableHead>Block</TableHead>
|
|
134
|
+
<TableHead>Txid</TableHead>
|
|
135
|
+
</TableRow>
|
|
136
|
+
</TableHeader>
|
|
137
|
+
<TableBody>
|
|
138
|
+
{view.states.map((state) => (
|
|
139
|
+
<TableRow key={state.txid}>
|
|
140
|
+
<TableCell>
|
|
141
|
+
<ToneBadge tone="neutral">{state.op}</ToneBadge>
|
|
142
|
+
</TableCell>
|
|
143
|
+
<TableCell>{formatTime(state.timestamp)}</TableCell>
|
|
144
|
+
<TableCell>{state.actor}</TableCell>
|
|
145
|
+
<TableCell>
|
|
146
|
+
<ToneBadge tone={indexTone(state.index)}>{state.index}</ToneBadge>
|
|
147
|
+
{state.refusal == null ? null : <div className="mt-1 max-w-xs whitespace-normal text-xs text-muted-foreground">{state.refusal}</div>}
|
|
148
|
+
</TableCell>
|
|
149
|
+
<TableCell>
|
|
150
|
+
<ToneBadge tone={networkTone(state.network)}>{state.network}</ToneBadge>
|
|
151
|
+
</TableCell>
|
|
152
|
+
<TableCell>
|
|
153
|
+
<YesNo value={state.proven} />
|
|
154
|
+
</TableCell>
|
|
155
|
+
<TableCell>
|
|
156
|
+
<YesNo value={state.proofPushed} />
|
|
157
|
+
</TableCell>
|
|
158
|
+
<TableCell>{state.blockHeight ?? <span className="text-muted-foreground">none</span>}</TableCell>
|
|
159
|
+
<TableCell>
|
|
160
|
+
<span className="flex items-center gap-1">
|
|
161
|
+
<Mono>{shortTxid(state.txid)}</Mono>
|
|
162
|
+
<CopyButton text={state.txid} label="Copy the txid" />
|
|
163
|
+
</span>
|
|
164
|
+
</TableCell>
|
|
165
|
+
</TableRow>
|
|
166
|
+
))}
|
|
167
|
+
</TableBody>
|
|
168
|
+
</Table>
|
|
169
|
+
</Section>
|
|
170
|
+
|
|
171
|
+
<Section title="Offers">
|
|
172
|
+
{offers.loading ? (
|
|
173
|
+
<Loading what="Loading the offers" />
|
|
174
|
+
) : offers.error != null || offers.data == null ? (
|
|
175
|
+
<ErrorNotice error={offers.error ?? new Error('no answer')} title="Could not load the offers" />
|
|
176
|
+
) : offers.data.length === 0 ? (
|
|
177
|
+
<p className="text-sm text-muted-foreground">No offers. Hand on makes one.</p>
|
|
178
|
+
) : (
|
|
179
|
+
<Table>
|
|
180
|
+
<TableHeader>
|
|
181
|
+
<TableRow>
|
|
182
|
+
<TableHead>Request</TableHead>
|
|
183
|
+
<TableHead>Terms</TableHead>
|
|
184
|
+
<TableHead>Status</TableHead>
|
|
185
|
+
<TableHead>Made</TableHead>
|
|
186
|
+
<TableHead>Expires</TableHead>
|
|
187
|
+
<TableHead />
|
|
188
|
+
</TableRow>
|
|
189
|
+
</TableHeader>
|
|
190
|
+
<TableBody>
|
|
191
|
+
{offers.data.map((offer) => (
|
|
192
|
+
<TableRow key={offer.requestId}>
|
|
193
|
+
<TableCell>
|
|
194
|
+
<Mono>{offer.requestId}</Mono>
|
|
195
|
+
</TableCell>
|
|
196
|
+
<TableCell className="whitespace-normal">
|
|
197
|
+
<span className="font-medium">{String(offer.terms.word ?? '')}</span>
|
|
198
|
+
{typeof offer.terms.note === 'string' && offer.terms.note !== '' ? <span className="text-muted-foreground"> {offer.terms.note}</span> : null}
|
|
199
|
+
</TableCell>
|
|
200
|
+
<TableCell>
|
|
201
|
+
<ToneBadge tone={statusTone(offer.status)}>{offer.status}</ToneBadge>
|
|
202
|
+
{offer.transferTxid == null ? null : <div className="mt-1 text-xs text-muted-foreground">{shortTxid(offer.transferTxid)}</div>}
|
|
203
|
+
</TableCell>
|
|
204
|
+
<TableCell>{formatTime(offer.createdAt)}</TableCell>
|
|
205
|
+
<TableCell>{formatTime(offer.expiresAt)}</TableCell>
|
|
206
|
+
<TableCell className="text-right">{offer.status === 'open' ? <WithdrawButton offer={offer} needsClaimCode={needsClaimCode} onDone={offers.reload} /> : null}</TableCell>
|
|
207
|
+
</TableRow>
|
|
208
|
+
))}
|
|
209
|
+
</TableBody>
|
|
210
|
+
</Table>
|
|
211
|
+
)}
|
|
212
|
+
</Section>
|
|
213
|
+
|
|
214
|
+
<Section title="Claims">
|
|
215
|
+
{claims.loading ? (
|
|
216
|
+
<Loading what="Loading the claims" />
|
|
217
|
+
) : claims.error != null || claims.data == null ? (
|
|
218
|
+
<ErrorNotice error={claims.error ?? new Error('no answer')} title="Could not load the claims" />
|
|
219
|
+
) : claims.data.length === 0 ? (
|
|
220
|
+
<p className="text-sm text-muted-foreground">No claims. A claim is a signed statement about the passport on its own rail; it never spends the passport.</p>
|
|
221
|
+
) : (
|
|
222
|
+
<Table>
|
|
223
|
+
<TableHeader>
|
|
224
|
+
<TableRow>
|
|
225
|
+
<TableHead>Event</TableHead>
|
|
226
|
+
<TableHead>When</TableHead>
|
|
227
|
+
<TableHead>Issued by</TableHead>
|
|
228
|
+
<TableHead>Signature</TableHead>
|
|
229
|
+
<TableHead>Registry</TableHead>
|
|
230
|
+
</TableRow>
|
|
231
|
+
</TableHeader>
|
|
232
|
+
<TableBody>
|
|
233
|
+
{claims.data.map((claim) => (
|
|
234
|
+
<TableRow key={claim.id}>
|
|
235
|
+
<TableCell>
|
|
236
|
+
{claim.claim.eventType}
|
|
237
|
+
<div className="text-xs text-muted-foreground">{claim.id}</div>
|
|
238
|
+
</TableCell>
|
|
239
|
+
<TableCell>{formatTime(claim.claim.timestamp)}</TableCell>
|
|
240
|
+
<TableCell>{claim.issuedBy}</TableCell>
|
|
241
|
+
<TableCell>
|
|
242
|
+
<ToneBadge tone={claim.verified === 'verified' ? 'pass' : 'fail'}>{claim.verified}</ToneBadge>
|
|
243
|
+
</TableCell>
|
|
244
|
+
<TableCell className="whitespace-normal">
|
|
245
|
+
<RegistryAnswer claim={claim} />
|
|
246
|
+
</TableCell>
|
|
247
|
+
</TableRow>
|
|
248
|
+
))}
|
|
249
|
+
</TableBody>
|
|
250
|
+
</Table>
|
|
251
|
+
)}
|
|
252
|
+
</Section>
|
|
253
|
+
|
|
254
|
+
{dialog === 'update' ? <UpdateDialog passport={view} needsClaimCode={needsClaimCode} onClose={close} onDone={passport.setData} /> : null}
|
|
255
|
+
{dialog === 'offer' ? <HandOnDialog passportId={view.passportId} needsClaimCode={needsClaimCode} onClose={close} onDone={offers.reload} /> : null}
|
|
256
|
+
{dialog === 'retire' ? <RetireDialog passportId={view.passportId} needsClaimCode={needsClaimCode} onClose={close} onDone={passport.setData} /> : null}
|
|
257
|
+
{dialog === 'claim' ? <ClaimDialog passportId={view.passportId} onClose={close} onDone={claims.reload} /> : null}
|
|
258
|
+
</div>
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function Stat({ label, value }: { label: string; value: ReactNode }) {
|
|
263
|
+
return (
|
|
264
|
+
<div className="rounded-lg border p-3">
|
|
265
|
+
<div className="text-xs text-muted-foreground">{label}</div>
|
|
266
|
+
<div className="text-xl font-semibold">{value}</div>
|
|
267
|
+
</div>
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function RegistryAnswer({ claim }: { claim: ClaimView }) {
|
|
272
|
+
if (claim.registry == null) return <span className="text-muted-foreground">not sent</span>
|
|
273
|
+
return (
|
|
274
|
+
<span className="text-xs">
|
|
275
|
+
<ToneBadge tone={claim.registry.accepted ? 'pass' : 'fail'}>{claim.registry.accepted ? 'accepted' : `HTTP ${claim.registry.status}`}</ToneBadge>
|
|
276
|
+
{claim.registry.attestationId == null ? null : <span className="ml-2 font-mono">{claim.registry.attestationId}</span>}
|
|
277
|
+
{claim.registry.detail == null ? null : <div className="mt-1 text-muted-foreground">{claim.registry.detail}</div>}
|
|
278
|
+
</span>
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function ClaimCodeField({ value, onChange }: { value: string; onChange: (value: string) => void }) {
|
|
283
|
+
return (
|
|
284
|
+
<Field label="Claim code" htmlFor="claimCode" required help="The holder acts with the claim code they accepted with.">
|
|
285
|
+
<Input id="claimCode" value={value} onChange={(e) => onChange(e.target.value)} required autoComplete="off" spellCheck={false} />
|
|
286
|
+
</Field>
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function WithdrawButton({ offer, needsClaimCode, onDone }: { offer: OfferView; needsClaimCode: boolean; onDone: () => void }) {
|
|
291
|
+
const [claimCode, setClaimCode] = useState('')
|
|
292
|
+
const [busy, setBusy] = useState(false)
|
|
293
|
+
const [error, setError] = useState<unknown>()
|
|
294
|
+
async function withdraw() {
|
|
295
|
+
setBusy(true)
|
|
296
|
+
setError(undefined)
|
|
297
|
+
try {
|
|
298
|
+
await api.withdrawOffer(offer.requestId, needsClaimCode ? claimCode : undefined)
|
|
299
|
+
onDone()
|
|
300
|
+
} catch (cause) {
|
|
301
|
+
setError(cause)
|
|
302
|
+
} finally {
|
|
303
|
+
setBusy(false)
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return (
|
|
307
|
+
<div className="flex flex-col items-end gap-1">
|
|
308
|
+
<div className="flex items-center gap-2">
|
|
309
|
+
{needsClaimCode ? <Input value={claimCode} onChange={(e) => setClaimCode(e.target.value)} placeholder="Claim code" className="h-8 w-40" aria-label="Claim code" /> : null}
|
|
310
|
+
<Button variant="outline" size="sm" onClick={withdraw} disabled={busy || (needsClaimCode && claimCode === '')}>
|
|
311
|
+
{busy ? 'Working' : 'Withdraw'}
|
|
312
|
+
</Button>
|
|
313
|
+
</div>
|
|
314
|
+
{error == null ? null : <span className="max-w-xs whitespace-normal text-xs text-destructive">{error instanceof Error ? error.message : String(error)}</span>}
|
|
315
|
+
</div>
|
|
316
|
+
)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function UpdateDialog({ passport, needsClaimCode, onClose, onDone }: { passport: PassportView; needsClaimCode: boolean; onClose: () => void; onDone: (view: PassportView) => void }) {
|
|
320
|
+
const profile = useLoad(() => api.profile(passport.profile), [passport.profile])
|
|
321
|
+
const [claimCode, setClaimCode] = useState('')
|
|
322
|
+
const [busy, setBusy] = useState(false)
|
|
323
|
+
const [error, setError] = useState<unknown>()
|
|
324
|
+
|
|
325
|
+
async function submit(values: PassportFormValues) {
|
|
326
|
+
setBusy(true)
|
|
327
|
+
setError(undefined)
|
|
328
|
+
try {
|
|
329
|
+
const view = await api.updatePassport(passport.passportId, { ...values, ...(needsClaimCode ? { claimCode } : {}) })
|
|
330
|
+
onDone(view)
|
|
331
|
+
onClose()
|
|
332
|
+
} catch (cause) {
|
|
333
|
+
setError(cause)
|
|
334
|
+
} finally {
|
|
335
|
+
setBusy(false)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return (
|
|
340
|
+
<Dialog open onOpenChange={(open) => (open ? undefined : onClose())}>
|
|
341
|
+
<DialogContent className="max-h-[90vh] overflow-y-auto sm:max-w-3xl">
|
|
342
|
+
<DialogHeader>
|
|
343
|
+
<DialogTitle>Update the passport</DialogTitle>
|
|
344
|
+
<DialogDescription>A new state carrying the payload you submit. The current public payload is filled in.</DialogDescription>
|
|
345
|
+
</DialogHeader>
|
|
346
|
+
<Alert>
|
|
347
|
+
<AlertTitle>Owner-tier fields start empty</AlertTitle>
|
|
348
|
+
<AlertDescription>
|
|
349
|
+
<p>The API never returns the encrypted owner tier, so those fields are blank here. What you submit becomes the new owner tier; leave them blank and it is written blank.</p>
|
|
350
|
+
</AlertDescription>
|
|
351
|
+
</Alert>
|
|
352
|
+
{profile.loading ? (
|
|
353
|
+
<Loading what="Loading the profile" />
|
|
354
|
+
) : profile.error != null || profile.data == null ? (
|
|
355
|
+
<ErrorNotice error={profile.error ?? new Error('no answer')} title={`Could not load ${passport.profile}`} />
|
|
356
|
+
) : (
|
|
357
|
+
<PassportForm
|
|
358
|
+
profile={profile.data}
|
|
359
|
+
initial={{ payload: isRecord(passport.payload) ? passport.payload : {} }}
|
|
360
|
+
submitLabel="Write the update"
|
|
361
|
+
busy={busy}
|
|
362
|
+
error={error}
|
|
363
|
+
onSubmit={submit}
|
|
364
|
+
after={needsClaimCode ? <ClaimCodeField value={claimCode} onChange={setClaimCode} /> : null}
|
|
365
|
+
/>
|
|
366
|
+
)}
|
|
367
|
+
</DialogContent>
|
|
368
|
+
</Dialog>
|
|
369
|
+
)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function HandOnDialog({ passportId, needsClaimCode, onClose, onDone }: { passportId: string; needsClaimCode: boolean; onClose: () => void; onDone: () => void }) {
|
|
373
|
+
const [word, setWord] = useState('Handed on')
|
|
374
|
+
const [note, setNote] = useState('')
|
|
375
|
+
const [claimCode, setClaimCode] = useState('')
|
|
376
|
+
const [busy, setBusy] = useState(false)
|
|
377
|
+
const [error, setError] = useState<unknown>()
|
|
378
|
+
const [result, setResult] = useState<{ offer: OfferView; claimCode?: string }>()
|
|
379
|
+
|
|
380
|
+
async function submit(event: FormEvent) {
|
|
381
|
+
event.preventDefault()
|
|
382
|
+
setBusy(true)
|
|
383
|
+
setError(undefined)
|
|
384
|
+
try {
|
|
385
|
+
const answer = await api.offerPassport(passportId, { terms: { word: word.trim(), ...(note.trim() === '' ? {} : { note: note.trim() }) }, ...(needsClaimCode ? { claimCode } : {}) })
|
|
386
|
+
setResult(answer)
|
|
387
|
+
onDone()
|
|
388
|
+
} catch (cause) {
|
|
389
|
+
setError(cause)
|
|
390
|
+
} finally {
|
|
391
|
+
setBusy(false)
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const acceptUrl = result == null ? '' : `${window.location.origin}/accept/${encodeURIComponent(result.offer.requestId)}`
|
|
396
|
+
|
|
397
|
+
return (
|
|
398
|
+
<Dialog open onOpenChange={(open) => (open ? undefined : onClose())}>
|
|
399
|
+
<DialogContent className="max-h-[90vh] overflow-y-auto">
|
|
400
|
+
<DialogHeader>
|
|
401
|
+
<DialogTitle>Hand on this passport</DialogTitle>
|
|
402
|
+
<DialogDescription>The platform offers it under these terms. The recipient accepts with a claim code, and the transfer is written then.</DialogDescription>
|
|
403
|
+
</DialogHeader>
|
|
404
|
+
{result == null ? (
|
|
405
|
+
<form onSubmit={submit} className="space-y-4">
|
|
406
|
+
<Field label="Terms word" htmlFor="offer-word" required help="One word for what is happening, for example Sold or Gifted.">
|
|
407
|
+
<Input id="offer-word" value={word} onChange={(e) => setWord(e.target.value)} required maxLength={40} />
|
|
408
|
+
</Field>
|
|
409
|
+
<Field label="Note" htmlFor="offer-note" help="Shown to the recipient before they decide.">
|
|
410
|
+
<Textarea id="offer-note" value={note} onChange={(e) => setNote(e.target.value)} maxLength={400} />
|
|
411
|
+
</Field>
|
|
412
|
+
{needsClaimCode ? <ClaimCodeField value={claimCode} onChange={setClaimCode} /> : null}
|
|
413
|
+
{error == null ? null : <ErrorNotice error={error} title="The offer was refused" />}
|
|
414
|
+
<DialogFooter>
|
|
415
|
+
<Button type="submit" disabled={busy || word.trim() === ''}>
|
|
416
|
+
{busy ? 'Working' : 'Make the offer'}
|
|
417
|
+
</Button>
|
|
418
|
+
</DialogFooter>
|
|
419
|
+
</form>
|
|
420
|
+
) : (
|
|
421
|
+
<div className="space-y-4">
|
|
422
|
+
<div className="rounded-lg border-2 border-amber-400 bg-amber-50 p-4 dark:border-amber-700 dark:bg-amber-950">
|
|
423
|
+
<p className="text-xs font-medium uppercase tracking-wide text-muted-foreground">Claim code</p>
|
|
424
|
+
<div className="mt-1 flex items-center gap-2">
|
|
425
|
+
<code className="text-2xl font-semibold tracking-wider">{result.claimCode ?? 'none'}</code>
|
|
426
|
+
{result.claimCode == null ? null : <CopyButton text={result.claimCode} label="Copy the claim code" />}
|
|
427
|
+
</div>
|
|
428
|
+
<p className="mt-3 text-sm">Give this code to the recipient out of band. It is shown once and never stored.</p>
|
|
429
|
+
</div>
|
|
430
|
+
<Field label="Accept link" help="Where the recipient enters the code.">
|
|
431
|
+
<div className="flex items-center gap-2">
|
|
432
|
+
<Mono>{acceptUrl}</Mono>
|
|
433
|
+
<CopyButton text={acceptUrl} label="Copy the accept link" />
|
|
434
|
+
</div>
|
|
435
|
+
</Field>
|
|
436
|
+
<p className="text-sm text-muted-foreground">
|
|
437
|
+
Offer {result.offer.requestId}, open until {formatTime(result.offer.expiresAt)}.
|
|
438
|
+
</p>
|
|
439
|
+
<DialogFooter>
|
|
440
|
+
<Button onClick={onClose}>Done</Button>
|
|
441
|
+
</DialogFooter>
|
|
442
|
+
</div>
|
|
443
|
+
)}
|
|
444
|
+
</DialogContent>
|
|
445
|
+
</Dialog>
|
|
446
|
+
)
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function RetireDialog({ passportId, needsClaimCode, onClose, onDone }: { passportId: string; needsClaimCode: boolean; onClose: () => void; onDone: (view: PassportView) => void }) {
|
|
450
|
+
const [reason, setReason] = useState('')
|
|
451
|
+
const [claimCode, setClaimCode] = useState('')
|
|
452
|
+
const [busy, setBusy] = useState(false)
|
|
453
|
+
const [error, setError] = useState<unknown>()
|
|
454
|
+
|
|
455
|
+
async function submit(event: FormEvent) {
|
|
456
|
+
event.preventDefault()
|
|
457
|
+
setBusy(true)
|
|
458
|
+
setError(undefined)
|
|
459
|
+
try {
|
|
460
|
+
const view = await api.retirePassport(passportId, { reason: reason.trim(), ...(needsClaimCode ? { claimCode } : {}) })
|
|
461
|
+
onDone(view)
|
|
462
|
+
onClose()
|
|
463
|
+
} catch (cause) {
|
|
464
|
+
setError(cause)
|
|
465
|
+
} finally {
|
|
466
|
+
setBusy(false)
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
return (
|
|
471
|
+
<Dialog open onOpenChange={(open) => (open ? undefined : onClose())}>
|
|
472
|
+
<DialogContent>
|
|
473
|
+
<DialogHeader>
|
|
474
|
+
<DialogTitle>Retire the passport</DialogTitle>
|
|
475
|
+
<DialogDescription>A final state. Nothing can be written after it.</DialogDescription>
|
|
476
|
+
</DialogHeader>
|
|
477
|
+
<form onSubmit={submit} className="space-y-4">
|
|
478
|
+
<Field label="Reason" htmlFor="retire-reason" required>
|
|
479
|
+
<Input id="retire-reason" value={reason} onChange={(e) => setReason(e.target.value)} required maxLength={200} placeholder="Recycled, destroyed, withdrawn" />
|
|
480
|
+
</Field>
|
|
481
|
+
{needsClaimCode ? <ClaimCodeField value={claimCode} onChange={setClaimCode} /> : null}
|
|
482
|
+
{error == null ? null : <ErrorNotice error={error} title="The retirement was refused" />}
|
|
483
|
+
<DialogFooter>
|
|
484
|
+
<Button type="submit" variant="destructive" disabled={busy || reason.trim() === ''}>
|
|
485
|
+
{busy ? 'Working' : 'Retire'}
|
|
486
|
+
</Button>
|
|
487
|
+
</DialogFooter>
|
|
488
|
+
</form>
|
|
489
|
+
</DialogContent>
|
|
490
|
+
</Dialog>
|
|
491
|
+
)
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function ClaimDialog({ passportId, onClose, onDone }: { passportId: string; onClose: () => void; onDone: () => void }) {
|
|
495
|
+
const [eventType, setEventType] = useState<EventType>('Origin')
|
|
496
|
+
const [submitToRegistry, setSubmitToRegistry] = useState(false)
|
|
497
|
+
const [busy, setBusy] = useState(false)
|
|
498
|
+
const [error, setError] = useState<unknown>()
|
|
499
|
+
const [result, setResult] = useState<ClaimView>()
|
|
500
|
+
|
|
501
|
+
async function submit(event: FormEvent) {
|
|
502
|
+
event.preventDefault()
|
|
503
|
+
setBusy(true)
|
|
504
|
+
setError(undefined)
|
|
505
|
+
try {
|
|
506
|
+
const claim = await api.addClaim(passportId, { eventType, ...(submitToRegistry ? { submit: true } : {}) })
|
|
507
|
+
setResult(claim)
|
|
508
|
+
onDone()
|
|
509
|
+
} catch (cause) {
|
|
510
|
+
setError(cause)
|
|
511
|
+
} finally {
|
|
512
|
+
setBusy(false)
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return (
|
|
517
|
+
<Dialog open onOpenChange={(open) => (open ? undefined : onClose())}>
|
|
518
|
+
<DialogContent>
|
|
519
|
+
<DialogHeader>
|
|
520
|
+
<DialogTitle>Add a claim</DialogTitle>
|
|
521
|
+
<DialogDescription>A signed statement about the passport's current state, on its own rail. It never spends the passport.</DialogDescription>
|
|
522
|
+
</DialogHeader>
|
|
523
|
+
{result == null ? (
|
|
524
|
+
<form onSubmit={submit} className="space-y-4">
|
|
525
|
+
<Field label="Event type" htmlFor="claim-event" required>
|
|
526
|
+
<Select value={eventType} onValueChange={(v) => setEventType(v as EventType)}>
|
|
527
|
+
<SelectTrigger id="claim-event" className="w-full">
|
|
528
|
+
<SelectValue />
|
|
529
|
+
</SelectTrigger>
|
|
530
|
+
<SelectContent>
|
|
531
|
+
{EVENT_TYPES.map((t) => (
|
|
532
|
+
<SelectItem key={t} value={t}>
|
|
533
|
+
{t}
|
|
534
|
+
</SelectItem>
|
|
535
|
+
))}
|
|
536
|
+
</SelectContent>
|
|
537
|
+
</Select>
|
|
538
|
+
</Field>
|
|
539
|
+
<label className="flex items-center gap-2 text-sm">
|
|
540
|
+
<input type="checkbox" checked={submitToRegistry} onChange={(e) => setSubmitToRegistry(e.target.checked)} />
|
|
541
|
+
Send to the registry
|
|
542
|
+
</label>
|
|
543
|
+
{error == null ? null : <ErrorNotice error={error} title="The claim was refused" />}
|
|
544
|
+
<DialogFooter>
|
|
545
|
+
<Button type="submit" disabled={busy}>
|
|
546
|
+
{busy ? 'Working' : 'Sign the claim'}
|
|
547
|
+
</Button>
|
|
548
|
+
</DialogFooter>
|
|
549
|
+
</form>
|
|
550
|
+
) : (
|
|
551
|
+
<div className="space-y-4">
|
|
552
|
+
<DefinitionList
|
|
553
|
+
entries={[
|
|
554
|
+
['Claim', <Mono key="id">{result.id}</Mono>],
|
|
555
|
+
['Event', result.claim.eventType],
|
|
556
|
+
['Signature', <ToneBadge key="v" tone={result.verified == null || result.verified === 'verified' ? 'pass' : 'fail'}>{result.verified ?? 'signed'}</ToneBadge>],
|
|
557
|
+
['Registry', <RegistryAnswer key="r" claim={result} />],
|
|
558
|
+
]}
|
|
559
|
+
/>
|
|
560
|
+
<DialogFooter>
|
|
561
|
+
<Button onClick={onClose}>Done</Button>
|
|
562
|
+
</DialogFooter>
|
|
563
|
+
</div>
|
|
564
|
+
)}
|
|
565
|
+
</DialogContent>
|
|
566
|
+
</Dialog>
|
|
567
|
+
)
|
|
568
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The public page a label's QR code opens: /01/<gtin>/21/<serial>. The
|
|
2
|
+
// identifier is the platform's passport host plus this path, which is what
|
|
3
|
+
// the brand minted; in development the API's host may differ from the Vite
|
|
4
|
+
// origin, so the host comes from /api/health before the origin is assumed.
|
|
5
|
+
import { useLocation } from 'react-router'
|
|
6
|
+
import { ErrorNotice, Loading } from '@/components/bits'
|
|
7
|
+
import { ReadPassport } from '@/components/read-passport'
|
|
8
|
+
import { useHealth } from '@/lib/session'
|
|
9
|
+
|
|
10
|
+
export function PublicPassport() {
|
|
11
|
+
const { health, loading, error } = useHealth()
|
|
12
|
+
const location = useLocation()
|
|
13
|
+
|
|
14
|
+
if (loading) return <Loading what="Reading the passport" />
|
|
15
|
+
const host = health?.identifiers.host
|
|
16
|
+
const passportId = host == null || host === '' ? `${window.location.origin}${location.pathname}` : `https://${host}${location.pathname}`
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className="mx-auto max-w-2xl space-y-6">
|
|
20
|
+
{error == null ? null : <ErrorNotice error={error} title="The API is not answering" />}
|
|
21
|
+
<ReadPassport passportId={passportId} />
|
|
22
|
+
</div>
|
|
23
|
+
)
|
|
24
|
+
}
|