Skip to content

Commit c6cbdf1

Browse files
committed
qt: Refactor ShowProgress to DispatchNotifications
1 parent 3bccd50 commit c6cbdf1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/qt/transactiontablemodel.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ class TransactionTablePriv
9696
*/
9797
QList<TransactionRecord> cachedWallet;
9898

99-
bool fQueueNotifications = false;
10099
/** True when model finishes loading all wallet transactions on start */
101100
bool m_loaded = false;
101+
/** True when transactions are being notified, for instance when scanning */
102+
bool m_loading = false;
102103
std::vector< TransactionNotification > vQueueNotifications;
103104

104105
void NotifyTransactionChanged(const uint256 &hash, ChangeType status);
105-
void ShowProgress(const std::string &title, int nProgress);
106+
void DispatchNotifications();
106107

107108
/* Query entire wallet anew from core.
108109
*/
@@ -721,22 +722,19 @@ void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeT
721722

722723
TransactionNotification notification(hash, status, showTransaction);
723724

724-
if (fQueueNotifications)
725+
if (m_loading)
725726
{
726727
vQueueNotifications.push_back(notification);
727728
return;
728729
}
729730
notification.invoke(parent);
730731
}
731732

732-
void TransactionTablePriv::ShowProgress(const std::string &title, int nProgress)
733+
void TransactionTablePriv::DispatchNotifications()
733734
{
734-
if (nProgress == 0)
735-
fQueueNotifications = true;
735+
if (m_loading) return;
736736

737-
if (nProgress == 100)
738737
{
739-
fQueueNotifications = false;
740738
if (vQueueNotifications.size() > 10) { // prevent balloon spam, show maximum 10 balloons
741739
bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
742740
assert(invoked);
@@ -758,7 +756,10 @@ void TransactionTableModel::subscribeToCoreSignals()
758756
{
759757
// Connect signals to wallet
760758
m_handler_transaction_changed = walletModel->wallet().handleTransactionChanged(std::bind(&TransactionTablePriv::NotifyTransactionChanged, priv, std::placeholders::_1, std::placeholders::_2));
761-
m_handler_show_progress = walletModel->wallet().handleShowProgress(std::bind(&TransactionTablePriv::ShowProgress, priv, std::placeholders::_1, std::placeholders::_2));
759+
m_handler_show_progress = walletModel->wallet().handleShowProgress([this](const std::string&, int progress) {
760+
priv->m_loading = progress < 100;
761+
priv->DispatchNotifications();
762+
});
762763
}
763764

764765
void TransactionTableModel::unsubscribeFromCoreSignals()

0 commit comments

Comments
 (0)