Skip to content

Commit

Permalink
fix sort by isWinner when no votes
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoseneca committed Feb 25, 2024
1 parent 7e9287f commit d7aa32f
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions packages/prop-house-webapp/src/state/slices/propHouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,32 @@ export const propHouseSlice = createSlice({
state.activeProposals =
action.payload === undefined
? undefined
: action.payload.map(proposal => {
if (COMPLETED_ROUND_OVERRIDES[proposal.round]) {
proposal.isWinner = COMPLETED_ROUND_OVERRIDES[proposal.round].winners.includes(proposal.id);
}
return proposal;
}).sort((a, b) => {
const votingPowerDifference = Number(b.votingPower) - Number(a.votingPower);
if (votingPowerDifference === 0) {
return a.receivedAt - b.receivedAt; // Tie-Breaking
}
return votingPowerDifference;
});
},
: action.payload
.map(proposal => {
if (COMPLETED_ROUND_OVERRIDES[proposal.round]) {
proposal.isWinner = COMPLETED_ROUND_OVERRIDES[proposal.round].winners.includes(
proposal.id,
);
}
return proposal;
})
.sort((a, b) => {
const aVP = Number(a.votingPower);
const bVP = Number(b.votingPower);

// If both proposals have 0 voting power, sort by isWinner (override)
if (aVP === 0 && bVP === 0) {
return a.isWinner ? -1 : 1;
}

// If both are tied, sort by receivedAt
const votingPowerDifference = aVP - bVP;
if (votingPowerDifference === 0) {
return a.receivedAt - b.receivedAt; // Tie-Breaking
}
return votingPowerDifference;
});
},
appendProposal: (state, action: PayloadAction<{ proposal: Proposal }>) => {
state.activeProposals?.push(action.payload.proposal);
},
Expand Down

0 comments on commit d7aa32f

Please sign in to comment.