Skip to content

Commit e0e5fca

Browse files
committed
refactor(sdk): make-answer-id-required-in-schema
1 parent 09e3971 commit e0e5fca

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@ export enum QuestionType {
3333
export const QuestionTypeSchema = z.nativeEnum(QuestionType);
3434

3535
export const AnswerSchema = z.object({
36-
id: z
37-
.string()
38-
.regex(/^0x[0-9a-fA-F]+$/)
39-
.optional(),
36+
id: z.string().regex(/^0x[0-9a-fA-F]+$/),
4037
title: z.string(),
4138
description: z.string(),
4239
reserved: z.boolean().optional(),
4340
});
4441

42+
export const RefuseToArbitrateAnswer = {
43+
id: "0x0",
44+
title: "Refuse to Arbitrate / Invalid",
45+
description: "Refuse to Arbitrate / Invalid",
46+
reserved: true,
47+
};
48+
4549
export const AttachmentSchema = z.object({
4650
label: z.string(),
4751
uri: z.string(),

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import mustache from "mustache";
22
import { DisputeDetails } from "./disputeDetailsTypes";
3-
import DisputeDetailsSchema from "./disputeDetailsSchema";
3+
import DisputeDetailsSchema, { RefuseToArbitrateAnswer } from "./disputeDetailsSchema";
44

55
export const populateTemplate = (mustacheTemplate: string, data: any): DisputeDetails => {
66
const render = mustache.render(mustacheTemplate, data);
@@ -11,5 +11,11 @@ export const populateTemplate = (mustacheTemplate: string, data: any): DisputeDe
1111
throw validation.error;
1212
}
1313

14+
// Filter out any existing answer with id 0 and add our standard Refuse to Arbitrate option
15+
(dispute as DisputeDetails).answers = [
16+
RefuseToArbitrateAnswer,
17+
...((dispute as DisputeDetails).answers.filter((answer) => answer.id && Number(answer.id) !== 0) || []),
18+
];
19+
1420
return dispute;
1521
};

kleros-sdk/src/utils/getDispute.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,5 @@ export const getDispute = async (disputeParameters: GetDisputeParameters): Promi
5656

5757
const populatedTemplate = populateTemplate(templateData, data);
5858

59-
// Filter out any existing answer with id 0 and add our standard Refuse to Arbitrate option
60-
populatedTemplate.answers = [
61-
{
62-
id: "0x0",
63-
title: "Refuse to Arbitrate / Invalid",
64-
description: "Refuse to Arbitrate / Invalid",
65-
reserved: true,
66-
},
67-
...(populatedTemplate.answers?.filter((answer) => answer.id && Number(answer.id) !== 0) || []),
68-
];
69-
7059
return populatedTemplate;
7160
};

0 commit comments

Comments
 (0)