Skip to content

Commit

Permalink
Merge branch 'proposal-based-votable-state' of github.com:dfinity/ic-…
Browse files Browse the repository at this point in the history
…js into proposal-based-votable-state
  • Loading branch information
mstrasinskis committed Oct 2, 2024
2 parents fe1eb82 + 10eabef commit 6745fe7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
12 changes: 6 additions & 6 deletions packages/nns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Parameters:
- `params.neurons`: The neurons to filter.
- `params.proposal`: The proposal to match against the selected neurons.

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/utils/neurons.utils.ts#L38)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/utils/neurons.utils.ts#L29)

#### :gear: votableNeurons

Expand All @@ -111,22 +111,22 @@ Parameters:
- `params.neurons`: The neurons to filter.
- `params.proposal`: The proposal to match against the selected neurons.

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/utils/neurons.utils.ts#L67)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/utils/neurons.utils.ts#L58)

#### :gear: votedNeurons

Filter the neurons that have voted for a proposal.

| Function | Type |
| -------------- | ----------------------------------------------------------------------------------------------------------- |
| `votedNeurons` | `({ neurons, proposal: { ballots }, }: { neurons: NeuronInfo[]; proposal: ProposalInfo; }) => NeuronInfo[]` |
| Function | Type |
| -------------- | ---------------------------------------------------------------------------------------------- |
| `votedNeurons` | `({ neurons, proposal, }: { neurons: NeuronInfo[]; proposal: ProposalInfo; }) => NeuronInfo[]` |

Parameters:

- `params.neurons`: The neurons to filter.
- `params.proposal`: The proposal for which some neurons might have already voted.

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/utils/neurons.utils.ts#L93)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/utils/neurons.utils.ts#L81)

### :factory: GenesisTokenCanister

Expand Down
11 changes: 5 additions & 6 deletions packages/nns/src/utils/neurons.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Vote } from "../enums/governance.enums";
import type { NeuronId } from "../types/common";
import type {
Ballot,
NeuronInfo,
Expand All @@ -8,13 +7,12 @@ import type {

const getNeuronVoteForProposal = ({
proposal: { ballots },
neuron: {neuronId},
neuron: { neuronId },
}: {
proposal: ProposalInfo;
neuron: NeuronInfo;
}): Vote | undefined => ballots.find(
({ neuronId: id }) => id === neuronId,
)?.vote;
}): Vote | undefined =>
ballots.find(({ neuronId: id }) => id === neuronId)?.vote;

/**
* Filter the neurons that are ineligible to vote to a proposal.
Expand Down Expand Up @@ -63,7 +61,8 @@ export const votableNeurons = ({
}: {
neurons: NeuronInfo[];
proposal: ProposalInfo;
}): NeuronInfo[] => neurons.filter(
}): NeuronInfo[] =>
neurons.filter(
(neuron: NeuronInfo) =>
getNeuronVoteForProposal({ proposal, neuron }) === Vote.Unspecified &&
ineligibleNeurons({ neurons, proposal }).find(
Expand Down

0 comments on commit 6745fe7

Please sign in to comment.