Skip to content

Commit 24616f0

Browse files
authored
Merge pull request #4123 from IntersectMBO/issue-4105
Live Voting - Refactor filtering of voted on proposals #4105
2 parents cf7e947 + ffb0863 commit 24616f0

File tree

4 files changed

+18
-85
lines changed

4 files changed

+18
-85
lines changed

govtool/backend/src/VVA/API.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ listProposals selectedTypes sortMode mPage mPageSize mDrepRaw mSearchQuery = do
434434
proposalsToRemove <- case mDrepRaw of
435435
Nothing -> return []
436436
Just drepId ->
437-
map (voteParamsProposalId . voteResponseVote)
437+
map (\VoteResponse { voteResponseProposal = ProposalResponse { proposalResponseTxHash, proposalResponseIndex } } ->
438+
(proposalResponseTxHash, proposalResponseIndex))
438439
<$> getVotes drepId [] Nothing Nothing
439440

440441
CacheEnv {proposalListCache} <- asks vvaCache
@@ -444,8 +445,8 @@ listProposals selectedTypes sortMode mPage mPageSize mDrepRaw mSearchQuery = do
444445

445446
mappedSortedAndFilteredProposals <- mapSortAndFilterProposals selectedTypes sortMode proposals
446447
let filteredProposals = filter
447-
( \p@ProposalResponse {proposalResponseId} ->
448-
proposalResponseId `notElem` proposalsToRemove
448+
(\p@ProposalResponse { proposalResponseTxHash, proposalResponseIndex } ->
449+
(proposalResponseTxHash, proposalResponseIndex) `notElem` proposalsToRemove
449450
&& isProposalSearchedFor mSearchQuery p
450451
) mappedSortedAndFilteredProposals
451452

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

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
useTranslation,
99
} from "@hooks";
1010
import { ValidatedGovernanceVotedOnCard } from "@organisms";
11-
import { getFullGovActionId } from "@utils";
1211

