@@ -455,12 +455,16 @@ void Controller::unlockIfEncrypted(std::function<void(void)> cb, std::function<v
|
||||
main->tr("Your wallet is encrypted.\nPlease enter your wallet password"), QLineEdit::Password);
|
||||
|
||||
if (password.isEmpty()) {
|
||||
QMessageBox::critical(main, main->tr("Wallet Decryption Failed"),
|
||||
main->tr("Please enter a valid password"),
|
||||
QMessageBox::Ok
|
||||
);
|
||||
error();
|
||||
return;
|
||||
}
|
||||
|
||||
zrpc->unlockWallet(password, [=](json reply) {
|
||||
if (isJsonSuccess(reply)) {
|
||||
if (isJsonResultSuccess(reply)) {
|
||||
cb();
|
||||
|
||||
// Refresh the wallet so the encryption status is now in sync.
|
||||
|
||||
@@ -263,10 +263,10 @@ void MainWindow::encryptWallet() {
|
||||
|
||||
if (d.exec() == QDialog::Accepted) {
|
||||
rpc->encryptWallet(ed.txtPassword->text(), [=](json res) {
|
||||
if (isJsonSuccess(res)) {
|
||||
if (isJsonResultSuccess(res)) {
|
||||
// Save the wallet
|
||||
rpc->saveWallet([=] (json reply) {
|
||||
if (isJsonSuccess(reply)) {
|
||||
if (isJsonResultSuccess(reply)) {
|
||||
QMessageBox::information(this, tr("Wallet Encrypted"),
|
||||
tr("Your wallet was successfully encrypted! The password will be needed to send funds or export private keys."),
|
||||
QMessageBox::Ok
|
||||
@@ -314,10 +314,10 @@ void MainWindow::removeWalletEncryption() {
|
||||
}
|
||||
|
||||
rpc->removeWalletEncryption(password, [=] (json res) {
|
||||
if (isJsonSuccess(res)) {
|
||||
if (isJsonResultSuccess(res)) {
|
||||
// Save the wallet
|
||||
rpc->saveWallet([=] (json reply) {
|
||||
if(isJsonSuccess(reply)) {
|
||||
if(isJsonResultSuccess(reply)) {
|
||||
QMessageBox::information(this, tr("Wallet Encryption Removed"),
|
||||
tr("Your wallet was successfully decrypted! You will no longer need a password to send funds or export private keys."),
|
||||
QMessageBox::Ok
|
||||
@@ -654,6 +654,13 @@ void MainWindow::exportSeed() {
|
||||
if (!rpc->getConnection())
|
||||
return;
|
||||
|
||||
|
||||
|
||||
rpc->fetchSeed([=](json reply) {
|
||||
if (isJsonError(reply)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDialog d(this);
|
||||
Ui_PrivKey pui;
|
||||
pui.setupUi(&d);
|
||||
@@ -665,16 +672,12 @@ void MainWindow::exportSeed() {
|
||||
|
||||
Settings::saveRestore(&d);
|
||||
|
||||
pui.privKeyTxt->setPlainText(tr("This might take several minutes. Loading..."));
|
||||
pui.privKeyTxt->setReadOnly(true);
|
||||
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
|
||||
pui.privKeyTxt->setPlainText(QString::fromStdString(reply.dump()));
|
||||
|
||||
pui.helpLbl->setText(tr("This is your wallet seed. Please back it up carefully and safely."));
|
||||
|
||||
// Disable the save button until it finishes loading
|
||||
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
|
||||
pui.buttonBox->button(QDialogButtonBox::Ok)->setVisible(false);
|
||||
|
||||
// Wire up save button
|
||||
QObject::connect(pui.buttonBox->button(QDialogButtonBox::Save), &QPushButton::clicked, [=] () {
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
|
||||
@@ -688,20 +691,10 @@ void MainWindow::exportSeed() {
|
||||
out << pui.privKeyTxt->toPlainText();
|
||||
});
|
||||
|
||||
rpc->fetchSeed([=](json reply) {
|
||||
if (isJsonError(reply)) {
|
||||
pui.privKeyTxt->setPlainText(tr("Error loading wallet seed: ") + QString::fromStdString(reply["error"]));
|
||||
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pui.privKeyTxt->setPlainText(QString::fromStdString(reply.dump()));
|
||||
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
|
||||
});
|
||||
|
||||
|
||||
d.exec();
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::exportAllKeys() {
|
||||
@@ -714,6 +707,18 @@ void MainWindow::exportKeys(QString addr) {
|
||||
|
||||
bool allKeys = addr.isEmpty() ? true : false;
|
||||
|
||||
auto fnUpdateUIWithKeys = [=](json reply) {
|
||||
if (isJsonError(reply)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reply.is_discarded() || !reply.is_array()) {
|
||||
QMessageBox::critical(this, tr("Error getting private keys"),
|
||||
tr("Error loading private keys: ") + QString::fromStdString(reply.dump()),
|
||||
QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
QDialog d(this);
|
||||
Ui_PrivKey pui;
|
||||
pui.setupUi(&d);
|
||||
@@ -725,7 +730,6 @@ void MainWindow::exportKeys(QString addr) {
|
||||
|
||||
Settings::saveRestore(&d);
|
||||
|
||||
pui.privKeyTxt->setPlainText(tr("This might take several minutes. Loading..."));
|
||||
pui.privKeyTxt->setReadOnly(true);
|
||||
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
|
||||
|
||||
@@ -734,9 +738,6 @@ void MainWindow::exportKeys(QString addr) {
|
||||
else
|
||||
pui.helpLbl->setText(tr("Private key for ") + addr);
|
||||
|
||||
// Disable the save button until it finishes loading
|
||||
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
|
||||
pui.buttonBox->button(QDialogButtonBox::Ok)->setVisible(false);
|
||||
|
||||
// Wire up save button
|
||||
QObject::connect(pui.buttonBox->button(QDialogButtonBox::Save), &QPushButton::clicked, [=] () {
|
||||
@@ -751,20 +752,6 @@ void MainWindow::exportKeys(QString addr) {
|
||||
out << pui.privKeyTxt->toPlainText();
|
||||
});
|
||||
|
||||
// Call the API
|
||||
auto isDialogAlive = std::make_shared<bool>(true);
|
||||
|
||||
auto fnUpdateUIWithKeys = [=](json reply) {
|
||||
// Check to see if we are still showing.
|
||||
if (! *(isDialogAlive.get()) ) return;
|
||||
|
||||
if (reply.is_discarded() || !reply.is_array()) {
|
||||
pui.privKeyTxt->setPlainText(tr("Error loading private keys: ") + QString::fromStdString(reply.dump()));
|
||||
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QString allKeysTxt;
|
||||
for (auto i : reply.get<json::array_t>()) {
|
||||
allKeysTxt = allKeysTxt % QString::fromStdString(i["private_key"]) % " # addr=" % QString::fromStdString(i["address"]) % "\n";
|
||||
@@ -772,6 +759,8 @@ void MainWindow::exportKeys(QString addr) {
|
||||
|
||||
pui.privKeyTxt->setPlainText(allKeysTxt);
|
||||
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
|
||||
|
||||
d.exec();
|
||||
};
|
||||
|
||||
if (allKeys) {
|
||||
@@ -780,9 +769,6 @@ void MainWindow::exportKeys(QString addr) {
|
||||
else {
|
||||
rpc->fetchPrivKey(addr, fnUpdateUIWithKeys);
|
||||
}
|
||||
|
||||
d.exec();
|
||||
*isDialogAlive = false;
|
||||
}
|
||||
|
||||
void MainWindow::setupBalancesTab() {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok|QDialogButtonBox::Save</set>
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Save</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -122,14 +122,13 @@ private:
|
||||
};
|
||||
|
||||
|
||||
inline bool isJsonSuccess(const json& res) {
|
||||
inline bool isJsonResultSuccess(const json& res) {
|
||||
return res.find("result") != res.end() &&
|
||||
QString::fromStdString(res["result"].get<json::string_t>()) == "success";
|
||||
}
|
||||
|
||||
inline bool isJsonError(const json& res) {
|
||||
return res.find("result") != res.end() &&
|
||||
QString::fromStdString(res["result"].get<json::string_t>()) == "error";
|
||||
return res.find("error") != res.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user