Skip to content

Commit a5ce62b

Browse files
authored
Merge pull request #3963 from IntersectMBO/3918-get-votes-matching-by-txhash-and-index
3918 get votes matching by txhash and index
2 parents e39ac50 + 1069058 commit a5ce62b

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

govtool/backend/src/VVA/API.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,22 +296,22 @@ getVotes (unHexText -> dRepId) selectedTypes sortMode mSearch = do
296296
CacheEnv {dRepGetVotesCache} <- asks vvaCache
297297
(votes, proposals) <- cacheRequest dRepGetVotesCache dRepId $ DRep.getVotes dRepId []
298298

299-
let voteMapByTxHash = Map.fromList $
300-
map (\vote -> (pack $ Prelude.takeWhile (/= '#') (unpack $ Types.voteGovActionId vote), vote)) votes
299+
let voteMapById = Map.fromList $
300+
map (\vote -> (Types.voteGovActionId vote, vote)) votes
301301

302302
processedProposals <- filter (isProposalSearchedFor mSearch) <$>
303303
mapSortAndFilterProposals selectedTypes sortMode proposals
304304

305-
return $
305+
return
306306
[ VoteResponse
307307
{ voteResponseVote = voteToResponse vote
308308
, voteResponseProposal = proposalResponse
309309
}
310310
| proposalResponse <- processedProposals
311-
, let txHash = unHexText (proposalResponseTxHash proposalResponse)
312-
, Just vote <- [Map.lookup txHash voteMapByTxHash]
311+
, let govActionId = unHexText (proposalResponseTxHash proposalResponse) <> "#" <> pack (show $ proposalResponseIndex proposalResponse)
312+
, Just vote <- [Map.lookup govActionId voteMapById]
313313
]
314-
314+
315315
drepInfo :: App m => HexText -> m DRepInfoResponse
316316
drepInfo (unHexText -> dRepId) = do
317317
CacheEnv {dRepInfoCache} <- asks vvaCache

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)