Skip to content

Commit bb24232

Browse files
committed
gui: Use menu for wallet migration
Once legacy wallets can no longer be loaded, we need to be able to migrate them without loading. Thus we should use a menu that lists the wallets in the wallet directory instead of an action which migrates the currently loaded wallet.
1 parent 2397dbe commit bb24232

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/qt/bitcoingui.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ void BitcoinGUI::createActions()
360360
m_migrate_wallet_action = new QAction(tr("Migrate Wallet"), this);
361361
m_migrate_wallet_action->setEnabled(false);
362362
m_migrate_wallet_action->setStatusTip(tr("Migrate a wallet"));
363+
m_migrate_wallet_menu = new QMenu(this);
363364

364365
showHelpMessageAction = new QAction(tr("&Command-line options"), this);
365366
showHelpMessageAction->setMenuRole(QAction::NoRole);
@@ -456,10 +457,33 @@ void BitcoinGUI::createActions()
456457
connect(m_close_all_wallets_action, &QAction::triggered, [this] {
457458
m_wallet_controller->closeAllWallets(this);
458459
});
459-
connect(m_migrate_wallet_action, &QAction::triggered, [this] {
460-
auto activity = new MigrateWalletActivity(m_wallet_controller, this);
461-
connect(activity, &MigrateWalletActivity::migrated, this, &BitcoinGUI::setCurrentWallet);
462-
activity->migrate(walletFrame->currentWalletModel()->wallet().getWalletName());
460+
connect(m_migrate_wallet_menu, &QMenu::aboutToShow, [this] {
461+
m_migrate_wallet_menu->clear();
462+
for (const auto& [wallet_name, info] : m_wallet_controller->listWalletDir()) {
463+
const auto& [loaded, format] = info;
464+
QString name = GUIUtil::WalletDisplayName(wallet_name);
465+
// Menu items remove single &. Single & are shown when && is in
466+
// the string, but only the first occurrence. So replace only
467+
// the first & with &&.
468+
name.replace(name.indexOf(QChar('&')), 1, QString("&&"));
469+
QAction* action = m_migrate_wallet_menu->addAction(name);
470+
471+
if (format != "bdb") {
472+
// This wallet is already migrated
473+
action->setEnabled(false);
474+
continue;
475+
}
476+
477+
connect(action, &QAction::triggered, [this, wallet_name] {
478+
auto activity = new MigrateWalletActivity(m_wallet_controller, this);
479+
connect(activity, &MigrateWalletActivity::migrated, this, &BitcoinGUI::setCurrentWallet);
480+
activity->migrate(wallet_name);
481+
});
482+
}
483+
if (m_migrate_wallet_menu->isEmpty()) {
484+
QAction* action = m_migrate_wallet_menu->addAction(tr("No wallets available"));
485+
action->setEnabled(false);
486+
}
463487
});
464488
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
465489
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::enableHistoryAction);
@@ -692,6 +716,8 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller, bool s
692716
m_open_wallet_action->setEnabled(true);
693717
m_open_wallet_action->setMenu(m_open_wallet_menu);
694718
m_restore_wallet_action->setEnabled(true);
719+
m_migrate_wallet_action->setEnabled(true);
720+
m_migrate_wallet_action->setMenu(m_migrate_wallet_menu);
695721

696722
GUIUtil::ExceptionSafeConnect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
697723
connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);
@@ -772,7 +798,6 @@ void BitcoinGUI::setCurrentWallet(WalletModel* wallet_model)
772798
}
773799
}
774800
updateWindowTitle();
775-
m_migrate_wallet_action->setEnabled(wallet_model->wallet().isLegacy());
776801
}
777802

778803
void BitcoinGUI::setCurrentWalletBySelectorIndex(int index)

0 commit comments

Comments
 (0)