Skip to content

Commit

Permalink
Merge #696: Switch RPCConsole wallet selection to the one most recent…
Browse files Browse the repository at this point in the history
…ly 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 #665 and specifically requested [in a comment](#665 (comment)).

ACKs for top commit:
  luke-jr:
    utACK 99c0eb9
  hebasto:
    ACK 99c0eb9, tested on Ubuntu 23.04.

Tree-SHA512: d5e5acdaa114130ad4d27fd3f25393bc8d02d92b5001cd39352601d04283cdad3bd62c4da6d369c69764e3b188e9cd3e83152c00b09bd42966082ad09037c328
  • Loading branch information
hebasto committed Jul 4, 2023
2 parents 7446cb1 + 99c0eb9 commit c71a96c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,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);
});
}
Expand Down Expand Up @@ -441,6 +442,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());
Expand All @@ -451,6 +453,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] {
Expand Down
6 changes: 6 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,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)
Expand Down
4 changes: 4 additions & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c71a96c

Please sign in to comment.