Skip to content

Commit 9b3c9ab

Browse files
authored
Merge pull request #1987 from kleros/feat/choose-dispute-kit-in-dispute-resolver
feat: allow choosing the disputekit in the resolver flow
2 parents 3507ef2 + 0c96fa2 commit 9b3c9ab

File tree

5 files changed

+83
-10
lines changed

5 files changed

+83
-10
lines changed

web/src/consts/index.ts

+12
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,15 @@ export const INVALID_DISPUTE_DATA_ERROR = `The dispute data is not valid, please
4242
export const RPC_ERROR = `RPC Error: Unable to fetch dispute data. Please avoid voting.`;
4343

4444
export const spamEvidencesIds: string[] = (import.meta.env.REACT_APP_SPAM_EVIDENCES_IDS ?? "").split(",");
45+
46+
export const getDisputeKitName = (id: number): string | undefined => {
47+
const universityDisputeKits: Record<number, string> = { 1: "Classic Dispute Kit" };
48+
const neoDisputeKits: Record<number, string> = { 1: "Classic Dispute Kit" };
49+
const testnetDisputeKits: Record<number, string> = { 1: "Classic Dispute Kit" };
50+
const devnetDisputeKits: Record<number, string> = { 1: "Classic Dispute Kit", 2: "Shutter Dispute Kit" };
51+
52+
if (isKlerosUniversity()) return universityDisputeKits[id];
53+
if (isKlerosNeo()) return neoDisputeKits[id];
54+
if (isTestnetDeployment()) return testnetDisputeKits[id];
55+
return devnetDisputeKits[id];
56+
};

web/src/context/NewDisputeContext.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ interface IDisputeData extends IDisputeTemplate {
4747
numberOfJurors: number;
4848
arbitrationCost?: string;
4949
aliasesArray?: AliasArray[];
50+
disputeKitId?: number;
5051
}
5152

5253
interface INewDisputeContext {
@@ -71,6 +72,7 @@ const getInitialDisputeData = (): IDisputeData => ({
7172
{ title: "", id: "2", description: "" },
7273
],
7374
aliasesArray: [{ name: "", address: "", id: "1" }],
75+
disputeKitId: 1,
7476
version: "1.0",
7577
});
7678

@@ -117,7 +119,7 @@ export const NewDisputeProvider: React.FC<{ children: React.ReactNode }> = ({ ch
117119

118120
const constructDisputeTemplate = (disputeData: IDisputeData) => {
119121
// eslint-disable-next-line @typescript-eslint/no-unused-vars
120-
const { courtId, numberOfJurors, arbitrationCost, ...baseTemplate } = disputeData;
122+
const { courtId, numberOfJurors, arbitrationCost, disputeKitId, ...baseTemplate } = disputeData;
121123

122124
if (!isUndefined(baseTemplate.aliasesArray)) {
123125
baseTemplate.aliasesArray = baseTemplate.aliasesArray.filter((item) => item.address !== "" && item.isValid);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
import { useGraphqlBatcher } from "context/GraphqlBatcher";
3+
import { graphql } from "src/graphql";
4+
import { SupportedDisputeKitsQuery } from "src/graphql/graphql";
5+
6+
const supportedDisputeKitsQuery = graphql(`
7+
query SupportedDisputeKits($id: ID!) {
8+
court(id: $id) {
9+
supportedDisputeKits {
10+
id
11+
}
12+
}
13+
}
14+
`);
15+
16+
export const useSupportedDisputeKits = (courtId?: string) => {
17+
const { graphqlBatcher } = useGraphqlBatcher();
18+
return useQuery<SupportedDisputeKitsQuery>({
19+
enabled: !!courtId,
20+
queryKey: ["SupportedDisputeKits", courtId],
21+
staleTime: Infinity,
22+
queryFn: async () =>
23+
await graphqlBatcher.fetch({
24+
id: crypto.randomUUID(),
25+
document: supportedDisputeKitsQuery,
26+
variables: { id: courtId },
27+
}),
28+
});
29+
};

web/src/pages/Resolver/NavigationButtons/SubmitDisputeButton.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ const SubmitDisputeButton: React.FC = () => {
4242
return userBalance && userBalance.value < arbitrationCost;
4343
}, [userBalance, disputeData]);
4444

45-
// TODO: decide which dispute kit to use
4645
const { data: submitCaseConfig, error } = useSimulateDisputeResolverCreateDisputeForTemplate({
4746
query: {
4847
enabled: !insufficientBalance && isTemplateValid(disputeTemplate),
4948
},
5049
args: [
51-
prepareArbitratorExtradata(disputeData.courtId ?? "1", disputeData.numberOfJurors ?? "", 1),
50+
prepareArbitratorExtradata(
51+
disputeData.courtId ?? "1",
52+
disputeData.numberOfJurors ?? "",
53+
disputeData.disputeKitId ?? 1
54+
),
5255
JSON.stringify(disputeTemplate),
5356
"",
5457
BigInt(disputeTemplate.answers.length),

web/src/pages/Resolver/Parameters/Court.tsx

+34-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React, { useMemo } from "react";
22
import styled, { css } from "styled-components";
33

4-
import { AlertMessage, DropdownCascader } from "@kleros/ui-components-library";
4+
import { AlertMessage, DropdownCascader, DropdownSelect } from "@kleros/ui-components-library";
55

66
import { useNewDisputeContext } from "context/NewDisputeContext";
77
import { rootCourtToItems, useCourtTree } from "hooks/queries/useCourtTree";
8+
import { useSupportedDisputeKits } from "queries/useSupportedDisputeKits";
9+
import { getDisputeKitName } from "consts/index";
810
import { isUndefined } from "utils/index";
911

1012
import { landscapeStyle } from "styles/landscapeStyle";
@@ -49,28 +51,52 @@ const AlertMessageContainer = styled.div`
4951
margin-top: 24px;
5052
`;
5153

54+
const StyledDropdownSelect = styled(DropdownSelect)`
55+
width: 84vw;
56+
margin-top: 24px;
57+
${landscapeStyle(
58+
() => css`
59+
width: ${responsiveSize(442, 700, 900)};
60+
`
61+
)}
62+
`;
63+
5264
const Court: React.FC = () => {
5365
const { disputeData, setDisputeData } = useNewDisputeContext();
54-
const { data } = useCourtTree();
55-
const items = useMemo(() => !isUndefined(data?.court) && [rootCourtToItems(data.court)], [data]);
56-
57-
const handleWrite = (courtId: string) => {
58-
setDisputeData({ ...disputeData, courtId: courtId });
66+
const { data: courtTree } = useCourtTree();
67+
const { data: supportedDisputeKits } = useSupportedDisputeKits(disputeData.courtId);
68+
const items = useMemo(() => !isUndefined(courtTree?.court) && [rootCourtToItems(courtTree.court)], [courtTree]);
69+
const disputeKitOptions = useMemo(() => {
70+
const supportedDisputeKitIDs = supportedDisputeKits?.court?.supportedDisputeKits.map((k) => Number(k.id)) || [];
71+
return supportedDisputeKitIDs.map((id) => ({ text: getDisputeKitName(id), value: id }));
72+
}, [supportedDisputeKits]);
73+
const handleCourtWrite = (courtId: string) => {
74+
setDisputeData({ ...disputeData, courtId, disputeKitId: undefined });
5975
};
6076

77+
const handleDisputeKitChange = (newValue: string | number) =>
78+
setDisputeData({ ...disputeData, disputeKitId: Number(newValue) });
79+
6180
return (
6281
<Container>
6382
<Header text="Select a court to arbitrate the case" />
6483
{items ? (
6584
<StyledDropdownCascader
6685
items={items}
67-
onSelect={(path: string | number) => typeof path === "string" && handleWrite(path.split("/").pop()!)}
86+
onSelect={(path: string | number) => typeof path === "string" && handleCourtWrite(path.split("/").pop()!)}
6887
placeholder="Select Court"
6988
value={`/courts/${disputeData.courtId}`}
7089
/>
7190
) : (
7291
<StyledSkeleton width={240} height={42} />
7392
)}
93+
<StyledDropdownSelect
94+
items={disputeKitOptions}
95+
disabled={!disputeData.courtId}
96+
placeholder={{ text: "Select Dispute Kit" }}
97+
defaultValue={disputeData.disputeKitId ?? 1}
98+
callback={handleDisputeKitChange}
99+
/>
74100
<AlertMessageContainer>
75101
<AlertMessage
76102
title="Check the courts available beforehand"
@@ -82,4 +108,5 @@ const Court: React.FC = () => {
82108
</Container>
83109
);
84110
};
111+
85112
export default Court;

0 commit comments

Comments
 (0)