Browse Source

Merge pull request #1575 from laanwj/2012_07_persistentbalancecheck

(UI) Persistently poll for balance change when number of blocks changed
miguelfreitas
Wladimir J. van der Laan 13 years ago
parent
commit
916b11fba5
  1. 25
      src/qt/walletmodel.cpp

25
src/qt/walletmodel.cpp

@ -23,13 +23,10 @@ WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *p
addressTableModel = new AddressTableModel(wallet, this); addressTableModel = new AddressTableModel(wallet, this);
transactionTableModel = new TransactionTableModel(wallet, this); transactionTableModel = new TransactionTableModel(wallet, this);
// This single-shot timer will be fired from the 'checkBalancedChanged' // This timer will be fired repeatedly to update the balance
// method repeatedly while either of the unconfirmed or immature balances
// are non-zero
pollTimer = new QTimer(this); pollTimer = new QTimer(this);
pollTimer->setInterval(MODEL_UPDATE_DELAY);
pollTimer->setSingleShot(true);
connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollBalanceChanged())); connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollBalanceChanged()));
pollTimer->start(MODEL_UPDATE_DELAY);
subscribeToCoreSignals(); subscribeToCoreSignals();
} }
@ -74,13 +71,12 @@ void WalletModel::updateStatus()
void WalletModel::pollBalanceChanged() void WalletModel::pollBalanceChanged()
{ {
if(nBestHeight != cachedNumBlocks) { if(nBestHeight != cachedNumBlocks)
{
// Balance and number of transactions might have changed
cachedNumBlocks = nBestHeight; cachedNumBlocks = nBestHeight;
checkBalanceChanged(); checkBalanceChanged();
} }
if(cachedUnconfirmedBalance || cachedImmatureBalance)
pollTimer->start();
} }
void WalletModel::checkBalanceChanged() void WalletModel::checkBalanceChanged()
@ -89,7 +85,8 @@ void WalletModel::checkBalanceChanged()
qint64 newUnconfirmedBalance = getUnconfirmedBalance(); qint64 newUnconfirmedBalance = getUnconfirmedBalance();
qint64 newImmatureBalance = getImmatureBalance(); qint64 newImmatureBalance = getImmatureBalance();
if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance) { if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance)
{
cachedBalance = newBalance; cachedBalance = newBalance;
cachedUnconfirmedBalance = newUnconfirmedBalance; cachedUnconfirmedBalance = newUnconfirmedBalance;
cachedImmatureBalance = newImmatureBalance; cachedImmatureBalance = newImmatureBalance;
@ -105,13 +102,11 @@ void WalletModel::updateTransaction(const QString &hash, int status)
// Balance and number of transactions might have changed // Balance and number of transactions might have changed
checkBalanceChanged(); checkBalanceChanged();
if(cachedUnconfirmedBalance || cachedImmatureBalance)
pollTimer->start();
int newNumTransactions = getNumTransactions(); int newNumTransactions = getNumTransactions();
if(cachedNumTransactions != newNumTransactions) { if(cachedNumTransactions != newNumTransactions)
emit numTransactionsChanged(newNumTransactions); {
cachedNumTransactions = newNumTransactions; cachedNumTransactions = newNumTransactions;
emit numTransactionsChanged(newNumTransactions);
} }
} }

Loading…
Cancel
Save