Skip to content
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
22 changes: 12 additions & 10 deletions src/gridcoin/voting/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,27 +603,29 @@ const PollRegistry::Sequence PollRegistry::Polls() const

const PollReference* PollRegistry::TryLatestActive() const
{
if (m_latest_poll && !m_latest_poll->Expired(GetAdjustedTime())) {
int64_t now = GetAdjustedTime();

if (m_latest_poll && !m_latest_poll->Expired(now)) {
return m_latest_poll;
}

if (m_polls.empty()) {
return nullptr;
}

const PollReference* latest = &m_polls.cbegin()->second;
const PollReference* latest_not_expired = nullptr;
int64_t latest_not_expired_timestamp = 0;

for (auto iter = ++m_polls.cbegin(); iter != m_polls.cend(); ++iter) {
if (iter->second.m_timestamp > latest->m_timestamp) {
latest = &iter->second;
// Go through m_polls finding the latest poll that is not expired.
for (auto iter = m_polls.cbegin(); iter != m_polls.cend(); ++iter) {
// Maybe more than one poll has the same timestamp... therefore use >=.
if (!iter->second.Expired(now) && iter->second.m_timestamp >= latest_not_expired_timestamp) {
latest_not_expired = &iter->second;
latest_not_expired_timestamp = latest_not_expired->m_timestamp;
}
}

if (latest->Expired(GetAdjustedTime())) {
return nullptr;
}

return latest;
return latest_not_expired;
}

const PollReference* PollRegistry::TryByTxid(const uint256 txid) const
Expand Down
24 changes: 24 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,15 @@ void BitcoinGUI::setVotingModel(VotingModel *votingModel)
overviewPage->setCurrentPollTitle(votingModel->getCurrentPollTitle());

connect(votingModel, &VotingModel::newPollReceived, this, &BitcoinGUI::handleNewPoll);

QTimer *expiry_check_timer = new QTimer(this);

// A call to handle possible expired poll on a timer will update the current polls section of the overview screen
// to remove a current poll that has expired.
connect(expiry_check_timer, &QTimer::timeout, this, &BitcoinGUI::handleExpiredPoll);

// Check every minute
expiry_check_timer->start(1000 * 60);
}

void BitcoinGUI::createTrayIcon()
Expand Down Expand Up @@ -1860,6 +1869,21 @@ void BitcoinGUI::handleNewPoll()
overviewPage->setCurrentPollTitle(votingModel->getCurrentPollTitle());
}

void BitcoinGUI::handleExpiredPoll()
{
// The only difference between this and handleNewPoll() is no call to the event notifier.

if (!clientModel || !clientModel->getOptionsModel()) {
return;
}

if (!votingModel) {
return;
}

overviewPage->setCurrentPollTitle(votingModel->getCurrentPollTitle());
}

// -----------------------------------------------------------------------------
// Class: ToolbarButtonIconFilter
// -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ private slots:
QString GetEstimatedStakingFrequency(unsigned int nEstimateTime);

void handleNewPoll();
void handleExpiredPoll();
};

//!
Expand Down