Skip to content

Commit

Permalink
Merge pull request #2066 from novasamatech/fix/tbaut-voting-power-sor…
Browse files Browse the repository at this point in the history
…ting

fix: Sort votes by voting power
  • Loading branch information
Tbaut authored Aug 12, 2024
2 parents 4a07d48 + 848bf63 commit bc723d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/renderer/features/governance/aggregates/voteHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { votingListService } from '../lib/votingListService';
import { networkSelectorModel } from '../model/networkSelector';
import { votingAssetModel } from '../model/votingAsset';
import { type AggregatedVoteHistory } from '../types/structs';
import { votingPowerSorting } from '../utils/votingPowerSorting';

import { proposerIdentityAggregate } from './proposerIdentity';
import { tracksAggregate } from './tracks';
Expand Down Expand Up @@ -42,22 +43,24 @@ const $voteHistory = combine(
for (const [referendumId, historyList] of Object.entries(history)) {
const votes = votingService.getReferendumVoting(referendumId, voting);

acc[referendumId] = historyList.flatMap(({ voter }) => {
const proposer = proposers[voter] ?? null;
const vote = votes[voter];
if (!vote) {
return [];
}

const splitVotes = votingListService.getDecoupledVotesFromVote(referendumId, vote);

return splitVotes.map((vote) => {
return {
...vote,
name: proposer ? proposer.parent.name : null,
};
});
});
acc[referendumId] = historyList
.flatMap(({ voter }) => {
const proposer = proposers[voter] ?? null;
const vote = votes[voter];
if (!vote) {
return [];
}

const splitVotes = votingListService.getDecoupledVotesFromVote(referendumId, vote);

return splitVotes.map((vote) => {
return {
...vote,
name: proposer ? proposer.parent.name : null,
};
});
})
.sort(votingPowerSorting);
}

return acc;
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/features/governance/utils/votingPowerSorting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { type AggregatedVoteHistory } from '../types/structs';

export const votingPowerSorting = (a: AggregatedVoteHistory, b: AggregatedVoteHistory) =>
b.votingPower.eq(a.votingPower) ? 0 : b.votingPower.gt(a.votingPower) ? 1 : -1;

0 comments on commit bc723d6

Please sign in to comment.