From 42da8a24083ab5ddbd7b73d5b94fc8a0e23d39be Mon Sep 17 00:00:00 2001 From: Khushboo Mehta Date: Mon, 14 Feb 2022 15:38:41 +0100 Subject: [PATCH] feat(@desktop/wallet): move accounts to cpp created skeleton for wallet_section added getAccounts api fixes #4750 --- src-cpp/app/CMakeLists.txt | 8 + src-cpp/app/boot/app_controller.cpp | 351 +++++++++--------- src-cpp/app/boot/app_controller.h | 61 +-- src-cpp/app/boot/app_controller_delegate.h | 2 - src-cpp/app/modules/main/controller.cpp | 12 +- src-cpp/app/modules/main/controller.h | 23 +- .../app/modules/main/controller_interface.h | 16 - .../main/interfaces/controller_interface.h | 17 + .../main/interfaces/module_access_interface.h | 23 ++ .../module_controller_delegate_interface.h | 12 - .../module_view_delegate_interface.h | 13 - src-cpp/app/modules/main/module.cpp | 58 ++- src-cpp/app/modules/main/module.h | 52 ++- .../modules/main/module_access_interface.h | 13 - src-cpp/app/modules/main/view.cpp | 13 +- src-cpp/app/modules/main/view.h | 20 +- .../main/wallet/accounts/controller.cpp | 34 ++ .../modules/main/wallet/accounts/controller.h | 39 ++ .../interfaces/controller_interface.h | 26 ++ .../interfaces/module_access_interface.h | 19 + .../app/modules/main/wallet/accounts/item.cpp | 71 ++++ .../app/modules/main/wallet/accounts/item.h | 46 +++ .../modules/main/wallet/accounts/model.cpp | 77 ++++ .../app/modules/main/wallet/accounts/model.h | 55 +++ .../modules/main/wallet/accounts/module.cpp | 72 ++++ .../app/modules/main/wallet/accounts/module.h | 48 +++ .../app/modules/main/wallet/accounts/view.cpp | 36 ++ .../app/modules/main/wallet/accounts/view.h | 44 +++ .../app/modules/main/wallet/controller.cpp | 23 ++ src-cpp/app/modules/main/wallet/controller.h | 32 ++ .../wallet/interfaces/controller_interface.h | 21 ++ .../interfaces/module_access_interface.h | 19 + src-cpp/app/modules/main/wallet/module.cpp | 67 ++++ src-cpp/app/modules/main/wallet/module.h | 47 +++ src-cpp/app/modules/main/wallet/view.cpp | 23 ++ src-cpp/app/modules/main/wallet/view.h | 31 ++ src-cpp/app_service/CMakeLists.txt | 2 + .../include/wallet_accounts/service.h | 29 ++ .../wallet_accounts/service_interface.h | 22 ++ .../include/wallet_accounts/wallet_account.h | 32 ++ .../include/wallet_accounts/wallet_token.h | 26 ++ .../wallet_accounts/dto/wallet_account.cpp | 20 + .../service/wallet_accounts/service.cpp | 44 +++ src-cpp/backend/CMakeLists.txt | 1 + .../backend/include/backend/wallet_accounts.h | 19 + src-cpp/backend/wallet_accounts.cpp | 25 ++ 46 files changed, 1417 insertions(+), 327 deletions(-) delete mode 100644 src-cpp/app/modules/main/controller_interface.h create mode 100644 src-cpp/app/modules/main/interfaces/controller_interface.h create mode 100644 src-cpp/app/modules/main/interfaces/module_access_interface.h delete mode 100644 src-cpp/app/modules/main/interfaces/module_controller_delegate_interface.h delete mode 100644 src-cpp/app/modules/main/interfaces/module_view_delegate_interface.h delete mode 100644 src-cpp/app/modules/main/module_access_interface.h create mode 100644 src-cpp/app/modules/main/wallet/accounts/controller.cpp create mode 100644 src-cpp/app/modules/main/wallet/accounts/controller.h create mode 100644 src-cpp/app/modules/main/wallet/accounts/interfaces/controller_interface.h create mode 100644 src-cpp/app/modules/main/wallet/accounts/interfaces/module_access_interface.h create mode 100644 src-cpp/app/modules/main/wallet/accounts/item.cpp create mode 100644 src-cpp/app/modules/main/wallet/accounts/item.h create mode 100644 src-cpp/app/modules/main/wallet/accounts/model.cpp create mode 100644 src-cpp/app/modules/main/wallet/accounts/model.h create mode 100644 src-cpp/app/modules/main/wallet/accounts/module.cpp create mode 100644 src-cpp/app/modules/main/wallet/accounts/module.h create mode 100644 src-cpp/app/modules/main/wallet/accounts/view.cpp create mode 100644 src-cpp/app/modules/main/wallet/accounts/view.h create mode 100644 src-cpp/app/modules/main/wallet/controller.cpp create mode 100644 src-cpp/app/modules/main/wallet/controller.h create mode 100644 src-cpp/app/modules/main/wallet/interfaces/controller_interface.h create mode 100644 src-cpp/app/modules/main/wallet/interfaces/module_access_interface.h create mode 100644 src-cpp/app/modules/main/wallet/module.cpp create mode 100644 src-cpp/app/modules/main/wallet/module.h create mode 100644 src-cpp/app/modules/main/wallet/view.cpp create mode 100644 src-cpp/app/modules/main/wallet/view.h create mode 100644 src-cpp/app_service/include/wallet_accounts/service.h create mode 100644 src-cpp/app_service/include/wallet_accounts/service_interface.h create mode 100644 src-cpp/app_service/include/wallet_accounts/wallet_account.h create mode 100644 src-cpp/app_service/include/wallet_accounts/wallet_token.h create mode 100644 src-cpp/app_service/service/wallet_accounts/dto/wallet_account.cpp create mode 100644 src-cpp/app_service/service/wallet_accounts/service.cpp create mode 100644 src-cpp/backend/include/backend/wallet_accounts.h create mode 100644 src-cpp/backend/wallet_accounts.cpp diff --git a/src-cpp/app/CMakeLists.txt b/src-cpp/app/CMakeLists.txt index 74977c0c98..eb4baab915 100644 --- a/src-cpp/app/CMakeLists.txt +++ b/src-cpp/app/CMakeLists.txt @@ -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 diff --git a/src-cpp/app/boot/app_controller.cpp b/src-cpp/app/boot/app_controller.cpp index 2c951b4b6b..4c3793fc2c 100644 --- a/src-cpp/app/boot/app_controller.cpp +++ b/src-cpp/app/boot/app_controller.cpp @@ -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(); + // 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(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(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) } diff --git a/src-cpp/app/boot/app_controller.h b/src-cpp/app/boot/app_controller.h index 56f0115e67..7d9317c138 100644 --- a/src-cpp/app/boot/app_controller.h +++ b/src-cpp/app/boot/app_controller.h @@ -1,40 +1,49 @@ -#pragma once +#ifndef APP_CONTROLLER_H +#define APP_CONTROLLER_H + +#include #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 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 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 diff --git a/src-cpp/app/boot/app_controller_delegate.h b/src-cpp/app/boot/app_controller_delegate.h index ccb849f2f2..2aee0fa826 100644 --- a/src-cpp/app/boot/app_controller_delegate.h +++ b/src-cpp/app/boot/app_controller_delegate.h @@ -5,7 +5,5 @@ class AppControllerDelegate public: virtual void startupDidLoad() = 0; - virtual void mainDidLoad() = 0; - virtual void userLoggedIn() = 0; }; diff --git a/src-cpp/app/modules/main/controller.cpp b/src-cpp/app/modules/main/controller.cpp index 91d27ef003..480c18e1b1 100644 --- a/src-cpp/app/modules/main/controller.cpp +++ b/src-cpp/app/modules/main/controller.cpp @@ -1,18 +1,16 @@ -#include "controller.h" -#include "accounts/service_interface.h" -#include "interfaces/module_controller_delegate_interface.h" #include +#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 \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/main/controller.h b/src-cpp/app/modules/main/controller.h index 7289b493d8..c681453817 100644 --- a/src-cpp/app/modules/main/controller.h +++ b/src-cpp/app/modules/main/controller.h @@ -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 +#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 \ No newline at end of file +} // namespace Modules + +#endif // CONTROLLER_H + diff --git a/src-cpp/app/modules/main/controller_interface.h b/src-cpp/app/modules/main/controller_interface.h deleted file mode 100644 index 1a1d128120..0000000000 --- a/src-cpp/app/modules/main/controller_interface.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src-cpp/app/modules/main/interfaces/controller_interface.h b/src-cpp/app/modules/main/interfaces/controller_interface.h new file mode 100644 index 0000000000..622e55c31d --- /dev/null +++ b/src-cpp/app/modules/main/interfaces/controller_interface.h @@ -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 diff --git a/src-cpp/app/modules/main/interfaces/module_access_interface.h b/src-cpp/app/modules/main/interfaces/module_access_interface.h new file mode 100644 index 0000000000..a7c0f0e8fd --- /dev/null +++ b/src-cpp/app/modules/main/interfaces/module_access_interface.h @@ -0,0 +1,23 @@ +#ifndef IMODULEACCESS_H +#define IMODULEACCESS_H + +#include + +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 diff --git a/src-cpp/app/modules/main/interfaces/module_controller_delegate_interface.h b/src-cpp/app/modules/main/interfaces/module_controller_delegate_interface.h deleted file mode 100644 index 5c87094ae7..0000000000 --- a/src-cpp/app/modules/main/interfaces/module_controller_delegate_interface.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -namespace Modules -{ -namespace Main -{ -class ModuleControllerDelegateInterface -{ -public: -}; -}; // namespace Main -}; // namespace Modules \ No newline at end of file diff --git a/src-cpp/app/modules/main/interfaces/module_view_delegate_interface.h b/src-cpp/app/modules/main/interfaces/module_view_delegate_interface.h deleted file mode 100644 index 110ba6fb77..0000000000 --- a/src-cpp/app/modules/main/interfaces/module_view_delegate_interface.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace Modules -{ -namespace Main -{ -class ModuleViewDelegateInterface -{ -public: - virtual void viewDidLoad() = 0; -}; -}; // namespace Main -}; // namespace Modules \ No newline at end of file diff --git a/src-cpp/app/modules/main/module.cpp b/src-cpp/app/modules/main/module.cpp index 0017d414d1..22178bb81a 100644 --- a/src-cpp/app/modules/main/module.cpp +++ b/src-cpp/app/modules/main/module.cpp @@ -1,45 +1,65 @@ -#include "module.h" -#include "controller.h" -#include "singleton.h" -#include "view.h" #include -#include #include -#include + +#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 walletsService) { - m_controller = new Controller(this); - m_view = new View(this); + m_controllerPtr = std::make_unique(); + m_viewPtr = std::make_unique(); + + // Submodules + m_walletModulePtr = std::make_unique(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(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 \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/main/module.h b/src-cpp/app/modules/main/module.h index 6169659baa..492eac3f6c 100644 --- a/src-cpp/app/modules/main/module.h +++ b/src-cpp/app/modules/main/module.h @@ -1,32 +1,48 @@ -#pragma once +#ifndef MODULE_H +#define MODULE_H + +#include +#include + +#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 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 m_viewPtr; + std::unique_ptr m_controllerPtr; + std::unique_ptr m_walletModulePtr; + + void connect(); public: - Module(AppControllerDelegate* delegate); - ~Module(); - void load() override; - void checkIfModuleDidLoad(); - void viewDidLoad() override; + explicit Module(std::shared_ptr 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 \ No newline at end of file +}; // namespace Modules + +#endif // MODULE_H diff --git a/src-cpp/app/modules/main/module_access_interface.h b/src-cpp/app/modules/main/module_access_interface.h deleted file mode 100644 index e9202cb751..0000000000 --- a/src-cpp/app/modules/main/module_access_interface.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace Modules -{ -namespace Main -{ -class ModuleAccessInterface -{ -public: - virtual void load() = 0; -}; -}; // namespace Main -}; // namespace Modules diff --git a/src-cpp/app/modules/main/view.cpp b/src-cpp/app/modules/main/view.cpp index b31833dd9b..889c3d046a 100644 --- a/src-cpp/app/modules/main/view.cpp +++ b/src-cpp/app/modules/main/view.cpp @@ -1,22 +1,19 @@ #include "view.h" -#include "interfaces/module_view_delegate_interface.h" -#include 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 \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/main/view.h b/src-cpp/app/modules/main/view.h index 93cced9695..2fe87646f6 100644 --- a/src-cpp/app/modules/main/view.h +++ b/src-cpp/app/modules/main/view.h @@ -1,6 +1,6 @@ -#pragma once +#ifndef VIEW_H +#define VIEW_H -#include "interfaces/module_view_delegate_interface.h" #include 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 \ No newline at end of file +} // namespace Modules + +#endif // VIEW_H + diff --git a/src-cpp/app/modules/main/wallet/accounts/controller.cpp b/src-cpp/app/modules/main/wallet/accounts/controller.cpp new file mode 100644 index 0000000000..f8d1ece73d --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/controller.cpp @@ -0,0 +1,34 @@ +#include + +#include "controller.h" + +namespace Modules +{ +namespace Main +{ +namespace Wallet +{ +namespace Accounts +{ +Controller::Controller(std::shared_ptr walletService, + QObject* parent) + : m_walletServicePtr(walletService), + QObject(parent) +{ } + +void Controller::init() +{ +} + +QList Controller::getWalletAccounts() +{ + QList wallet_accounts; + if(nullptr != m_walletServicePtr) + wallet_accounts = m_walletServicePtr->getWalletAccounts(); + + return wallet_accounts; +} +} // namespace Accounts +} // namespace Wallet +} // namespace Main +} // namespace Modules diff --git a/src-cpp/app/modules/main/wallet/accounts/controller.h b/src-cpp/app/modules/main/wallet/accounts/controller.h new file mode 100644 index 0000000000..81bdb36f4b --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/controller.h @@ -0,0 +1,39 @@ +#ifndef WALLET_ACCOUNT_CONTROLLER_H +#define WALLET_ACCOUNT_CONTROLLER_H + +#include + +#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 walletService, QObject* parent = nullptr); + ~Controller() = default; + + void init() override; + + QList getWalletAccounts(); + +private: + std::shared_ptr m_walletServicePtr; +}; +} // namespace Accounts +} // namespace Wallet +} // namespace Main +} // namespace Modules + +#endif // WALLET_ACCOUNT_CONTROLLER_H diff --git a/src-cpp/app/modules/main/wallet/accounts/interfaces/controller_interface.h b/src-cpp/app/modules/main/wallet/accounts/interfaces/controller_interface.h new file mode 100644 index 0000000000..919380af85 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/interfaces/controller_interface.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 diff --git a/src-cpp/app/modules/main/wallet/accounts/interfaces/module_access_interface.h b/src-cpp/app/modules/main/wallet/accounts/interfaces/module_access_interface.h new file mode 100644 index 0000000000..b7f4e571c9 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/interfaces/module_access_interface.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 diff --git a/src-cpp/app/modules/main/wallet/accounts/item.cpp b/src-cpp/app/modules/main/wallet/accounts/item.cpp new file mode 100644 index 0000000000..1dc29fae21 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/item.cpp @@ -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 diff --git a/src-cpp/app/modules/main/wallet/accounts/item.h b/src-cpp/app/modules/main/wallet/accounts/item.h new file mode 100644 index 0000000000..a7c0a006ff --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/item.h @@ -0,0 +1,46 @@ +#ifndef WALLET_ACCOUNT_ITEM_H +#define WALLET_ACCOUNT_ITEM_H + +#include + +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 diff --git a/src-cpp/app/modules/main/wallet/accounts/model.cpp b/src-cpp/app/modules/main/wallet/accounts/model.cpp new file mode 100644 index 0000000000..30ab1040ad --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/model.cpp @@ -0,0 +1,77 @@ +#include "model.h" + +namespace Modules +{ +namespace Main +{ +namespace Wallet +{ +namespace Accounts +{ +Model::Model(QObject* parent) + : QAbstractListModel(parent) +{ } + +QHash Model::roleNames() const +{ + QHash 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 &items) +{ + beginResetModel(); + m_items = items; + endResetModel(); +} + +} // namespace Accounts +} // namespace Wallet +} // namespace Main +} // namespace Modules diff --git a/src-cpp/app/modules/main/wallet/accounts/model.h b/src-cpp/app/modules/main/wallet/accounts/model.h new file mode 100644 index 0000000000..17c2127b6b --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/model.h @@ -0,0 +1,55 @@ +#ifndef WALLET_ACCOUNT_MODEL_H +#define WALLET_ACCOUNT_MODEL_H + +#include +#include +#include + +#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 roleNames() const; + virtual int rowCount(const QModelIndex&) const; + virtual QVariant data(const QModelIndex& index, int role) const; + void setItems(QVector &items); + +private: + QVector m_items; +}; + +} // namespace Accounts +} // namespace Wallet +} // namespace Main +} // namespace Modules + +#endif // WALLET_ACCOUNT_MODEL_H diff --git a/src-cpp/app/modules/main/wallet/accounts/module.cpp b/src-cpp/app/modules/main/wallet/accounts/module.cpp new file mode 100644 index 0000000000..9434b251e1 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/module.cpp @@ -0,0 +1,72 @@ +#include +#include + +#include "module.h" +#include "singleton.h" + +namespace Modules +{ +namespace Main +{ +namespace Wallet +{ +namespace Accounts +{ +Module::Module(std::shared_ptr walletsService) +{ + m_controllerPtr = std::make_unique(walletsService); + m_viewPtr = std::make_unique(); + + 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 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 diff --git a/src-cpp/app/modules/main/wallet/accounts/module.h b/src-cpp/app/modules/main/wallet/accounts/module.h new file mode 100644 index 0000000000..4ad261e93b --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/module.h @@ -0,0 +1,48 @@ +#ifndef WALLET_ACCOUNT_MODULE_H +#define WALLET_ACCOUNT_MODULE_H + +#include + +#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 m_viewPtr; + std::unique_ptr m_controllerPtr; + + bool m_moduleLoaded; + + void connect(); + void refreshWalletAccounts(); +public: + explicit Module(std::shared_ptr 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 diff --git a/src-cpp/app/modules/main/wallet/accounts/view.cpp b/src-cpp/app/modules/main/wallet/accounts/view.cpp new file mode 100644 index 0000000000..b6e6ebc27f --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/view.cpp @@ -0,0 +1,36 @@ +#include + +#include "view.h" + +namespace Modules +{ +namespace Main +{ +namespace Wallet +{ +namespace Accounts +{ +View::View(QObject* parent) + : QObject(parent) +{ + m_modelPtr = std::make_shared(); +} + +void View::load() +{ + emit viewLoaded(); +} + +Model* View::getModel() +{ + return m_modelPtr.get(); +} + +void View::setModelItems(QVector &accounts) { + m_modelPtr->setItems(accounts); + modelChanged(); +} +} // namespace Accounts +} // namespace Wallet +} // namespace Main +} // namespace Modules diff --git a/src-cpp/app/modules/main/wallet/accounts/view.h b/src-cpp/app/modules/main/wallet/accounts/view.h new file mode 100644 index 0000000000..faefc134fa --- /dev/null +++ b/src-cpp/app/modules/main/wallet/accounts/view.h @@ -0,0 +1,44 @@ +#ifndef WALLET_ACCOUNT_VIEW_H +#define WALLET_ACCOUNT_VIEW_H + +#include +#include + +#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 &accounts); + +private: + std::shared_ptr m_modelPtr; + +public slots: + Model* getModel(); + +signals: + void viewLoaded(); + void modelChanged(); +}; +} // namespace Accounts +} // namespace Wallet +} // namespace Main +} // namespace Modules + +#endif // WALLET_ACCOUNT_VIEW_H diff --git a/src-cpp/app/modules/main/wallet/controller.cpp b/src-cpp/app/modules/main/wallet/controller.cpp new file mode 100644 index 0000000000..6f79677165 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/controller.cpp @@ -0,0 +1,23 @@ +#include + +#include "controller.h" + +namespace Modules +{ +namespace Main +{ +namespace Wallet +{ +Controller::Controller(std::shared_ptr walletService, + QObject* parent) + : m_walletService(walletService), + QObject(parent) +{ } + +void Controller::init() +{ +} + +} // namespace Onboarding +} // namespace Startup +} // namespace Modules diff --git a/src-cpp/app/modules/main/wallet/controller.h b/src-cpp/app/modules/main/wallet/controller.h new file mode 100644 index 0000000000..f0de4bc2c9 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/controller.h @@ -0,0 +1,32 @@ +#ifndef WALLET_CONTROLLER_H +#define WALLET_CONTROLLER_H + +#include + +#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 walletService, QObject* parent = nullptr); + ~Controller() = default; + void init() override; + +private: + std::shared_ptr m_walletService; +}; +} // namespace Wallet +} // namespace Main +} // namespace Modules + +#endif // WALLET_CONTROLLER_H diff --git a/src-cpp/app/modules/main/wallet/interfaces/controller_interface.h b/src-cpp/app/modules/main/wallet/interfaces/controller_interface.h new file mode 100644 index 0000000000..354e5418f2 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/interfaces/controller_interface.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 diff --git a/src-cpp/app/modules/main/wallet/interfaces/module_access_interface.h b/src-cpp/app/modules/main/wallet/interfaces/module_access_interface.h new file mode 100644 index 0000000000..cad21097f2 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/interfaces/module_access_interface.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 diff --git a/src-cpp/app/modules/main/wallet/module.cpp b/src-cpp/app/modules/main/wallet/module.cpp new file mode 100644 index 0000000000..f022080fd6 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/module.cpp @@ -0,0 +1,67 @@ +#include +#include + +#include "module.h" +#include "singleton.h" +#include "accounts/module.h" + +namespace Modules +{ +namespace Main +{ +namespace Wallet +{ +Module::Module(std::shared_ptr walletsService) +{ + m_controllerPtr = std::make_unique(walletsService); + m_viewPtr = std::make_unique(); + + // Sub-Modules + m_accountsModulePtr = std::make_unique(walletsService); + + m_moduleLoaded = false; + connect(); +} + +void Module::connect() +{ + QObject::connect(m_viewPtr.get(), SIGNAL(viewLoaded()), this, SLOT(viewDidLoad())); + QObject::connect(dynamic_cast(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 diff --git a/src-cpp/app/modules/main/wallet/module.h b/src-cpp/app/modules/main/wallet/module.h new file mode 100644 index 0000000000..a33b12dda7 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/module.h @@ -0,0 +1,47 @@ +#ifndef WALLET_MODULE_H +#define WALLET_MODULE_H + +#include + +#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 m_viewPtr; + std::unique_ptr m_controllerPtr; + std::unique_ptr m_accountsModulePtr; + + bool m_moduleLoaded; + + void connect(); +public: + explicit Module(std::shared_ptr 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 diff --git a/src-cpp/app/modules/main/wallet/view.cpp b/src-cpp/app/modules/main/wallet/view.cpp new file mode 100644 index 0000000000..c23f1b2b19 --- /dev/null +++ b/src-cpp/app/modules/main/wallet/view.cpp @@ -0,0 +1,23 @@ +#include + +#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 diff --git a/src-cpp/app/modules/main/wallet/view.h b/src-cpp/app/modules/main/wallet/view.h new file mode 100644 index 0000000000..146733bd4f --- /dev/null +++ b/src-cpp/app/modules/main/wallet/view.h @@ -0,0 +1,31 @@ +#ifndef WALLET_VIEW_H +#define WALLET_VIEW_H + +#include + +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 + diff --git a/src-cpp/app_service/CMakeLists.txt b/src-cpp/app_service/CMakeLists.txt index 5c8cef6616..261dbb4009 100644 --- a/src-cpp/app_service/CMakeLists.txt +++ b/src-cpp/app_service/CMakeLists.txt @@ -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 diff --git a/src-cpp/app_service/include/wallet_accounts/service.h b/src-cpp/app_service/include/wallet_accounts/service.h new file mode 100644 index 0000000000..1aea0b8a29 --- /dev/null +++ b/src-cpp/app_service/include/wallet_accounts/service.h @@ -0,0 +1,29 @@ +#ifndef WALLETACCOUNTSSERVICE_H +#define WALLETACCOUNTSSERVICE_H + +#include +#include + +#include "wallet_account.h" +#include "service_interface.h" + +namespace Wallets +{ + +class Service : public ServiceInterface +{ +private: + void fetchAccounts(); + + QMap m_walletAccounts; + +public: + Service(); + ~Service() = default; + + void init() override; + QList getWalletAccounts() override; +}; +} // namespace Wallets + +#endif // WALLETACCOUNTSERVICE_H diff --git a/src-cpp/app_service/include/wallet_accounts/service_interface.h b/src-cpp/app_service/include/wallet_accounts/service_interface.h new file mode 100644 index 0000000000..01eb8f7234 --- /dev/null +++ b/src-cpp/app_service/include/wallet_accounts/service_interface.h @@ -0,0 +1,22 @@ +#ifndef WALLETACCOUNTSSERVICEINTERFACE_H +#define WALLETACCOUNTSSERVICEINTERFACE_H + +#include +#include +#include + +#include "../app_service.h" +#include "wallet_account.h" + +namespace Wallets +{ + +class ServiceInterface : public AppService +{ +public: + virtual QList getWalletAccounts() = 0; +}; + +} // namespace Wallets + +#endif // WALLETACCOUNTSSERVICEINTERFACE_H diff --git a/src-cpp/app_service/include/wallet_accounts/wallet_account.h b/src-cpp/app_service/include/wallet_accounts/wallet_account.h new file mode 100644 index 0000000000..cd391f799b --- /dev/null +++ b/src-cpp/app_service/include/wallet_accounts/wallet_account.h @@ -0,0 +1,32 @@ +#ifndef WALLETACCOUNTDTO_H +#define WALLETACCOUNTDTO_H + +#include +#include +#include +#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 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 diff --git a/src-cpp/app_service/include/wallet_accounts/wallet_token.h b/src-cpp/app_service/include/wallet_accounts/wallet_token.h new file mode 100644 index 0000000000..9918e8a521 --- /dev/null +++ b/src-cpp/app_service/include/wallet_accounts/wallet_token.h @@ -0,0 +1,26 @@ +#ifndef WALLETTOKENDTO_H +#define WALLETTOKENDTO_H + +#include +#include +#include + +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 diff --git a/src-cpp/app_service/service/wallet_accounts/dto/wallet_account.cpp b/src-cpp/app_service/service/wallet_accounts/dto/wallet_account.cpp new file mode 100644 index 0000000000..4a38caccf8 --- /dev/null +++ b/src-cpp/app_service/service/wallet_accounts/dto/wallet_account.cpp @@ -0,0 +1,20 @@ +#include "wallet_accounts/wallet_account.h" +//#include "backend/accounts.h" +#include +#include +#include +#include + +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; +} diff --git a/src-cpp/app_service/service/wallet_accounts/service.cpp b/src-cpp/app_service/service/wallet_accounts/service.cpp new file mode 100644 index 0000000000..caa43f597a --- /dev/null +++ b/src-cpp/app_service/service/wallet_accounts/service.cpp @@ -0,0 +1,44 @@ +#include + +#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 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 Service::getWalletAccounts() +{ + return m_walletAccounts.values(); +} + +} // namespace Wallets diff --git a/src-cpp/backend/CMakeLists.txt b/src-cpp/backend/CMakeLists.txt index 75bb57781f..7655b4a9ab 100644 --- a/src-cpp/backend/CMakeLists.txt +++ b/src-cpp/backend/CMakeLists.txt @@ -2,6 +2,7 @@ add_library(backend accounts.cpp types.cpp utils.cpp + wallet_accounts.cpp ) target_include_directories(backend diff --git a/src-cpp/backend/include/backend/wallet_accounts.h b/src-cpp/backend/include/backend/wallet_accounts.h new file mode 100644 index 0000000000..df2e572ee3 --- /dev/null +++ b/src-cpp/backend/include/backend/wallet_accounts.h @@ -0,0 +1,19 @@ +#ifndef WALLETACCOUNT_BACKEND_H +#define WALLETACCOUNT_BACKEND_H + +#include + +#include "backend/types.h" + +namespace Backend +{ +namespace Wallet +{ +namespace Accounts +{ +Backend::RpcResponse getAccounts(); +} // namespace Accounts +} // namespace Wallet +} // namespace Backend + +#endif // WALLETACCOUNT_BACKEND_H diff --git a/src-cpp/backend/wallet_accounts.cpp b/src-cpp/backend/wallet_accounts.cpp new file mode 100644 index 0000000000..098df3c122 --- /dev/null +++ b/src-cpp/backend/wallet_accounts.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +#include "backend/wallet_accounts.h" +#include "backend/types.h" +#include "backend/utils.h" +#include "libstatus.h" + +namespace Backend +{ +namespace Wallet +{ +namespace Accounts +{ +RpcResponse getAccounts() +{ + QJsonObject inputJSON{{"jsonrpc", "2.0"}, {"method", "accounts_getAccounts"}, {"params", QJsonValue()}}; + auto result = CallPrivateRPC(Utils::jsonToStr(inputJSON).toUtf8().data()); + return RpcResponse(result, QJsonDocument::fromJson(result)["result"].toArray()); +} +} // namespace Accounts +} // namespace Wallet +} // namespace Backend +