diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -450,18 +450,15 @@ &BitcoinGUI::openClicked); connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] { m_open_wallet_menu->clear(); - std::vector available_wallets = - m_wallet_controller->getWalletsAvailableToOpen(); - std::vector wallets = m_node.listWalletDir(); - for (const auto &path : wallets) { + for (const std::pair &i : + m_wallet_controller->listWalletDir()) { + const std::string &path = i.first; QString name = path.empty() ? QString("[" + tr("default wallet") + "]") : QString::fromStdString(path); QAction *action = m_open_wallet_menu->addAction(name); - if (std::find(available_wallets.begin(), - available_wallets.end(), - path) == available_wallets.end()) { + if (i.second) { // This wallet is already loaded action->setEnabled(false); continue; @@ -500,7 +497,7 @@ &QObject::deleteLater); }); } - if (wallets.empty()) { + if (m_open_wallet_menu->isEmpty()) { QAction *action = m_open_wallet_menu->addAction(tr("No wallets available")); action->setEnabled(false); diff --git a/src/qt/walletcontroller.h b/src/qt/walletcontroller.h --- a/src/qt/walletcontroller.h +++ b/src/qt/walletcontroller.h @@ -10,7 +10,7 @@ #include -#include +#include #include #include @@ -43,7 +43,10 @@ ~WalletController(); std::vector getWallets() const; - std::vector getWalletsAvailableToOpen() const; + + //! Returns all wallet names in the wallet dir mapped to whether the wallet + //! is loaded. + std::map listWalletDir() const; OpenWalletActivity *openWallet(const CChainParams ¶ms, const std::string &name, diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -44,14 +44,16 @@ return m_wallets; } -std::vector WalletController::getWalletsAvailableToOpen() const { +std::map WalletController::listWalletDir() const { QMutexLocker locker(&m_mutex); - std::vector wallets = m_node.listWalletDir(); + std::map wallets; + for (const std::string &name : m_node.listWalletDir()) { + wallets[name] = false; + } for (WalletModel *wallet_model : m_wallets) { - auto it = std::remove(wallets.begin(), wallets.end(), - wallet_model->wallet().getWalletName()); + auto it = wallets.find(wallet_model->wallet().getWalletName()); if (it != wallets.end()) { - wallets.erase(it); + it->second = true; } } return wallets;