Skip to content

Commit c71a96c

Browse files
committed
Merge bitcoin-core/gui#696: Switch RPCConsole wallet selection to the one most recently opened/restored/created
99c0eb9 Fix RPCConsole wallet selection (John Moffett) Pull request description: 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 PR makes the RPC Console switch to the wallet just opened / restored / created from the menu bar, which is how the main GUI now works. Similar to bitcoin-core/gui#665 and specifically requested [in a comment](bitcoin-core/gui#665 (comment)). ACKs for top commit: luke-jr: utACK 99c0eb9 hebasto: ACK 99c0eb9, tested on Ubuntu 23.04. Tree-SHA512: d5e5acdaa114130ad4d27fd3f25393bc8d02d92b5001cd39352601d04283cdad3bd62c4da6d369c69764e3b188e9cd3e83152c00b09bd42966082ad09037c328
2 parents 7446cb1 + 99c0eb9 commit c71a96c

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
@@ -412,6 +412,7 @@ void BitcoinGUI::createActions()
412412
connect(action, &QAction::triggered, [this, path] {
413413
auto activity = new OpenWalletActivity(m_wallet_controller, this);
414414
connect(activity, &OpenWalletActivity::opened, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection);
415+
connect(activity, &OpenWalletActivity::opened, rpcConsole, &RPCConsole::setCurrentWallet, Qt::QueuedConnection);
415416
activity->open(path);
416417
});
417418
}
@@ -441,6 +442,7 @@ void BitcoinGUI::createActions()
441442

442443
auto activity = new RestoreWalletActivity(m_wallet_controller, this);
443444
connect(activity, &RestoreWalletActivity::restored, this, &BitcoinGUI::setCurrentWallet, Qt::QueuedConnection);
445+
connect(activity, &RestoreWalletActivity::restored, rpcConsole, &RPCConsole::setCurrentWallet, Qt::QueuedConnection);
444446

445447
auto backup_file_path = fs::PathFromString(backup_file.toStdString());
446448
activity->restore(backup_file_path, wallet_name.toStdString());
@@ -451,6 +453,7 @@ void BitcoinGUI::createActions()
451453
connect(m_create_wallet_action, &QAction::triggered, [this] {
452454
auto activity = new CreateWalletActivity(m_wallet_controller, this);
453455
connect(activity, &CreateWalletActivity::created, this, &BitcoinGUI::setCurrentWallet);
456+
connect(activity, &CreateWalletActivity::created, rpcConsole, &RPCConsole::setCurrentWallet);
454457
activity->create();
455458
});
456459
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
@@ -797,6 +797,12 @@ void RPCConsole::removeWallet(WalletModel * const walletModel)
797797
ui->WalletSelectorLabel->setVisible(false);
798798
}
799799
}
800+
801+
void RPCConsole::setCurrentWallet(WalletModel* const wallet_model)
802+
{
803+
QVariant data = QVariant::fromValue(wallet_model);
804+
ui->WalletSelector->setCurrentIndex(ui->WalletSelector->findData(data));
805+
}
800806
#endif
801807

802808
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)