Skip to content

Commit a3476f8

Browse files
authored
feat: SSRI Demo (#152)
1 parent 20cc1a6 commit a3476f8

11 files changed

+4346
-2378
lines changed

packages/demo/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"dependencies": {
1818
"@lit/react": "^1.0.5",
19+
"@uiw/react-json-view": "2.0.0-alpha.30",
1920
"lucide-react": "^0.427.0",
2021
"next": "14.2.10",
2122
"react": "^18",
@@ -24,6 +25,8 @@
2425
"devDependencies": {
2526
"@ckb-ccc/connector-react": "workspace:*",
2627
"@ckb-ccc/lumos-patches": "workspace:*",
28+
"@ckb-ccc/ssri": "workspace:*",
29+
"@ckb-ccc/udt": "workspace:*",
2730
"@ckb-lumos/ckb-indexer": "^0.24.0-next.1",
2831
"@ckb-lumos/common-scripts": "^0.24.0-next.1",
2932
"@ckb-lumos/config-manager": "^0.24.0-next.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"use client";
2+
3+
import { TextInput } from "@/src/components/Input";
4+
import { Button } from "@/src/components/Button";
5+
6+
7+
interface HexInputProps {
8+
value: string;
9+
onChange: (value: string) => void;
10+
onRemove?: () => void;
11+
label?: string;
12+
placeholder?: string;
13+
}
14+
15+
interface HexArrayInputProps {
16+
value: string[];
17+
onChange: (value: string[]) => void;
18+
label?: string;
19+
}
20+
21+
export const HexInput: React.FC<HexInputProps> = ({
22+
value,
23+
label = "Hex Value",
24+
placeholder = "Enter hex value (with 0x prefix)",
25+
onChange,
26+
onRemove,
27+
}) => {
28+
return (
29+
<div className="flex w-full flex-col gap-2 rounded border p-2">
30+
<TextInput
31+
label={label}
32+
placeholder={placeholder}
33+
state={[
34+
value,
35+
(newValue) => {
36+
// Ensure hex format
37+
const hexValue = newValue.startsWith("0x")
38+
? newValue
39+
: `0x${newValue}`;
40+
onChange(hexValue);
41+
},
42+
]}
43+
className="w-full"
44+
/>
45+
{onRemove && (
46+
<Button
47+
onClick={onRemove}
48+
className="self-start rounded bg-red-500 px-2 py-1 text-white"
49+
>
50+
Remove
51+
</Button>
52+
)}
53+
</div>
54+
);
55+
};
56+
57+
export const HexArrayInput: React.FC<HexArrayInputProps> = ({
58+
value = [],
59+
onChange,
60+
label = "Hex Values",
61+
}) => {
62+
const addHexValue = () => {
63+
onChange([...value, "0x"]);
64+
};
65+
66+
const removeHexValue = (index: number) => {
67+
const newValues = [...value];
68+
newValues.splice(index, 1);
69+
onChange(newValues);
70+
};
71+
72+
const updateHexValue = (index: number, hexValue: string) => {
73+
const newValues = [...value];
74+
newValues[index] = hexValue;
75+
onChange(newValues);
76+
};
77+
78+
return (
79+
<div className="flex flex-col gap-2">
80+
<label className="font-semibold">{label}</label>
81+
{value.map((hexValue, index) => (
82+
<HexInput
83+
key={index}
84+
value={hexValue}
85+
label={`Hex Value ${index + 1}`}
86+
placeholder={`Enter hex value (with 0x prefix)`}
87+
onChange={(updatedValue) => updateHexValue(index, updatedValue)}
88+
onRemove={() => removeHexValue(index)}
89+
/>
90+
))}
91+
<Button
92+
onClick={addHexValue}
93+
className="self-start rounded bg-green-500 px-2 py-1 text-white"
94+
>
95+
Add Hex Value
96+
</Button>
97+
</div>
98+
);
99+
};

0 commit comments

Comments
 (0)