Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(qt): allow refreshing wallet data without crashing #6456

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ class TransactionTablePriv

/* Query entire wallet anew from core.
*/
void refreshWallet(interfaces::Wallet& wallet)
void refreshWallet(interfaces::Wallet& wallet, bool force = false)
{
parent->beginResetModel();
assert(!m_loaded);
assert(!m_loaded || force);
cachedWallet.clear();
try {
for (const auto& wtx : wallet.getWalletTxs()) {
if (TransactionRecord::showTransaction()) {
Expand Down Expand Up @@ -284,9 +285,9 @@ TransactionTableModel::~TransactionTableModel()
delete priv;
}

void TransactionTableModel::refreshWallet()
void TransactionTableModel::refreshWallet(bool force)
{
priv->refreshWallet(walletModel->wallet());
priv->refreshWallet(walletModel->wallet(), force);
}

/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
Expand Down Expand Up @@ -846,12 +847,13 @@ void TransactionTablePriv::DispatchNotifications()

vQueueNotifications[i].invoke(parent);
}
vQueueNotifications.clear();
} else {
// it's much faster to just refresh the whole thing instead
bool invoked = QMetaObject::invokeMethod(parent, "refreshWallet", Qt::QueuedConnection);
// it's much faster to just drop all the queued notifications and refresh the whole thing instead
vQueueNotifications.clear();
bool invoked = QMetaObject::invokeMethod(parent, "refreshWallet", Qt::QueuedConnection, Q_ARG(bool, true));
assert(invoked);
}
vQueueNotifications.clear();
}

void TransactionTableModel::subscribeToCoreSignals()
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactiontablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class TransactionTableModel : public QAbstractTableModel

public Q_SLOTS:
/* Refresh the whole wallet, helpful for huge notification queues */
void refreshWallet();
void refreshWallet(bool foce = false);
/* New transaction, or transaction changed status */
void updateTransaction(const QString &hash, int status, bool showTransaction);
void updateAddressBook(const QString &address, const QString &label,
Expand Down
Loading