feat(@desktop/wallet): move accounts to cpp
created skeleton for wallet_section added getAccounts api fixes #4750
This commit is contained in:
parent
0acfd9b50c
commit
42da8a2408
|
@ -20,6 +20,14 @@ add_library(app
|
|||
modules/main/controller.cpp
|
||||
modules/main/module.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
|
||||
|
|
|
@ -7,232 +7,233 @@
|
|||
|
||||
AppController::AppController()
|
||||
{
|
||||
// result.statusFoundation = statusFoundation
|
||||
// result.statusFoundation = statusFoundation
|
||||
|
||||
// # Global
|
||||
// result.localAppSettingsVariant = newQVariant(singletonInstance.localAppSettings)
|
||||
// result.localAccountSettingsVariant = newQVariant(singletonInstance.localAccountSettings)
|
||||
// result.localAccountSensitiveSettingsVariant = newQVariant(singletonInstance.localAccountSensitiveSettings)
|
||||
// result.userProfileVariant = newQVariant(singletonInstance.userProfile)
|
||||
// result.globalUtilsVariant = newQVariant(singletonInstance.utils)
|
||||
// # Global
|
||||
// result.localAppSettingsVariant = newQVariant(singletonInstance.localAppSettings)
|
||||
// result.localAccountSettingsVariant = newQVariant(singletonInstance.localAccountSettings)
|
||||
// result.localAccountSensitiveSettingsVariant = newQVariant(singletonInstance.localAccountSensitiveSettings)
|
||||
// result.userProfileVariant = newQVariant(singletonInstance.userProfile)
|
||||
// result.globalUtilsVariant = newQVariant(singletonInstance.utils)
|
||||
|
||||
// # Services
|
||||
// result.settingsService = settings_service.newService()
|
||||
// result.nodeConfigurationService = node_configuration_service.newService(statusFoundation.fleetConfiguration,
|
||||
// result.settingsService)
|
||||
// result.osNotificationService = os_notification_service.newService(statusFoundation.status.events)
|
||||
// result.keychainService = keychain_service.newService(statusFoundation.status.events)
|
||||
// result.ethService = eth_service.newService()
|
||||
m_accountsService = new Accounts::Service();
|
||||
// result.networkService = network_service.newService()
|
||||
// result.contactsService = contacts_service.newService(statusFoundation.status.events, statusFoundation.threadpool)
|
||||
// result.chatService = chat_service.newService(statusFoundation.status.events, result.contactsService)
|
||||
// result.communityService = community_service.newService(statusFoundation.status.events)
|
||||
// result.messageService = message_service.newService(statusFoundation.status.events, statusFoundation.threadpool)
|
||||
// result.activityCenterService = activity_center_service.newService(statusFoundation.status.events,
|
||||
// statusFoundation.threadpool, result.chatService)
|
||||
// result.tokenService = token_service.newService(statusFoundation.status.events, statusFoundation.threadpool,
|
||||
// result.settingsService)
|
||||
// result.collectibleService = collectible_service.newService(result.settingsService)
|
||||
// result.walletAccountService = wallet_account_service.newService(statusFoundation.status.events, result.settingsService,
|
||||
// result.accountsService, result.tokenService)
|
||||
// result.transactionService = transaction_service.newService(statusFoundation.status.events, statusFoundation.threadpool,
|
||||
// result.walletAccountService)
|
||||
// result.bookmarkService = bookmark_service.newService()
|
||||
// result.profileService = profile_service.newService()
|
||||
// result.stickersService = stickers_service.newService(
|
||||
// statusFoundation.status.events,
|
||||
// statusFoundation.threadpool,
|
||||
// result.ethService,
|
||||
// result.settingsService,
|
||||
// result.walletAccountService,
|
||||
// result.transactionService,
|
||||
// result.networkService,
|
||||
// result.chatService
|
||||
// )
|
||||
// result.aboutService = about_service.newService(statusFoundation.status.events, statusFoundation.threadpool,
|
||||
// result.settingsService)
|
||||
// result.dappPermissionsService = dapp_permissions_service.newService()
|
||||
// result.languageService = language_service.newService()
|
||||
// # result.mnemonicService = mnemonic_service.newService()
|
||||
// result.privacyService = privacy_service.newService(statusFoundation.status.events, result.settingsService,
|
||||
// result.accountsService)
|
||||
// result.providerService = provider_service.newService(result.dappPermissionsService, result.settingsService)
|
||||
// result.savedAddressService = saved_address_service.newService(statusFoundation.status.events)
|
||||
// result.devicesService = devices_service.newService(statusFoundation.status.events, result.settingsService)
|
||||
// result.mailserversService = mailservers_service.newService(statusFoundation.status.events, statusFoundation.marathon,
|
||||
// result.settingsService, result.nodeConfigurationService, statusFoundation.fleetConfiguration)
|
||||
// # Services
|
||||
// result.settingsService = settings_service.newService()
|
||||
// result.nodeConfigurationService = node_configuration_service.newService(statusFoundation.fleetConfiguration,
|
||||
// result.settingsService)
|
||||
// result.osNotificationService = os_notification_service.newService(statusFoundation.status.events)
|
||||
// result.keychainService = keychain_service.newService(statusFoundation.status.events)
|
||||
// result.ethService = eth_service.newService()
|
||||
m_accountsService = new Accounts::Service();
|
||||
m_walletServicePtr = std::make_shared<Wallets::Service>();
|
||||
// result.networkService = network_service.newService()
|
||||
// result.contactsService = contacts_service.newService(statusFoundation.status.events, statusFoundation.threadpool)
|
||||
// result.chatService = chat_service.newService(statusFoundation.status.events, result.contactsService)
|
||||
// result.communityService = community_service.newService(statusFoundation.status.events)
|
||||
// result.messageService = message_service.newService(statusFoundation.status.events, statusFoundation.threadpool)
|
||||
// result.activityCenterService = activity_center_service.newService(statusFoundation.status.events,
|
||||
// statusFoundation.threadpool, result.chatService)
|
||||
// result.tokenService = token_service.newService(statusFoundation.status.events, statusFoundation.threadpool,
|
||||
// result.settingsService)
|
||||
// result.collectibleService = collectible_service.newService(result.settingsService)
|
||||
// result.walletAccountService = wallet_account_service.newService(statusFoundation.status.events, result.settingsService,
|
||||
// result.accountsService, result.tokenService)
|
||||
// result.transactionService = transaction_service.newService(statusFoundation.status.events, statusFoundation.threadpool,
|
||||
// result.walletAccountService)
|
||||
// result.bookmarkService = bookmark_service.newService()
|
||||
// result.profileService = profile_service.newService()
|
||||
// result.stickersService = stickers_service.newService(
|
||||
// statusFoundation.status.events,
|
||||
// statusFoundation.threadpool,
|
||||
// result.ethService,
|
||||
// result.settingsService,
|
||||
// result.walletAccountService,
|
||||
// result.transactionService,
|
||||
// result.networkService,
|
||||
// result.chatService
|
||||
// )
|
||||
// result.aboutService = about_service.newService(statusFoundation.status.events, statusFoundation.threadpool,
|
||||
// result.settingsService)
|
||||
// result.dappPermissionsService = dapp_permissions_service.newService()
|
||||
// result.languageService = language_service.newService()
|
||||
// # result.mnemonicService = mnemonic_service.newService()
|
||||
// result.privacyService = privacy_service.newService(statusFoundation.status.events, result.settingsService,
|
||||
// result.accountsService)
|
||||
// result.providerService = provider_service.newService(result.dappPermissionsService, result.settingsService)
|
||||
// result.savedAddressService = saved_address_service.newService(statusFoundation.status.events)
|
||||
// result.devicesService = devices_service.newService(statusFoundation.status.events, result.settingsService)
|
||||
// result.mailserversService = mailservers_service.newService(statusFoundation.status.events, statusFoundation.marathon,
|
||||
// result.settingsService, result.nodeConfigurationService, statusFoundation.fleetConfiguration)
|
||||
|
||||
// # Modules
|
||||
m_startupModule = new Modules::Startup::Module(this, /*keychainService,*/ m_accountsService);
|
||||
// # Modules
|
||||
m_startupModule = new Modules::Startup::Module(this, /*keychainService,*/ m_accountsService);
|
||||
|
||||
m_mainModule = new Modules::Main::Module(this
|
||||
// statusFoundation.status.events,
|
||||
// result.keychainService,
|
||||
// result.accountsService,
|
||||
// result.chatService,
|
||||
// result.communityService,
|
||||
// result.messageService,
|
||||
// result.tokenService,
|
||||
// result.transactionService,
|
||||
// result.collectibleService,
|
||||
// result.walletAccountService,
|
||||
// result.bookmarkService,
|
||||
// result.profileService,
|
||||
// result.settingsService,
|
||||
// result.contactsService,
|
||||
// result.aboutService,
|
||||
// result.dappPermissionsService,
|
||||
// result.languageService,
|
||||
// # result.mnemonicService,
|
||||
// result.privacyService,
|
||||
// result.providerService,
|
||||
// result.stickersService,
|
||||
// result.activityCenterService,
|
||||
// result.savedAddressService,
|
||||
// result.nodeConfigurationService,
|
||||
// result.devicesService,
|
||||
// result.mailserversService
|
||||
);
|
||||
m_mainModulePtr = std::make_unique<Modules::Main::Module>(m_walletServicePtr
|
||||
// statusFoundation.status.events,
|
||||
// result.keychainService,
|
||||
// result.accountsService,
|
||||
// result.chatService,
|
||||
// result.communityService,
|
||||
// result.messageService,
|
||||
// result.tokenService,
|
||||
// result.transactionService,
|
||||
// result.collectibleService,
|
||||
// result.walletAccountService,
|
||||
// result.bookmarkService,
|
||||
// result.profileService,
|
||||
// result.settingsService,
|
||||
// result.contactsService,
|
||||
// result.aboutService,
|
||||
// result.dappPermissionsService,
|
||||
// result.languageService,
|
||||
// # result.mnemonicService,
|
||||
// result.privacyService,
|
||||
// result.providerService,
|
||||
// result.stickersService,
|
||||
// result.activityCenterService,
|
||||
// result.savedAddressService,
|
||||
// result.nodeConfigurationService,
|
||||
// result.devicesService,
|
||||
// result.mailserversService
|
||||
);
|
||||
|
||||
// # Do connections
|
||||
connect();
|
||||
// # Do connections
|
||||
connect();
|
||||
}
|
||||
|
||||
AppController::~AppController()
|
||||
{
|
||||
delete m_startupModule;
|
||||
delete m_mainModule;
|
||||
|
||||
delete m_accountsService;
|
||||
delete m_startupModule;
|
||||
delete m_accountsService;
|
||||
}
|
||||
|
||||
void AppController::connect()
|
||||
{
|
||||
// self.statusFoundation.status.events.once("nodeStopped") do(a: Args):
|
||||
// TODO: remove this once accounts are not tracked in the AccountsModel
|
||||
// self.statusFoundation.status.reset()
|
||||
// self.statusFoundation.status.events.once("nodeStopped") do(a: Args):
|
||||
// TODO: remove this once accounts are not tracked in the AccountsModel
|
||||
// self.statusFoundation.status.reset()
|
||||
QObject::connect(dynamic_cast<QObject*>(m_mainModulePtr.get()), SIGNAL(loaded()), this, SLOT(mainDidLoad()));
|
||||
}
|
||||
|
||||
void AppController::startupDidLoad()
|
||||
{
|
||||
// singletonInstance.engine.setRootContextProperty("localAppSettings", self.localAppSettingsVariant)
|
||||
// singletonInstance.engine.setRootContextProperty("localAccountSettings", self.localAccountSettingsVariant)
|
||||
// singletonInstance.engine.load(newQUrl("qrc:///main.qml"))
|
||||
// singletonInstance.engine.setRootContextProperty("localAppSettings", self.localAppSettingsVariant)
|
||||
// singletonInstance.engine.setRootContextProperty("localAccountSettings", self.localAccountSettingsVariant)
|
||||
// singletonInstance.engine.load(newQUrl("qrc:///main.qml"))
|
||||
|
||||
// We need to init a language service once qml is loaded
|
||||
// self.languageService.init()
|
||||
// We need to init a language service once qml is loaded
|
||||
// self.languageService.init()
|
||||
}
|
||||
|
||||
void AppController::mainDidLoad()
|
||||
{
|
||||
//self.statusFoundation.onLoggedIn()
|
||||
m_startupModule->moveToAppState();
|
||||
//self.statusFoundation.onLoggedIn()
|
||||
m_startupModule->moveToAppState();
|
||||
|
||||
//self.mainModule.checkForStoringPassword()
|
||||
//self.mainModule.checkForStoringPassword()
|
||||
}
|
||||
|
||||
void AppController::start()
|
||||
{
|
||||
// self.ethService.init()
|
||||
m_accountsService->init();
|
||||
// self.ethService.init()
|
||||
m_accountsService->init();
|
||||
|
||||
m_startupModule->load();
|
||||
m_startupModule->load();
|
||||
}
|
||||
|
||||
void AppController::load()
|
||||
{
|
||||
qWarning() << "TODO: init services and load main module";
|
||||
// self.settingsService.init()
|
||||
// self.nodeConfigurationService.init()
|
||||
// self.contactsService.init()
|
||||
// self.chatService.init()
|
||||
// self.messageService.init()
|
||||
// self.communityService.init()
|
||||
// self.bookmarkService.init()
|
||||
// self.tokenService.init()
|
||||
// self.dappPermissionsService.init()
|
||||
// self.providerService.init()
|
||||
// self.walletAccountService.init()
|
||||
// self.transactionService.init()
|
||||
// self.stickersService.init()
|
||||
// self.networkService.init()
|
||||
// self.activityCenterService.init()
|
||||
// self.savedAddressService.init()
|
||||
// self.aboutService.init()
|
||||
// self.devicesService.init()
|
||||
// self.mailserversService.init()
|
||||
qWarning() << "TODO: init services and load main module";
|
||||
m_walletServicePtr->init();
|
||||
// self.settingsService.init()
|
||||
// self.nodeConfigurationService.init()
|
||||
// self.contactsService.init()
|
||||
// self.chatService.init()
|
||||
// self.messageService.init()
|
||||
// self.communityService.init()
|
||||
// self.bookmarkService.init()
|
||||
// self.tokenService.init()
|
||||
// self.dappPermissionsService.init()
|
||||
// self.providerService.init()
|
||||
// self.walletAccountService.init()
|
||||
// self.transactionService.init()
|
||||
// self.stickersService.init()
|
||||
// self.networkService.init()
|
||||
// self.activityCenterService.init()
|
||||
// self.savedAddressService.init()
|
||||
// self.aboutService.init()
|
||||
// self.devicesService.init()
|
||||
// self.mailserversService.init()
|
||||
|
||||
// let pubKey = self.settingsService.getPublicKey()
|
||||
// singletonInstance.localAccountSensitiveSettings.setFileName(pubKey)
|
||||
// singletonInstance.engine.setRootContextProperty("localAccountSensitiveSettings", self.localAccountSensitiveSettingsVariant)
|
||||
// singletonInstance.engine.setRootContextProperty("globalUtils", self.globalUtilsVariant)
|
||||
// let pubKey = self.settingsService.getPublicKey()
|
||||
// singletonInstance.localAccountSensitiveSettings.setFileName(pubKey)
|
||||
// singletonInstance.engine.setRootContextProperty("localAccountSensitiveSettings", self.localAccountSensitiveSettingsVariant)
|
||||
// singletonInstance.engine.setRootContextProperty("globalUtils", self.globalUtilsVariant)
|
||||
|
||||
// # other global instances
|
||||
// self.buildAndRegisterLocalAccountSensitiveSettings()
|
||||
// self.buildAndRegisterUserProfile()
|
||||
// # other global instances
|
||||
// self.buildAndRegisterLocalAccountSensitiveSettings()
|
||||
// self.buildAndRegisterUserProfile()
|
||||
|
||||
// # load main module
|
||||
m_mainModule->load(
|
||||
// self.statusFoundation.status.events,
|
||||
// self.settingsService,
|
||||
// self.contactsService,
|
||||
// self.chatService,
|
||||
// self.communityService,
|
||||
// self.messageService
|
||||
);
|
||||
// # load main module
|
||||
m_mainModulePtr->load(
|
||||
// self.statusFoundation.status.events,
|
||||
// self.settingsService,
|
||||
// self.contactsService,
|
||||
// self.chatService,
|
||||
// self.communityService,
|
||||
// self.messageService
|
||||
);
|
||||
}
|
||||
|
||||
void AppController::userLoggedIn()
|
||||
{
|
||||
//self.statusFoundation.status.startMessenger()
|
||||
AppController::load();
|
||||
//self.statusFoundation.status.startMessenger()
|
||||
AppController::load();
|
||||
|
||||
// Once user is logged in and main module is loaded we need to check if it gets here importing mnemonic or not
|
||||
// and delete mnemonic in the first case.
|
||||
auto importedAccount = m_accountsService->getImportedAccount();
|
||||
if(importedAccount.isValid())
|
||||
{
|
||||
// self.privacyService.removeMnemonic();
|
||||
}
|
||||
// Once user is logged in and main module is loaded we need to check if it gets here importing mnemonic or not
|
||||
// and delete mnemonic in the first case.
|
||||
auto importedAccount = m_accountsService->getImportedAccount();
|
||||
if(importedAccount.isValid())
|
||||
{
|
||||
// self.privacyService.removeMnemonic();
|
||||
}
|
||||
}
|
||||
|
||||
void AppController::buildAndRegisterLocalAccountSensitiveSettings()
|
||||
{
|
||||
|
||||
// var pubKey = self.settingsService.getPublicKey()
|
||||
// singletonInstance.localAccountSensitiveSettings.setFileName(pubKey)
|
||||
// singletonInstance.engine.setRootContextProperty("localAccountSensitiveSettings", self.localAccountSensitiveSettingsVariant)
|
||||
// var pubKey = self.settingsService.getPublicKey()
|
||||
// singletonInstance.localAccountSensitiveSettings.setFileName(pubKey)
|
||||
// singletonInstance.engine.setRootContextProperty("localAccountSensitiveSettings", self.localAccountSensitiveSettingsVariant)
|
||||
}
|
||||
|
||||
void AppController::buildAndRegisterUserProfile()
|
||||
{
|
||||
// let pubKey = self.settingsService.getPublicKey()
|
||||
// let preferredName = self.settingsService.getPreferredName()
|
||||
// let ensUsernames = self.settingsService.getEnsUsernames()
|
||||
// let firstEnsName = if (ensUsernames.len > 0): ensUsernames[0] else: ""
|
||||
// let sendUserStatus = self.settingsService.getSendStatusUpdates()
|
||||
// // This is still not in use. Read a comment in UserProfile.
|
||||
// // let currentUserStatus = self.settingsService.getCurrentUserStatus()
|
||||
// let pubKey = self.settingsService.getPublicKey()
|
||||
// let preferredName = self.settingsService.getPreferredName()
|
||||
// let ensUsernames = self.settingsService.getEnsUsernames()
|
||||
// let firstEnsName = if (ensUsernames.len > 0): ensUsernames[0] else: ""
|
||||
// let sendUserStatus = self.settingsService.getSendStatusUpdates()
|
||||
// // This is still not in use. Read a comment in UserProfile.
|
||||
// // let currentUserStatus = self.settingsService.getCurrentUserStatus()
|
||||
|
||||
// let loggedInAccount = self.accountsService.getLoggedInAccount()
|
||||
// var thumbnail, large: string
|
||||
// for img in loggedInAccount.images:
|
||||
// if(img.imgType == "large"):
|
||||
// large = img.uri
|
||||
// elif(img.imgType == "thumbnail"):
|
||||
// thumbnail = img.uri
|
||||
// let loggedInAccount = self.accountsService.getLoggedInAccount()
|
||||
// var thumbnail, large: string
|
||||
// for img in loggedInAccount.images:
|
||||
// if(img.imgType == "large"):
|
||||
// large = img.uri
|
||||
// elif(img.imgType == "thumbnail"):
|
||||
// thumbnail = img.uri
|
||||
|
||||
// let meAsContact = self.contactsService.getContactById(pubKey)
|
||||
// let meAsContact = self.contactsService.getContactById(pubKey)
|
||||
|
||||
// singletonInstance.userProfile.setFixedData(loggedInAccount.name, loggedInAccount.keyUid, loggedInAccount.identicon,
|
||||
// pubKey)
|
||||
// singletonInstance.userProfile.setPreferredName(preferredName)
|
||||
// singletonInstance.userProfile.setEnsName(meAsContact.name)
|
||||
// singletonInstance.userProfile.setFirstEnsName(firstEnsName)
|
||||
// singletonInstance.userProfile.setThumbnailImage(thumbnail)
|
||||
// singletonInstance.userProfile.setLargeImage(large)
|
||||
// singletonInstance.userProfile.setUserStatus(sendUserStatus)
|
||||
// singletonInstance.userProfile.setFixedData(loggedInAccount.name, loggedInAccount.keyUid, loggedInAccount.identicon,
|
||||
// pubKey)
|
||||
// singletonInstance.userProfile.setPreferredName(preferredName)
|
||||
// singletonInstance.userProfile.setEnsName(meAsContact.name)
|
||||
// singletonInstance.userProfile.setFirstEnsName(firstEnsName)
|
||||
// singletonInstance.userProfile.setThumbnailImage(thumbnail)
|
||||
// singletonInstance.userProfile.setLargeImage(large)
|
||||
// singletonInstance.userProfile.setUserStatus(sendUserStatus)
|
||||
|
||||
// singletonInstance.engine.setRootContextProperty("userProfile", self.userProfileVariant)
|
||||
// singletonInstance.engine.setRootContextProperty("userProfile", self.userProfileVariant)
|
||||
}
|
||||
|
|
|
@ -1,40 +1,49 @@
|
|||
#pragma once
|
||||
#ifndef APP_CONTROLLER_H
|
||||
#define APP_CONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#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 "app_controller_delegate.h"
|
||||
#include "app_service.h"
|
||||
|
||||
class AppController : public AppControllerDelegate
|
||||
class AppController : public QObject, AppControllerDelegate
|
||||
{
|
||||
//statusFoundation: StatusFoundation
|
||||
Q_OBJECT
|
||||
//statusFoundation: StatusFoundation
|
||||
|
||||
// Global
|
||||
//localAppSettingsVariant: QVariant
|
||||
//localAccountSettingsVariant: QVariant
|
||||
//localAccountSensitiveSettingsVariant: QVariant
|
||||
//userProfileVariant: QVariant
|
||||
//globalUtilsVariant: QVariant
|
||||
// Global
|
||||
//localAppSettingsVariant: QVariant
|
||||
//localAccountSettingsVariant: QVariant
|
||||
//localAccountSensitiveSettingsVariant: QVariant
|
||||
//userProfileVariant: QVariant
|
||||
//globalUtilsVariant: QVariant
|
||||
|
||||
// Services
|
||||
Accounts::Service* m_accountsService;
|
||||
// Services
|
||||
Accounts::Service* m_accountsService;
|
||||
std::shared_ptr<Wallets::Service> m_walletServicePtr;
|
||||
|
||||
// Modules
|
||||
Modules::Startup::ModuleAccessInterface* m_startupModule;
|
||||
Modules::Main::ModuleAccessInterface* m_mainModule;
|
||||
// Modules
|
||||
// To-Do make this a shared pointer and remove circular dependency.
|
||||
Modules::Startup::ModuleAccessInterface* m_startupModule;
|
||||
std::unique_ptr<Modules::Main::IModuleAccess> m_mainModulePtr;
|
||||
|
||||
public:
|
||||
AppController();
|
||||
~AppController();
|
||||
void start();
|
||||
|
||||
AppController();
|
||||
~AppController();
|
||||
void start();
|
||||
public slots:
|
||||
void mainDidLoad();
|
||||
private:
|
||||
void connect();
|
||||
void startupDidLoad() override;
|
||||
void mainDidLoad();
|
||||
void load();
|
||||
void userLoggedIn() override;
|
||||
void buildAndRegisterLocalAccountSensitiveSettings();
|
||||
void buildAndRegisterUserProfile();
|
||||
void connect();
|
||||
void startupDidLoad() override;
|
||||
void load();
|
||||
void userLoggedIn() override;
|
||||
void buildAndRegisterLocalAccountSensitiveSettings();
|
||||
void buildAndRegisterUserProfile();
|
||||
};
|
||||
|
||||
#endif // APP_CONTROLLER_H
|
||||
|
|
|
@ -5,7 +5,5 @@ class AppControllerDelegate
|
|||
public:
|
||||
virtual void startupDidLoad() = 0;
|
||||
|
||||
virtual void mainDidLoad() = 0;
|
||||
|
||||
virtual void userLoggedIn() = 0;
|
||||
};
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
#include "controller.h"
|
||||
#include "accounts/service_interface.h"
|
||||
#include "interfaces/module_controller_delegate_interface.h"
|
||||
#include <QDebug>
|
||||
|
||||
#include "controller.h"
|
||||
|
||||
namespace Modules
|
||||
{
|
||||
namespace Main
|
||||
{
|
||||
Controller::Controller(ModuleControllerDelegateInterface* delegate, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_delegate(delegate)
|
||||
Controller::Controller(QObject* parent)
|
||||
: QObject(parent)
|
||||
{ }
|
||||
|
||||
void Controller::init() { }
|
||||
|
||||
} // namespace Main
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -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 "interfaces/controller_interface.h"
|
||||
#include "signals.h"
|
||||
|
||||
namespace Modules
|
||||
{
|
||||
namespace Main
|
||||
{
|
||||
|
||||
class Controller : public QObject, ControllerInterface
|
||||
class Controller : public QObject, IController
|
||||
{
|
||||
public:
|
||||
Controller(ModuleControllerDelegateInterface* delegate, QObject* parent = nullptr);
|
||||
void init() override;
|
||||
explicit Controller(QObject* parent = nullptr);
|
||||
~Controller() = default;
|
||||
|
||||
private:
|
||||
ModuleControllerDelegateInterface* m_delegate;
|
||||
void init() override;
|
||||
};
|
||||
|
||||
} // namespace Main
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
||||
#endif // CONTROLLER_H
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -1,12 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
namespace Modules
|
||||
{
|
||||
namespace Main
|
||||
{
|
||||
class ModuleControllerDelegateInterface
|
||||
{
|
||||
public:
|
||||
};
|
||||
}; // namespace Main
|
||||
}; // namespace Modules
|
|
@ -1,13 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
namespace Modules
|
||||
{
|
||||
namespace Main
|
||||
{
|
||||
class ModuleViewDelegateInterface
|
||||
{
|
||||
public:
|
||||
virtual void viewDidLoad() = 0;
|
||||
};
|
||||
}; // namespace Main
|
||||
}; // namespace Modules
|
|
@ -1,45 +1,65 @@
|
|||
#include "module.h"
|
||||
#include "controller.h"
|
||||
#include "singleton.h"
|
||||
#include "view.h"
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
#include <QQmlContext>
|
||||
#include <QVariant>
|
||||
|
||||
#include "module.h"
|
||||
#include "singleton.h"
|
||||
#include "modules/main/wallet/module.h"
|
||||
|
||||
namespace Modules
|
||||
{
|
||||
namespace Main
|
||||
{
|
||||
Module::Module(AppControllerDelegate* delegate)
|
||||
: m_delegate(delegate)
|
||||
Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService)
|
||||
{
|
||||
m_controller = new Controller(this);
|
||||
m_view = new View(this);
|
||||
m_controllerPtr = std::make_unique<Controller>();
|
||||
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;
|
||||
delete m_view;
|
||||
QObject::connect(m_viewPtr.get(), &View::viewLoaded, this, &Module::viewDidLoad);
|
||||
QObject::connect(dynamic_cast<QObject*>(m_walletModulePtr.get()), SIGNAL(loaded()), this, SLOT(walletDidLoad()));
|
||||
}
|
||||
|
||||
void Module::load()
|
||||
{
|
||||
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("mainModule", m_view);
|
||||
m_controller->init();
|
||||
m_view->load();
|
||||
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("mainModule", m_viewPtr.get());
|
||||
m_controllerPtr->init();
|
||||
m_viewPtr->load();
|
||||
|
||||
m_walletModulePtr->load();
|
||||
}
|
||||
|
||||
void Module::checkIfModuleDidLoad()
|
||||
{
|
||||
m_delegate->mainDidLoad();
|
||||
if(!m_walletModulePtr->isLoaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_moduleLoaded = true;
|
||||
emit loaded();
|
||||
}
|
||||
|
||||
void Module::viewDidLoad()
|
||||
{
|
||||
Module::checkIfModuleDidLoad();
|
||||
Module::checkIfModuleDidLoad();
|
||||
}
|
||||
|
||||
void Module::walletDidLoad()
|
||||
{
|
||||
Module::checkIfModuleDidLoad();
|
||||
}
|
||||
|
||||
bool Module::isLoaded()
|
||||
{
|
||||
return m_moduleLoaded;
|
||||
}
|
||||
|
||||
} // namespace Main
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -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 "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 <QVariant>
|
||||
|
||||
namespace Modules
|
||||
{
|
||||
namespace Main
|
||||
{
|
||||
class Module : public ModuleAccessInterface, ModuleControllerDelegateInterface, ModuleViewDelegateInterface
|
||||
class Module : public QObject, virtual public IModuleAccess
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
AppControllerDelegate* m_delegate;
|
||||
View* m_view;
|
||||
Controller* m_controller;
|
||||
bool m_moduleLoaded;
|
||||
|
||||
std::unique_ptr<View> m_viewPtr;
|
||||
std::unique_ptr<Controller> m_controllerPtr;
|
||||
std::unique_ptr<Modules::Main::Wallet::IWalletModuleAccess> m_walletModulePtr;
|
||||
|
||||
void connect();
|
||||
|
||||
public:
|
||||
Module(AppControllerDelegate* delegate);
|
||||
~Module();
|
||||
void load() override;
|
||||
void checkIfModuleDidLoad();
|
||||
void viewDidLoad() override;
|
||||
explicit Module(std::shared_ptr<Wallets::ServiceInterface> walletService);
|
||||
~Module() = default;
|
||||
|
||||
void load() override;
|
||||
bool isLoaded() override;
|
||||
void checkIfModuleDidLoad();
|
||||
|
||||
public slots:
|
||||
void viewDidLoad();
|
||||
void walletDidLoad();
|
||||
|
||||
signals:
|
||||
void loaded() override;
|
||||
};
|
||||
}; // namespace Main
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
||||
#endif // MODULE_H
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
namespace Modules
|
||||
{
|
||||
namespace Main
|
||||
{
|
||||
class ModuleAccessInterface
|
||||
{
|
||||
public:
|
||||
virtual void load() = 0;
|
||||
};
|
||||
}; // namespace Main
|
||||
}; // namespace Modules
|
|
@ -1,22 +1,19 @@
|
|||
#include "view.h"
|
||||
#include "interfaces/module_view_delegate_interface.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace Modules
|
||||
{
|
||||
namespace Main
|
||||
{
|
||||
|
||||
View::View(ModuleViewDelegateInterface* delegate, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_delegate(delegate)
|
||||
View::View(QObject* parent)
|
||||
: QObject(parent)
|
||||
{ }
|
||||
|
||||
void View::load()
|
||||
{
|
||||
// In some point, here, we will setup some exposed main module related things.
|
||||
m_delegate->viewDidLoad();
|
||||
// At some point, here, we will setup some exposed main module related things.
|
||||
emit viewLoaded();
|
||||
}
|
||||
|
||||
} // namespace Main
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#ifndef VIEW_H
|
||||
#define VIEW_H
|
||||
|
||||
#include "interfaces/module_view_delegate_interface.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace Modules
|
||||
|
@ -10,14 +10,18 @@ namespace Main
|
|||
|
||||
class View : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr);
|
||||
void load();
|
||||
explicit View(QObject* parent = nullptr);
|
||||
~View() = default;
|
||||
|
||||
private:
|
||||
ModuleViewDelegateInterface* m_delegate;
|
||||
void load();
|
||||
signals:
|
||||
void viewLoaded();
|
||||
};
|
||||
} // namespace Main
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
||||
#endif // VIEW_H
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -3,6 +3,8 @@ add_library(app_service
|
|||
service/accounts/dto/account.cpp
|
||||
service/accounts/dto/generated_account.cpp
|
||||
service/accounts/service.cpp
|
||||
service/wallet_accounts/dto/wallet_account.cpp
|
||||
service/wallet_accounts/service.cpp
|
||||
)
|
||||
|
||||
target_include_directories(app_service
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -2,6 +2,7 @@ add_library(backend
|
|||
accounts.cpp
|
||||
types.cpp
|
||||
utils.cpp
|
||||
wallet_accounts.cpp
|
||||
)
|
||||
|
||||
target_include_directories(backend
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue