Skip to content

Commit 6ee1d71

Browse files
committed
chore(web): update-draw-juror-button-for-university-court
1 parent 1d3969e commit 6ee1d71

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styled from "styled-components";
33

44
import { usePublicClient } from "wagmi";
55

6-
import { Button } from "@kleros/ui-components-library";
6+
import { Button, Field } from "@kleros/ui-components-library";
77

88
import { useSimulateKlerosCoreDraw, useWriteKlerosCoreDraw } from "hooks/contracts/generated";
99
import { useSortitionModulePhase } from "hooks/useSortitionModule";
@@ -18,6 +18,8 @@ import { Phases } from "components/Phase";
1818

1919
import { IBaseMaintenanceButton } from ".";
2020
import { Link } from "react-router-dom";
21+
import { isKlerosUniversity } from "src/consts";
22+
import { isAddress } from "viem";
2123

2224
const StyledButton = styled(Button)`
2325
width: 100%;
@@ -29,17 +31,24 @@ interface IDrawButton extends IBaseMaintenanceButton {
2931
period?: string;
3032
}
3133

34+
const isUniversity = isKlerosUniversity();
35+
3236
const DrawButton: React.FC<IDrawButton> = ({ id, numberOfVotes, setIsOpen, period }) => {
33-
const [isSending, setIsSending] = useState(false);
3437
const publicClient = usePublicClient();
3538
const { data: maintenanceData } = useDisputeMaintenanceQuery(id);
3639
const { data: phase } = useSortitionModulePhase();
40+
const [isSending, setIsSending] = useState(false);
41+
const [drawJuror, setDrawJuror] = useState("");
3742

3843
const isDrawn = useMemo(() => maintenanceData?.dispute?.currentRound.jurorsDrawn, [maintenanceData]);
3944

4045
const canDraw = useMemo(
41-
() => !isUndefined(maintenanceData) && !isDrawn && period === Period.Evidence && phase === Phases.drawing,
42-
[maintenanceData, isDrawn, phase, period]
46+
() =>
47+
!isUndefined(maintenanceData) &&
48+
!isDrawn &&
49+
period === Period.Evidence &&
50+
(isUniversity ? true : phase === Phases.drawing),
51+
[maintenanceData, isDrawn, phase, period, isUniversity]
4352
);
4453

4554
const needToPassPhase = useMemo(
@@ -53,17 +62,30 @@ const DrawButton: React.FC<IDrawButton> = ({ id, numberOfVotes, setIsOpen, perio
5362
isError,
5463
} = useSimulateKlerosCoreDraw({
5564
query: {
56-
enabled: !isUndefined(id) && !isUndefined(numberOfVotes) && !isUndefined(period) && canDraw,
65+
enabled:
66+
!isUndefined(id) &&
67+
!isUndefined(numberOfVotes) &&
68+
!isUndefined(period) &&
69+
canDraw &&
70+
(isUniversity ? isAddress(drawJuror) : true),
5771
},
58-
args: [BigInt(id ?? 0), BigInt(numberOfVotes ?? 0)],
72+
// eslint-disable-next-line
73+
// @ts-ignore
74+
args: [BigInt(id ?? 0), isUniversity ? drawJuror : BigInt(numberOfVotes ?? 0)],
5975
});
6076

6177
const { writeContractAsync: draw } = useWriteKlerosCoreDraw();
6278

6379
const isLoading = useMemo(() => isLoadingConfig || isSending, [isLoadingConfig, isSending]);
6480
const isDisabled = useMemo(
65-
() => isUndefined(id) || isUndefined(numberOfVotes) || isError || isLoading || !canDraw,
66-
[id, numberOfVotes, isError, isLoading, canDraw]
81+
() =>
82+
isUndefined(id) ||
83+
isUndefined(numberOfVotes) ||
84+
isError ||
85+
isLoading ||
86+
!canDraw ||
87+
(isUniversity && !isAddress(drawJuror)),
88+
[id, numberOfVotes, isError, isLoading, canDraw, isUniversity, drawJuror]
6789
);
6890
const handleClick = () => {
6991
if (!drawConfig || !publicClient) return;
@@ -77,12 +99,15 @@ const DrawButton: React.FC<IDrawButton> = ({ id, numberOfVotes, setIsOpen, perio
7799
};
78100
return (
79101
<>
80-
{needToPassPhase ? (
102+
{needToPassPhase && !isUniversity ? (
81103
<StyledLabel>
82104
Jurors can be drawn in <small>drawing</small> phase.
83105
<br /> Pass phase <Link to="/courts/1/purpose/#maintenance">here</Link>.
84106
</StyledLabel>
85107
) : null}
108+
{isUniversity && canDraw ? (
109+
<Field placeholder="Juror Address" onChange={(e) => setDrawJuror(e.target.value)} value={drawJuror} />
110+
) : null}
86111
<StyledButton text="Draw" small isLoading={isLoading} disabled={isDisabled} onClick={handleClick} />
87112
</>
88113
);

0 commit comments

Comments
 (0)