From 878a31f026b64706a0521b853209e59cb4253341 Mon Sep 17 00:00:00 2001 From: jamescowens Date: Mon, 20 Jul 2020 22:32:42 -0400 Subject: [PATCH] Add transactionUpdated signal With the hide loop in the updatedTransactions method in the overview page, the updateTransactions needs to be called after the underlying transaction model has recevied a new row, because the getLimit is set to a higher value than is visible on purpose to avoid a resort. The signal that would normally be used, numTransactionsChanged, does NOT work for this purpose, because that signal is only sent when the size of the number of transactions in the wallet is changed. The size will change if the wallet is just keys and a resync or rescan is done, but the situation when an old wallet is used with existing transactions, but the blockchain is synced from zero will not work. The wallet size is constant then for old transactions relinked. To handle this case I had to add a new signal transactionUpdated which is sent when WalletModel::updateTransaction is called. --- src/qt/overviewpage.cpp | 2 +- src/qt/overviewpage.h | 2 +- src/qt/walletmodel.cpp | 12 ++++++++++-- src/qt/walletmodel.h | 5 +++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index a936c52a70..204c2c91be 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -280,7 +280,7 @@ void OverviewPage::setWalletModel(WalletModel *model) connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); - connect(model, SIGNAL(numTransactionsChanged(int)), this, SLOT(updateTransactions())); + connect(model, SIGNAL(transactionUpdated()), this, SLOT(updateTransactions())); UpdateBoincUtilization(); } diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index 41f36a8935..6c870e585f 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -48,7 +48,6 @@ public slots: private: int getNumTransactionsForView(); - void updateTransactions(); Ui::OverviewPage *ui; ResearcherModel *researcherModel; @@ -63,6 +62,7 @@ public slots: private slots: void updateDisplayUnit(); + void updateTransactions(); void updateResearcherStatus(); void updateMagnitude(); void updatePendingAccrual(); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 41be1f564f..cce29d8791 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -126,16 +126,24 @@ void WalletModel::checkBalanceChanged() void WalletModel::updateTransaction(const QString &hash, int status) { - if(transactionTableModel) + if (transactionTableModel) + { transactionTableModel->updateTransaction(hash, status); + // Note this is subtly different than the below. If a resync is being done on a wallet + // that already has transactions, the numTransactionsChanged will not be emitted after the + // wallet is loaded because the size() does not change. See the comments in the header file. + emit transactionUpdated(); + } + // Balance and number of transactions might have changed checkBalanceChanged(); int newNumTransactions = getNumTransactions(); - if(cachedNumTransactions != newNumTransactions) + if (cachedNumTransactions != newNumTransactions) { cachedNumTransactions = newNumTransactions; + emit numTransactionsChanged(newNumTransactions); } } diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index ec65ce8279..4f6580ac8e 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -163,6 +163,11 @@ public slots: void pollBalanceChanged(); signals: + // Transaction updated. This is necessary because on a resync from zero with an existing wallet. + // the numTransactionsChanged signal will not be emitted, and therefore the overpage transaction list + // needs this signal instead. + void transactionUpdated(); + // Signal that balance in wallet changed void balanceChanged(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);