Skip to content

Commit 48a757f

Browse files
feat(web-devtools): custom-context-input
1 parent 3a6d207 commit 48a757f

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

kleros-sdk/src/dataMappings/utils/disputeDetailsSchema.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { normalize } from "viem/ens";
55
export const isHexAddress = (str: string): boolean => /^0x[a-fA-F0-9]{40}$/.test(str);
66
export const isHexId = (str: string): boolean => /^0x[a-fA-F0-9]{1,64}$/.test(str);
77
export const isMultiaddr = (str: string): boolean =>
8-
/^\/(?:ip4|ip6|dns4|dns6|dnsaddr|tcp|udp|utp|tls|ws|wss|p2p-circuit|p2p-webrtc-star|p2p-webrtc-direct|p2p-websocket-star|onion|ipfs)(\/[^\s\/]+)+$|^ipfs:\/\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)?$/.test(
8+
/^\/(?:ip4|ip6|dns4|dns6|dnsaddr|tcp|udp|utp|tls|ws|wss|p2p-circuit|p2p-webrtc-star|p2p-webrtc-direct|p2p-websocket-star|onion)(\/[^\s\/]+)+$|^ipfs:\/\/[a-zA-Z0-9]+(\/[^\s]*)?$/.test(
99
str
1010
);
1111

@@ -56,9 +56,7 @@ const DisputeDetailsSchema = z.object({
5656
description: z.string(),
5757
question: z.string(),
5858
answers: z.array(AnswerSchema),
59-
policyURI: z.string().refine((value) => isMultiaddr(value), {
60-
message: "Provided policy URI is not a valid multiaddr.",
61-
}),
59+
policyURI: z.string(),
6260
attachment: AttachmentSchema.optional(),
6361
frontendUrl: z.string().optional(),
6462
metadata: MetadataSchema.optional(),

web-devtools/src/app/(main)/dispute-template/FetchDisputeRequestInput.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ const StyledA = styled.a`
4646
const presets = [
4747
{
4848
title: "Escrow",
49-
txnHash: "0x85e60cb407c9a38e625263cc762ff4283d01f38201825e1d20109d8664cfa7d4",
49+
txnHash: "0x2565b756e500240544f7fc36f938462c7efbbd2e343c57979f81fecdf1054e23",
5050
chainId: 421614,
5151
},
5252
{
5353
title: "Curated Lists",
54-
txnHash: "0x6e5ad6f7436ef8570b50b0fbec76a11ccedbed85030c670e59d8f6617a499108",
54+
txnHash: "0xa7981830bf8144ab2070f3a639bd36b204c4c48ee1fafef66abaf60272418ed4",
5555
chainId: 421614,
5656
},
5757
{
5858
title: "Trump-Biden",
59-
txnHash: "0x9a3a420174f3c55c2b3eb2e77266777b74028b845e528a90142b5b57aafbdb90",
59+
txnHash: "0x83934c07f6476b2fd8c43cf856819134a58c007cb6938c6990fb3058b243ba0c",
6060
chainId: 421614,
6161
},
6262
];

web-devtools/src/app/(main)/dispute-template/page.tsx

+26-2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ const UpperContainer = styled.div`
105105
`
106106
)}
107107
`;
108+
109+
const StyledJSONEditor = styled(JSONEditor)`
110+
height: 300px;
111+
width: 100%;
112+
`;
108113
const StyledForm = styled.form`
109114
display: flex;
110115
flex-direction: column;
@@ -150,6 +155,7 @@ const DisputeTemplateView = () => {
150155
const [disputeDetails, setDisputeDetails] = useState<DisputeDetails | undefined>(undefined);
151156
const [disputeTemplateInput, setDisputeTemplateInput] = useState<string>("");
152157
const [dataMappingsInput, setDataMappingsInput] = useState<string>("");
158+
const [customContextInput, setCustomContextInput] = useState<string>("{}");
153159

154160
const [params, setParams] = useState<DisputeRequest>({
155161
_arbitrable: "0x10f7A6f42Af606553883415bc8862643A6e63fdA",
@@ -178,7 +184,13 @@ const DisputeTemplateView = () => {
178184
setLoading(true);
179185

180186
setTimeout(() => {
181-
const initialContext = {
187+
let customContext = null;
188+
try {
189+
customContext = JSON.parse(customContextInput);
190+
} catch (error) {
191+
console.log("Error parsing custom context", error);
192+
}
193+
let initialContext = {
182194
arbitrator: debouncedParams._arbitrator,
183195
arbitrable: debouncedParams._arbitrable,
184196
arbitratorDisputeID: debouncedParams._arbitratorDisputeID,
@@ -187,6 +199,8 @@ const DisputeTemplateView = () => {
187199
templateUri: debouncedParams._templateUri,
188200
};
189201

202+
if (customContext) initialContext = { ...initialContext, ...customContext };
203+
190204
const fetchData = async () => {
191205
try {
192206
const data = dataMappingsInput ? await executeActions(JSON.parse(dataMappingsInput), initialContext) : {};
@@ -210,7 +224,7 @@ const DisputeTemplateView = () => {
210224
if (disputeTemplateInput || dataMappingsInput || debouncedParams) {
211225
scheduleFetchData();
212226
}
213-
}, [disputeTemplateInput, dataMappingsInput, debouncedParams]);
227+
}, [disputeTemplateInput, dataMappingsInput, debouncedParams, customContextInput]);
214228

215229
return (
216230
<>
@@ -280,6 +294,16 @@ const DisputeTemplateView = () => {
280294
placeholder="ipfs://... (optional)"
281295
/>
282296
</StyledRow>
297+
<StyledRow>
298+
<StyledP>{"Custom Context :"}</StyledP>
299+
<StyledJSONEditor
300+
content={{ text: customContextInput }}
301+
mode={Mode.text}
302+
onChange={(val: any) => {
303+
setCustomContextInput(val.text);
304+
}}
305+
/>
306+
</StyledRow>
283307
</StyledForm>
284308
<div>
285309
<FetchFromIDInput

web-devtools/src/components/JSONEditor.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ const JSONEditor = (props: any) => {
5959
}
6060
}, [props]);
6161

62-
return <Container ref={refContainer}></Container>;
62+
return <Container ref={refContainer} className={props.className}></Container>;
6363
};
6464
export default JSONEditor;

0 commit comments

Comments
 (0)