@@ -106,13 +106,12 @@ wallet (wallet_a)
106
106
});
107
107
}
108
108
109
- void rai_qt::self_pane::refresh_balance ( )
109
+ void rai_qt::self_pane::set_balance_text (std::pair<rai:: uint128_t , rai:: uint128_t > balance_a )
110
110
{
111
- auto balance (wallet.node .balance_pending (wallet.account ));
112
- auto final_text (std::string (" Balance: " ) + wallet.format_balance (balance.first ));
113
- if (!balance.second .is_zero ())
111
+ auto final_text (std::string (" Balance: " ) + wallet.format_balance (balance_a.first ));
112
+ if (!balance_a.second .is_zero ())
114
113
{
115
- final_text += " \n Pending: " + wallet.format_balance (balance .second );
114
+ final_text += " \n Pending: " + wallet.format_balance (balance_a .second );
116
115
}
117
116
wallet.self .balance_label ->setText (QString (final_text.c_str ()));
118
117
}
@@ -153,6 +152,7 @@ wallet (wallet_a)
153
152
layout->addWidget (account_key_button);
154
153
layout->addWidget (back);
155
154
window->setLayout (layout);
155
+
156
156
QObject::connect (use_account, &QPushButton::released, [this ]() {
157
157
auto selection (view->selectionModel ()->selection ().indexes ());
158
158
if (selection.size () == 1 )
@@ -1045,8 +1045,44 @@ active_status (*this)
1045
1045
refresh ();
1046
1046
}
1047
1047
1048
+ void rai_qt::wallet::ongoing_refresh ()
1049
+ {
1050
+ std::weak_ptr<rai_qt::wallet> wallet_w (shared_from_this ());
1051
+
1052
+ // Update balance if needed. This happens on an alarm thread, which posts back to the UI
1053
+ // to do the actual rendering. This avoid UI lockups as balance_pending may take several
1054
+ // seconds if there's a lot of pending transactions.
1055
+ if (needs_balance_refresh)
1056
+ {
1057
+ needs_balance_refresh = false ;
1058
+ auto balance_l (node.balance_pending (account));
1059
+ application.postEvent (&processor, new eventloop_event ([wallet_w, balance_l]() {
1060
+ if (auto this_l = wallet_w.lock ())
1061
+ {
1062
+ this_l->self .set_balance_text (balance_l);
1063
+ }
1064
+ }));
1065
+ }
1066
+
1067
+ // Updates the status line periodically with bootstrap status and block counts.
1068
+ application.postEvent (&processor, new eventloop_event ([wallet_w]() {
1069
+ if (auto this_l = wallet_w.lock ())
1070
+ {
1071
+ this_l->active_status .set_text ();
1072
+ }
1073
+ }));
1074
+
1075
+ node.alarm .add (std::chrono::steady_clock::now () + std::chrono::seconds (5 ), [wallet_w]() {
1076
+ if (auto wallet_l = wallet_w.lock ())
1077
+ {
1078
+ wallet_l->ongoing_refresh ();
1079
+ }
1080
+ });
1081
+ }
1082
+
1048
1083
void rai_qt::wallet::start ()
1049
1084
{
1085
+ ongoing_refresh ();
1050
1086
std::weak_ptr<rai_qt::wallet> this_w (shared_from_this ());
1051
1087
QObject::connect (settings_button, &QPushButton::released, [this_w]() {
1052
1088
if (auto this_l = this_w.lock ())
@@ -1250,15 +1286,7 @@ void rai_qt::wallet::start ()
1250
1286
node.observers .account_balance .add ([this_w](rai::account const & account_a, bool is_pending) {
1251
1287
if (auto this_l = this_w.lock ())
1252
1288
{
1253
- this_l->application .postEvent (&this_l->processor , new eventloop_event ([this_w, account_a]() {
1254
- if (auto this_l = this_w.lock ())
1255
- {
1256
- if (account_a == this_l->account )
1257
- {
1258
- this_l->self .refresh_balance ();
1259
- }
1260
- }
1261
- }));
1289
+ this_l->needs_balance_refresh = this_l->needs_balance_refresh || account_a == this_l->account ;
1262
1290
}
1263
1291
});
1264
1292
node.observers .wallet .add ([this_w](bool active_a) {
@@ -1358,7 +1386,7 @@ void rai_qt::wallet::refresh ()
1358
1386
assert (wallet_m->store .exists (transaction, account));
1359
1387
}
1360
1388
self.account_text ->setText (QString (account.to_account ().c_str ()));
1361
- self. refresh_balance () ;
1389
+ needs_balance_refresh = true ;
1362
1390
accounts.refresh ();
1363
1391
history.refresh ();
1364
1392
account_viewer.history .refresh ();
@@ -1841,10 +1869,10 @@ wallet (wallet_a)
1841
1869
this ->wallet .pop_main_stack ();
1842
1870
});
1843
1871
QObject::connect (search_for_receivables, &QPushButton::released, [this ]() {
1844
- this ->wallet .wallet_m ->search_pending ();
1872
+ std::thread ([ this ] { this ->wallet .wallet_m ->search_pending (); }). detach ();
1845
1873
});
1846
1874
QObject::connect (bootstrap, &QPushButton::released, [this ]() {
1847
- this ->wallet .node .bootstrap_initiator .bootstrap ();
1875
+ std::thread ([ this ] { this ->wallet .node .bootstrap_initiator .bootstrap (); }). detach ();
1848
1876
});
1849
1877
QObject::connect (create_block, &QPushButton::released, [this ]() {
1850
1878
this ->wallet .push_main_stack (this ->wallet .block_creation .window );
0 commit comments