feat(@desktop/wallet): move accounts to cpp

created skeleton for wallet_section
added getAccounts api

fixes #4750
This commit is contained in:
Khushboo Mehta 2022-02-14 15:38:41 +01:00 committed by Khushboo-dev-cpp
parent 0acfd9b50c
commit 42da8a2408
46 changed files with 1417 additions and 327 deletions

View File

@ -20,6 +20,14 @@ add_library(app
modules/main/controller.cpp modules/main/controller.cpp
modules/main/module.cpp modules/main/module.cpp
modules/main/view.cpp modules/main/view.cpp
modules/main/wallet/controller.cpp
modules/main/wallet/module.cpp
modules/main/wallet/view.cpp
modules/main/wallet/accounts/controller.cpp
modules/main/wallet/accounts/module.cpp
modules/main/wallet/accounts/view.cpp
modules/main/wallet/accounts/model.cpp
modules/main/wallet/accounts/item.cpp
) )
target_include_directories(app target_include_directories(app

View File

@ -24,6 +24,7 @@ AppController::AppController()
// result.keychainService = keychain_service.newService(statusFoundation.status.events) // result.keychainService = keychain_service.newService(statusFoundation.status.events)
// result.ethService = eth_service.newService() // result.ethService = eth_service.newService()
m_accountsService = new Accounts::Service(); m_accountsService = new Accounts::Service();
m_walletServicePtr = std::make_shared<Wallets::Service>();
// result.networkService = network_service.newService() // result.networkService = network_service.newService()
// result.contactsService = contacts_service.newService(statusFoundation.status.events, statusFoundation.threadpool) // result.contactsService = contacts_service.newService(statusFoundation.status.events, statusFoundation.threadpool)
// result.chatService = chat_service.newService(statusFoundation.status.events, result.contactsService) // result.chatService = chat_service.newService(statusFoundation.status.events, result.contactsService)
@ -66,7 +67,7 @@ AppController::AppController()
// # Modules // # Modules
m_startupModule = new Modules::Startup::Module(this, /*keychainService,*/ m_accountsService); m_startupModule = new Modules::Startup::Module(this, /*keychainService,*/ m_accountsService);
m_mainModule = new Modules::Main::Module(this m_mainModulePtr = std::make_unique<Modules::Main::Module>(m_walletServicePtr
// statusFoundation.status.events, // statusFoundation.status.events,
// result.keychainService, // result.keychainService,
// result.accountsService, // result.accountsService,
@ -102,8 +103,6 @@ AppController::AppController()
AppController::~AppController() AppController::~AppController()
{ {
delete m_startupModule; delete m_startupModule;
delete m_mainModule;
delete m_accountsService; delete m_accountsService;
} }
@ -112,6 +111,7 @@ void AppController::connect()
// self.statusFoundation.status.events.once("nodeStopped") do(a: Args): // self.statusFoundation.status.events.once("nodeStopped") do(a: Args):
// TODO: remove this once accounts are not tracked in the AccountsModel // TODO: remove this once accounts are not tracked in the AccountsModel
// self.statusFoundation.status.reset() // self.statusFoundation.status.reset()
QObject::connect(dynamic_cast<QObject*>(m_mainModulePtr.get()), SIGNAL(loaded()), this, SLOT(mainDidLoad()));
} }
void AppController::startupDidLoad() void AppController::startupDidLoad()
@ -143,6 +143,7 @@ void AppController::start()
void AppController::load() void AppController::load()
{ {
qWarning() << "TODO: init services and load main module"; qWarning() << "TODO: init services and load main module";
m_walletServicePtr->init();
// self.settingsService.init() // self.settingsService.init()
// self.nodeConfigurationService.init() // self.nodeConfigurationService.init()
// self.contactsService.init() // self.contactsService.init()
@ -173,7 +174,7 @@ void AppController::load()
// self.buildAndRegisterUserProfile() // self.buildAndRegisterUserProfile()
// # load main module // # load main module
m_mainModule->load( m_mainModulePtr->load(
// self.statusFoundation.status.events, // self.statusFoundation.status.events,
// self.settingsService, // self.settingsService,
// self.contactsService, // self.contactsService,

View File

@ -1,13 +1,18 @@
#pragma once #ifndef APP_CONTROLLER_H
#define APP_CONTROLLER_H
#include <QObject>
#include "accounts/service.h" #include "accounts/service.h"
#include "../modules/main/module_access_interface.h" #include "wallet_accounts/service.h"
#include "../modules/main/interfaces/module_access_interface.h"
#include "../modules/startup/module_access_interface.h" #include "../modules/startup/module_access_interface.h"
#include "app_controller_delegate.h" #include "app_controller_delegate.h"
#include "app_service.h" #include "app_service.h"
class AppController : public AppControllerDelegate class AppController : public QObject, AppControllerDelegate
{ {
Q_OBJECT
//statusFoundation: StatusFoundation //statusFoundation: StatusFoundation
// Global // Global
@ -19,22 +24,26 @@ class AppController : public AppControllerDelegate
// Services // Services
Accounts::Service* m_accountsService; Accounts::Service* m_accountsService;
std::shared_ptr<Wallets::Service> m_walletServicePtr;
// Modules // Modules
// To-Do make this a shared pointer and remove circular dependency.
Modules::Startup::ModuleAccessInterface* m_startupModule; Modules::Startup::ModuleAccessInterface* m_startupModule;
Modules::Main::ModuleAccessInterface* m_mainModule; std::unique_ptr<Modules::Main::IModuleAccess> m_mainModulePtr;
public: public:
AppController(); AppController();
~AppController(); ~AppController();
void start(); void start();
public slots:
void mainDidLoad();
private: private:
void connect(); void connect();
void startupDidLoad() override; void startupDidLoad() override;
void mainDidLoad();
void load(); void load();
void userLoggedIn() override; void userLoggedIn() override;
void buildAndRegisterLocalAccountSensitiveSettings(); void buildAndRegisterLocalAccountSensitiveSettings();
void buildAndRegisterUserProfile(); void buildAndRegisterUserProfile();
}; };
#endif // APP_CONTROLLER_H

View File

@ -5,7 +5,5 @@ class AppControllerDelegate
public: public:
virtual void startupDidLoad() = 0; virtual void startupDidLoad() = 0;
virtual void mainDidLoad() = 0;
virtual void userLoggedIn() = 0; virtual void userLoggedIn() = 0;
}; };

View File

@ -1,15 +1,13 @@
#include "controller.h"
#include "accounts/service_interface.h"
#include "interfaces/module_controller_delegate_interface.h"
#include <QDebug> #include <QDebug>
#include "controller.h"
namespace Modules namespace Modules
{ {
namespace Main namespace Main
{ {
Controller::Controller(ModuleControllerDelegateInterface* delegate, QObject* parent) Controller::Controller(QObject* parent)
: QObject(parent) : QObject(parent)
, m_delegate(delegate)
{ } { }
void Controller::init() { } void Controller::init() { }

View File

@ -1,24 +1,27 @@
#pragma once #ifndef CONTROLLER_H
#define CONTROLLER_H
#include "controller_interface.h"
#include "interfaces/module_controller_delegate_interface.h"
#include "signals.h"
#include <QObject> #include <QObject>
#include "interfaces/controller_interface.h"
#include "signals.h"
namespace Modules namespace Modules
{ {
namespace Main namespace Main
{ {
class Controller : public QObject, ControllerInterface class Controller : public QObject, IController
{ {
public: public:
Controller(ModuleControllerDelegateInterface* delegate, QObject* parent = nullptr); explicit Controller(QObject* parent = nullptr);
void init() override; ~Controller() = default;
private: void init() override;
ModuleControllerDelegateInterface* m_delegate;
}; };
} // namespace Main } // namespace Main
} // namespace Modules } // namespace Modules
#endif // CONTROLLER_H

View File

@ -1,16 +0,0 @@
#pragma once
namespace Modules
{
namespace Main
{
// Abstract class for any input/interaction with this module.
class ControllerInterface
{
public:
virtual void init() = 0;
};
} // namespace Main
} // namespace Modules

View File

@ -0,0 +1,17 @@
#ifndef ICONTROLLER_H
#define ICONTROLLER_H
namespace Modules
{
namespace Main
{
// Abstract class for any input/interaction with this module.
class IController
{
public:
virtual void init() = 0;
};
} // namespace Main
} // namespace Modules
#endif // ICONTROLLER_H

View File

@ -0,0 +1,23 @@
#ifndef IMODULEACCESS_H
#define IMODULEACCESS_H
#include <QObject>
namespace Modules
{
namespace Main
{
class IModuleAccess
{
public:
virtual void load() = 0;
virtual bool isLoaded() = 0;
signals:
virtual void loaded() = 0;
};
}; // namespace Main
}; // namespace Modules
Q_DECLARE_INTERFACE(Modules::Main::IModuleAccess, "Modules::Main::IModuleAccess");
#endif // IMODULEACCESS_H

View File

@ -1,12 +0,0 @@
#pragma once
namespace Modules
{
namespace Main
{
class ModuleControllerDelegateInterface
{
public:
};
}; // namespace Main
}; // namespace Modules

View File

@ -1,13 +0,0 @@
#pragma once
namespace Modules
{
namespace Main
{
class ModuleViewDelegateInterface
{
public:
virtual void viewDidLoad() = 0;
};
}; // namespace Main
}; // namespace Modules

View File

@ -1,39 +1,49 @@
#include "module.h"
#include "controller.h"
#include "singleton.h"
#include "view.h"
#include <QDebug> #include <QDebug>
#include <QObject>
#include <QQmlContext> #include <QQmlContext>
#include <QVariant>
#include "module.h"
#include "singleton.h"
#include "modules/main/wallet/module.h"
namespace Modules namespace Modules
{ {
namespace Main namespace Main
{ {
Module::Module(AppControllerDelegate* delegate) Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService)
: m_delegate(delegate)
{ {
m_controller = new Controller(this); m_controllerPtr = std::make_unique<Controller>();
m_view = new View(this); m_viewPtr = std::make_unique<View>();
// Submodules
m_walletModulePtr = std::make_unique<Modules::Main::Wallet::Module>(walletsService);
m_moduleLoaded = false;
connect();
} }
Module::~Module() void Module::connect()
{ {
delete m_controller; QObject::connect(m_viewPtr.get(), &View::viewLoaded, this, &Module::viewDidLoad);
delete m_view; QObject::connect(dynamic_cast<QObject*>(m_walletModulePtr.get()), SIGNAL(loaded()), this, SLOT(walletDidLoad()));
} }
void Module::load() void Module::load()
{ {
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("mainModule", m_view); Global::Singleton::instance()->engine()->rootContext()->setContextProperty("mainModule", m_viewPtr.get());
m_controller->init(); m_controllerPtr->init();
m_view->load(); m_viewPtr->load();
m_walletModulePtr->load();
} }
void Module::checkIfModuleDidLoad() void Module::checkIfModuleDidLoad()
{ {
m_delegate->mainDidLoad(); if(!m_walletModulePtr->isLoaded())
{
return;
}
m_moduleLoaded = true;
emit loaded();
} }
void Module::viewDidLoad() void Module::viewDidLoad()
@ -41,5 +51,15 @@ void Module::viewDidLoad()
Module::checkIfModuleDidLoad(); Module::checkIfModuleDidLoad();
} }
void Module::walletDidLoad()
{
Module::checkIfModuleDidLoad();
}
bool Module::isLoaded()
{
return m_moduleLoaded;
}
} // namespace Main } // namespace Main
} // namespace Modules } // namespace Modules

View File

@ -1,32 +1,48 @@
#pragma once #ifndef MODULE_H
#define MODULE_H
#include <QObject>
#include <QPointer>
#include "interfaces/module_access_interface.h"
#include "wallet_accounts/service_interface.h"
#include "wallet/interfaces/module_access_interface.h"
#include "app_controller_delegate.h"
#include "controller.h" #include "controller.h"
#include "interfaces/module_controller_delegate_interface.h"
#include "interfaces/module_view_delegate_interface.h"
#include "login/module_access_interface.h"
#include "module_access_interface.h"
#include "onboarding/module_access_interface.h"
#include "view.h" #include "view.h"
#include <QVariant>
namespace Modules namespace Modules
{ {
namespace Main namespace Main
{ {
class Module : public ModuleAccessInterface, ModuleControllerDelegateInterface, ModuleViewDelegateInterface class Module : public QObject, virtual public IModuleAccess
{ {
Q_OBJECT
private: private:
AppControllerDelegate* m_delegate; bool m_moduleLoaded;
View* m_view;
Controller* m_controller; std::unique_ptr<View> m_viewPtr;
std::unique_ptr<Controller> m_controllerPtr;
std::unique_ptr<Modules::Main::Wallet::IWalletModuleAccess> m_walletModulePtr;
void connect();
public: public:
Module(AppControllerDelegate* delegate); explicit Module(std::shared_ptr<Wallets::ServiceInterface> walletService);
~Module(); ~Module() = default;
void load() override; void load() override;
bool isLoaded() override;
void checkIfModuleDidLoad(); void checkIfModuleDidLoad();
void viewDidLoad() override;
public slots:
void viewDidLoad();
void walletDidLoad();
signals:
void loaded() override;
}; };
}; // namespace Main }; // namespace Main
}; // namespace Modules }; // namespace Modules
#endif // MODULE_H

View File

@ -1,13 +0,0 @@
#pragma once
namespace Modules
{
namespace Main
{
class ModuleAccessInterface
{
public:
virtual void load() = 0;
};
}; // namespace Main
}; // namespace Modules

View File

@ -1,21 +1,18 @@
#include "view.h" #include "view.h"
#include "interfaces/module_view_delegate_interface.h"
#include <QObject>
namespace Modules namespace Modules
{ {
namespace Main namespace Main
{ {
View::View(ModuleViewDelegateInterface* delegate, QObject* parent) View::View(QObject* parent)
: QObject(parent) : QObject(parent)
, m_delegate(delegate)
{ } { }
void View::load() void View::load()
{ {
// In some point, here, we will setup some exposed main module related things. // At some point, here, we will setup some exposed main module related things.
m_delegate->viewDidLoad(); emit viewLoaded();
} }
} // namespace Main } // namespace Main

View File

@ -1,6 +1,6 @@
#pragma once #ifndef VIEW_H
#define VIEW_H
#include "interfaces/module_view_delegate_interface.h"
#include <QObject> #include <QObject>
namespace Modules namespace Modules
@ -13,11 +13,15 @@ class View : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr); explicit View(QObject* parent = nullptr);
void load(); ~View() = default;
private: void load();
ModuleViewDelegateInterface* m_delegate; signals:
void viewLoaded();
}; };
} // namespace Main } // namespace Main
} // namespace Modules } // namespace Modules
#endif // VIEW_H

View File

@ -0,0 +1,34 @@
#include <QDebug>
#include "controller.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
Controller::Controller(std::shared_ptr<Wallets::ServiceInterface> walletService,
QObject* parent)
: m_walletServicePtr(walletService),
QObject(parent)
{ }
void Controller::init()
{
}
QList<Wallets::WalletAccountDto> Controller::getWalletAccounts()
{
QList<Wallets::WalletAccountDto> wallet_accounts;
if(nullptr != m_walletServicePtr)
wallet_accounts = m_walletServicePtr->getWalletAccounts();
return wallet_accounts;
}
} // namespace Accounts
} // namespace Wallet
} // namespace Main
} // namespace Modules

View File

@ -0,0 +1,39 @@
#ifndef WALLET_ACCOUNT_CONTROLLER_H
#define WALLET_ACCOUNT_CONTROLLER_H
#include <QObject>
#include "wallet_accounts/wallet_account.h"
#include "wallet_accounts/service_interface.h"
#include "interfaces/controller_interface.h"
#include "signals.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
class Controller : public QObject, IAccountsController
{
Q_OBJECT
public:
explicit Controller(std::shared_ptr<Wallets::ServiceInterface> walletService, QObject* parent = nullptr);
~Controller() = default;
void init() override;
QList<Wallets::WalletAccountDto> getWalletAccounts();
private:
std::shared_ptr<Wallets::ServiceInterface> m_walletServicePtr;
};
} // namespace Accounts
} // namespace Wallet
} // namespace Main
} // namespace Modules
#endif // WALLET_ACCOUNT_CONTROLLER_H

View File

@ -0,0 +1,26 @@
#ifndef IWALLETACCOUNTSCONTROLLER_H
#define IWALLETACCOUNTSCONTROLLER_H
#include "../../../interfaces/controller_interface.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
// Abstract class for any input/interaction with this module.
class IAccountsController: public IController
{
public:
virtual void init() = 0;
};
} // namespave Accounts
} // namespace Wallet
} // namespace Main
} // namespace Modules
#endif // IWALLETACCOUNTSCONTROLLER_H

