Skip to content

Commit 0a830f4

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 264e2b9 commit 0a830f4

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
@@ -67,6 +67,10 @@ WalletModel::~WalletModel()
6767

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

0 commit comments

Comments
 (0)