Merge 3ec033ed32 into merged_master (Bitcoin PR bitcoin-core/gui#121)

This commit is contained in:
Andrew Poelstra 2021-07-18 01:09:47 +00:00
commit 2893856697

View file

@ -99,18 +99,20 @@ public:
*/
QList<TransactionRecord> cachedWallet;
bool fQueueNotifications = false;
/** True when model finishes loading all wallet transactions on start */
bool m_loaded = false;
/** True when transactions are being notified, for instance when scanning */
bool m_loading = false;
std::vector< TransactionNotification > vQueueNotifications;
void NotifyTransactionChanged(const uint256 &hash, ChangeType status);
void ShowProgress(const std::string &title, int nProgress);
void DispatchNotifications();
/* Query entire wallet anew from core.
*/
void refreshWallet(interfaces::Wallet& wallet)
{
qDebug() << "TransactionTablePriv::refreshWallet";
cachedWallet.clear();
assert(!m_loaded);
{
for (const auto& wtx : wallet.getWalletTxs()) {
if (TransactionRecord::showTransaction()) {
@ -118,6 +120,8 @@ public:
}
}
}
m_loaded = true;
DispatchNotifications();
}
/* Update our model of the wallet incrementally, to synchronize our model of the wallet
@ -252,12 +256,12 @@ TransactionTableModel::TransactionTableModel(const PlatformStyle *_platformStyle
fProcessingQueuedTransactions(false),
platformStyle(_platformStyle)
{
subscribeToCoreSignals();
columns << QString() << QString() << tr("Date") << tr("Type") << tr("Label") << tr("Amount");
priv->refreshWallet(walletModel->wallet());
connect(walletModel->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &TransactionTableModel::updateDisplayUnit);
subscribeToCoreSignals();
}
TransactionTableModel::~TransactionTableModel()
@ -723,7 +727,7 @@ void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeT
TransactionNotification notification(hash, status, showTransaction);
if (fQueueNotifications)
if (!m_loaded || m_loading)
{
vQueueNotifications.push_back(notification);
return;
@ -731,36 +735,34 @@ void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeT
notification.invoke(parent);
}
void TransactionTablePriv::ShowProgress(const std::string &title, int nProgress)
void TransactionTablePriv::DispatchNotifications()
{
if (nProgress == 0)
fQueueNotifications = true;
if (!m_loaded || m_loading) return;
if (nProgress == 100)
if (vQueueNotifications.size() > 10) { // prevent balloon spam, show maximum 10 balloons
bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
assert(invoked);
}
for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
{
fQueueNotifications = false;
if (vQueueNotifications.size() > 10) { // prevent balloon spam, show maximum 10 balloons
bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
if (vQueueNotifications.size() - i <= 10) {
bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
assert(invoked);
}
for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
{
if (vQueueNotifications.size() - i <= 10) {
bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
assert(invoked);
}
vQueueNotifications[i].invoke(parent);
}
vQueueNotifications.clear();
vQueueNotifications[i].invoke(parent);
}
vQueueNotifications.clear();
}
void TransactionTableModel::subscribeToCoreSignals()
{
// Connect signals to wallet
m_handler_transaction_changed = walletModel->wallet().handleTransactionChanged(std::bind(&TransactionTablePriv::NotifyTransactionChanged, priv, std::placeholders::_1, std::placeholders::_2));
m_handler_show_progress = walletModel->wallet().handleShowProgress(std::bind(&TransactionTablePriv::ShowProgress, priv, std::placeholders::_1, std::placeholders::_2));
m_handler_show_progress = walletModel->wallet().handleShowProgress([this](const std::string&, int progress) {
priv->m_loading = progress < 100;
priv->DispatchNotifications();
});
}
void TransactionTableModel::unsubscribeFromCoreSignals()