View File

@ -0,0 +1,19 @@
#ifndef IWALLETACCOUNTMODULEACCESS_H
#define IWALLETACCOUNTMODULEACCESS_H
#include "../../../interfaces/module_access_interface.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
class IWalletAccountsModuleAccess: virtual public IModuleAccess
{
};
}; // namespace Wallet
}; // namespace Main
}; // namespace Modules\
#endif // IWALLETACCOUNTMODULEACCESS_H

View File

@ -0,0 +1,71 @@
#include "item.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
Item::Item(QString name, QString address, QString path, QString color, QString publicKey, QString walletType, bool isWallet, bool isChat, float currencyBalance)
: m_name(name),
m_address(address),
m_path(path),
m_color(color),
m_publicKey(publicKey),
m_walletType(walletType),
m_isWallet(isWallet),
m_isChat(isChat),
m_currencyBalance(currencyBalance)
{ }
QString Item::getName()
{
return m_name;
}
QString Item::getAddress()
{
return m_address;
}
QString Item::getPath()
{
return m_path;
}
QString Item::getColor()
{
return m_color;
}
QString Item::getPublicKey()
{
return m_publicKey;
}
QString Item::getWalletType()
{
return m_walletType;
}
bool Item::getIsWallet()
{
return m_isWallet;
}
bool Item::getIsChat()
{
return m_isChat;
}
float Item::getCurrencyBalance()
{
return m_currencyBalance;
}
} // namespace Accounts
} // namespace Wallet
} // namespace Main
} // namespace Modules

