@@ -3,10 +3,16 @@ import React, { useContext, createContext, useMemo } from "react";
33import { useParams } from "react-router-dom" ;
44import { useAccount } from "wagmi" ;
55
6- import { REFETCH_INTERVAL } from "consts/index" ;
7- import { useReadDisputeKitClassicIsVoteActive } from "hooks/contracts/generated" ;
6+ import { REFETCH_INTERVAL , DisputeKits } from "consts/index" ;
7+ import {
8+ useReadDisputeKitClassicIsVoteActive ,
9+ useReadDisputeKitShutterIsVoteActive ,
10+ useReadDisputeKitGatedIsVoteActive ,
11+ useReadDisputeKitGatedShutterIsVoteActive ,
12+ } from "hooks/contracts/generated" ;
813import { useDisputeDetailsQuery } from "hooks/queries/useDisputeDetailsQuery" ;
914import { useDrawQuery } from "hooks/queries/useDrawQuery" ;
15+ import { useDisputeKitAddresses } from "hooks/useDisputeKitAddresses" ;
1016import { isUndefined } from "utils/index" ;
1117
1218interface IVotingContext {
@@ -35,29 +41,74 @@ export const VotingContextProvider: React.FC<{ children: React.ReactNode }> = ({
3541 const { data : drawData , isLoading } = useDrawQuery ( address ?. toLowerCase ( ) , id , disputeData ?. dispute ?. currentRound . id ) ;
3642 const roundId = disputeData ?. dispute ?. currentRoundIndex ;
3743 const voteId = drawData ?. draws ?. [ 0 ] ?. voteIDNum ;
38- const { data : hasVotedClassic } = useReadDisputeKitClassicIsVoteActive ( {
44+
45+ const disputeKitAddress = disputeData ?. dispute ?. currentRound ?. disputeKit ?. address ;
46+ const { disputeKitName } = useDisputeKitAddresses ( { disputeKitAddress } ) ;
47+
48+ const hookArgs = [ BigInt ( id ?? 0 ) , roundId , voteId ] as const ;
49+ const isEnabled = ! isUndefined ( roundId ) && ! isUndefined ( voteId ) ;
50+
51+ // Only call the hook for the specific dispute kit type
52+ const classicVoteResult = useReadDisputeKitClassicIsVoteActive ( {
53+ query : {
54+ enabled : isEnabled && disputeKitName === DisputeKits . Classic ,
55+ refetchInterval : REFETCH_INTERVAL ,
56+ } ,
57+ args : hookArgs ,
58+ } ) ;
59+
60+ const shutterVoteResult = useReadDisputeKitShutterIsVoteActive ( {
61+ query : {
62+ enabled : isEnabled && disputeKitName === DisputeKits . Shutter ,
63+ refetchInterval : REFETCH_INTERVAL ,
64+ } ,
65+ args : hookArgs ,
66+ } ) ;
67+
68+ const gatedVoteResult = useReadDisputeKitGatedIsVoteActive ( {
3969 query : {
40- enabled : ! isUndefined ( roundId ) && ! isUndefined ( voteId ) ,
70+ enabled : isEnabled && disputeKitName === DisputeKits . Gated ,
4171 refetchInterval : REFETCH_INTERVAL ,
4272 } ,
43- args : [ BigInt ( id ?? 0 ) , roundId , voteId ] ,
73+ args : hookArgs ,
4474 } ) ;
4575
76+ const gatedShutterVoteResult = useReadDisputeKitGatedShutterIsVoteActive ( {
77+ query : {
78+ enabled : isEnabled && disputeKitName === DisputeKits . GatedShutter ,
79+ refetchInterval : REFETCH_INTERVAL ,
80+ } ,
81+ args : hookArgs ,
82+ } ) ;
83+
84+ const hasVoted = useMemo ( ( ) => {
85+ switch ( disputeKitName ) {
86+ case DisputeKits . Classic :
87+ return classicVoteResult . data ;
88+ case DisputeKits . Shutter :
89+ return shutterVoteResult . data ;
90+ case DisputeKits . Gated :
91+ return gatedVoteResult . data ;
92+ case DisputeKits . GatedShutter :
93+ return gatedShutterVoteResult . data ;
94+ default :
95+ return undefined ;
96+ }
97+ } , [
98+ disputeKitName ,
99+ classicVoteResult . data ,
100+ shutterVoteResult . data ,
101+ gatedVoteResult . data ,
102+ gatedShutterVoteResult . data ,
103+ ] ) ;
104+
46105 const wasDrawn = useMemo ( ( ) => ! isUndefined ( drawData ) && drawData . draws . length > 0 , [ drawData ] ) ;
47106 const isHiddenVotes = useMemo ( ( ) => disputeData ?. dispute ?. court . hiddenVotes ?? false , [ disputeData ] ) ;
48107 const isCommitPeriod = useMemo ( ( ) => disputeData ?. dispute ?. period === "commit" , [ disputeData ] ) ;
49108 const isVotingPeriod = useMemo ( ( ) => disputeData ?. dispute ?. period === "vote" , [ disputeData ] ) ;
50109
51110 const commited = useMemo ( ( ) => ! isUndefined ( drawData ) && drawData ?. draws ?. [ 0 ] ?. vote ?. commited , [ drawData ] ) ;
52111 const commit = useMemo ( ( ) => drawData ?. draws ?. [ 0 ] ?. vote ?. commit , [ drawData ] ) ;
53-
54- const hasVoted = useMemo ( ( ) => {
55- if ( isHiddenVotes && isCommitPeriod ) {
56- return commited ;
57- }
58- return hasVotedClassic ;
59- } , [ isHiddenVotes , isCommitPeriod , commited , hasVotedClassic ] ) ;
60-
61112 return (
62113 < VotingContext . Provider
63114 value = { useMemo (
0 commit comments