@@ -95,25 +95,27 @@ class TransactionTablePriv
9595 */
9696 QList<TransactionRecord> cachedWallet;
9797
98- bool fQueueNotifications = false ;
98+ bool m_loaded = false ;
99+ int m_progress = 100 ;
99100 std::vector< TransactionNotification > vQueueNotifications;
100101
101102 void NotifyTransactionChanged (const uint256 &hash, ChangeType status);
102- void ShowProgress ( const std::string &title, int nProgress );
103+ void DispatchNotifications ( );
103104
104105 /* Query entire wallet anew from core.
105106 */
106107 void refreshWallet (interfaces::Wallet& wallet)
107108 {
108- qDebug () << " TransactionTablePriv::refreshWallet" ;
109- cachedWallet.clear ();
109+ assert (cachedWallet.empty ());
110110 {
111111 for (const auto & wtx : wallet.getWalletTxs ()) {
112112 if (TransactionRecord::showTransaction ()) {
113113 cachedWallet.append (TransactionRecord::decomposeTransaction (wtx));
114114 }
115115 }
116116 }
117+ m_loaded = true ;
118+ DispatchNotifications ();
117119 }
118120
119121 /* Update our model of the wallet incrementally, to synchronize our model of the wallet
@@ -248,12 +250,12 @@ TransactionTableModel::TransactionTableModel(const PlatformStyle *_platformStyle
248250 fProcessingQueuedTransactions(false ),
249251 platformStyle(_platformStyle)
250252{
253+ subscribeToCoreSignals ();
254+
251255 columns << QString () << QString () << tr (" Date" ) << tr (" Type" ) << tr (" Label" ) << BitcoinUnits::getAmountColumnTitle (walletModel->getOptionsModel ()->getDisplayUnit ());
252256 priv->refreshWallet (walletModel->wallet ());
253257
254258 connect (walletModel->getOptionsModel (), &OptionsModel::displayUnitChanged, this , &TransactionTableModel::updateDisplayUnit);
255-
256- subscribeToCoreSignals ();
257259}
258260
259261TransactionTableModel::~TransactionTableModel ()
@@ -712,44 +714,42 @@ void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeT
712714
713715 TransactionNotification notification (hash, status, showTransaction);
714716
715- if (fQueueNotifications )
717+ if (!m_loaded || m_progress < 100 )
716718 {
717719 vQueueNotifications.push_back (notification);
718720 return ;
719721 }
720722 notification.invoke (parent);
721723}
722724
723- void TransactionTablePriv::ShowProgress ( const std::string &title, int nProgress )
725+ void TransactionTablePriv::DispatchNotifications ( )
724726{
725- if (nProgress == 0 )
726- fQueueNotifications = true ;
727+ if (!m_loaded || m_progress < 100 ) return ;
727728
728- if (nProgress == 100 )
729+ if (vQueueNotifications.size () > 10 ) { // prevent balloon spam, show maximum 10 balloons
730+ bool invoked = QMetaObject::invokeMethod (parent, " setProcessingQueuedTransactions" , Qt::QueuedConnection, Q_ARG (bool , true ));
731+ assert (invoked);
732+ }
733+ for (unsigned int i = 0 ; i < vQueueNotifications.size (); ++i)
729734 {
730- fQueueNotifications = false ;
731- if (vQueueNotifications.size () > 10 ) { // prevent balloon spam, show maximum 10 balloons
732- bool invoked = QMetaObject::invokeMethod (parent, " setProcessingQueuedTransactions" , Qt::QueuedConnection, Q_ARG (bool , true ));
735+ if (vQueueNotifications.size () - i <= 10 ) {
736+ bool invoked = QMetaObject::invokeMethod (parent, " setProcessingQueuedTransactions" , Qt::QueuedConnection, Q_ARG (bool , false ));
733737 assert (invoked);
734738 }
735- for (unsigned int i = 0 ; i < vQueueNotifications.size (); ++i)
736- {
737- if (vQueueNotifications.size () - i <= 10 ) {
738- bool invoked = QMetaObject::invokeMethod (parent, " setProcessingQueuedTransactions" , Qt::QueuedConnection, Q_ARG (bool , false ));
739- assert (invoked);
740- }
741739
742- vQueueNotifications[i].invoke (parent);
743- }
744- vQueueNotifications.clear ();
740+ vQueueNotifications[i].invoke (parent);
745741 }
742+ vQueueNotifications.clear ();
746743}
747744
748745void TransactionTableModel::subscribeToCoreSignals ()
749746{
750747 // Connect signals to wallet
751748 m_handler_transaction_changed = walletModel->wallet ().handleTransactionChanged (std::bind (&TransactionTablePriv::NotifyTransactionChanged, priv, std::placeholders::_1, std::placeholders::_2));
752- m_handler_show_progress = walletModel->wallet ().handleShowProgress (std::bind (&TransactionTablePriv::ShowProgress, priv, std::placeholders::_1, std::placeholders::_2));
749+ m_handler_show_progress = walletModel->wallet ().handleShowProgress ([this ](const std::string&, int progress) {
750+ priv->m_progress = progress;
751+ priv->DispatchNotifications ();
752+ });
753753}
754754
755755void TransactionTableModel::unsubscribeFromCoreSignals ()
0 commit comments