View File

@ -0,0 +1,46 @@
#ifndef WALLET_ACCOUNT_ITEM_H
#define WALLET_ACCOUNT_ITEM_H
#include <QString>
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
class Item
{
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;
public:
Item(QString name, QString address, QString path, QString color, QString publicKey, QString walletType, bool isWallet, bool isChat, float currencyBalance);
~Item() = default;
QString getName();
QString getAddress();
QString getPath();
QString getColor();
QString getPublicKey();
QString getWalletType();
bool getIsWallet();
bool getIsChat();
float getCurrencyBalance();
};
} // namespace Accounts
} // namespace Wallet
} // namespace Main
} // namespace Modules
#endif // WALLET_ACCOUNT_ITEM_H

View File

@ -0,0 +1,77 @@
#include "model.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
Model::Model(QObject* parent)
: QAbstractListModel(parent)
{ }
QHash<int, QByteArray> Model::roleNames() const
{
QHash<int, QByteArray> roles;
roles[Name] = "name";
roles[Address] = "address";
roles[Path] = "path";
roles[Color] = "color";
roles[PublicKey] = "publicKey";
roles[WalletType] = "walletType";
roles[IsWallet] = "isWallet";
roles[IsChat] = "isChat";
roles[Assets] = "assets";
roles[CurrencyBalance] = "currencyBalance";
return roles;
}
int Model::rowCount(const QModelIndex& parent = QModelIndex()) const
{
return m_items.size();
}
QVariant Model::data(const QModelIndex& index, int role) const
{
if(!index.isValid())
{
return QVariant();
}
if(index.row() < 0 || index.row() > m_items.size())
{
return QVariant();
}
Item item = m_items[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 Assets: return QVariant(item.ge());
case CurrencyBalance: return QVariant(item.getCurrencyBalance());
}
return QVariant();
}
void Model::setItems(QVector<Item> &items)
{
beginResetModel();
m_items = items;
endResetModel();
}
} // namespace Accounts
} // namespace Wallet
} // namespace Main
} // namespace Modules

