Skip to content

Commit 99c0eb9

Browse files
committed
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.
1 parent b264410 commit 99c0eb9

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/qt/bitcoingui.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ void BitcoinGUI::createActions()
411411
connect(action, &QAction::triggered, [this, path] {
412412
auto activity = new OpenWalletActivity(m_wallet_controller, this);
413413
connect(activity, &OpenWalletActivity::opened, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection);
414+
connect(activity, &OpenWalletActivity::opened, rpcConsole, &RPCConsole::setCurrentWallet, Qt::QueuedConnection);
414415
activity->open(path);
415416
});
416417
}
@@ -440,6 +441,7 @@ void BitcoinGUI::createActions()
440441

441442
auto activity = new RestoreWalletActivity(m_wallet_controller, this);
442443
connect(activity, &RestoreWalletActivity::restored, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection);
444+
connect(activity, &RestoreWalletActivity::restored, rpcConsole, &RPCConsole::setCurrentWallet, Qt::QueuedConnection);
443445

444446
auto backup_file_path = fs::PathFromString(backup_file.toStdString());
445447
activity->restore(backup_file_path, wallet_name.toStdString());
@@ -450,6 +452,7 @@ void BitcoinGUI::createActions()
450452
connect(m_create_wallet_action, &QAction::triggered, [this] {
451453
auto activity = new CreateWalletActivity(m_wallet_controller, this);
452454
connect(activity, &CreateWalletActivity::created, this, &BitcoinGUI::setCurrentWallet);
455+
connect(activity, &CreateWalletActivity::created, rpcConsole, &RPCConsole::setCurrentWallet);
453456
activity->create();
454457
});
455458
connect(m_close_all_wallets_action, &QAction::triggered, [this] {

src/qt/rpcconsole.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,12 @@ void RPCConsole::removeWallet(WalletModel * const walletModel)
798798
ui->WalletSelectorLabel->setVisible(false);
799799
}
800800
}
801+
802+
void RPCConsole::setCurrentWallet(WalletModel* const wallet_model)
803+
{
804+
QVariant data = QVariant::fromValue(wallet_model);
805+
ui->WalletSelector->setCurrentIndex(ui->WalletSelector->findData(data));
806+
}
801807
#endif
802808

803809
static QString categoryClass(int category)

src/qt/rpcconsole.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public Q_SLOTS:
136136
void unbanSelectedNode();
137137
/** set which tab has the focus (is visible) */
138138
void setTabFocus(enum TabTypes tabType);
139+
#ifdef ENABLE_WALLET
140+
/** Set the current (ie - active) wallet */
141+
void setCurrentWallet(WalletModel* const wallet_model);
142+
#endif // ENABLE_WALLET
139143

140144
private:
141145
struct TranslatedStrings {

0 commit comments

Comments
 (0)