feat(@desktop/wallet): cpp: Added apis for
1. Generate new API 2. Import accounts by PK 3. Import account by seed phrase 4. Add watch only address 5. delete account 6. current account
This commit is contained in:
parent
6f335fd0ae
commit
d47ac2d5f7
|
@ -1,12 +1,15 @@
|
|||
#include <QDebug>
|
||||
#include <QQmlContext>
|
||||
|
||||
#include "app_controller.h"
|
||||
#include "accounts/service.h"
|
||||
#include "app_service.h"
|
||||
#include "modules/main/module.h"
|
||||
#include "modules/startup/module.h"
|
||||
#include <QDebug>
|
||||
#include "singleton.h"
|
||||
|
||||
AppController::AppController()
|
||||
{
|
||||
// To-do remove when transition to c++ is complete
|
||||
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("cppApp", true);
|
||||
// result.statusFoundation = statusFoundation
|
||||
|
||||
// # Global
|
||||
|
|
|
@ -17,16 +17,6 @@ class Module : public QObject, virtual public IModuleAccess
|
|||
Q_OBJECT
|
||||
Q_INTERFACES(Modules::Main::IModuleAccess)
|
||||
|
||||
private:
|
||||
bool m_moduleLoaded;
|
||||
|
||||
View* m_viewPtr;
|
||||
Controller* m_controllerPtr;
|
||||
Modules::Main::IModuleAccess* m_walletModulePtr;
|
||||
|
||||
void connect();
|
||||
void checkIfModuleDidLoad();
|
||||
|
||||
public:
|
||||
explicit Module(std::shared_ptr<Wallets::ServiceInterface> walletService, QObject* parent = nullptr);
|
||||
~Module() = default;
|
||||
|
@ -40,6 +30,17 @@ public slots:
|
|||
|
||||
signals:
|
||||
void loaded() override;
|
||||
|
||||
private:
|
||||
void connect();
|
||||
void checkIfModuleDidLoad();
|
||||
|
||||
private:
|
||||
View* m_viewPtr;
|
||||
Controller* m_controllerPtr;
|
||||
Modules::Main::IModuleAccess* m_walletModulePtr;
|
||||
bool m_moduleLoaded;
|
||||
|
||||
};
|
||||
} // namespace Modules::Main
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ View::View(QObject* parent)
|
|||
void View::load()
|
||||
{
|
||||
// Add Wallet Section to Sections model
|
||||
auto walletSectionItem = new Shared::Models::SectionItem(WALLET_SECTION_ID,
|
||||
auto walletSectionItem = new Shared::Models::SectionItem(this,
|
||||
WALLET_SECTION_ID,
|
||||
Shared::Models::SectionType::Wallet,
|
||||
WALLET_SECTION_NAME,
|
||||
"",
|
||||
|
@ -20,7 +21,7 @@ void View::load()
|
|||
WALLET_SECTION_ICON,
|
||||
"",
|
||||
false,
|
||||
this);
|
||||
true);
|
||||
addItem(walletSectionItem);
|
||||
setActiveSection(WALLET_SECTION_ID);
|
||||
|
||||
|
@ -33,12 +34,12 @@ void View::addItem(Shared::Models::SectionItem* item)
|
|||
emit sectionsModelChanged();
|
||||
}
|
||||
|
||||
Shared::Models::SectionModel* View::getSectionsModel()
|
||||
Shared::Models::SectionModel* View::getSectionsModel() const
|
||||
{
|
||||
return m_sectionModelPtr;
|
||||
}
|
||||
|
||||
Shared::Models::SectionItem* View::getActiveSection()
|
||||
Shared::Models::SectionItem* View::getActiveSection() const
|
||||
{
|
||||
return m_sectionModelPtr->getActiveItem();
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ public:
|
|||
|
||||
void addItem(Shared::Models::SectionItem* item);
|
||||
|
||||
Shared::Models::SectionModel* getSectionsModel();
|
||||
Shared::Models::SectionItem* getActiveSection();
|
||||
Shared::Models::SectionModel* getSectionsModel() const;
|
||||
Shared::Models::SectionItem* getActiveSection() const;
|
||||
void setActiveSection(const QString& Id);
|
||||
|
||||
signals:
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
|
||||
#include "controller.h"
|
||||
|
||||
const QString WALLETSERVICE_NULL_ERROR = "wallet service pointer is null";
|
||||
|
||||
namespace Modules::Main::Wallet::Accounts
|
||||
{
|
||||
Controller::Controller(std::shared_ptr<Wallets::ServiceInterface> walletService, QObject* parent)
|
||||
: m_walletServicePtr(walletService)
|
||||
, QObject(parent)
|
||||
Controller::Controller(std::shared_ptr<Wallets::ServiceInterface> walletService,
|
||||
QObject* parent)
|
||||
: QObject(parent),
|
||||
m_walletServicePtr(walletService)
|
||||
{ }
|
||||
|
||||
void Controller::init() { }
|
||||
|
@ -14,8 +17,60 @@ void Controller::init() { }
|
|||
QList<Wallets::WalletAccountDto> Controller::getWalletAccounts()
|
||||
{
|
||||
QList<Wallets::WalletAccountDto> wallet_accounts;
|
||||
if(nullptr != m_walletServicePtr) wallet_accounts = m_walletServicePtr->getWalletAccounts();
|
||||
if(m_walletServicePtr)
|
||||
{
|
||||
wallet_accounts = m_walletServicePtr->getWalletAccounts();
|
||||
}
|
||||
|
||||
return wallet_accounts;
|
||||
}
|
||||
|
||||
QString Controller::generateNewAccount(const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
QString error = WALLETSERVICE_NULL_ERROR;
|
||||
if(m_walletServicePtr)
|
||||
{
|
||||
error = m_walletServicePtr->generateNewAccount(password, accountName, color);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
QString Controller::addAccountsFromPrivateKey(const QString& privateKey, const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
QString error = WALLETSERVICE_NULL_ERROR;
|
||||
if(m_walletServicePtr)
|
||||
{
|
||||
error = m_walletServicePtr->addAccountsFromPrivateKey(privateKey, password, accountName, color);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
QString Controller::addAccountsFromSeed(const QString& seedPhrase, const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
QString error = WALLETSERVICE_NULL_ERROR;
|
||||
if(m_walletServicePtr)
|
||||
{
|
||||
error = m_walletServicePtr->addAccountsFromSeed(seedPhrase, password, accountName, color);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
QString Controller::addWatchOnlyAccount(const QString& address, const QString& accountName, const QString& color)
|
||||
{
|
||||
QString error = WALLETSERVICE_NULL_ERROR;
|
||||
if(m_walletServicePtr)
|
||||
{
|
||||
error = m_walletServicePtr->addWatchOnlyAccount(address, accountName, color);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
void Controller::deleteAccount(const QString& address)
|
||||
{
|
||||
if(m_walletServicePtr)
|
||||
{
|
||||
m_walletServicePtr->deleteAccount(address);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Modules::Main::Wallet::Accounts
|
||||
|
|
|
@ -21,6 +21,11 @@ public:
|
|||
void init() override;
|
||||
|
||||
QList<Wallets::WalletAccountDto> getWalletAccounts();
|
||||
QString generateNewAccount(const QString& password, const QString& accountName, const QString& color);
|
||||
QString addAccountsFromPrivateKey(const QString& privateKey, const QString& password, const QString& accountName, const QString& color);
|
||||
QString addAccountsFromSeed(const QString& seedPhrase, const QString& password, const QString& accountName, const QString& color);
|
||||
QString addWatchOnlyAccount(const QString& address, const QString& accountName , const QString& color);
|
||||
void deleteAccount(const QString& address);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Wallets::ServiceInterface> m_walletServicePtr;
|
||||
|
|
|
@ -2,16 +2,18 @@
|
|||
|
||||
namespace Modules::Main::Wallet::Accounts
|
||||
{
|
||||
Item::Item(QString name,
|
||||
QString address,
|
||||
QString path,
|
||||
QString color,
|
||||
QString publicKey,
|
||||
QString walletType,
|
||||
Item::Item(QObject* parent,
|
||||
const QString& name,
|
||||
const QString& address,
|
||||
const QString& path,
|
||||
const QString& color,
|
||||
const QString& publicKey,
|
||||
const QString& walletType,
|
||||
bool isWallet,
|
||||
bool isChat,
|
||||
float currencyBalance)
|
||||
: m_name(name)
|
||||
: QObject(parent)
|
||||
, m_name(name)
|
||||
, m_address(address)
|
||||
, m_path(path)
|
||||
, m_color(color)
|
||||
|
@ -67,4 +69,30 @@ float Item::getCurrencyBalance() const
|
|||
return m_currencyBalance;
|
||||
}
|
||||
|
||||
void Item::setData(Item* item)
|
||||
{
|
||||
if(item)
|
||||
{
|
||||
m_name = item->getName();
|
||||
emit nameChanged();
|
||||
m_address = item->getAddress();
|
||||
emit addressChanged();
|
||||
m_path = item->getPath();
|
||||
emit pathChanged();
|
||||
m_color = item->getColor();
|
||||
emit colorChanged();
|
||||
m_publicKey = item->getPublicKey();
|
||||
emit publicKeyChanged();
|
||||
m_walletType = item->getWalletType();
|
||||
emit walletTypeChanged();
|
||||
m_isWallet = item->getIsWallet();
|
||||
emit isWalletChanged();
|
||||
m_isChat = item->getIsChat();
|
||||
emit isChatChanged();
|
||||
m_currencyBalance = item->getCurrencyBalance();
|
||||
emit currencyBalanceChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Modules::Main::Wallet::Accounts
|
||||
|
|
|
@ -1,33 +1,35 @@
|
|||
#ifndef WALLET_ACCOUNT_ITEM_H
|
||||
#define WALLET_ACCOUNT_ITEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
namespace Modules::Main::Wallet::Accounts
|
||||
{
|
||||
class Item
|
||||
class Item: public QObject
|
||||
{
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_address;
|
||||
QString m_path;
|
||||
QString m_color;
|
||||
QString m_publicKey;
|
||||
QString m_walletType;
|
||||
bool m_isWallet;
|
||||
bool m_isChat;
|
||||
float m_currencyBalance;
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ getName NOTIFY nameChanged);
|
||||
Q_PROPERTY(QString address READ getAddress NOTIFY addressChanged);
|
||||
Q_PROPERTY(QString path READ getPath NOTIFY pathChanged);
|
||||
Q_PROPERTY(QString color READ getColor NOTIFY colorChanged);
|
||||
Q_PROPERTY(QString publicKey READ getPublicKey NOTIFY publicKeyChanged);
|
||||
Q_PROPERTY(QString walletType READ getWalletType NOTIFY walletTypeChanged);
|
||||
Q_PROPERTY(bool isWallet READ getIsWallet NOTIFY isWalletChanged);
|
||||
Q_PROPERTY(bool isChat READ getIsChat NOTIFY isChatChanged);
|
||||
Q_PROPERTY(float currencyBalance READ getCurrencyBalance NOTIFY currencyBalanceChanged);
|
||||
|
||||
public:
|
||||
Item(QString name,
|
||||
QString address,
|
||||
QString path,
|
||||
QString color,
|
||||
QString publicKey,
|
||||
QString walletType,
|
||||
bool isWallet,
|
||||
bool isChat,
|
||||
float currencyBalance);
|
||||
Item(QObject* parent = nullptr,
|
||||
const QString& name = "",
|
||||
const QString& address = "",
|
||||
const QString& path = "",
|
||||
const QString& color = "",
|
||||
const QString& publicKey = "",
|
||||
const QString& walletType = "",
|
||||
bool isWallet = false,
|
||||
bool isChat = false,
|
||||
float currencyBalance = 0);
|
||||
~Item() = default;
|
||||
|
||||
const QString& getName() const;
|
||||
|
@ -39,6 +41,30 @@ public:
|
|||
bool getIsWallet() const;
|
||||
bool getIsChat() const;
|
||||
float getCurrencyBalance() const;
|
||||
void setData(Item *item);
|
||||
|
||||
signals:
|
||||
void nameChanged();
|
||||
void addressChanged();
|
||||
void pathChanged();
|
||||
void colorChanged();
|
||||
void publicKeyChanged();
|
||||
void walletTypeChanged();
|
||||
void isWalletChanged();
|
||||
void isChatChanged();
|
||||
void currencyBalanceChanged();
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_address;
|
||||
QString m_path;
|
||||
QString m_color;
|
||||
QString m_publicKey;
|
||||
QString m_walletType;
|
||||
bool m_isWallet;
|
||||
bool m_isChat;
|
||||
float m_currencyBalance;
|
||||
|
||||
};
|
||||
} // namespace Modules::Main::Wallet::Accounts
|
||||
|
||||
|
|
|
@ -34,36 +34,45 @@ QVariant Model::data(const QModelIndex& index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
if(index.row() < 0 || index.row() > m_items.size())
|
||||
if(index.row() < 0 || index.row() >= m_items.size())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Item item = m_items[index.row()];
|
||||
const Item* item = m_items.at(index.row());
|
||||
|
||||
switch(role)
|
||||
{
|
||||
case Name: return QVariant(item.getName());
|
||||
case Address: return QVariant(item.getAddress());
|
||||
case Path: return QVariant(item.getPath());
|
||||
case Color: return QVariant(item.getColor());
|
||||
case PublicKey: return QVariant(item.getPublicKey());
|
||||
case WalletType: return QVariant(item.getWalletType());
|
||||
case IsWallet: return QVariant(item.getIsWallet());
|
||||
case IsChat:
|
||||
return QVariant(item.getIsChat());
|
||||
case Name: return item->getName();
|
||||
case Address: return item->getAddress();
|
||||
case Path: return item->getPath();
|
||||
case Color: return item->getColor();
|
||||
case PublicKey: return item->getPublicKey();
|
||||
case WalletType: return item->getWalletType();
|
||||
case IsWallet: return item->getIsWallet();
|
||||
case IsChat: return item->getIsChat();
|
||||
// case Assets: return QVariant(item.ge());
|
||||
case CurrencyBalance: return QVariant(item.getCurrencyBalance());
|
||||
case CurrencyBalance: return item->getCurrencyBalance();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void Model::setItems(QVector<Item>& items)
|
||||
void Model::setItems(const QVector<Item*>& items)
|
||||
{
|
||||
beginResetModel();
|
||||
m_items = items;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
Item* Model::getItemByIndex(int index) const
|
||||
{
|
||||
Item* returnItemPtr = nullptr;
|
||||
if((index > 0) && (index < m_items.size()))
|
||||
{
|
||||
returnItemPtr = m_items.at(index);
|
||||
}
|
||||
return returnItemPtr;
|
||||
}
|
||||
|
||||
} // namespace Modules::Main::Wallet::Accounts
|
||||
|
|
|
@ -34,10 +34,11 @@ public:
|
|||
QHash<int, QByteArray> roleNames() const override;
|
||||
int rowCount(const QModelIndex&) const override;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
void setItems(QVector<Item>& items);
|
||||
void setItems(const QVector<Item*>& items);
|
||||
Item* getItemByIndex(int index) const;
|
||||
|
||||
private:
|
||||
QVector<Item> m_items;
|
||||
QVector<Item*> m_items;
|
||||
};
|
||||
} // namespace Modules::Main::Wallet::Accounts
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObjec
|
|||
: QObject(parent)
|
||||
{
|
||||
m_controllerPtr = new Controller(walletsService, this);
|
||||
m_viewPtr = new View(this);
|
||||
m_viewPtr = new View(m_controllerPtr, this);
|
||||
|
||||
m_moduleLoaded = false;
|
||||
|
||||
|
@ -36,29 +36,8 @@ bool Module::isLoaded()
|
|||
|
||||
void Module::viewDidLoad()
|
||||
{
|
||||
refreshWalletAccounts();
|
||||
m_moduleLoaded = true;
|
||||
emit loaded();
|
||||
}
|
||||
|
||||
void Module::refreshWalletAccounts()
|
||||
{
|
||||
auto walletAccounts = m_controllerPtr->getWalletAccounts();
|
||||
|
||||
if(walletAccounts.size() > 0)
|
||||
{
|
||||
QVector<Item> items;
|
||||
foreach(const auto& acc, walletAccounts)
|
||||
{
|
||||
items << Item(
|
||||
acc.name, acc.address, acc.path, acc.color, acc.publicKey, acc.walletType, acc.isWallet, acc.isChat, 0);
|
||||
}
|
||||
|
||||
m_viewPtr->setModelItems(items);
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "No accounts found!";
|
||||
}
|
||||
}
|
||||
} // namespace Modules::Main::Wallet::Accounts
|
||||
|
|
|
@ -14,16 +14,6 @@ class Module : public QObject, virtual public IModuleAccess
|
|||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Modules::Main::IModuleAccess)
|
||||
|
||||
private:
|
||||
View* m_viewPtr;
|
||||
Controller* m_controllerPtr;
|
||||
|
||||
bool m_moduleLoaded;
|
||||
|
||||
void connect();
|
||||
void refreshWalletAccounts();
|
||||
|
||||
public:
|
||||
explicit Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject* parent);
|
||||
~Module() = default;
|
||||
|
@ -36,6 +26,15 @@ public slots:
|
|||
|
||||
signals:
|
||||
void loaded() override;
|
||||
|
||||
private:
|
||||
void connect();
|
||||
|
||||
private:
|
||||
View* m_viewPtr;
|
||||
Controller* m_controllerPtr;
|
||||
|
||||
bool m_moduleLoaded;
|
||||
};
|
||||
} // namespace Modules::Main::Wallet::Accounts
|
||||
|
||||
|
|
|
@ -4,25 +4,143 @@
|
|||
|
||||
namespace Modules::Main::Wallet::Accounts
|
||||
{
|
||||
View::View(QObject* parent)
|
||||
: QObject(parent)
|
||||
View::View(Controller *controller, QObject* parent)
|
||||
: QObject(parent),
|
||||
m_controllerPtr(controller)
|
||||
{
|
||||
m_modelPtr = new Model(this);
|
||||
m_currentAccountPtr = new Item(this);
|
||||
}
|
||||
|
||||
void View::load()
|
||||
{
|
||||
refreshWalletAccounts();
|
||||
emit viewLoaded();
|
||||
}
|
||||
|
||||
Model* View::getModel()
|
||||
Model* View::getModel() const
|
||||
{
|
||||
return m_modelPtr;
|
||||
}
|
||||
|
||||
void View::setModelItems(QVector<Item>& accounts)
|
||||
{
|
||||
void View::setModelItems(const QVector<Item*>& accounts) {
|
||||
m_modelPtr->setItems(accounts);
|
||||
m_currentAccountPtr->setData(accounts.at(0));
|
||||
modelChanged();
|
||||
}
|
||||
|
||||
void View::refreshWalletAccounts()
|
||||
{
|
||||
auto walletAccounts = m_controllerPtr->getWalletAccounts();
|
||||
|
||||
if(walletAccounts.size() > 0)
|
||||
{
|
||||
QVector<Item*> items;
|
||||
foreach(const auto& acc, walletAccounts)
|
||||
{
|
||||
items << new Item(this, acc.name, acc.address, acc.path, acc.color, acc.publicKey, acc.walletType, acc.isWallet, acc.isChat, 0);
|
||||
}
|
||||
setModelItems(items);
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning()<<"No accounts found!";
|
||||
}
|
||||
}
|
||||
|
||||
QString View::generateNewAccount(const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
QString error = "";
|
||||
if(m_controllerPtr)
|
||||
{
|
||||
error = m_controllerPtr->generateNewAccount(password, accountName, color);
|
||||
if(error.isEmpty())
|
||||
{
|
||||
refreshWalletAccounts();
|
||||
}
|
||||
}
|
||||
else {
|
||||
error = "controller pointer is null";
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
QString View::addAccountsFromPrivateKey(const QString& privateKey, const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
QString error = "";
|
||||
if(m_controllerPtr)
|
||||
{
|
||||
error = m_controllerPtr->addAccountsFromPrivateKey(privateKey, password, accountName, color);
|
||||
if(error.isEmpty())
|
||||
{
|
||||
refreshWalletAccounts();
|
||||
}
|
||||
}
|
||||
else {
|
||||
error = "controller pointer is null";
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
QString View::addAccountsFromSeed(const QString& seedPhrase, const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
QString error = "";
|
||||
if(m_controllerPtr)
|
||||
{
|
||||
error = m_controllerPtr->addAccountsFromSeed(seedPhrase, password, accountName, color);
|
||||
if(error.isEmpty())
|
||||
{
|
||||
refreshWalletAccounts();
|
||||
}
|
||||
}
|
||||
else {
|
||||
error = "controller pointer is null";
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
QString View::addWatchOnlyAccount(const QString& address, const QString& accountName , const QString& color)
|
||||
{
|
||||
QString error = "";
|
||||
if(m_controllerPtr)
|
||||
{
|
||||
error = m_controllerPtr->addWatchOnlyAccount(address, accountName, color);
|
||||
if(error.isEmpty())
|
||||
{
|
||||
refreshWalletAccounts();
|
||||
}
|
||||
}
|
||||
else {
|
||||
error = "controller pointer is null";
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
void View::deleteAccount(const QString& address)
|
||||
{
|
||||
if(m_controllerPtr)
|
||||
{
|
||||
m_controllerPtr->deleteAccount(address);
|
||||
refreshWalletAccounts();
|
||||
}
|
||||
else {
|
||||
qWarning()<<"controller pointer is null";
|
||||
}
|
||||
}
|
||||
|
||||
void View::switchAccount(int index)
|
||||
{
|
||||
auto itemAtIndex = m_modelPtr->getItemByIndex(index);
|
||||
if(itemAtIndex)
|
||||
{
|
||||
m_currentAccountPtr->setData(itemAtIndex);
|
||||
emit currentAccountChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Item* View::getCurrentAccount() const
|
||||
{
|
||||
return m_currentAccountPtr;
|
||||
}
|
||||
|
||||
} // namespace Modules::Main::Wallet::Accounts
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <memory>
|
||||
|
||||
#include "model.h"
|
||||
#include "controller.h"
|
||||
#include "item.h"
|
||||
|
||||
namespace Modules::Main::Wallet::Accounts
|
||||
{
|
||||
|
@ -12,23 +14,36 @@ class View : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Model* model READ getModel NOTIFY modelChanged)
|
||||
Q_PROPERTY(Item* currentAccount READ getCurrentAccount NOTIFY currentAccountChanged)
|
||||
|
||||
public:
|
||||
explicit View(QObject* parent = nullptr);
|
||||
explicit View(Controller* controller, QObject* parent = nullptr);
|
||||
~View() = default;
|
||||
|
||||
void load();
|
||||
void setModelItems(QVector<Item>& accounts);
|
||||
void setModelItems(const QVector<Item*>& accounts);
|
||||
Model* getModel() const;
|
||||
Item* getCurrentAccount() const;
|
||||
|
||||
private:
|
||||
Model* m_modelPtr;
|
||||
|
||||
public slots:
|
||||
Model* getModel();
|
||||
Q_INVOKABLE QString generateNewAccount(const QString& password, const QString& accountName, const QString& color);
|
||||
Q_INVOKABLE QString addAccountsFromPrivateKey(const QString& privateKey, const QString& password, const QString& accountName, const QString& color);
|
||||
Q_INVOKABLE QString addAccountsFromSeed(const QString& seedPhrase, const QString& password, const QString& accountName, const QString& color);
|
||||
Q_INVOKABLE QString addWatchOnlyAccount(const QString& address, const QString& accountName , const QString& color);
|
||||
Q_INVOKABLE void deleteAccount(const QString& address);
|
||||
Q_INVOKABLE void switchAccount(int index);
|
||||
|
||||
signals:
|
||||
void viewLoaded();
|
||||
void modelChanged();
|
||||
void currentAccountChanged();
|
||||
|
||||
private:
|
||||
void refreshWalletAccounts();
|
||||
|
||||
private:
|
||||
Model* m_modelPtr;
|
||||
Controller* m_controllerPtr;
|
||||
Item* m_currentAccountPtr;
|
||||
};
|
||||
} // namespace Modules::Main::Wallet::Accounts
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
namespace Modules::Main::Wallet
|
||||
{
|
||||
Controller::Controller(std::shared_ptr<Wallets::ServiceInterface> walletService, QObject* parent)
|
||||
: m_walletService(walletService)
|
||||
, QObject(parent)
|
||||
: QObject(parent),
|
||||
m_walletService(walletService)
|
||||
{ }
|
||||
|
||||
void Controller::init() { }
|
||||
|
|
|
@ -16,15 +16,6 @@ class Module : public QObject, virtual public IModuleAccess
|
|||
Q_OBJECT
|
||||
Q_INTERFACES(Modules::Main::IModuleAccess)
|
||||
|
||||
private:
|
||||
View* m_viewPtr;
|
||||
Controller* m_controllerPtr;
|
||||
IModuleAccess* m_accountsModulePtr;
|
||||
|
||||
bool m_moduleLoaded;
|
||||
|
||||
void connect();
|
||||
|
||||
public:
|
||||
explicit Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject* parent);
|
||||
~Module() = default;
|
||||
|
@ -33,11 +24,22 @@ public:
|
|||
bool isLoaded() override;
|
||||
|
||||
void checkIfModuleDidLoad();
|
||||
|
||||
public slots:
|
||||
void viewDidLoad();
|
||||
void accountsDidLoad();
|
||||
|
||||
signals:
|
||||
void loaded() override;
|
||||
|
||||
private:
|
||||
void connect();
|
||||
|
||||
private:
|
||||
View* m_viewPtr;
|
||||
Controller* m_controllerPtr;
|
||||
IModuleAccess* m_accountsModulePtr;
|
||||
bool m_moduleLoaded;
|
||||
};
|
||||
} // namespace Modules::Main::Wallet
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
namespace Shared::Models
|
||||
{
|
||||
SectionItem::SectionItem(const QString& id,
|
||||
SectionItem::SectionItem(QObject* parent,
|
||||
const QString& id,
|
||||
SectionType sectionType,
|
||||
const QString& name,
|
||||
const QString& description,
|
||||
|
@ -22,8 +23,7 @@ SectionItem::SectionItem(const QString& id,
|
|||
bool canManageUsers,
|
||||
bool canRequestAccess,
|
||||
int access,
|
||||
bool ensOnly,
|
||||
QObject* parent)
|
||||
bool ensOnly)
|
||||
: QObject(parent)
|
||||
, m_id(id)
|
||||
, m_sectionType(sectionType)
|
||||
|
|
|
@ -8,7 +8,8 @@ namespace Shared::Models
|
|||
{
|
||||
enum SectionType
|
||||
{
|
||||
Chat = 0,
|
||||
Unkown = -1,
|
||||
Chat,
|
||||
Community,
|
||||
Wallet,
|
||||
Browser,
|
||||
|
@ -39,15 +40,16 @@ class SectionItem : public QObject
|
|||
Q_PROPERTY(bool ensOnly READ getIsEnsOnly)
|
||||
|
||||
public:
|
||||
SectionItem(const QString &id,
|
||||
SectionType sectionType,
|
||||
const QString& name,
|
||||
const QString& description,
|
||||
const QString& image,
|
||||
const QString& icon,
|
||||
const QString& color,
|
||||
SectionItem(QObject* parent = nullptr,
|
||||
const QString& id = "",
|
||||
SectionType sectionType = SectionType::Unkown,
|
||||
const QString& name = "",
|
||||
const QString& description = "",
|
||||
const QString& image = "",
|
||||
const QString& icon = "",
|
||||
const QString& color = "",
|
||||
bool active = false,
|
||||
bool enabled = true,
|
||||
bool enabled = false,
|
||||
bool amISectionAdmin = false,
|
||||
bool hasNotification = false,
|
||||
int notificationsCount = 0,
|
||||
|
@ -57,8 +59,7 @@ public:
|
|||
bool canManageUsers = false,
|
||||
bool canRequestAccess = false,
|
||||
int access = 0,
|
||||
bool ensOnly = false,
|
||||
QObject* parent = nullptr);
|
||||
bool ensOnly = false);
|
||||
~SectionItem() = default;
|
||||
|
||||
// Getters
|
||||
|
|
|
@ -55,26 +55,25 @@ QVariant SectionModel::data(const QModelIndex& index, int role) const
|
|||
|
||||
switch(role)
|
||||
{
|
||||
case Id: return QVariant(item->getId());
|
||||
case SectionType: return QVariant(item->getSectionType());
|
||||
case Name: return QVariant(item->getName());
|
||||
case AmISectionAdmin: return QVariant(item->getAmISectionAdmin());
|
||||
case Description: return QVariant(item->getDescription());
|
||||
case Image: return QVariant(item->getImage());
|
||||
case Icon: return QVariant(item->getIcon());
|
||||
case Color: return QVariant(item->getColor());
|
||||
case HasNotification: return QVariant(item->getHasNotification());
|
||||
case NotificationsCount: return QVariant(item->getNotificationsCount());
|
||||
case Active: return QVariant(item->getIsActive());
|
||||
case Enabled: return QVariant(item->getIsEnabled());
|
||||
case Joined: return QVariant(item->getHasJoined());
|
||||
case IsMember: return QVariant(item->getIsMember());
|
||||
case CanJoin: return QVariant(item->getCanJoin());
|
||||
case CanManageUsers: return QVariant(item->getCanManageUsers());
|
||||
case CanRequestAccess: return QVariant(item->getCanRequestAccess());
|
||||
case Access: return QVariant(item->getAccess());
|
||||
case EnsOnly:
|
||||
return QVariant(item->getIsEnsOnly());
|
||||
case Id: return item->getId();
|
||||
case SectionType: return item->getSectionType();
|
||||
case Name: return item->getName();
|
||||
case AmISectionAdmin: return item->getAmISectionAdmin();
|
||||
case Description: return item->getDescription();
|
||||
case Image: return item->getImage();
|
||||
case Icon: return item->getIcon();
|
||||
case Color: return item->getColor();
|
||||
case HasNotification: return item->getHasNotification();
|
||||
case NotificationsCount: return item->getNotificationsCount();
|
||||
case Active: return item->getIsActive();
|
||||
case Enabled: return item->getIsEnabled();
|
||||
case Joined: return item->getHasJoined();
|
||||
case IsMember: return item->getIsMember();
|
||||
case CanJoin: return item->getCanJoin();
|
||||
case CanManageUsers: return item->getCanManageUsers();
|
||||
case CanRequestAccess: return item->getCanRequestAccess();
|
||||
case Access: return item->getAccess();
|
||||
case EnsOnly: return item->getIsEnsOnly();
|
||||
// To Do
|
||||
case MembersModel: return QVariant();
|
||||
case PendingRequestsToJoinModel: return QVariant();
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
#ifndef WALLETACCOUNTSSERVICE_H
|
||||
#define WALLETACCOUNTSSERVICE_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
#include "service_interface.h"
|
||||
#include "wallet_account.h"
|
||||
#include "service_interface.h"
|
||||
|
||||
namespace Wallets
|
||||
{
|
||||
|
||||
class Service : public ServiceInterface
|
||||
class Service : public ServiceInterface, public QObject
|
||||
{
|
||||
private:
|
||||
void fetchAccounts();
|
||||
void refreshAccounts();
|
||||
|
||||
QMap<QString, WalletAccountDto> m_walletAccounts;
|
||||
|
||||
|
@ -22,7 +24,14 @@ public:
|
|||
~Service() = default;
|
||||
|
||||
void init() override;
|
||||
|
||||
QList<WalletAccountDto> getWalletAccounts() override;
|
||||
QString generateNewAccount(const QString& password, const QString& accountName, const QString& color) override;
|
||||
QString addAccountsFromPrivateKey(const QString& privateKey, const QString& password, const QString& accountName, const QString& color) override;
|
||||
QString addAccountsFromSeed(const QString& seedPhrase, const QString& password, const QString& accountName, const QString& color) override;
|
||||
QString addWatchOnlyAccount(const QString& address, const QString& accountName , const QString& color) override;
|
||||
void deleteAccount(const QString& address) override;
|
||||
|
||||
};
|
||||
} // namespace Wallets
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@ class ServiceInterface : public AppService
|
|||
{
|
||||
public:
|
||||
virtual QList<WalletAccountDto> getWalletAccounts() = 0;
|
||||
virtual QString generateNewAccount(const QString& password, const QString& accountName, const QString& color) = 0;
|
||||
virtual QString addAccountsFromPrivateKey(const QString& privateKey, const QString& password, const QString& accountName, const QString& color) = 0;
|
||||
virtual QString addAccountsFromSeed(const QString& seedPhrase, const QString& password, const QString& accountName, const QString& color) = 0;
|
||||
virtual QString addWatchOnlyAccount(const QString& address, const QString& accountName , const QString& color) = 0;
|
||||
virtual void deleteAccount(const QString& address) = 0;
|
||||
};
|
||||
|
||||
} // namespace Wallets
|
||||
|
|
|
@ -22,6 +22,7 @@ void Service::fetchAccounts()
|
|||
try
|
||||
{
|
||||
auto response = Backend::Wallet::Accounts::getAccounts();
|
||||
|
||||
QVector<WalletAccountDto> result;
|
||||
foreach(const QJsonValue& value, response.m_result)
|
||||
{
|
||||
|
@ -35,9 +36,65 @@ void Service::fetchAccounts()
|
|||
}
|
||||
}
|
||||
|
||||
void Service::refreshAccounts()
|
||||
{
|
||||
fetchAccounts();
|
||||
// do other thing like get balances and build token here later
|
||||
}
|
||||
|
||||
|
||||
QList<WalletAccountDto> Service::getWalletAccounts()
|
||||
{
|
||||
return m_walletAccounts.values();
|
||||
}
|
||||
|
||||
QString Service::generateNewAccount(const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
auto response = Backend::Wallet::Accounts::generateNewAccount(password, accountName, color);
|
||||
if(response.m_error.m_message.isEmpty())
|
||||
{
|
||||
refreshAccounts();
|
||||
}
|
||||
return response.m_error.m_message;
|
||||
}
|
||||
|
||||
QString Service::addAccountsFromPrivateKey(const QString& privateKey, const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
auto response = Backend::Wallet::Accounts::addAccountsFromPrivateKey(privateKey, password, accountName, color);
|
||||
if(response.m_error.m_message.isEmpty())
|
||||
{
|
||||
refreshAccounts();
|
||||
}
|
||||
return response.m_error.m_message;
|
||||
}
|
||||
|
||||
QString Service::addAccountsFromSeed(const QString& seedPhrase, const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
auto response = Backend::Wallet::Accounts::addAccountsFromSeed(seedPhrase, password, accountName, color);
|
||||
if(response.m_error.m_message.isEmpty())
|
||||
{
|
||||
refreshAccounts();
|
||||
}
|
||||
return response.m_error.m_message;
|
||||
}
|
||||
|
||||
QString Service::addWatchOnlyAccount(const QString& address, const QString& accountName , const QString& color)
|
||||
{
|
||||
auto response = Backend::Wallet::Accounts::addWatchOnlyAccount(address, accountName, color);
|
||||
if(response.m_error.m_message.isEmpty())
|
||||
{
|
||||
refreshAccounts();
|
||||
}
|
||||
return response.m_error.m_message;
|
||||
}
|
||||
|
||||
void Service::deleteAccount(const QString& address)
|
||||
{
|
||||
auto response = Backend::Wallet::Accounts::deleteAccount(address);
|
||||
if(response.m_error.m_message.isEmpty())
|
||||
{
|
||||
refreshAccounts();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Wallets
|
||||
|
|
|
@ -25,10 +25,12 @@ public:
|
|||
class RpcError
|
||||
{
|
||||
public:
|
||||
int m_code;
|
||||
double m_code;
|
||||
QString m_message;
|
||||
|
||||
friend ostream& operator<<(ostream& os, Backend::RpcError& r);
|
||||
RpcError() = default;
|
||||
RpcError(double code, QString message);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -43,8 +45,14 @@ public:
|
|||
|
||||
public:
|
||||
RpcResponse(QString jsonrpc, T result)
|
||||
: m_jsonrpc(jsonrpc)
|
||||
, m_result(result)
|
||||
{ }
|
||||
|
||||
RpcResponse(QString jsonrpc, T result, RpcError error)
|
||||
: m_jsonrpc(jsonrpc)
|
||||
, m_result(result)
|
||||
, m_error(error)
|
||||
{ }
|
||||
};
|
||||
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
namespace Backend::Wallet::Accounts
|
||||
{
|
||||
Backend::RpcResponse<QJsonArray> getAccounts();
|
||||
Backend::RpcResponse<QString> generateNewAccount(const QString& password, const QString& accountName, const QString& color);
|
||||
Backend::RpcResponse<QString> addAccountsFromPrivateKey(const QString& privateKey, const QString& password, const QString& accountName, const QString& color);
|
||||
Backend::RpcResponse<QString> addAccountsFromSeed(const QString& seedPhrase, const QString& password, const QString& accountName, const QString& color);
|
||||
Backend::RpcResponse<QString> addWatchOnlyAccount(const QString& address, const QString& accountName , const QString& color);
|
||||
Backend::RpcResponse<QString> deleteAccount(const QString& address);
|
||||
} // namespace Backend::Wallet::Accounts
|
||||
|
||||
#endif // WALLETACCOUNT_BACKEND_H
|
||||
|
|
|
@ -9,6 +9,11 @@ ostream& operator<<(ostream& os, const Backend::RpcError& r)
|
|||
<< std::endl);
|
||||
}
|
||||
|
||||
Backend::RpcError::RpcError(double code, QString message):
|
||||
m_code(code),
|
||||
m_message(message)
|
||||
{}
|
||||
|
||||
Backend::RpcException::RpcException(const std::string& message)
|
||||
: m_message(message)
|
||||
{ }
|
||||
|
|
|
@ -13,7 +13,62 @@ RpcResponse<QJsonArray> getAccounts()
|
|||
{
|
||||
QJsonObject inputJSON{{"jsonrpc", "2.0"}, {"method", "accounts_getAccounts"}, {"params", QJsonValue()}};
|
||||
auto result = CallPrivateRPC(Utils::jsonToStr(inputJSON).toUtf8().data());
|
||||
return RpcResponse<QJsonArray>(result, QJsonDocument::fromJson(result)["result"].toArray());
|
||||
auto obj = QJsonDocument::fromJson(result).object();
|
||||
Backend::Utils::throwOnError(obj);
|
||||
return RpcResponse<QJsonArray>(result, obj["result"].toArray(), RpcError(-1, QJsonDocument::fromJson(result)["error"].toString()));
|
||||
}
|
||||
|
||||
RpcResponse<QString> generateNewAccount(const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
QString hashedPassword(Backend::Utils::hashString(password));
|
||||
QJsonArray payload = {hashedPassword, accountName, color};
|
||||
QJsonObject inputJSON{{"jsonrpc", "2.0"}, {"method", "accounts_generateAccount"}, {"params", payload}};
|
||||
auto result = CallPrivateRPC(Utils::jsonToStr(inputJSON).toUtf8().data());
|
||||
auto response = QJsonDocument::fromJson(result);
|
||||
return RpcResponse<QString>(result,response["result"].toString(),
|
||||
RpcError(response["error"]["code"].toDouble(), response["error"]["message"].toString()));
|
||||
}
|
||||
|
||||
RpcResponse<QString> addAccountsFromPrivateKey(const QString& privateKey, const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
QString hashedPassword(Backend::Utils::hashString(password));
|
||||
QJsonArray payload = {privateKey, hashedPassword, accountName, color};
|
||||
QJsonObject inputJSON{{"jsonrpc", "2.0"}, {"method", "accounts_addAccountWithMnemonic"}, {"params", payload}};
|
||||
auto result = CallPrivateRPC(Utils::jsonToStr(inputJSON).toUtf8().data());
|
||||
auto response = QJsonDocument::fromJson(result);
|
||||
return RpcResponse<QString>(result,response["result"].toString(),
|
||||
RpcError(response["error"]["code"].toDouble(), response["error"]["message"].toString()));
|
||||
}
|
||||
|
||||
RpcResponse<QString> addAccountsFromSeed(const QString& seedPhrase, const QString& password, const QString& accountName, const QString& color)
|
||||
{
|
||||
QString hashedPassword(Backend::Utils::hashString(password));
|
||||
QJsonArray payload = {seedPhrase, hashedPassword, accountName, color};
|
||||
QJsonObject inputJSON{{"jsonrpc", "2.0"}, {"method", "accounts_addAccountWithPrivateKey"}, {"params", payload}};
|
||||
auto result = CallPrivateRPC(Utils::jsonToStr(inputJSON).toUtf8().data());
|
||||
auto response = QJsonDocument::fromJson(result);
|
||||
return RpcResponse<QString>(result,response["result"].toString(),
|
||||
RpcError(response["error"]["code"].toDouble(), response["error"]["message"].toString()));
|
||||
}
|
||||
|
||||
RpcResponse<QString> addWatchOnlyAccount(const QString& address, const QString& accountName , const QString& color)
|
||||
{
|
||||
QJsonArray payload = {address, accountName, color};
|
||||
QJsonObject inputJSON{{"jsonrpc", "2.0"}, {"method", "accounts_addAccountWatch"}, {"params", payload}};
|
||||
auto result = CallPrivateRPC(Utils::jsonToStr(inputJSON).toUtf8().data());
|
||||
auto response = QJsonDocument::fromJson(result);
|
||||
return RpcResponse<QString>(result,response["result"].toString(),
|
||||
RpcError(response["error"]["code"].toDouble(), response["error"]["message"].toString()));
|
||||
}
|
||||
|
||||
RpcResponse<QString> deleteAccount(const QString& address)
|
||||
{
|
||||
QJsonArray payload = {address};
|
||||
QJsonObject inputJSON{{"jsonrpc", "2.0"}, {"method", "accounts_deleteAccount"}, {"params", payload}};
|
||||
auto result = CallPrivateRPC(Utils::jsonToStr(inputJSON).toUtf8().data());
|
||||
auto response = QJsonDocument::fromJson(result);
|
||||
return RpcResponse<QString>(result,response["result"].toString(),
|
||||
RpcError(response["error"]["code"].toDouble(), response["error"]["message"].toString()));
|
||||
}
|
||||
|
||||
} // namespace Backend::Wallet::Accounts
|
||||
|
|
|
@ -2,9 +2,11 @@ pragma Singleton
|
|||
|
||||
import QtQuick 2.13
|
||||
|
||||
import utils 1.0
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
property var currentAccount: walletSectionCurrent
|
||||
property var currentAccount: Constants.isCppApp ? walletSectionAccounts.currentAccount: walletSectionCurrent
|
||||
property var accounts: walletSectionAccounts.model
|
||||
property var appSettings: localAppSettings
|
||||
property var accountSensitiveSettings: localAccountSensitiveSettings
|
||||
|
@ -97,7 +99,10 @@ QtObject {
|
|||
}
|
||||
|
||||
function switchAccount(newIndex) {
|
||||
walletSection.switchAccount(newIndex)
|
||||
if(Constants.isCppApp)
|
||||
walletSectionAccounts.switchAccount(newIndex)
|
||||
else
|
||||
walletSection.switchAccount(newIndex)
|
||||
}
|
||||
|
||||
function generateNewAccount(password, accountName, color) {
|
||||
|
|
|
@ -213,4 +213,6 @@ QtObject {
|
|||
//% "Continuing will require a transaction to connect the username with your current chat key."
|
||||
"connected-different-key": qsTrId("ens-username-connected-with-different-key"),
|
||||
}
|
||||
|
||||
readonly property bool isCppApp: cppApp ? cppApp : false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue