Merge branch 'pulls/150'
This commit is contained in:
commit
0eacc16003
2 changed files with 150 additions and 47 deletions
196
rai/qt/qt.cpp
196
rai/qt/qt.cpp
|
@ -1091,6 +1091,7 @@ void rai_qt::wallet::refresh ()
|
|||
accounts.refresh ();
|
||||
history.refresh ();
|
||||
account_viewer.history.refresh ();
|
||||
settings.refresh_representative ();
|
||||
}
|
||||
|
||||
void rai_qt::wallet::update_connected ()
|
||||
|
@ -1138,7 +1139,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")),
|
||||
|
@ -1171,68 +1172,169 @@ 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);
|
||||
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] ()
|
||||
{
|
||||
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] ()
|
||||
{
|
||||
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 ();
|
||||
}
|
||||
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] ()
|
||||
{
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
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);
|
||||
});
|
||||
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 ()
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace rai_qt {
|
|||
{
|
||||
public:
|
||||
settings (rai_qt::wallet &);
|
||||
void refresh_representative ();
|
||||
void activate ();
|
||||
void update_locked (bool, bool);
|
||||
QWidget * window;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue