From fdbb02984554fc54d98507eb7169e715460376b5 Mon Sep 17 00:00:00 2001 From: janko33bd Date: Sat, 13 Jan 2018 23:09:45 +0100 Subject: [PATCH] repairing staking icon --- src/qt/bitcoingui.cpp | 31 +++++++++++++++++++++++++++---- src/qt/bitcoingui.h | 2 ++ src/qt/walletframe.cpp | 8 -------- src/qt/walletframe.h | 2 -- src/qt/walletmodel.cpp | 18 +----------------- src/qt/walletmodel.h | 1 - src/qt/walletview.cpp | 7 ------- src/qt/walletview.h | 2 -- 8 files changed, 30 insertions(+), 41 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 8773ba29a..43d3741d2 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -16,10 +16,13 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" +#include "validation.h" +#include "rpc/server.h" #ifdef ENABLE_WALLET #include "walletframe.h" #include "walletmodel.h" +#include "wallet/wallet.h" #endif // ENABLE_WALLET #ifdef Q_OS_MAC @@ -222,9 +225,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n { QTimer *timerStakingIcon = new QTimer(labelStakingIcon); connect(timerStakingIcon, SIGNAL(timeout()), this, SLOT(updateStakingIcon())); + QTimer::singleShot(1000, this, SLOT(updateStakingIcon())); timerStakingIcon->start(30 * 1000); - - updateStakingIcon(); } @@ -1090,10 +1092,29 @@ void BitcoinGUI::toggleHidden() showNormalIfMinimized(true); } +void BitcoinGUI::updateWeight() +{ + if(!pwalletMain) + return; + + TRY_LOCK(cs_main, lockMain); + if (!lockMain) + return; + + TRY_LOCK(pwalletMain->cs_wallet, lockWallet); + if (!lockWallet) + return; + +#ifdef ENABLE_WALLET + if (pwalletMain) + nWeight = pwalletMain->GetStakeWeight(); +#endif +} + + void BitcoinGUI::updateStakingIcon() { - if (walletFrame) - nWeight = walletFrame->updateWeight(); + updateWeight(); if (nLastCoinStakeSearchInterval && nWeight) { @@ -1133,6 +1154,8 @@ void BitcoinGUI::updateStakingIcon() labelStakingIcon->setToolTip(tr("Not staking because wallet is syncing")); else if (!nWeight) labelStakingIcon->setToolTip(tr("Not staking because you don't have mature coins")); + else if (pwalletMain && pwalletMain->IsLocked()) + labelStakingIcon->setToolTip(tr("Not staking because wallet is locked")); else labelStakingIcon->setToolTip(tr("Not staking")); } diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index a58ec5574..4b8cf6a04 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -225,6 +225,8 @@ private Q_SLOTS: void showNormalIfMinimized(bool fToggleHidden = false); /** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */ void toggleHidden(); + + void updateWeight(); void updateStakingIcon(); diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 3e844a066..1b9426a4f 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -183,14 +183,6 @@ void WalletFrame::lockWallet() walletView->lockWallet(); } -unsigned long long WalletFrame::updateWeight() -{ - WalletView *walletView = currentWalletView(); - if (walletView) - return walletView->updateWeight(); - return 0; -} - void WalletFrame::usedSendingAddresses() { WalletView *walletView = currentWalletView(); diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 22ba5186c..b7fe7292e 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -76,8 +76,6 @@ public Q_SLOTS: void lockWallet(); - unsigned long long updateWeight(); - /** Show used sending addresses */ void usedSendingAddresses(); /** Show used receiving addresses */ diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index d4f55908d..8c52c4033 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -695,20 +695,4 @@ bool WalletModel::abandonTransaction(uint256 hash) const bool WalletModel::hdEnabled() const { return wallet->IsHDEnabled(); -} - -unsigned long long WalletModel::updateWeight() -{ - if (!wallet) - return 0; - - TRY_LOCK(cs_main, lockMain); - if (!lockMain) - return 0; - - TRY_LOCK(wallet->cs_wallet, lockWallet); - if (!lockWallet) - return 0; - - return wallet->GetStakeWeight(); -} +} \ No newline at end of file diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 9fa084305..c93798b76 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -199,7 +199,6 @@ public: void loadReceiveRequests(std::vector& vReceiveRequests); bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest); - unsigned long long updateWeight(); bool hdEnabled() const; diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index a1b5b2131..5d4da8253 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -288,13 +288,6 @@ void WalletView::lockWallet() walletModel->setWalletLocked(true); } -unsigned long long WalletView::updateWeight() -{ - if(walletModel) - return walletModel->updateWeight(); - return 0; -} - void WalletView::usedSendingAddresses() { if(!walletModel) diff --git a/src/qt/walletview.h b/src/qt/walletview.h index ae579a2e2..c0c9cf291 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -112,8 +112,6 @@ public Q_SLOTS: /** Show progress dialog e.g. for rescan */ void showProgress(const QString &title, int nProgress); - unsigned long long updateWeight(); - Q_SIGNALS: /** Signal that we want to show the main window */ void showNormalIfMinimized();