@@ -3,10 +3,10 @@ import styled from "styled-components";
3
3
4
4
import { usePublicClient } from "wagmi" ;
5
5
6
- import { Button } from "@kleros/ui-components-library" ;
6
+ import { Button , Field } from "@kleros/ui-components-library" ;
7
7
8
8
import { useSimulateKlerosCoreDraw , useWriteKlerosCoreDraw } from "hooks/contracts/generated" ;
9
- import { useSortitionModulePhase } from "hooks/useSortitionModulePhase " ;
9
+ import { useSortitionModulePhase } from "hooks/useSortitionModule " ;
10
10
import { wrapWithToast } from "utils/wrapWithToast" ;
11
11
12
12
import useDisputeMaintenanceQuery from "queries/useDisputeMaintenanceQuery" ;
@@ -18,6 +18,8 @@ import { Phases } from "components/Phase";
18
18
19
19
import { IBaseMaintenanceButton } from "." ;
20
20
import { Link } from "react-router-dom" ;
21
+ import { isKlerosUniversity } from "src/consts" ;
22
+ import { isAddress } from "viem" ;
21
23
22
24
const StyledButton = styled ( Button ) `
23
25
width: 100%;
@@ -29,17 +31,24 @@ interface IDrawButton extends IBaseMaintenanceButton {
29
31
period ?: string ;
30
32
}
31
33
34
+ const isUniversity = isKlerosUniversity ( ) ;
35
+
32
36
const DrawButton : React . FC < IDrawButton > = ( { id, numberOfVotes, setIsOpen, period } ) => {
33
- const [ isSending , setIsSending ] = useState ( false ) ;
34
37
const publicClient = usePublicClient ( ) ;
35
38
const { data : maintenanceData } = useDisputeMaintenanceQuery ( id ) ;
36
39
const { data : phase } = useSortitionModulePhase ( ) ;
40
+ const [ isSending , setIsSending ] = useState ( false ) ;
41
+ const [ drawJuror , setDrawJuror ] = useState ( "" ) ;
37
42
38
43
const isDrawn = useMemo ( ( ) => maintenanceData ?. dispute ?. currentRound . jurorsDrawn , [ maintenanceData ] ) ;
39
44
40
45
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 ]
43
52
) ;
44
53
45
54
const needToPassPhase = useMemo (
@@ -53,17 +62,30 @@ const DrawButton: React.FC<IDrawButton> = ({ id, numberOfVotes, setIsOpen, perio
53
62
isError,
54
63
} = useSimulateKlerosCoreDraw ( {
55
64
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 ) ,
57
71
} ,
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 ) ] ,
59
75
} ) ;
60
76
61
77
const { writeContractAsync : draw } = useWriteKlerosCoreDraw ( ) ;
62
78
63
79
const isLoading = useMemo ( ( ) => isLoadingConfig || isSending , [ isLoadingConfig , isSending ] ) ;
64
80
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 ]
67
89
) ;
68
90
const handleClick = ( ) => {
69
91
if ( ! drawConfig || ! publicClient ) return ;
@@ -77,12 +99,15 @@ const DrawButton: React.FC<IDrawButton> = ({ id, numberOfVotes, setIsOpen, perio
77
99
} ;
78
100
return (
79
101
< >
80
- { needToPassPhase ? (
102
+ { needToPassPhase && ! isUniversity ? (
81
103
< StyledLabel >
82
104
Jurors can be drawn in < small > drawing</ small > phase.
83
105
< br /> Pass phase < Link to = "/courts/1/purpose/#maintenance" > here</ Link > .
84
106
</ StyledLabel >
85
107
) : null }
108
+ { isUniversity && canDraw ? (
109
+ < Field placeholder = "Juror Address" onChange = { ( e ) => setDrawJuror ( e . target . value ) } value = { drawJuror } />
110
+ ) : null }
86
111
< StyledButton text = "Draw" small isLoading = { isLoading } disabled = { isDisabled } onClick = { handleClick } />
87
112
</ >
88
113
) ;
0 commit comments