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:
@@ -209,16 +209,27 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
config->server = Settings::getInstance()->getSettings().server;
|
config->server = Settings::getInstance()->getSettings().server;
|
||||||
// 3. Attempt to restore wallet with the seed phrase
|
// 3. Attempt to restore wallet with the seed phrase
|
||||||
{
|
{
|
||||||
char* resp = litelib_initialize_new_from_phrase(config->dangerous, config->server.toStdString().c_str(),
|
QString reply = "";
|
||||||
seed.toStdString().c_str(), birthday, number);
|
try {
|
||||||
QString reply = litelib_process_response(resp);
|
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") {
|
if (reply.toUpper().trimmed() != "OK") {
|
||||||
QMessageBox::warning(this, tr("Failed to restore wallet"),
|
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,
|
tr("Couldn't restore the wallet") + "\n" + reply,
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Finally attempt to save the wallet
|
// 4. Finally attempt to save the wallet
|
||||||
|
|||||||
Reference in New Issue
Block a user