diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 608bbd0f..201d5293 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -15,6 +15,7 @@ namespace { static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 10; static const int DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS = 60; + static const int WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS = 5; } class WalletListenerImpl : public Bitmonero::WalletListener @@ -90,12 +91,19 @@ Wallet::Status Wallet::status() const Wallet::ConnectionStatus Wallet::connected() { qDebug("Checking wallet connection status"); - ConnectionStatus newStatus = static_cast(m_walletImpl->connected()); - if(newStatus != m_connectionStatus) { - m_connectionStatus = newStatus; - emit connectionStatusChanged(); + + // cache connection status + if(m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl){ + qDebug("connectionStatus query"); + ConnectionStatus newStatus = static_cast(m_walletImpl->connected()); + if(newStatus != m_connectionStatus) { + m_connectionStatus = newStatus; + emit connectionStatusChanged(); + } + m_connectionStatusTime.restart(); } - return newStatus; + + return m_connectionStatus; } bool Wallet::synchronized() const @@ -425,10 +433,15 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent) , m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS) , m_daemonBlockChainTargetHeight(0) , m_daemonBlockChainTargetHeightTtl(DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS) + , m_connectionStatusTtl(WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS) { m_history = new TransactionHistory(m_walletImpl->history(), this); m_walletImpl->setListener(new WalletListenerImpl(this)); m_connectionStatus = Wallet::ConnectionStatus_Disconnected; + // start cache timers + m_connectionStatusTime.restart(); + m_daemonBlockChainHeightTime.restart(); + m_daemonBlockChainTargetHeightTime.restart(); } Wallet::~Wallet() diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index f9cf8792..6eddd8bd 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -220,6 +220,8 @@ private: mutable quint64 m_daemonBlockChainTargetHeight; int m_daemonBlockChainTargetHeightTtl; ConnectionStatus m_connectionStatus; + int m_connectionStatusTtl; + mutable QTime m_connectionStatusTime; };