View File

@ -0,0 +1,55 @@
#ifndef WALLET_ACCOUNT_MODEL_H
#define WALLET_ACCOUNT_MODEL_H
#include <QAbstractListModel>
#include <QHash>
#include <QVector>
#include "item.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
class Model : public QAbstractListModel
{
Q_OBJECT
public:
enum ModelRole
{
Name = Qt::UserRole + 1,
Address,
Path,
Color,
PublicKey,
WalletType,
IsWallet,
IsChat,
Assets,
CurrencyBalance
};
explicit Model(QObject* parent = nullptr);
~Model() = default;
QHash<int, QByteArray> roleNames() const;
virtual int rowCount(const QModelIndex&) const;
virtual QVariant data(const QModelIndex& index, int role) const;
void setItems(QVector<Item> &items);
private:
QVector<Item> m_items;
};
} // namespace Accounts
} // namespace Wallet
} // namespace Main
} // namespace Modules
#endif // WALLET_ACCOUNT_MODEL_H

View File

@ -0,0 +1,72 @@
#include <QDebug>
#include <QQmlContext>
#include "module.h"
#include "singleton.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService)
{
m_controllerPtr = std::make_unique<Controller>(walletsService);
m_viewPtr = std::make_unique<View>();
m_moduleLoaded = false;
connect();
}
void Module::connect()
{
QObject::connect(m_viewPtr.get(), &View::viewLoaded, this, &Module::viewDidLoad);
}
void Module::load()
{
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("walletSectionAccounts", m_viewPtr.get());
m_controllerPtr->init();
m_viewPtr->load();
}
bool Module::isLoaded()
{
return m_moduleLoaded;
}
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 Accounts
} // namespace Main
} // namespace Wallet
} // namespace Modules

