@@ -6,13 +6,16 @@ import { usePublicClient } from "wagmi";
66import { Button } from "@kleros/ui-components-library" ;
77
88import { useSimulateKlerosCoreDraw , useWriteKlerosCoreDraw } from "hooks/contracts/generated" ;
9+ import { useSortitionModulePhase } from "hooks/useSortitionModulePhase" ;
910import { wrapWithToast } from "utils/wrapWithToast" ;
1011
1112import useDisputeMaintenanceQuery from "queries/useDisputeMaintenanceQuery" ;
1213
1314import { Period } from "src/graphql/graphql" ;
1415import { isUndefined } from "src/utils" ;
1516
17+ import { Phases } from "components/Phase" ;
18+
1619import { IBaseMaintenanceButton } from "." ;
1720
1821const StyledButton = styled ( Button ) `
@@ -28,21 +31,22 @@ const DrawButton: React.FC<IDrawButton> = ({ id, numberOfVotes, setIsOpen, perio
2831 const [ isSending , setIsSending ] = useState ( false ) ;
2932 const publicClient = usePublicClient ( ) ;
3033 const { data : maintenanceData } = useDisputeMaintenanceQuery ( id ) ;
34+ const { data : phase } = useSortitionModulePhase ( ) ;
3135
3236 const isDrawn = useMemo ( ( ) => maintenanceData ?. dispute ?. currentRound . jurorsDrawn , [ maintenanceData ] ) ;
3337
38+ const canDraw = useMemo (
39+ ( ) => ! isUndefined ( maintenanceData ) && ! isDrawn && period === Period . Evidence && phase === Phases . drawing ,
40+ [ maintenanceData , isDrawn , phase , period ]
41+ ) ;
42+
3443 const {
3544 data : drawConfig ,
3645 isLoading : isLoadingConfig ,
3746 isError,
3847 } = useSimulateKlerosCoreDraw ( {
3948 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 ,
4650 } ,
4751 args : [ BigInt ( id ?? 0 ) , BigInt ( numberOfVotes ?? 0 ) ] ,
4852 } ) ;
@@ -51,9 +55,8 @@ const DrawButton: React.FC<IDrawButton> = ({ id, numberOfVotes, setIsOpen, perio
5155
5256 const isLoading = useMemo ( ( ) => isLoadingConfig || isSending , [ isLoadingConfig , isSending ] ) ;
5357 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 ]
5760 ) ;
5861 const handleClick = ( ) => {
5962 if ( ! drawConfig || ! publicClient ) return ;
0 commit comments