1312
type DashboardGovernanceActionsVotedOnProps = {
1413
searchPhrase?: string;
@@ -25,41 +24,14 @@ export const DashboardGovernanceActionsVotedOn = ({
2524

2625
const {
2726
data: votes,
28-
areDRepVotesLoading,
29-
isFetching,
27+
areDRepVotesLoading
3028
} = useGetDRepVotesQuery(chosenFilters, chosenSorting, searchPhrase);
3129

32-
// TODO: Filtering here is some kind of craziness. It should be done on the backend.
33-
const filteredData = useMemo(() => {
34-
if (!votes?.length) return [];
35-
if (!searchPhrase) return votes.flatMap((entry) => entry.actions);
30+
const proposals = useMemo(() =>
31+
votes.flatMap((entry) => entry.actions),
32+
[votes, searchPhrase, pendingTransaction.vote]);
3633

37-
const lowerSearch = searchPhrase.toLowerCase();
38-
39-
return votes.flatMap((entry) =>
40-
entry.actions.filter((action) => {
41-
const hash = getFullGovActionId(
42-
action.proposal.txHash,
43-
action.proposal.index,
44-
).toLowerCase();
45-
46-
const title = action.proposal.title?.toLowerCase() || "";
47-
const motivation = action.proposal.motivation?.toLowerCase() || "";
48-
const rationale = action.proposal.rationale?.toLowerCase() || "";
49-
const abstract = action.proposal.abstract?.toLowerCase() || "";
50-
51-
return (
52-
hash.includes(lowerSearch) ||
53-
title.includes(lowerSearch) ||
54-
motivation.includes(lowerSearch) ||
55-
rationale.includes(lowerSearch) ||
56-
abstract.includes(lowerSearch)
57-
);
58-
}),
59-
);
60-
}, [votes, searchPhrase, pendingTransaction.vote]);
61-
62-
return areDRepVotesLoading || isFetching ? (
34+
return areDRepVotesLoading ? (
6335
<Box py={4} display="flex" justifyContent="center">
6436
<CircularProgress />
6537
</Box>
@@ -69,7 +41,7 @@ export const DashboardGovernanceActionsVotedOn = ({
6941
<Typography py={4} fontWeight="300">
7042
{t("govActions.youHaventVotedYet")}
7143
</Typography>
72-
) : !filteredData?.length ? (
44+
) : !proposals?.length ? (
7345
<Typography py={4} fontWeight="300">
7446
{t("govActions.noResultsForTheSearch")}
7547
</Typography>
@@ -81,7 +53,7 @@ export const DashboardGovernanceActionsVotedOn = ({
8153
screenWidth < 420 ? "290px" : isMobile ? "324px" : "350px"
8254
}, 1fr))`}
8355
>
84-
{filteredData.map((item) => (
56+
{proposals.map((item) => (
8557
<Box pb={4.25} key={item.proposal.txHash + item.proposal.index}>
8658
<ValidatedGovernanceVotedOnCard
8759
votedProposal={item}

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

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { Typography } from "@atoms";
44
import { useCardano, useDataActionsBar } from "@context";
55
import {
66
useFetchNextPageDetector,
7-
useGetDRepVotesQuery,
87
useGetProposalsInfiniteQuery,
9-
useGetVoterInfo,
108
useSaveScrollPosition,
119
useScreenDimension,
1210
useTranslation,
@@ -26,7 +24,6 @@ export const GovernanceActionsToVote = ({
2624
const { isMobile, screenWidth } = useScreenDimension();
2725
const { debouncedSearchText, ...dataActionsBarProps } = useDataActionsBar();
2826
const { chosenSorting, chosenFilters } = dataActionsBarProps;
29-
const { voter } = useGetVoterInfo();
3027
const { t } = useTranslation();
3128

3229
const {
@@ -49,59 +46,21 @@ export const GovernanceActionsToVote = ({
4946
proposalsHaveNextPage,
5047
);
5148

52-
const {
53-
data: votes,
54-
areDRepVotesLoading,
55-
isFetching: isFetchingVotes,
56-
} = useGetDRepVotesQuery(chosenFilters, chosenSorting, debouncedSearchText);
57-
5849
const saveScrollPosition = useSaveScrollPosition(
5950
isProposalsLoading,
6051
isProposalsFetching,
6152
);
6253

63-
const mappedData = useMemo(
54+
const mappedProposals = useMemo(
6455
() => removeDuplicatedProposals(proposals),
65-
[proposals, voter?.isRegisteredAsDRep, isProposalsFetchingNextPage],
56+
[proposals, isProposalsFetchingNextPage],
6657
);
6758

68-
// TODO: Filtering here is some kind of craziness. It should be done on the backend.
69-
const filteredProposals = useMemo(() => {
70-
const list = mappedData ?? [];
71-
if (!votes?.length) return list;
72-
73-
const proposalsFromVotes = votes
74-
.flatMap((v) => v?.actions ?? [])
75-
.map((a) => a?.proposal)
76-
.filter(Boolean);
77-
78-
const votedKeys = new Set(
79-
proposalsFromVotes
80-
.map((p) => ({
81-
id: p?.id ?? p?.id,
82-
tx: p?.txHash ?? p?.txHash,
83-
}))
84-
.filter(({ id, tx }) => Boolean(id && tx))
85-
.map(({ id, tx }) => `${id}:${tx}`),
86-
);
87-
88-
if (votedKeys.size === 0) return list;
89-
90-
return list.filter((p) => {
91-
const id = p?.id ?? p?.id;
92-
const tx = p?.txHash ?? p?.txHash;
93-
if (!id || !tx) return true;
94-
return !votedKeys.has(`${id}:${tx}`);
95-
});
96-
}, [mappedData, voter?.isRegisteredAsDRep, isProposalsFetchingNextPage]);
97-
9859
return (
9960
<>
100-
{!filteredProposals ||
61+
{!mappedProposals ||
10162
isEnableLoading ||
102-
isProposalsLoading ||
103-
areDRepVotesLoading ||
104-
isFetchingVotes ? (
63+
isProposalsLoading ? (
10564
<Box
10665
sx={{
10766
alignItems: "center",
@@ -113,7 +72,7 @@ export const GovernanceActionsToVote = ({
11372
>
11473
<CircularProgress />
11574
</Box>
116-
) : !filteredProposals?.length ? (
75+
) : !mappedProposals?.length ? (
11776
<Typography fontWeight={300} sx={{ py: 4 }}>
11877
{t("govActions.noResultsForTheSearch")}
11978
</Typography>
@@ -125,7 +84,7 @@ export const GovernanceActionsToVote = ({
12584
screenWidth < 420 ? "290px" : isMobile ? "324px" : "350px"
12685
}, 1fr))`}
12786
>
128-
{filteredProposals.map((item) => (
87+
{mappedProposals.map((item) => (
12988
<Box pb={4.25} key={item.txHash + item.index}>
13089
<ValidatedGovernanceActionCard
13190
{...item}

govtool/frontend/src/hooks/queries/useGetDRepVotesQuery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const useGetDRepVotesQuery = (
3232
enabled: !!dRepID,
3333
refetchOnWindowFocus: true,
3434
keepPreviousData: true,
35+
refetchInterval: 20000,
3536
});
3637

3738
const groupedByType = data?.reduce((groups, item) => {

0 commit comments

Comments
 (0)