@@ -3,10 +3,16 @@ import React, { useContext, createContext, useMemo } from "react";
3
3
import { useParams } from "react-router-dom" ;
4
4
import { useAccount } from "wagmi" ;
5
5
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" ;
8
13
import { useDisputeDetailsQuery } from "hooks/queries/useDisputeDetailsQuery" ;
9
14
import { useDrawQuery } from "hooks/queries/useDrawQuery" ;
15
+ import { useDisputeKitAddresses } from "hooks/useDisputeKitAddresses" ;
10
16
import { isUndefined } from "utils/index" ;
11
17
12
18
interface IVotingContext {
@@ -35,29 +41,74 @@ export const VotingContextProvider: React.FC<{ children: React.ReactNode }> = ({
35
41
const { data : drawData , isLoading } = useDrawQuery ( address ?. toLowerCase ( ) , id , disputeData ?. dispute ?. currentRound . id ) ;
36
42
const roundId = disputeData ?. dispute ?. currentRoundIndex ;
37
43
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 ( {
39
69
query : {
40
- enabled : ! isUndefined ( roundId ) && ! isUndefined ( voteId ) ,
70
+ enabled : isEnabled && disputeKitName === DisputeKits . Gated ,
41
71
refetchInterval : REFETCH_INTERVAL ,
42
72
} ,
43
- args : [ BigInt ( id ?? 0 ) , roundId , voteId ] ,
73
+ args : hookArgs ,
44
74
} ) ;
45
75
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
+
46
105
const wasDrawn = useMemo ( ( ) => ! isUndefined ( drawData ) && drawData . draws . length > 0 , [ drawData ] ) ;
47
106
const isHiddenVotes = useMemo ( ( ) => disputeData ?. dispute ?. court . hiddenVotes ?? false , [ disputeData ] ) ;
48
107
const isCommitPeriod = useMemo ( ( ) => disputeData ?. dispute ?. period === "commit" , [ disputeData ] ) ;
49
108
const isVotingPeriod = useMemo ( ( ) => disputeData ?. dispute ?. period === "vote" , [ disputeData ] ) ;
50
109
51
110
const commited = useMemo ( ( ) => ! isUndefined ( drawData ) && drawData ?. draws ?. [ 0 ] ?. vote ?. commited , [ drawData ] ) ;
52
111
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
-
61
112
return (
62
113
< VotingContext . Provider
63
114
value = { useMemo (
0 commit comments