Skip to content

Commit 32a8c6a

Browse files
committed
gui: Add openWallet and getWalletsAvailableToOpen to WalletController
1 parent ab288b4 commit 32a8c6a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/qt/walletcontroller.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <algorithm>
1111

12+
#include <QMessageBox>
1213
#include <QMutexLocker>
1314
#include <QThread>
1415

@@ -37,6 +38,30 @@ std::vector<WalletModel*> WalletController::getWallets() const
3738
return m_wallets;
3839
}
3940

41+
std::vector<std::string> WalletController::getWalletsAvailableToOpen() const
42+
{
43+
QMutexLocker locker(&m_mutex);
44+
std::vector<std::string> wallets = m_node.listWalletDir();
45+
for (WalletModel* wallet_model : m_wallets) {
46+
auto it = std::remove(wallets.begin(), wallets.end(), wallet_model->wallet().getWalletName());
47+
if (it != wallets.end()) wallets.erase(it);
48+
}
49+
return wallets;
50+
}
51+
52+
WalletModel* WalletController::openWallet(const std::string& name, QWidget* parent)
53+
{
54+
std::string error, warning;
55+
WalletModel* wallet_model = getOrCreateWallet(m_node.loadWallet(name, error, warning));
56+
if (!wallet_model) {
57+
QMessageBox::warning(parent, tr("Open Wallet"), QString::fromStdString(error));
58+
}
59+
if (!warning.empty()) {
60+
QMessageBox::information(parent, tr("Open Wallet"), QString::fromStdString(warning));
61+
}
62+
return wallet_model;
63+
}
64+
4065
WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet)
4166
{
4267
QMutexLocker locker(&m_mutex);

src/qt/walletcontroller.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class WalletController : public QObject
3737
~WalletController();
3838

3939
std::vector<WalletModel*> getWallets() const;
40+
std::vector<std::string> getWalletsAvailableToOpen() const;
41+
42+
WalletModel* openWallet(const std::string& name, QWidget* parent = nullptr);
4043

4144
private Q_SLOTS:
4245
void addWallet(WalletModel* wallet_model);

0 commit comments

Comments
 (0)