Skip to content

Commit

Permalink
Updated the pollCheckBalance method to be more like upstream version (#…
Browse files Browse the repository at this point in the history
…933)

* Updated the pollCheckBalance method to be more like upstream version

* Moved check stakes logic into checkbalance function to make sure it always runs when check balance is called

* Removed redundant call

* Wrong expression for checking block count
  • Loading branch information
mxaddict authored Feb 17, 2022
1 parent 7de6fac commit dcc479c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *wallet, Op
cachedAmountExp(-1)
{
fHaveWatchOnly = wallet->HaveWatchOnly();
fForceCheckBalanceChanged = true;

addressTableModel = new AddressTableModel(wallet, this);
transactionTableModel = new TransactionTableModel(platformStyle, wallet, this);
Expand All @@ -75,8 +74,7 @@ void WalletModel::StartBalanceTimer()
{
// This timer will be fired repeatedly to update the balance
pollTimer = new QTimer(this);
connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollBalanceChanged(true)));
pollBalanceChanged(true);
connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollBalanceChanged()));
pollTimer->start(MODEL_UPDATE_DELAY);
}

Expand Down Expand Up @@ -160,8 +158,12 @@ void WalletModel::updateStatus()
Q_EMIT encryptionStatusChanged(newEncryptionStatus);
}

void WalletModel::pollBalanceChanged(bool calledByPoll)
void WalletModel::pollBalanceChanged()
{
// Avoid recomputing wallet balances unless a TransactionChanged or
// BlockTip notification was received.
if (!fForceCheckBalanceChanged && chainActive.Height() == cachedNumBlocks) return;

// Get required locks upfront. This avoids the GUI from getting stuck on
// periodical polls if the core is holding the locks for a longer time -
// for example, during a wallet rescan.
Expand All @@ -171,19 +173,18 @@ void WalletModel::pollBalanceChanged(bool calledByPoll)
TRY_LOCK(wallet->cs_wallet, lockWallet);
if(!lockWallet)
return;
if(fForceCheckBalanceChanged || calledByPoll)
{

if (fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks) {
fForceCheckBalanceChanged = false;

// Balance and number of transactions might have changed
cachedNumBlocks = chainActive.Height();

checkBalanceChanged();
checkStakesChanged();
}

if(transactionTableModel && chainActive.Height() != cachedNumBlocks)
transactionTableModel->updateConfirmations();
if(transactionTableModel)
transactionTableModel->updateConfirmations();
}
}

void WalletModel::checkBalanceChanged()
Expand Down Expand Up @@ -246,6 +247,8 @@ void WalletModel::checkBalanceChanged()
newPrivateBalanceLocked
);
}

checkStakesChanged();
}

void WalletModel::checkStakesChanged()
Expand Down
2 changes: 1 addition & 1 deletion src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public Q_SLOTS:
/* Watch-only added */
void updateWatchOnlyFlag(bool fHaveWatchonly);
/* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
void pollBalanceChanged(bool calledByPoll = false);
void pollBalanceChanged();
};

#endif // NAVCOIN_QT_WALLETMODEL_H

0 comments on commit dcc479c

Please sign in to comment.