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.
This commit is contained in:
Duke
2023-03-04 12:02:32 -05:00
parent 1e6e77055b
commit 5d5447aced

View File

@@ -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);
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"),
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