From c041a540781be406a699bfd881098698b36fe9e9 Mon Sep 17 00:00:00 2001 From: SergiySW Date: Fri, 30 Jun 2017 09:46:53 +0300 Subject: [PATCH 1/4] GUI: show representative --- rai/qt/qt.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++----- rai/qt/qt.hpp | 1 + 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index 07fb1d3c..90e08cf2 100755 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -1049,6 +1049,7 @@ void rai_qt::wallet::refresh () accounts.refresh (); history.refresh (); account_viewer.history.refresh (); + settings.refresh_representative (); } void rai_qt::wallet::update_connected () @@ -1096,7 +1097,7 @@ new_password (new QLineEdit), retype_password (new QLineEdit), change (new QPushButton ("Set/Change password")), sep2 (new QFrame), -representative (new QLabel), +representative (new QLabel ("Account representative:")), new_representative (new QLineEdit), change_rep (new QPushButton ("Change representative")), back (new QPushButton ("Back")), @@ -1163,13 +1164,46 @@ wallet (wallet_a) rai::account representative_l; if (!representative_l.decode_account (new_representative->text ().toStdString ())) { - change_rep->setEnabled (false); + rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, false); + if (this->wallet.wallet_m->store.valid_password (transaction)) { - rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, true); - this->wallet.wallet_m->store.representative_set (transaction, representative_l); + change_rep->setEnabled (false); + { + rai::transaction transaction_l (this->wallet.wallet_m->store.environment, nullptr, true); + this->wallet.wallet_m->store.representative_set (transaction_l, representative_l); + } + auto block (this->wallet.wallet_m->change_sync (this->wallet.account, representative_l)); + change_rep->setEnabled (true); + show_button_success (*change_rep); + change_rep->setText ("Represenative was changed"); + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () + { + show_button_ok (*change_rep); + change_rep->setText ("Change representative"); + }); } - auto block (this->wallet.wallet_m->change_sync (this->wallet.account, representative_l)); - change_rep->setEnabled (true); + else + { + show_button_error (*change_rep); + change_rep->setText ("Wallet is locked, unlock it"); + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () + { + show_button_ok (*change_rep); + change_rep->setText ("Change representative"); + }); + } + } + else + { + show_line_error (*new_representative); + show_button_error (*change_rep); + change_rep->setText ("Invalid account"); + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () + { + show_line_ok (*new_representative); + show_button_ok (*change_rep); + change_rep->setText ("Change representative"); + }); } }); QObject::connect (back, &QPushButton::released, [this] () @@ -1191,6 +1225,25 @@ wallet (wallet_a) this->wallet.wallet_m->store.password.value_set (empty); update_locked (true, true); }); + representative->setToolTip ("In the infrequent case where the network needs to make a global decision,\nyour wallet software performs a balance-weighted vote to determine\nthe outcome. Since not everyone can remain online and perform this duty,\nyour wallet names a representative that can vote with, but cannot spend,\nyour balance."); + refresh_representative (); +} + +void rai_qt::settings::refresh_representative () +{ + rai::transaction transaction (this->wallet.wallet_m->node.store.environment, nullptr, false); + rai::account_info info; + auto error (this->wallet.wallet_m->node.store.account_get (transaction, this->wallet.account, info)); + if (!error) + { + auto block (this->wallet.wallet_m->node.store.block_get (transaction, info.rep_block)); + assert (block != nullptr); + new_representative->setText (block->representative ().to_account ().c_str ()); + } + else + { + new_representative->setText (this->wallet.wallet_m->store.representative (transaction).to_account ().c_str ()); + } } void rai_qt::settings::activate () diff --git a/rai/qt/qt.hpp b/rai/qt/qt.hpp index 8b58c0ea..b7fe1cc8 100644 --- a/rai/qt/qt.hpp +++ b/rai/qt/qt.hpp @@ -26,6 +26,7 @@ namespace rai_qt { { public: settings (rai_qt::wallet &); + void refresh_representative (); void activate (); void update_locked (bool, bool); QWidget * window; From 9088d3236bbd3564914ec99589e3f99e58e4cffb Mon Sep 17 00:00:00 2001 From: SergiySW Date: Fri, 30 Jun 2017 10:16:05 +0300 Subject: [PATCH 2/4] GUI: change password with locked wallet & invalid unlock password --- rai/qt/qt.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index 90e08cf2..d489997c 100755 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -1158,6 +1158,16 @@ wallet (wallet_a) } } } + else + { + show_button_error (*change); + change->setText ("Wallet is locked, unlock it"); + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () + { + show_button_ok (*change); + change->setText ("Set/Change password"); + }); + } }); QObject::connect (change_rep, &QPushButton::released, [this] () { @@ -1217,6 +1227,18 @@ wallet (wallet_a) { password->clear (); } + else + { + show_line_error (*password); + show_button_error (*unlock); + unlock->setText ("Invalid password"); + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () + { + show_line_ok (*password); + show_button_ok (*unlock); + unlock->setText ("Unlock"); + }); + } }); QObject::connect (lock, &QPushButton::released, [this] () { From efb7547a3b955d0f21fd3325b609400a6f13c6fb Mon Sep 17 00:00:00 2001 From: SergiySW Date: Fri, 30 Jun 2017 10:20:26 +0300 Subject: [PATCH 3/4] GUI: Password was changed notification --- rai/qt/qt.cpp | 63 ++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index d489997c..d2ac1ad2 100755 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -1130,34 +1130,41 @@ wallet (wallet_a) layout->addStretch (); layout->addWidget (back); window->setLayout (layout); - QObject::connect (change, &QPushButton::released, [this] () - { + QObject::connect (change, &QPushButton::released, [this] () + { rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, true); - if (this->wallet.wallet_m->store.valid_password (transaction)) - { - if (new_password->text ().isEmpty()) - { - new_password->clear (); - new_password->setPlaceholderText ("Empty Password - try again: New password"); - retype_password->clear (); - retype_password->setPlaceholderText ("Empty Password - try again: Retype password"); - } - else - { - if (new_password->text () == retype_password->text ()) - { - this->wallet.wallet_m->store.rekey (transaction, std::string (new_password->text ().toLocal8Bit ())); - new_password->clear (); - retype_password->clear (); - retype_password->setPlaceholderText ("Retype password"); - } - else - { - retype_password->clear (); - retype_password->setPlaceholderText ("Password mismatch"); - } - } - } + if (this->wallet.wallet_m->store.valid_password (transaction)) + { + if (new_password->text ().isEmpty()) + { + new_password->clear (); + new_password->setPlaceholderText ("Empty Password - try again: New password"); + retype_password->clear (); + retype_password->setPlaceholderText ("Empty Password - try again: Retype password"); + } + else + { + if (new_password->text () == retype_password->text ()) + { + this->wallet.wallet_m->store.rekey (transaction, std::string (new_password->text ().toLocal8Bit ())); + new_password->clear (); + retype_password->clear (); + retype_password->setPlaceholderText ("Retype password"); + show_button_success (*change); + change->setText ("Password was changed"); + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () + { + show_button_ok (*change); + change->setText ("Set/Change password"); + }); + } + else + { + retype_password->clear (); + retype_password->setPlaceholderText ("Password mismatch"); + } + } + } else { show_button_error (*change); @@ -1168,7 +1175,7 @@ wallet (wallet_a) change->setText ("Set/Change password"); }); } - }); + }); QObject::connect (change_rep, &QPushButton::released, [this] () { rai::account representative_l; From 7ea7f60fd3e8c0268c4edd3b106287dd5b366ec1 Mon Sep 17 00:00:00 2001 From: SergiySW Date: Fri, 30 Jun 2017 20:01:54 +0300 Subject: [PATCH 4/4] GUI: disallow lock with non-empty password field because many users trying to set password this way --- rai/qt/qt.cpp | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index d2ac1ad2..0343f494 100755 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -1223,13 +1223,13 @@ wallet (wallet_a) }); } }); - QObject::connect (back, &QPushButton::released, [this] () - { - assert (this->wallet.main_stack->currentWidget () == window); + QObject::connect (back, &QPushButton::released, [this] () + { + assert (this->wallet.main_stack->currentWidget () == window); this->wallet.pop_main_stack (); - }); - QObject::connect (unlock, &QPushButton::released, [this] () - { + }); + QObject::connect (unlock, &QPushButton::released, [this] () + { if (!this->wallet.wallet_m->enter_password (std::string (password->text ().toLocal8Bit ()))) { password->clear (); @@ -1246,13 +1246,33 @@ wallet (wallet_a) unlock->setText ("Unlock"); }); } - }); - QObject::connect (lock, &QPushButton::released, [this] () - { - rai::raw_key empty; - empty.data.clear (); - this->wallet.wallet_m->store.password.value_set (empty); - update_locked (true, true); + }); + QObject::connect (lock, &QPushButton::released, [this] () + { + if (password->text ().isEmpty()) + { + rai::raw_key empty; + empty.data.clear (); + this->wallet.wallet_m->store.password.value_set (empty); + update_locked (true, true); + } + else + { + show_line_error (*password); + show_button_error (*lock); + lock->setText ("Error"); + show_line_success (*new_password); + show_button_success (*change); + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () + { + show_line_ok (*password); + password->clear (); + show_button_ok (*lock); + lock->setText ("Lock"); + show_line_ok (*new_password); + show_button_ok (*change); + }); + } }); representative->setToolTip ("In the infrequent case where the network needs to make a global decision,\nyour wallet software performs a balance-weighted vote to determine\nthe outcome. Since not everyone can remain online and perform this duty,\nyour wallet names a representative that can vote with, but cannot spend,\nyour balance."); refresh_representative ();