Skip to content

Commit 7da603a

Browse files
committed
gui: Add a menu item to restore then migrate a wallet file
Some users will have backups of a legacy wallet which cannot be restored due to being a legacy wallet, and therefore cannot be migrated from the GUI. This menu item allows such users to restore and migrate their wallets in a single action.
1 parent 8e91b85 commit 7da603a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/qt/bitcoingui.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,32 @@ void BitcoinGUI::createActions()
481481
QAction* action = m_migrate_wallet_menu->addAction(tr("No wallets available"));
482482
action->setEnabled(false);
483483
}
484+
m_migrate_wallet_menu->addSeparator();
485+
QAction* restore_migrate_file_action = m_migrate_wallet_menu->addAction(tr("Restore and Migrate Wallet File..."));
486+
restore_migrate_file_action->setEnabled(true);
487+
488+
connect(restore_migrate_file_action, &QAction::triggered, [this] {
489+
QString name_data_file = tr("Wallet Data");
490+
QString title_windows = tr("Restore and Migrate Wallet Backup");
491+
492+
QString backup_file = GUIUtil::getOpenFileName(this, title_windows, QString(), name_data_file + QLatin1String(" (*.dat)"), nullptr);
493+
if (backup_file.isEmpty()) return;
494+
495+
bool wallet_name_ok;
496+
/*: Title of pop-up window shown when the user is attempting to
497+
restore a wallet. */
498+
QString title = tr("Restore and Migrate Wallet");
499+
//: Label of the input field where the name of the wallet is entered.
500+
QString label = tr("Wallet Name");
501+
QString wallet_name = QInputDialog::getText(this, title, label, QLineEdit::Normal, "", &wallet_name_ok);
502+
if (!wallet_name_ok || wallet_name.isEmpty()) return;
503+
504+
auto activity = new MigrateWalletActivity(m_wallet_controller, this);
505+
connect(activity, &MigrateWalletActivity::migrated, this, &BitcoinGUI::setCurrentWallet);
506+
connect(activity, &MigrateWalletActivity::migrated, rpcConsole, &BitcoinGUI::setCurrentWallet);
507+
auto backup_file_path = fs::PathFromString(backup_file.toStdString());
508+
activity->restore_and_migrate(backup_file_path, wallet_name.toStdString());
509+
});
484510
});
485511
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
486512
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::enableHistoryAction);

0 commit comments

Comments
 (0)