From c5d1d5892a38b96642beac8dca2cc1ce785258d8 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sat, 25 Nov 2023 01:11:53 -0500 Subject: [PATCH] Correct last vote handling in poll card The handling for last vote did not really work in the case where the walletholder votes multiple times. This commit implements a sensible and correct version. --- src/gridcoin/voting/result.cpp | 22 +++++++++++++++++++++- src/qt/forms/voting/pollcard.ui | 4 ++-- src/qt/voting/pollcard.cpp | 9 ++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/gridcoin/voting/result.cpp b/src/gridcoin/voting/result.cpp index 98a8b72dee..ef523a2cd3 100644 --- a/src/gridcoin/voting/result.cpp +++ b/src/gridcoin/voting/result.cpp @@ -1248,7 +1248,11 @@ void PollResult::TallyVote(VoteDetail detail) if (detail.m_ismine != ISMINE_NO) { m_self_voted = true; - m_self_vote_detail = detail; + + m_self_vote_detail.m_amount += detail.m_amount; + m_self_vote_detail.m_mining_id = detail.m_mining_id; + m_self_vote_detail.m_magnitude = detail.m_magnitude; + m_self_vote_detail.m_ismine = detail.m_ismine; } for (const auto& response_pair : detail.m_responses) { @@ -1258,6 +1262,22 @@ void PollResult::TallyVote(VoteDetail detail) m_responses[response_offset].m_weight += response_weight; m_responses[response_offset].m_votes += 1.0 / detail.m_responses.size(); m_total_weight += response_weight; + + if (detail.m_ismine != ISMINE_NO) { + bool choice_found = false; + + for (auto& choice : m_self_vote_detail.m_responses) { + if (choice.first == response_offset) { + choice.second += response_weight; + choice_found = true; + break; + } + } + + if (!choice_found) { + m_self_vote_detail.m_responses.push_back(std::make_pair(response_offset, response_weight)); + } + } } m_votes.emplace_back(std::move(detail)); diff --git a/src/qt/forms/voting/pollcard.ui b/src/qt/forms/voting/pollcard.ui index 2bad4f8d81..10312b84d6 100644 --- a/src/qt/forms/voting/pollcard.ui +++ b/src/qt/forms/voting/pollcard.ui @@ -201,14 +201,14 @@ - Your Last Vote: + Your Vote(s): - Your Vote Weight: + Your Vote Weight(s): diff --git a/src/qt/voting/pollcard.cpp b/src/qt/voting/pollcard.cpp index 6680209bdd..1071192d00 100644 --- a/src/qt/voting/pollcard.cpp +++ b/src/qt/voting/pollcard.cpp @@ -39,6 +39,7 @@ PollCard::PollCard(const PollItem& poll_item, QWidget* parent) ui->myPercentAVWLabel->setText("N/A"); } else { QString choices_str; + QString weights_str; int64_t my_total_weight = 0; @@ -49,11 +50,17 @@ PollCard::PollCard(const PollItem& poll_item, QWidget* parent) choices_str = QString(poll_item.m_choices[choice.first].m_label); } + if (!weights_str.isEmpty()) { + weights_str += ", " + QString::number(choice.second / COIN); + } else { + weights_str = QString::number(choice.second / COIN); + } + my_total_weight += choice.second / COIN; } ui->myLastVoteAnswerLabel->setText(choices_str); - ui->myVoteWeightLabel->setText(QString::number(my_total_weight)); + ui->myVoteWeightLabel->setText(weights_str); if (poll_item.m_active_weight) ui->myPercentAVWLabel->setText(QString::number((double) my_total_weight / (double) poll_item.m_active_weight * (double) 100.0, 'f', 4) + '\%');