Skip to content

Commit 6ec6e9e

Browse files
committed
feat(qt): add lifecycle and vote-aware sorting in proposal list
1 parent 27d7f26 commit 6ec6e9e

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/qt/proposalmodel.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,22 @@ QVariant ProposalModel::data(const QModelIndex& index, int role) const
234234
{
235235
// Edit role is used for sorting, so return the raw values where possible
236236
switch (index.column()) {
237-
case Column::STATUS:
238-
return static_cast<int>(proposal->status(isFundable));
237+
case Column::STATUS: {
238+
// Two-level sort: status group (passing before failing), then
239+
// vote margin within each group (winning by most sorts first).
240+
const auto deficit{nAbsVoteReq - proposal->getAbsoluteYesCount()};
241+
switch (proposal->status(isFundable)) {
242+
case ProposalStatus::Funded: return (0 << 16) + deficit;
243+
case ProposalStatus::Passing: return (1 << 16) + deficit;
244+
case ProposalStatus::Unfunded: return (2 << 16) + deficit;
245+
case ProposalStatus::Voting: return (3 << 16) + deficit;
246+
case ProposalStatus::Confirming: return (4 << 16) + deficit;
247+
case ProposalStatus::Pending: return (5 << 16) + deficit;
248+
case ProposalStatus::Failing: return (6 << 16) + deficit;
249+
case ProposalStatus::Lapsed: return (7 << 16) + deficit;
250+
} // no default case, so the compiler can warn about missing cases
251+
return 0;
252+
}
239253
case Column::HASH:
240254
return proposal->hash();
241255
case Column::TITLE:

0 commit comments

Comments
 (0)