Skip to content

Commit

Permalink
Add transactionUpdated signal
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jamescowens committed Jul 21, 2020
1 parent 2de0da7 commit 878a31f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/overviewpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public slots:

private:
int getNumTransactionsForView();
void updateTransactions();

Ui::OverviewPage *ui;
ResearcherModel *researcherModel;
Expand All @@ -63,6 +62,7 @@ public slots:

private slots:
void updateDisplayUnit();
void updateTransactions();
void updateResearcherStatus();
void updateMagnitude();
void updatePendingAccrual();
Expand Down
12 changes: 10 additions & 2 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 878a31f

Please sign in to comment.