Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -108,11 +108,14 @@ export const DashboardGovernanceActions = () => {
);

// White Magic :)
const filterOutAlreadyVotedProposals = () => {
if (!votes) return proposals;
const shouldFilter =
voter?.isRegisteredAsDRep || voter?.isRegisteredAsSoleVoter;

const filteredProposals = useMemo(() => {
if (!shouldFilter || !proposals || !votes) return proposals;

return proposals
?.map((proposalCategory) => {
.map((proposalCategory) => {
const filteredActions = proposalCategory.actions.filter((action) => {
const hasVote = votes.some((voteCategory) =>
voteCategory.actions.some(
Expand All @@ -121,7 +124,6 @@ export const DashboardGovernanceActions = () => {
voteAction.proposal.index === action.index,
),
);

return !hasVote;
});

Expand All @@ -131,9 +133,7 @@ export const DashboardGovernanceActions = () => {
};
})
.filter((category) => category.actions.length > 0);
};

const filteredProposals = filterOutAlreadyVotedProposals();
}, [proposals, votes, shouldFilter]);

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