View File

@ -0,0 +1,48 @@
#ifndef WALLET_ACCOUNT_MODULE_H
#define WALLET_ACCOUNT_MODULE_H
#include <QObject>
#include "wallet_accounts/service_interface.h"
#include "interfaces/module_access_interface.h"
#include "controller.h"
#include "view.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
class Module : public QObject, virtual public IWalletAccountsModuleAccess
{
Q_OBJECT
private:
std::unique_ptr<View> m_viewPtr;
std::unique_ptr<Controller> m_controllerPtr;
bool m_moduleLoaded;
void connect();
void refreshWalletAccounts();
public:
explicit Module(std::shared_ptr<Wallets::ServiceInterface> walletsService);
~Module() = default;
void load() override;
bool isLoaded() override;
public slots:
void viewDidLoad();
signals:
void loaded() override;
};
}; // namespace Accounts
}; // namespace Wallet
}; // namespace Main
}; // namespace Modules
#endif // WALLET_ACCOUNT_MODULE_H

View File

@ -0,0 +1,36 @@
#include <QDebug>
#include "view.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
View::View(QObject* parent)
: QObject(parent)
{
m_modelPtr = std::make_shared<Model>();
}
void View::load()
{
emit viewLoaded();
}
Model* View::getModel()
{
return m_modelPtr.get();
}
void View::setModelItems(QVector<Item> &accounts) {
m_modelPtr->setItems(accounts);
modelChanged();
}
} // namespace Accounts
} // namespace Wallet
} // namespace Main
} // namespace Modules

