Browse Source

Improve error handling when restoring from seedphrase

We now catch exceptions in litelib_initialize_new_from_phrase and no longer save an empty/invalid wallet
if there were errors.
pull/125/head
Duke 1 year ago
parent
commit
5d5447aced
  1. 27
      src/mainwindow.cpp

27
src/mainwindow.cpp

@ -209,16 +209,27 @@ MainWindow::MainWindow(QWidget *parent) :
config->server = Settings::getInstance()->getSettings().server;
// 3. Attempt to restore wallet with the seed phrase
{
char* resp = litelib_initialize_new_from_phrase(config->dangerous, config->server.toStdString().c_str(),
seed.toStdString().c_str(), birthday, number);
QString reply = litelib_process_response(resp);
if (reply.toUpper().trimmed() != "OK") {
QMessageBox::warning(this, tr("Failed to restore wallet"),
QString reply = "";
try {
char* resp = litelib_initialize_new_from_phrase(config->dangerous, config->server.toStdString().c_str(),
seed.toStdString().c_str(), birthday, number);
reply = litelib_process_response(resp);
if (reply.toUpper().trimmed() != "OK") {
QMessageBox::warning(this, tr("Failed to restore wallet"),
tr("Couldn't restore the wallet") + "\n" + reply,
QMessageBox::Ok);
return false;
}
} catch (const std::exception& e) {
//TODO: try another server with getRandomServer()
qDebug() << __func__ << ": caught an exception! Bailing out: " << e.what();
QMessageBox::warning(this, tr("Failed to restore wallet"),
tr("Couldn't restore the wallet") + "\n" + reply,
QMessageBox::Ok);
}
return false;
}
}
// 4. Finally attempt to save the wallet

Loading…
Cancel
Save