@@ -6,13 +6,16 @@ import { usePublicClient } from "wagmi";
6
6
import { Button } from "@kleros/ui-components-library" ;
7
7
8
8
import { useSimulateKlerosCoreDraw , useWriteKlerosCoreDraw } from "hooks/contracts/generated" ;
9
+ import { useSortitionModulePhase } from "hooks/useSortitionModulePhase" ;
9
10
import { wrapWithToast } from "utils/wrapWithToast" ;
10
11
11
12
import useDisputeMaintenanceQuery from "queries/useDisputeMaintenanceQuery" ;
12
13
13
14
import { Period } from "src/graphql/graphql" ;
14
15
import { isUndefined } from "src/utils" ;
15
16
17
+ import { Phases } from "components/Phase" ;
18
+
16
19
import { IBaseMaintenanceButton } from "." ;
17
20
18
21
const StyledButton = styled ( Button ) `
@@ -28,21 +31,22 @@ const DrawButton: React.FC<IDrawButton> = ({ id, numberOfVotes, setIsOpen, perio
28
31
const [ isSending , setIsSending ] = useState ( false ) ;
29
32
const publicClient = usePublicClient ( ) ;
30
33
const { data : maintenanceData } = useDisputeMaintenanceQuery ( id ) ;
34
+ const { data : phase } = useSortitionModulePhase ( ) ;
31
35
32
36
const isDrawn = useMemo ( ( ) => maintenanceData ?. dispute ?. currentRound . jurorsDrawn , [ maintenanceData ] ) ;
33
37
38
+ const canDraw = useMemo (
39
+ ( ) => ! isUndefined ( maintenanceData ) && ! isDrawn && period === Period . Evidence && phase === Phases . drawing ,
40
+ [ maintenanceData , isDrawn , phase , period ]
41
+ ) ;
42
+
34
43
const {
35
44
data : drawConfig ,
36
45
isLoading : isLoadingConfig ,
37
46
isError,
38
47
} = useSimulateKlerosCoreDraw ( {
39
48
query : {
40
- enabled :
41
- ! isUndefined ( id ) &&
42
- ! isUndefined ( numberOfVotes ) &&
43
- ! isUndefined ( period ) &&
44
- period === Period . Evidence &&
45
- ! isDrawn ,
49
+ enabled : ! isUndefined ( id ) && ! isUndefined ( numberOfVotes ) && ! isUndefined ( period ) && canDraw ,
46
50
} ,
47
51
args : [ BigInt ( id ?? 0 ) , BigInt ( numberOfVotes ?? 0 ) ] ,
48
52
} ) ;
@@ -51,9 +55,8 @@ const DrawButton: React.FC<IDrawButton> = ({ id, numberOfVotes, setIsOpen, perio
51
55
52
56
const isLoading = useMemo ( ( ) => isLoadingConfig || isSending , [ isLoadingConfig , isSending ] ) ;
53
57
const isDisabled = useMemo (
54
- ( ) =>
55
- isUndefined ( id ) || isUndefined ( numberOfVotes ) || isError || isLoading || period !== Period . Evidence || isDrawn ,
56
- [ id , numberOfVotes , isError , isLoading , period , isDrawn ]
58
+ ( ) => isUndefined ( id ) || isUndefined ( numberOfVotes ) || isError || isLoading || ! canDraw ,
59
+ [ id , numberOfVotes , isError , isLoading , canDraw ]
57
60
) ;
58
61
const handleClick = ( ) => {
59
62
if ( ! drawConfig || ! publicClient ) return ;
0 commit comments