View File

@ -0,0 +1,44 @@
#ifndef WALLET_ACCOUNT_VIEW_H
#define WALLET_ACCOUNT_VIEW_H
#include <QObject>
#include <memory>
#include "model.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
namespace Accounts
{
class View : public QObject
{
Q_OBJECT
Q_PROPERTY(Model* accountsModel READ getModel NOTIFY modelChanged)
public:
explicit View(QObject* parent = nullptr);
~View() = default;
void load();
void setModelItems(QVector<Item> &accounts);
private:
std::shared_ptr<Model> m_modelPtr;
public slots:
Model* getModel();
signals:
void viewLoaded();
void modelChanged();
};
} // namespace Accounts
} // namespace Wallet
} // namespace Main
} // namespace Modules
#endif // WALLET_ACCOUNT_VIEW_H

View File

@ -0,0 +1,23 @@
#include <QDebug>
#include "controller.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
Controller::Controller(std::shared_ptr<Wallets::ServiceInterface> walletService,
QObject* parent)
: m_walletService(walletService),
QObject(parent)
{ }
void Controller::init()
{
}
} // namespace Onboarding
} // namespace Startup
} // namespace Modules

View File

@ -0,0 +1,32 @@
#ifndef WALLET_CONTROLLER_H
#define WALLET_CONTROLLER_H
#include <QObject>
#include "wallet_accounts/service_interface.h"
#include "interfaces/controller_interface.h"
#include "signals.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
class Controller : public QObject, IWalletController
{
Q_OBJECT
public:
explicit Controller(std::shared_ptr<Wallets::ServiceInterface> walletService, QObject* parent = nullptr);
~Controller() = default;
void init() override;
private:
std::shared_ptr<Wallets::ServiceInterface> m_walletService;
};
} // namespace Wallet
} // namespace Main
} // namespace Modules
#endif // WALLET_CONTROLLER_H

View File

@ -0,0 +1,21 @@
#ifndef IWALLETCONTROLLER_H
#define IWALLETCONTROLLER_H
#include "../../interfaces/controller_interface.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
// Abstract class for any input/interaction with this module.
class IWalletController: public IController
{
};
} // namespace Wallet
} // namespace Main
} // namespace Modules
#endif // IWALLETCONTROLLER_H

View File

@ -0,0 +1,19 @@
#ifndef IWALLETMODULEACCESS_H
#define IWALLETMODULEACCESS_H
#include "../../interfaces/module_access_interface.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
class IWalletModuleAccess: virtual public IModuleAccess
{
};
}; // namespace Wallet
}; // namespace Main
}; // namespace Modules
#endif // IWALLETMODULEACCESS_H

