Skip to content

Commit

Permalink
Use ballots from proposal to evaluate voted state
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrasinskis committed Sep 24, 2024
1 parent c8bc175 commit bd1788c
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions packages/nns/src/utils/neurons.utils.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import type { Vote } from "../enums/governance.enums";
import type { NeuronId } from "../types/common";
import type {
Ballot,
BallotInfo,
NeuronInfo,
ProposalId,
ProposalInfo,
} from "../types/governance_converters";

const voteForProposal = ({
recentBallots,
proposalId,
ballots,
neuronId,
}: {
recentBallots: BallotInfo[];
proposalId: ProposalId | undefined;
ballots: Ballot[];
neuronId: NeuronId | undefined;
}): Vote | undefined => {
if (!proposalId) {
if (!neuronId) {
return undefined;
}

const ballot: BallotInfo | undefined = recentBallots.find(
({ proposalId: id }: BallotInfo) => id === proposalId,
const ballot: Ballot | undefined = ballots.find(
({ neuronId: id }) => id === neuronId,
);
return ballot?.vote;
};
Expand Down Expand Up @@ -72,11 +71,11 @@ export const votableNeurons = ({
neurons: NeuronInfo[];
proposal: ProposalInfo;
}): NeuronInfo[] => {
const { id: proposalId } = proposal;
const { ballots } = proposal;

return neurons.filter(
({ recentBallots, neuronId }: NeuronInfo) =>
voteForProposal({ recentBallots, proposalId }) === undefined &&
({ neuronId }: NeuronInfo) =>
voteForProposal({ ballots, neuronId }) === undefined &&
ineligibleNeurons({ neurons, proposal }).find(
({ neuronId: ineligibleNeuronId }: NeuronInfo) =>
ineligibleNeuronId === neuronId,
Expand All @@ -93,12 +92,12 @@ export const votableNeurons = ({
*/
export const votedNeurons = ({
neurons,
proposal: { id: proposalId },
proposal: { ballots },
}: {
neurons: NeuronInfo[];
proposal: ProposalInfo;
}): NeuronInfo[] =>
neurons.filter(
({ recentBallots }: NeuronInfo) =>
voteForProposal({ recentBallots, proposalId }) !== undefined,
({ neuronId }: NeuronInfo) =>
voteForProposal({ ballots, neuronId }) !== undefined,
);

0 comments on commit bd1788c

Please sign in to comment.