forked from Dshield-xyz/Dshield
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThresholdDisclosure.tsx
More file actions
72 lines (68 loc) · 2.43 KB
/
Copy pathThresholdDisclosure.tsx
File metadata and controls
72 lines (68 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { useState } from "react";
import { ShieldedNote } from "@/lib/notes";
import { generateThresholdProof } from "@/lib/prover";
import { Button } from "@/components/ui/Button";
import { useToast } from "@/components/ui/Toast";
interface Props {
notes: ShieldedNote[];
}
export default function ThresholdDisclosure({ notes }: Props) {
const [selectedNote, setSelectedNote] = useState<ShieldedNote | null>(null);
const [threshold, setThreshold] = useState<string>("");
const [proof, setProof] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const { toast } = useToast();
async function handleGenerate() {
if (!selectedNote || !threshold) return;
setLoading(true);
try {
const result = await generateThresholdProof(selectedNote, threshold);
setProof(JSON.stringify(result, null, 2));
toast("Threshold proof generated", "success");
} catch (e) {
toast(`Error: ${e}`, "error");
} finally {
setLoading(false);
}
}
return (
<div className="p-4 glassmorphism rounded-xl backdrop-blur-sm">
<h2 className="mb-4 text-xl font-semibold">Threshold Disclosure</h2>
<div className="mb-4">
<label className="block text-sm font-medium mb-1">Select Note</label>
<select
className="w-full rounded border p-2"
value={selectedNote?.commitment ?? ""}
onChange={(e) => {
const note = notes.find((n) => n.commitment === e.target.value);
setSelectedNote(note ?? null);
}}
>
<option value="">-- Choose a note --</option>
{notes.map((note) => (
<option key={note.commitment} value={note.commitment}>
{note.commitment.slice(0, 12)}…
</option>
))}
</select>
</div>
<div className="mb-4">
<label className="block text-sm font-medium mb-1">Threshold (e.g., 1000)</label>
<input
type="text"
className="w-full rounded border p-2"
value={threshold}
onChange={(e) => setThreshold(e.target.value)}
/>
</div>
<Button onClick={handleGenerate} disabled={loading || !selectedNote || !threshold}>
{loading ? "Generating…" : "Generate Proof"}
</Button>
{proof && (
<pre className="mt-4 max-h-64 overflow-auto rounded bg-zinc-900 p-2 text-xs text-green-400">
{proof}
</pre>
)}
</div>
);
}