diff --git a/govtool/backend/src/VVA/API.hs b/govtool/backend/src/VVA/API.hs index ca7660358..ba5e56a4e 100644 --- a/govtool/backend/src/VVA/API.hs +++ b/govtool/backend/src/VVA/API.hs @@ -401,9 +401,12 @@ listProposals selectedTypes sortMode mPage mPageSize mDrepRaw mSearchQuery = do -- proposals that the provided Drep has already voted on should be filtered out proposalsToRemove <- case mDrepRaw of Nothing -> return [] - Just drepId -> - map (voteParamsProposalId . voteResponseVote) - <$> getVotes drepId [] Nothing Nothing + Just drepId -> do + votes <- getVotes drepId [] Nothing Nothing + return + [ (proposalResponseTxHash p, proposalResponseIndex p) + | VoteResponse{voteResponseProposal = p} <- votes + ] CacheEnv {proposalListCache} <- asks vvaCache @@ -412,9 +415,9 @@ listProposals selectedTypes sortMode mPage mPageSize mDrepRaw mSearchQuery = do mappedSortedAndFilteredProposals <- mapSortAndFilterProposals selectedTypes sortMode proposals let filteredProposals = filter - ( \p@ProposalResponse {proposalResponseId} -> - proposalResponseId `notElem` proposalsToRemove - && isProposalSearchedFor mSearchQuery p + (\p@ProposalResponse{proposalResponseTxHash, proposalResponseIndex} -> + (proposalResponseTxHash, proposalResponseIndex) `notElem` proposalsToRemove + && isProposalSearchedFor mSearchQuery p ) mappedSortedAndFilteredProposals let total = length filteredProposals :: Int diff --git a/govtool/frontend/src/components/organisms/DashboardGovernanceActions.tsx b/govtool/frontend/src/components/organisms/DashboardGovernanceActions.tsx index b2e6e6fa4..878527c02 100644 --- a/govtool/frontend/src/components/organisms/DashboardGovernanceActions.tsx +++ b/govtool/frontend/src/components/organisms/DashboardGovernanceActions.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useCallback } from "react"; +import { useState, useEffect, useCallback, useMemo } from "react"; import { Box, CircularProgress, Tab, Tabs, styled } from "@mui/material"; import { useLocation, useNavigate } from "react-router-dom"; @@ -107,7 +107,33 @@ export const DashboardGovernanceActions = () => { debouncedSearchText, ); -const filteredProposals = proposals; + // White Magic :) + const shouldFilter = + voter?.isRegisteredAsDRep || voter?.isRegisteredAsSoleVoter; + +const filteredProposals = useMemo(() => { + if (!shouldFilter || !proposals || !votes) return proposals; + + return proposals + .map((proposalCategory) => { + const filteredActions = proposalCategory.actions.filter((action) => { + const hasVote = votes.some((voteCategory) => + voteCategory.actions.some( + (voteAction) => + voteAction.proposal.txHash === action.txHash && + voteAction.proposal.index === action.index, + ), + ); + return !hasVote; + }); + + return { + ...proposalCategory, + actions: filteredActions, + }; + }) + .filter((category) => category.actions.length > 0); +}, [proposals, votes, shouldFilter]); const { state } = useLocation(); const [content, setContent] = useState(