View File

@ -0,0 +1,67 @@
#include <QDebug>
#include <QQmlContext>
#include "module.h"
#include "singleton.h"
#include "accounts/module.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService)
{
m_controllerPtr = std::make_unique<Controller>(walletsService);
m_viewPtr = std::make_unique<View>();
// Sub-Modules
m_accountsModulePtr = std::make_unique<Modules::Main::Wallet::Accounts::Module>(walletsService);
m_moduleLoaded = false;
connect();
}
void Module::connect()
{
QObject::connect(m_viewPtr.get(), SIGNAL(viewLoaded()), this, SLOT(viewDidLoad()));
QObject::connect(dynamic_cast<QObject*>(m_accountsModulePtr.get()), SIGNAL(loaded()), this, SLOT(accountsDidLoad()));
}
void Module::load()
{
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("walletSection", m_viewPtr.get());
m_controllerPtr->init();
m_viewPtr->load();
m_accountsModulePtr->load();
}
bool Module::isLoaded()
{
return m_moduleLoaded;
}
void Module::checkIfModuleDidLoad()
{
if(!m_accountsModulePtr->isLoaded())
{
return;
}
m_moduleLoaded = true;
emit loaded();
}
void Module::viewDidLoad()
{
checkIfModuleDidLoad();
}
void Module::accountsDidLoad()
{
checkIfModuleDidLoad();
}
} // namespace Main
} // namespace Wallet
} // namespace Modules

View File

@ -0,0 +1,47 @@
#ifndef WALLET_MODULE_H
#define WALLET_MODULE_H
#include <QObject>
#include "wallet_accounts/service_interface.h"
#include "interfaces/module_access_interface.h"
#include "accounts/interfaces/module_access_interface.h"
#include "controller.h"
#include "view.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
class Module : public QObject, virtual public IWalletModuleAccess
{
Q_OBJECT
private:
std::unique_ptr<View> m_viewPtr;
std::unique_ptr<Controller> m_controllerPtr;
std::unique_ptr<IWalletAccountsModuleAccess> m_accountsModulePtr;
bool m_moduleLoaded;
void connect();
public:
explicit Module(std::shared_ptr<Wallets::ServiceInterface> walletsService);
~Module() = default;
void load() override;
bool isLoaded() override;
void checkIfModuleDidLoad();
public slots:
void viewDidLoad();
void accountsDidLoad();
signals:
void loaded() override;
};
}; // namespace Wallet
}; // namespace Main
}; // namespace Modules
#endif // WALLET_MODULE_H

View File

@ -0,0 +1,23 @@
#include <QDebug>
#include "view.h"
namespace Modules
{
namespace Main
{
namespace Wallet
{
View::View(QObject* parent)
: QObject(parent)
{
}
void View::load()
{
emit viewLoaded();
}
} // namespace Wallet
} // namespace Main
} // namespace Modules

View File

@ -0,0 +1,31 @@
#ifndef WALLET_VIEW_H
#define WALLET_VIEW_H
#include <QObject>
namespace Modules
{
namespace Main
{
namespace Wallet
{
class View : public QObject
{
Q_OBJECT
public:
explicit View(QObject* parent = nullptr);
~View() = default;
void load();
signals:
void viewLoaded();
};
} // namespace Wallet
} // namespace Main
} // namespace Modules
#endif // WALLET_VIEW_H

View File

