Skip to content

Commit a9ad1f3

Browse files
author
Adam Tomaszczyk
committed
Fix backend filtering of proposals by drepId (filter out voted on)
1 parent e39ac50 commit a9ad1f3

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

govtool/backend/src/VVA/API.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,12 @@ listProposals selectedTypes sortMode mPage mPageSize mDrepRaw mSearchQuery = do
401401
-- proposals that the provided Drep has already voted on should be filtered out
402402
proposalsToRemove <- case mDrepRaw of
403403
Nothing -> return []
404-
Just drepId ->
405-
map (voteParamsProposalId . voteResponseVote)
406-
<$> getVotes drepId [] Nothing Nothing
404+
Just drepId -> do
405+
votes <- getVotes drepId [] Nothing Nothing
406+
return
407+
[ (proposalResponseTxHash p, proposalResponseIndex p)
408+
| VoteResponse{voteResponseProposal = p} <- votes
409+
]
407410

408411
CacheEnv {proposalListCache} <- asks vvaCache
409412

@@ -412,9 +415,9 @@ listProposals selectedTypes sortMode mPage mPageSize mDrepRaw mSearchQuery = do
412415

413416
mappedSortedAndFilteredProposals <- mapSortAndFilterProposals selectedTypes sortMode proposals
414417
let filteredProposals = filter
415-
( \p@ProposalResponse {proposalResponseId} ->
416-
proposalResponseId `notElem` proposalsToRemove
417-
&& isProposalSearchedFor mSearchQuery p
418+
(\p@ProposalResponse{proposalResponseTxHash, proposalResponseIndex} ->
419+
(proposalResponseTxHash, proposalResponseIndex) `notElem` proposalsToRemove
420+
&& isProposalSearchedFor mSearchQuery p
418421
) mappedSortedAndFilteredProposals
419422

420423
let total = length filteredProposals :: Int

govtool/frontend/src/components/organisms/DashboardGovernanceActions.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useCallback } from "react";
1+
import { useState, useEffect, useCallback, useMemo } from "react";
22
import { Box, CircularProgress, Tab, Tabs, styled } from "@mui/material";
33
import { useLocation, useNavigate } from "react-router-dom";
44

@@ -107,7 +107,33 @@ export const DashboardGovernanceActions = () => {
107107
debouncedSearchText,
108108
);
109109

110-
const filteredProposals = proposals;
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) => {
119+
const filteredActions = proposalCategory.actions.filter((action) => {
120+
const hasVote = votes.some((voteCategory) =>
121+
voteCategory.actions.some(
122+
(voteAction) =>
123+
voteAction.proposal.txHash === action.txHash &&
124+
voteAction.proposal.index === action.index,
125+
),
126+
);
127+
return !hasVote;
128+
});
129+
130+
return {
131+
...proposalCategory,
132+
actions: filteredActions,
133+
};
134+
})
135+
.filter((category) => category.actions.length > 0);
136+
}, [proposals, votes, shouldFilter]);
111137

112138
const { state } = useLocation();
113139
const [content, setContent] = useState<number>(

0 commit comments

Comments
 (0)