Skip to content

Commit fc3d4ca

Browse files
committed
feat: allow choosing the disputekit in the resolver flow
1 parent c055621 commit fc3d4ca

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

web/src/context/NewDisputeContext.tsx

Lines changed: 3 additions & 1 deletion
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);

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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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";
@@ -14,6 +14,7 @@ import { StyledSkeleton } from "components/StyledSkeleton";
1414
import Header from "pages/Resolver/Header";
1515

1616
import NavigationButtons from "../NavigationButtons";
17+
import { isKlerosNeo, isKlerosUniversity, isTestnetDeployment } from "src/consts";
1718

1819
const Container = styled.div`
1920
display: flex;
@@ -49,28 +50,56 @@ const AlertMessageContainer = styled.div`
4950
margin-top: 24px;
5051
`;
5152

53+
const StyledDropdownSelect = styled(DropdownSelect)`
54+
width: 84vw;
55+
margin-top: 24px;
56+
${landscapeStyle(
57+
() => css`
58+
width: ${responsiveSize(442, 700, 900)};
59+
`
60+
)}
61+
`;
62+
5263
const Court: React.FC = () => {
5364
const { disputeData, setDisputeData } = useNewDisputeContext();
5465
const { data } = useCourtTree();
5566
const items = useMemo(() => !isUndefined(data?.court) && [rootCourtToItems(data.court)], [data]);
5667

57-
const handleWrite = (courtId: string) => {
58-
setDisputeData({ ...disputeData, courtId: courtId });
68+
const disputeKitOptions = useMemo(() => {
69+
if (isKlerosUniversity()) return [{ text: "Classic Dispute Kit", value: 1 }];
70+
if (isKlerosNeo()) return [{ text: "Classic Dispute Kit", value: 1 }];
71+
if (isTestnetDeployment()) return [{ text: "Classic Dispute Kit", value: 1 }];
72+
const options = [{ text: "Classic Dispute Kit", value: 1 }];
73+
if (disputeData.courtId === "1") options.push({ text: "Shutter Dispute Kit", value: 2 });
74+
return options;
75+
}, [disputeData.courtId]);
76+
77+
const handleCourtWrite = (courtId: string) => {
78+
const newDisputeKitId = courtId === "1" ? (disputeData.disputeKitId ?? 1) : 1;
79+
setDisputeData({ ...disputeData, courtId, disputeKitId: newDisputeKitId });
5980
};
6081

82+
const handleDisputeKitChange = (newValue: string | number) =>
83+
setDisputeData({ ...disputeData, disputeKitId: Number(newValue) });
84+
6185
return (
6286
<Container>
6387
<Header text="Select a court to arbitrate the case" />
6488
{items ? (
6589
<StyledDropdownCascader
6690
items={items}
67-
onSelect={(path: string | number) => typeof path === "string" && handleWrite(path.split("/").pop()!)}
91+
onSelect={(path: string | number) => typeof path === "string" && handleCourtWrite(path.split("/").pop()!)}
6892
placeholder="Select Court"
6993
value={`/courts/${disputeData.courtId}`}
7094
/>
7195
) : (
7296
<StyledSkeleton width={240} height={42} />
7397
)}
98+
<StyledDropdownSelect
99+
defaultValue={disputeData.disputeKitId ?? 1}
100+
items={disputeKitOptions}
101+
callback={handleDisputeKitChange}
102+
/>
74103
<AlertMessageContainer>
75104
<AlertMessage
76105
title="Check the courts available beforehand"
@@ -82,4 +111,5 @@ const Court: React.FC = () => {
82111
</Container>
83112
);
84113
};
114+
85115
export default Court;

0 commit comments

Comments
 (0)