From 99c0eb9701e71f16aa360a420b7e4851d5b92510 Mon Sep 17 00:00:00 2001 From: John Moffett Date: Mon, 9 Jan 2023 14:39:00 -0500 Subject: [PATCH] Fix RPCConsole wallet selection If a user opens multiple wallets in the GUI from the menu bar, the last one opened is the active one in the main window. However, For the RPC Console window, the _first_ one opened is active. This can be confusing, as wallet RPC commands may be sent to a wallet the user didn't intend. This commit makes the RPC Console switch to the wallet opened from the menu bar. --- src/qt/bitcoingui.cpp | 3 +++ src/qt/rpcconsole.cpp | 6 ++++++ src/qt/rpcconsole.h | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index a0731b337aa..f3866b507b3 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -411,6 +411,7 @@ void BitcoinGUI::createActions() connect(action, &QAction::triggered, [this, path] { auto activity = new OpenWalletActivity(m_wallet_controller, this); connect(activity, &OpenWalletActivity::opened, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection); + connect(activity, &OpenWalletActivity::opened, rpcConsole, &RPCConsole::setCurrentWallet, Qt::QueuedConnection); activity->open(path); }); } @@ -440,6 +441,7 @@ void BitcoinGUI::createActions() auto activity = new RestoreWalletActivity(m_wallet_controller, this); connect(activity, &RestoreWalletActivity::restored, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection); + connect(activity, &RestoreWalletActivity::restored, rpcConsole, &RPCConsole::setCurrentWallet, Qt::QueuedConnection); auto backup_file_path = fs::PathFromString(backup_file.toStdString()); activity->restore(backup_file_path, wallet_name.toStdString()); @@ -450,6 +452,7 @@ void BitcoinGUI::createActions() connect(m_create_wallet_action, &QAction::triggered, [this] { auto activity = new CreateWalletActivity(m_wallet_controller, this); connect(activity, &CreateWalletActivity::created, this, &BitcoinGUI::setCurrentWallet); + connect(activity, &CreateWalletActivity::created, rpcConsole, &RPCConsole::setCurrentWallet); activity->create(); }); connect(m_close_all_wallets_action, &QAction::triggered, [this] { diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 843cd46d13f..be733f7a890 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -798,6 +798,12 @@ void RPCConsole::removeWallet(WalletModel * const walletModel) ui->WalletSelectorLabel->setVisible(false); } } + +void RPCConsole::setCurrentWallet(WalletModel* const wallet_model) +{ + QVariant data = QVariant::fromValue(wallet_model); + ui->WalletSelector->setCurrentIndex(ui->WalletSelector->findData(data)); +} #endif static QString categoryClass(int category) diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 32a75204918..65eef7fbba3 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -136,6 +136,10 @@ public Q_SLOTS: void unbanSelectedNode(); /** set which tab has the focus (is visible) */ void setTabFocus(enum TabTypes tabType); +#ifdef ENABLE_WALLET + /** Set the current (ie - active) wallet */ + void setCurrentWallet(WalletModel* const wallet_model); +#endif // ENABLE_WALLET private: struct TranslatedStrings {