Skip to content

Commit 4827c21

Browse files
committed
Backing out unwanted changes
1 parent 76b81f3 commit 4827c21

File tree

3 files changed

+82
-14
lines changed

3 files changed

+82
-14
lines changed

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

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

1213
type DashboardGovernanceActionsVotedOnProps = {
1314
searchPhrase?: string;
@@ -24,14 +25,41 @@ export const DashboardGovernanceActionsVotedOn = ({
2425

2526
const {
2627
data: votes,
27-
areDRepVotesLoading
28+
areDRepVotesLoading,
29+
isFetching,
2830
} = useGetDRepVotesQuery(chosenFilters, chosenSorting, searchPhrase);
2931

30-
const proposals = useMemo(() =>
31-
votes.flatMap((entry) => entry.actions),
32-
[votes, searchPhrase, pendingTransaction.vote]);
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);
3336

34-
return areDRepVotesLoading ? (
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 ? (
3563
<Box py={4} display="flex" justifyContent="center">
3664
<CircularProgress />
3765
</Box>
@@ -41,7 +69,7 @@ export const DashboardGovernanceActionsVotedOn = ({
4169
<Typography py={4} fontWeight="300">
4270
{t("govActions.youHaventVotedYet")}
4371
</Typography>
44-
) : !proposals?.length ? (
72+
) : !filteredData?.length ? (
4573
<Typography py={4} fontWeight="300">
4674
{t("govActions.noResultsForTheSearch")}
4775
</Typography>
@@ -53,7 +81,7 @@ export const DashboardGovernanceActionsVotedOn = ({
5381
screenWidth < 420 ? "290px" : isMobile ? "324px" : "350px"
5482
}, 1fr))`}
5583
>
56-
{proposals.map((item) => (
84+
{filteredData.map((item) => (
5785
<Box pb={4.25} key={item.proposal.txHash + item.proposal.index}>
5886
<ValidatedGovernanceVotedOnCard
5987
votedProposal={item}

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

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { Typography } from "@atoms";
44
import { useCardano, useDataActionsBar } from "@context";
55
import {
66
useFetchNextPageDetector,
7+
useGetDRepVotesQuery,
78
useGetProposalsInfiniteQuery,
9+
useGetVoterInfo,
810
useSaveScrollPosition,
911
useScreenDimension,
1012
useTranslation,
@@ -24,6 +26,7 @@ export const GovernanceActionsToVote = ({
2426
const { isMobile, screenWidth } = useScreenDimension();
2527
const { debouncedSearchText, ...dataActionsBarProps } = useDataActionsBar();
2628
const { chosenSorting, chosenFilters } = dataActionsBarProps;
29+
const { voter } = useGetVoterInfo();
2730
const { t } = useTranslation();
2831

2932
const {
@@ -46,21 +49,59 @@ export const GovernanceActionsToVote = ({
4649
proposalsHaveNextPage,
4750
);
4851

52+
const {
53+
data: votes,
54+
areDRepVotesLoading,
55+
isFetching: isFetchingVotes,
56+
} = useGetDRepVotesQuery(chosenFilters, chosenSorting, debouncedSearchText);
57+
4958
const saveScrollPosition = useSaveScrollPosition(
5059
isProposalsLoading,
5160
isProposalsFetching,
5261
);
5362

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

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+
5998
return (
6099
<>
61-
{!mappedProposals ||
100+
{!filteredProposals ||
62101
isEnableLoading ||
63-
isProposalsLoading ? (
102+
isProposalsLoading ||
103+
areDRepVotesLoading ||
104+
isFetchingVotes ? (
64105
<Box
65106
sx={{
66107
alignItems: "center",
@@ -72,7 +113,7 @@ export const GovernanceActionsToVote = ({
72113
>
73114
<CircularProgress />
74115
</Box>
75-
) : !mappedProposals?.length ? (
116+
) : !filteredProposals?.length ? (
76117
<Typography fontWeight={300} sx={{ py: 4 }}>
77118
{t("govActions.noResultsForTheSearch")}
78119
</Typography>
@@ -84,7 +125,7 @@ export const GovernanceActionsToVote = ({
84125
screenWidth < 420 ? "290px" : isMobile ? "324px" : "350px"
85126
}, 1fr))`}
86127
>
87-
{mappedProposals.map((item) => (
128+
{filteredProposals.map((item) => (
88129
<Box pb={4.25} key={item.txHash + item.index}>
89130
<ValidatedGovernanceActionCard
90131
{...item}

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

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

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

0 commit comments

Comments
 (0)