Skip to content

Commit 696683d

Browse files
committed
GUI: use cached balance in overviewpage and sendcoinsdialog.
Plus, calculate the cached balance right when the wallet model, so the wallet widgets don't need to redo the same balance calculation multiple times when they are waiting for the model balance polling timer.
1 parent 08e7407 commit 696683d

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/qt/overviewpage.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,13 @@ void OverviewPage::setWalletModel(WalletModel *model)
277277
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);
278278

279279
// Keep up to date with wallet
280-
interfaces::Wallet& wallet = model->wallet();
281-
interfaces::WalletBalances balances = wallet.getBalances();
282-
setBalance(balances);
280+
setBalance(model->getCachedBalance());
283281
connect(model, &WalletModel::balanceChanged, this, &OverviewPage::setBalance);
284282

285283
connect(model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &OverviewPage::updateDisplayUnit);
286284

287-
updateWatchOnlyLabels(wallet.haveWatchOnly() && !model->wallet().privateKeysDisabled());
285+
interfaces::Wallet& wallet = model->wallet();
286+
updateWatchOnlyLabels(wallet.haveWatchOnly() && !wallet.privateKeysDisabled());
288287
connect(model, &WalletModel::notifyWatchonlyChanged, [this](bool showWatchOnly) {
289288
updateWatchOnlyLabels(showWatchOnly && !walletModel->wallet().privateKeysDisabled());
290289
});

src/qt/sendcoinsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ void SendCoinsDialog::setBalance(const interfaces::WalletBalances& balances)
718718

719719
void SendCoinsDialog::refreshBalance()
720720
{
721-
setBalance(model->wallet().getBalances());
721+
setBalance(model->getCachedBalance());
722722
ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
723723
updateSmartFeeLabel();
724724
}

src/qt/walletmodel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ WalletModel::~WalletModel()
6666

6767
void WalletModel::startPollBalance()
6868
{
69+
// Update the cached balance right away, so every view can make use of it,
70+
// so them don't need to waste resources recalculating it.
71+
pollBalanceChanged();
72+
6973
// This timer will be fired repeatedly to update the balance
7074
// Since the QTimer::timeout is a private signal, it cannot be used
7175
// in the GUIUtil::ExceptionSafeConnect directly.

0 commit comments

Comments
 (0)