diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index babb2ce51..1fa05d550 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -371,13 +371,12 @@ void BitcoinGUI::createActions() connect(openAction, &QAction::triggered, this, &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; @@ -410,7 +409,7 @@ void BitcoinGUI::createActions() assert(invoked); }); } - 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.cpp b/src/qt/walletcontroller.cpp index 019bd6582..3bb0b8dbb 100644 --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -46,13 +46,16 @@ std::vector WalletController::getWallets() const 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()); - if (it != wallets.end()) wallets.erase(it); + auto it = wallets.find(wallet_model->wallet().getWalletName()); + if (it != wallets.end()) it->second = true; } return wallets; } diff --git a/src/qt/walletcontroller.h b/src/qt/walletcontroller.h index 19b3a8225..dcd64aac7 100644 --- a/src/qt/walletcontroller.h +++ b/src/qt/walletcontroller.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -41,7 +41,10 @@ public: ~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 std::string& name, QWidget* parent = nullptr); void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);