1- import { useState , useEffect , useCallback } from "react" ;
1+ import { useState , useEffect , useCallback , useMemo } from "react" ;
22import { Box , CircularProgress , Tab , Tabs , styled } from "@mui/material" ;
33import { useLocation , useNavigate } from "react-router-dom" ;
44
@@ -88,8 +88,12 @@ export const DashboardGovernanceActions = () => {
8888 const prevFilters = usePrevious ( queryFilters ) ;
8989 const prevSorting = usePrevious ( chosenSorting ) ;
9090
91- const stableFilters = isAdjusting ? prevFilters ?? queryFilters : queryFilters ;
92- const stableSorting = isAdjusting ? prevSorting ?? chosenSorting : chosenSorting ;
91+ const stableFilters = isAdjusting
92+ ? prevFilters ?? queryFilters
93+ : queryFilters ;
94+ const stableSorting = isAdjusting
95+ ? prevSorting ?? chosenSorting
96+ : chosenSorting ;
9397
9498 const { proposals, isProposalsLoading } = useGetProposalsQuery ( {
9599 filters : stableFilters ,
@@ -103,16 +107,23 @@ export const DashboardGovernanceActions = () => {
103107 debouncedSearchText ,
104108 ) ;
105109
106- // TODO: Black magic - that filtering should be done on the backend
107- const filteredProposals = proposals
108- ?. map ( ( proposalCategory ) => {
110+ // White Magic :)
111+ const shouldFilter =
112+ voter ?. isRegisteredAsDRep || voter ?. isRegisteredAsSoleVoter ;
113+
114+ const filteredProposals = useMemo ( ( ) => {
115+ if ( ! shouldFilter || ! proposals || ! votes ) return proposals ;
116+
117+ return proposals
118+ . map ( ( proposalCategory ) => {
109119 const filteredActions = proposalCategory . actions . filter ( ( action ) => {
110- const hasVote = votes ? .some ( ( voteCategory ) =>
120+ const hasVote = votes . some ( ( voteCategory ) =>
111121 voteCategory . actions . some (
112- ( voteAction ) => voteAction . proposal . txHash === action . txHash ,
122+ ( voteAction ) =>
123+ voteAction . proposal . txHash === action . txHash &&
124+ voteAction . proposal . index === action . index ,
113125 ) ,
114126 ) ;
115-
116127 return ! hasVote ;
117128 } ) ;
118129
@@ -122,6 +133,7 @@ export const DashboardGovernanceActions = () => {
122133 } ;
123134 } )
124135 . filter ( ( category ) => category . actions . length > 0 ) ;
136+ } , [ proposals , votes , shouldFilter ] ) ;
125137
126138 const { state } = useLocation ( ) ;
127139 const [ content , setContent ] = useState < number > (
0 commit comments