Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui, voting: Implement poll result caching and poll stale indicator #2709

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/gridcoin/voting/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,9 @@ void PollRegistry::AddVote(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIRED(
*poll_ref->m_ptitle,
poll_ref->Votes().size());

if (fQtActive && !poll_ref->Expired(GetAdjustedTime())) {
uiInterface.NewVoteReceived(poll_ref->Txid());
}
}
}

Expand All @@ -1068,13 +1071,19 @@ void PollRegistry::AddVote(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIRED(
return;
}
poll_ref->LinkVote(ctx.m_tx.GetHash());

if (fQtActive && !poll_ref->Expired(GetAdjustedTime())) {
uiInterface.NewVoteReceived(poll_ref->Txid());
}
}
}

void PollRegistry::DeletePoll(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIRED(cs_main, PollRegistry::cs_poll_registry)
{
const auto payload = ctx->SharePayloadAs<PollPayload>();

int64_t poll_time = payload->m_poll.m_timestamp;

m_polls.erase(ToLower(payload->m_poll.m_title));

m_polls_by_txid.erase(ctx.m_tx.GetHash());
Expand All @@ -1085,6 +1094,10 @@ void PollRegistry::DeletePoll(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIR
payload->m_poll.m_title,
m_polls.size());

if (fQtActive) {
uiInterface.NewPollReceived(poll_time);;
}

}

void PollRegistry::DeleteVote(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIRED(cs_main, PollRegistry::cs_poll_registry)
Expand All @@ -1100,6 +1113,10 @@ void PollRegistry::DeleteVote(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIR
ctx.m_tx.GetHash().GetHex(),
*poll_ref->m_ptitle,
poll_ref->Votes().size());

if (fQtActive && !poll_ref->Expired(GetAdjustedTime())) {
uiInterface.NewVoteReceived(poll_ref->Txid());
}
}

return;
Expand All @@ -1114,6 +1131,10 @@ void PollRegistry::DeleteVote(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIR

if (PollReference* poll_ref = TryBy(title)) {
poll_ref->UnlinkVote(ctx.m_tx.GetHash());

if (fQtActive && !poll_ref->Expired(GetAdjustedTime())) {
uiInterface.NewVoteReceived(poll_ref->Txid());
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/node/ui_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#include "uint256.h"
#include <node/ui_interface.h>

#include <boost/signals2/optional_last_value.hpp>
Expand All @@ -25,6 +26,7 @@ struct UISignals {
boost::signals2::signal<CClientUIInterface::MRCChangedSig> MRCChanged;
boost::signals2::signal<CClientUIInterface::BeaconChangedSig> BeaconChanged;
boost::signals2::signal<CClientUIInterface::NewPollReceivedSig> NewPollReceived;
boost::signals2::signal<CClientUIInterface::NewVoteReceivedSig> NewVoteReceived;
boost::signals2::signal<CClientUIInterface::NotifyScraperEventSig> NotifyScraperEvent;
boost::signals2::signal<CClientUIInterface::ThreadSafeAskFeeSig> ThreadSafeAskFee;
boost::signals2::signal<CClientUIInterface::ThreadSafeHandleURISig> ThreadSafeHandleURI;
Expand Down Expand Up @@ -53,6 +55,7 @@ ADD_SIGNALS_IMPL_WRAPPER(AccrualChangedFromStakeOrMRC);
ADD_SIGNALS_IMPL_WRAPPER(MRCChanged);
ADD_SIGNALS_IMPL_WRAPPER(BeaconChanged);
ADD_SIGNALS_IMPL_WRAPPER(NewPollReceived);
ADD_SIGNALS_IMPL_WRAPPER(NewVoteReceived);
ADD_SIGNALS_IMPL_WRAPPER(NotifyScraperEvent);
ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeAskFee);
ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeHandleURI);
Expand All @@ -78,6 +81,7 @@ void CClientUIInterface::AccrualChangedFromStakeOrMRC() { return g_ui_signals.Ac
void CClientUIInterface::MRCChanged() { return g_ui_signals.MRCChanged(); }
void CClientUIInterface::BeaconChanged() { return g_ui_signals.BeaconChanged(); }
void CClientUIInterface::NewPollReceived(int64_t poll_time) { return g_ui_signals.NewPollReceived(poll_time); }
void CClientUIInterface::NewVoteReceived(const uint256& poll_txid) { return g_ui_signals.NewVoteReceived(poll_txid); }
void CClientUIInterface::NotifyAlertChanged(const uint256 &hash, ChangeType status) { return g_ui_signals.NotifyAlertChanged(hash, status); }
void CClientUIInterface::NotifyScraperEvent(const scrapereventtypes& ScraperEventtype, ChangeType status, const std::string& message) { return g_ui_signals.NotifyScraperEvent(ScraperEventtype, status, message); }

Expand Down
3 changes: 3 additions & 0 deletions src/node/ui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class CClientUIInterface
/** New poll received **/
ADD_SIGNALS_DECL_WRAPPER(NewPollReceived, void, int64_t poll_time);

/** New vote received **/
ADD_SIGNALS_DECL_WRAPPER(NewVoteReceived, void, const uint256& poll_txid);

/**
* New, updated or cancelled alert.
* @note called with lock cs_mapAlerts held.
Expand Down
7 changes: 7 additions & 0 deletions src/qt/forms/voting/pollcard.ui
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="staleLabel">
<property name="text">
<string>Stale</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="validatedLabel">
<property name="text">
Expand Down
8 changes: 8 additions & 0 deletions src/qt/res/stylesheets/dark_stylesheet.qss
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,14 @@ PollCard #invalidLabel {
color: rgb(150, 0, 0);
}

PollCard #staleLabel {
border: 0.065em solid rgb(240, 0, 0);
border-radius: 0.65em;
padding: 0.1em 0.3em;
color: rgb(255, 255, 255);
background-color: rgb(240, 0, 0);
}

PollCard #remainingLabel,
PollResultChoiceItem #percentageLabel,
PollResultChoiceItem #weightLabel,
Expand Down
8 changes: 8 additions & 0 deletions src/qt/res/stylesheets/light_stylesheet.qss
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,14 @@ PollCard #invalidLabel {
color: rgb(150, 0, 0);
}

PollCard #staleLabel {
border: 0.065em solid rgb(240, 0, 0);
border-radius: 0.65em;
padding: 0.1em 0.3em;
color: rgb(255, 255, 255);
background-color: rgb(240, 0, 0);
}

PollCard #remainingLabel,
PollResultChoiceItem #percentageLabel,
PollResultChoiceItem #weightLabel,
Expand Down
6 changes: 6 additions & 0 deletions src/qt/voting/pollcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ PollCard::PollCard(const PollItem& poll_item, QWidget* parent)
ui->invalidLabel->show();
}

if (poll_item.m_stale) {
ui->staleLabel->show();
} else {
ui->staleLabel->hide();
}

ui->topAnswerLabel->setText(poll_item.m_top_answer);

if (!poll_item.m_finished) {
Expand Down
Loading