Skip to content

Commit 80daee0

Browse files
committed
[Qt] Call checkBalanceChanged() periodically instead for every updated transaction
1 parent f30801a commit 80daee0

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/qt/walletmodel.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *p
3636
{
3737
fProcessingQueuedTransactions = false;
3838
fHaveWatchOnly = wallet->HaveWatchOnly();
39+
fForceCheckBalanceChanged = false;
3940

4041
addressTableModel = new AddressTableModel(wallet, this);
4142
transactionTableModel = new TransactionTableModel(wallet, this);
@@ -121,8 +122,10 @@ void WalletModel::pollBalanceChanged()
121122
if(!lockWallet)
122123
return;
123124

124-
if(chainActive.Height() != cachedNumBlocks)
125+
if(fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks)
125126
{
127+
fForceCheckBalanceChanged = false;
128+
126129
// Balance and number of transactions might have changed
127130
cachedNumBlocks = chainActive.Height();
128131

@@ -167,7 +170,7 @@ void WalletModel::updateTransaction(const QString &hash, int status)
167170
transactionTableModel->updateTransaction(hash, status);
168171

169172
// Balance and number of transactions might have changed
170-
checkBalanceChanged();
173+
fForceCheckBalanceChanged = true;
171174
}
172175

173176
void WalletModel::updateAddressBook(const QString &address, const QString &label,
@@ -344,6 +347,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
344347
}
345348
emit coinsSent(wallet, rcp, transaction_array);
346349
}
350+
checkBalanceChanged(); // update balance immediately, otherwise there could be a short noticeable delay until pollBalanceChanged hits
347351

348352
return SendCoinsReturn(OK);
349353
}
@@ -473,11 +477,6 @@ static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet,
473477

474478
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
475479
{
476-
// emits signal "showProgress"
477-
QMetaObject::invokeMethod(walletmodel, "showProgress", Qt::QueuedConnection,
478-
Q_ARG(QString, QString::fromStdString(title)),
479-
Q_ARG(int, nProgress));
480-
481480
if (nProgress == 0)
482481
fQueueNotifications = true;
483482

@@ -495,6 +494,11 @@ static void ShowProgress(WalletModel *walletmodel, const std::string &title, int
495494
}
496495
std::vector<std::pair<uint256, ChangeType> >().swap(vQueueNotifications); // clear
497496
}
497+
498+
// emits signal "showProgress"
499+
QMetaObject::invokeMethod(walletmodel, "showProgress", Qt::QueuedConnection,
500+
Q_ARG(QString, QString::fromStdString(title)),
501+
Q_ARG(int, nProgress));
498502
}
499503

500504
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)

src/qt/walletmodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class WalletModel : public QObject
199199
CWallet *wallet;
200200
bool fProcessingQueuedTransactions;
201201
bool fHaveWatchOnly;
202+
bool fForceCheckBalanceChanged;
202203

203204
// Wallet has an options model for wallet-specific options
204205
// (transaction fee, for example)

0 commit comments

Comments
 (0)