@ -3,6 +3,8 @@ add_library(app_service
service/accounts/dto/account.cpp service/accounts/dto/account.cpp
service/accounts/dto/generated_account.cpp service/accounts/dto/generated_account.cpp
service/accounts/service.cpp service/accounts/service.cpp
service/wallet_accounts/dto/wallet_account.cpp
service/wallet_accounts/service.cpp
) )
target_include_directories(app_service target_include_directories(app_service

View File

@ -0,0 +1,29 @@
#ifndef WALLETACCOUNTSSERVICE_H
#define WALLETACCOUNTSSERVICE_H
#include <QString>
#include <QMap>
#include "wallet_account.h"
#include "service_interface.h"
namespace Wallets
{
class Service : public ServiceInterface
{
private:
void fetchAccounts();
QMap<QString, WalletAccountDto> m_walletAccounts;
public:
Service();
~Service() = default;
void init() override;
QList<WalletAccountDto> getWalletAccounts() override;
};
} // namespace Wallets
#endif // WALLETACCOUNTSERVICE_H

View File

@ -0,0 +1,22 @@
#ifndef WALLETACCOUNTSSERVICEINTERFACE_H
#define WALLETACCOUNTSSERVICEINTERFACE_H
#include <QJsonValue>
#include <QList>
#include <memory>
#include "../app_service.h"
#include "wallet_account.h"
namespace Wallets
{
class ServiceInterface : public AppService
{
public:
virtual QList<WalletAccountDto> getWalletAccounts() = 0;
};
} // namespace Wallets
#endif // WALLETACCOUNTSSERVICEINTERFACE_H

View File

@ -0,0 +1,32 @@
#ifndef WALLETACCOUNTDTO_H
#define WALLETACCOUNTDTO_H
#include <QJsonValue>
#include <QString>
#include <QVector>
#include "wallet_token.h"
namespace Wallets
{
class WalletAccountDto
{
public:
QString name;
QString address;
QString path;
QString color;
QString publicKey;
QString walletType;
bool isWallet;
bool isChat;
QVector<WalletTokenDto> tokens;
};
WalletAccountDto toWalletAccountDto(const QJsonValue jsonObj);
//WalletAccountDto getCurrencyBalance*(): float =
// return self.tokens.map(t => t.currencyBalance).foldl(a + b, 0.0)
} // namespace Wallet
#endif // WALLETACCOUNTDTO_H

View File

@ -0,0 +1,26 @@
#ifndef WALLETTOKENDTO_H
#define WALLETTOKENDTO_H
#include <QJsonValue>
#include <QString>
#include <QVector>
namespace Wallets
{
class WalletTokenDto
{
public:
QString name;
QString address;
QString symbol;
int decimals;
bool hasIcon;
QString color;
bool isCustom;
float balance;
float currencyBalance;
};
} // namespace Wallet
#endif // WALLETTOKENDTO_H

View File

@ -0,0 +1,20 @@
#include "wallet_accounts/wallet_account.h"
//#include "backend/accounts.h"
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>
#include <QStringList>
Wallets::WalletAccountDto Wallets::toWalletAccountDto(const QJsonValue jsonObj)
{
auto result = Wallets::WalletAccountDto();
result.name = jsonObj["name"].toString();
result.address = jsonObj["address"].toString();
result.path = jsonObj["path"].toString();
result.color = jsonObj["color"].toString();
result.isWallet = jsonObj["wallet"].toBool();
result.isChat = jsonObj["chat"].toBool();
result.publicKey = jsonObj["public-key"].toString();
result.walletType = jsonObj["type"].toString();
return result;
}

View File

@ -0,0 +1,44 @@
#include <QDebug>
#include "wallet_accounts/service.h"
#include "backend/wallet_accounts.h"
namespace Wallets
{
Service::Service()
{
// do nothing
}
void Service::init()
{
fetchAccounts();
}
void Service::fetchAccounts()
{
try
{
auto response = Backend::Wallet::Accounts::getAccounts();
QVector<WalletAccountDto> result;
foreach(const QJsonValue& value, response.m_result)
{
auto account = toWalletAccountDto(value);
if(!account.isChat)
m_walletAccounts[account.address] = account;
}
}
catch(Backend::RpcException& e)
{
qWarning() << e.what();
}
}
QList<WalletAccountDto> Service::getWalletAccounts()
{
return m_walletAccounts.values();
}
} // namespace Wallets

View File

@ -2,6 +2,7 @@ add_library(backend
accounts.cpp accounts.cpp
types.cpp types.cpp
utils.cpp utils.cpp
wallet_accounts.cpp
) )
target_include_directories(backend target_include_directories(backend

View File

@ -0,0 +1,19 @@
#ifndef WALLETACCOUNT_BACKEND_H
#define WALLETACCOUNT_BACKEND_H
#include <QJsonArray>
#include "backend/types.h"
namespace Backend
{
namespace Wallet
{
namespace Accounts
{
Backend::RpcResponse<QJsonArray> getAccounts();
} // namespace Accounts
} // namespace Wallet
} // namespace Backend
#endif // WALLETACCOUNT_BACKEND_H

View File

@ -0,0 +1,25 @@
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include "backend/wallet_accounts.h"
#include "backend/types.h"
#include "backend/utils.h"
#include "libstatus.h"
namespace Backend
{
namespace Wallet
{
namespace Accounts
{
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());
}
} // namespace Accounts
} // namespace Wallet
} // namespace Backend