From 6154a89cf6bf9f539204ad987decc1c372a95769 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Thu, 25 Nov 2021 14:43:50 +0100 Subject: [PATCH] refactor(general): modules' structure aligned There were a lot of modules with an empty concept which are useless that way, doesn't do the purpose. Also some modules were not informing parent module about their states even order of operation within module itself was missed. Now we have all those things aligned and this commit should stop propagating such concepts caused by copying a module. --- src/app/modules/main/app_search/module.nim | 3 +- .../main/browser_section/bookmark/module.nim | 15 ++--- .../main/browser_section/dapps/module.nim | 10 +-- .../main/browser_section/provider/module.nim | 5 +- src/app/modules/main/io_interface.nim | 2 +- src/app/modules/main/module.nim | 9 +++ .../module_app_search_delegate_interface.nim | 2 + ...module_chat_section_delegate_interface.nim | 3 + .../main/profile_section/about/controller.nim | 17 ++--- .../profile_section/about/io_interface.nim | 9 +-- .../main/profile_section/about/module.nim | 27 ++++---- .../main/profile_section/about/view.nim | 3 + .../profile_section/contacts/controller.nim | 32 ++++----- .../profile_section/contacts/io_interface.nim | 9 +-- .../main/profile_section/contacts/module.nim | 66 ++++++++++--------- .../main/profile_section/contacts/view.nim | 3 + .../main/profile_section/io_interface.nim | 19 ++++++ .../profile_section/language/controller.nim | 17 +++-- .../profile_section/language/io_interface.nim | 9 +-- .../main/profile_section/language/module.nim | 26 +++++--- .../main/profile_section/language/view.nim | 3 + .../profile_section/mnemonic/controller.nim | 22 ++++--- .../profile_section/mnemonic/io_interface.nim | 9 +-- .../main/profile_section/mnemonic/module.nim | 32 +++++---- .../main/profile_section/mnemonic/view.nim | 3 + .../modules/main/profile_section/module.nim | 49 ++++++++++++-- .../profile_section/privacy/controller.nim | 18 ++--- .../profile_section/privacy/io_interface.nim | 9 +-- .../main/profile_section/privacy/module.nim | 28 ++++---- .../main/profile_section/privacy/view.nim | 3 + .../profile_section/profile/controller.nim | 22 +++---- .../profile_section/profile/io_interface.nim | 12 ++-- .../main/profile_section/profile/module.nim | 37 ++++++----- .../main/profile_section/profile/view.nim | 3 + src/app/modules/main/profile_section/view.nim | 3 + .../modules/main/stickers/io_interface.nim | 4 ++ src/app/modules/main/stickers/module.nim | 6 +- src/app/modules/main/stickers/view.nim | 3 + .../account_tokens/controller.nim | 19 +++--- .../account_tokens/io_interface.nim | 9 +-- .../wallet_section/account_tokens/module.nim | 32 +++++---- .../wallet_section/account_tokens/view.nim | 3 + .../wallet_section/accounts/controller.nim | 29 ++++---- .../wallet_section/accounts/io_interface.nim | 9 +-- .../main/wallet_section/accounts/module.nim | 48 ++++++++------ .../main/wallet_section/accounts/view.nim | 3 + .../wallet_section/all_tokens/controller.nim | 22 +++---- .../all_tokens/io_interface.nim | 9 +-- .../main/wallet_section/all_tokens/module.nim | 44 +++++++------ .../main/wallet_section/all_tokens/view.nim | 3 + .../collectibles/collectible/controller.nim | 17 ++--- .../collectibles/collectible/io_interface.nim | 9 +-- .../collectibles/collectible/module.nim | 25 ++++--- .../collectibles/collectible/view.nim | 3 + .../collectibles/collectibles/controller.nim | 19 +++--- .../collectibles/io_interface.nim | 9 +-- .../collectibles/collectibles/module.nim | 33 ++++++---- .../collectibles/collectibles/view.nim | 3 + .../collectibles/collections/controller.nim | 19 +++--- .../collectibles/collections/io_interface.nim | 9 +-- .../collectibles/collections/module.nim | 31 +++++---- .../collectibles/collections/view.nim | 3 + .../collectibles/controller.nim | 19 +++--- .../collectibles/io_interface.nim | 13 ++-- .../wallet_section/collectibles/module.nim | 58 ++++++++++------ .../current_account/controller.nim | 21 +++--- .../current_account/io_interface.nim | 9 +-- .../wallet_section/current_account/module.nim | 32 +++++---- .../wallet_section/current_account/view.nim | 3 + .../main/wallet_section/io_interface.nim | 26 ++++++++ .../modules/main/wallet_section/module.nim | 58 +++++++++++++--- .../transactions/controller.nim | 26 ++++---- .../transactions/io_interface.nim | 9 +-- .../wallet_section/transactions/module.nim | 58 ++++++++-------- .../main/wallet_section/transactions/view.nim | 3 + src/app/modules/main/wallet_section/view.nim | 3 + 76 files changed, 810 insertions(+), 490 deletions(-) create mode 100644 src/app/modules/main/private_interfaces/module_app_search_delegate_interface.nim diff --git a/src/app/modules/main/app_search/module.nim b/src/app/modules/main/app_search/module.nim index f11f73fd33..a028843cf2 100644 --- a/src/app/modules/main/app_search/module.nim +++ b/src/app/modules/main/app_search/module.nim @@ -60,7 +60,8 @@ method isLoaded*(self: Module): bool = return self.moduleLoaded method viewDidLoad*(self: Module) = - self.delegate.chatSectionDidLoad() + self.moduleLoaded = true + self.delegate.appSearchDidLoad() method getModuleAsVariant*(self: Module): QVariant = return self.viewVariant diff --git a/src/app/modules/main/browser_section/bookmark/module.nim b/src/app/modules/main/browser_section/bookmark/module.nim index b028b5d361..8f533f9d56 100644 --- a/src/app/modules/main/browser_section/bookmark/module.nim +++ b/src/app/modules/main/browser_section/bookmark/module.nim @@ -33,23 +33,18 @@ method delete*(self: Module) = method load*(self: Module) = singletonInstance.engine.setRootContextProperty("bookmarkModule", self.viewVariant) self.view.load() - let bookmarks = self.controller.getBookmarks() - for b in bookmarks: - self.view.addItem(initItem(b.name, b.url, b.imageUrl)) method isLoaded*(self: Module): bool = return self.moduleLoaded -proc checkIfModuleDidLoad(self: Module) = +method viewDidLoad*(self: Module) = + let bookmarks = self.controller.getBookmarks() + for b in bookmarks: + self.view.addItem(initItem(b.name, b.url, b.imageUrl)) + self.moduleLoaded = true self.delegate.bookmarkDidLoad() -method providerDidLoad*(self: Module) = - self.checkIfModuleDidLoad() - -method viewDidLoad*(self: Module) = - self.checkIfModuleDidLoad() - method storeBookmark*(self: Module, url: string, name: string) = if url == "": self.view.addItem(initItem(name, url, "")) # These URLs are not stored but added direclty to the UI diff --git a/src/app/modules/main/browser_section/dapps/module.nim b/src/app/modules/main/browser_section/dapps/module.nim index ddd05419b9..02eaac1d05 100644 --- a/src/app/modules/main/browser_section/dapps/module.nim +++ b/src/app/modules/main/browser_section/dapps/module.nim @@ -46,21 +46,15 @@ method fetchPermissions(self: Module, dapp: string) = method load*(self: Module) = singletonInstance.engine.setRootContextProperty("dappPermissionsModule", self.viewVariant) self.view.load() - self.fetchDapps() method isLoaded*(self: Module): bool = return self.moduleLoaded -proc checkIfModuleDidLoad(self: Module) = +method viewDidLoad*(self: Module) = + self.fetchDapps() self.moduleLoaded = true self.delegate.dappsDidLoad() -method dappsDidLoad*(self: Module) = - self.checkIfModuleDidLoad() - -method viewDidLoad*(self: Module) = - self.checkIfModuleDidLoad() - method hasPermission*(self: Module, hostname: string, permission: string): bool = self.controller.hasPermission(hostname, permission.toPermission()) diff --git a/src/app/modules/main/browser_section/provider/module.nim b/src/app/modules/main/browser_section/provider/module.nim index 837b1af730..95aff1588e 100644 --- a/src/app/modules/main/browser_section/provider/module.nim +++ b/src/app/modules/main/browser_section/provider/module.nim @@ -48,13 +48,10 @@ method setDappsAddress*(self: Module, value: string) = method onDappAddressChanged*(self: Module, value: string) = self.view.dappsAddress = value -proc checkIfModuleDidLoad(self: Module) = +method viewDidLoad*(self: Module) = self.moduleLoaded = true self.delegate.providerDidLoad() -method viewDidLoad*(self: Module) = - self.checkIfModuleDidLoad() - method disconnect*(self: Module) = self.controller.disconnect() diff --git a/src/app/modules/main/io_interface.nim b/src/app/modules/main/io_interface.nim index 540f4bcb13..095a78f4df 100644 --- a/src/app/modules/main/io_interface.nim +++ b/src/app/modules/main/io_interface.nim @@ -10,7 +10,7 @@ include ./private_interfaces/module_controller_delegate_interface # Defines how submodules of this module communicate with this module include ./private_interfaces/module_chat_section_delegate_interface -include ./private_interfaces/module_community_section_delegate_interface +include ./private_interfaces/module_app_search_delegate_interface include ./private_interfaces/module_browser_section_delegate_interface # This way (using concepts) is used only for the modules managed by AppController diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index df08c3451c..b729c3985a 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -247,6 +247,9 @@ proc checkIfModuleDidLoad [T](self: Module[T]) = if(not self.stickersModule.isLoaded()): return + if(not self.appSearchModule.isLoaded()): + return + self.moduleLoaded = true self.delegate.mainDidLoad() @@ -256,6 +259,12 @@ method chatSectionDidLoad*[T](self: Module[T]) = method communitySectionDidLoad*[T](self: Module[T]) = self.checkIfModuleDidLoad() +method appSearchDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +proc stickersDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + proc walletSectionDidLoad*[T](self: Module[T]) = self.checkIfModuleDidLoad() diff --git a/src/app/modules/main/private_interfaces/module_app_search_delegate_interface.nim b/src/app/modules/main/private_interfaces/module_app_search_delegate_interface.nim new file mode 100644 index 0000000000..2bd1c09cf2 --- /dev/null +++ b/src/app/modules/main/private_interfaces/module_app_search_delegate_interface.nim @@ -0,0 +1,2 @@ +method appSearchDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/private_interfaces/module_chat_section_delegate_interface.nim b/src/app/modules/main/private_interfaces/module_chat_section_delegate_interface.nim index 5ea851e89b..cd18d0acbe 100644 --- a/src/app/modules/main/private_interfaces/module_chat_section_delegate_interface.nim +++ b/src/app/modules/main/private_interfaces/module_chat_section_delegate_interface.nim @@ -1,5 +1,8 @@ method chatSectionDidLoad*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method communitySectionDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + method onActiveChatChange*(self: AccessInterface, sectionId: string, chatId: string) {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/profile_section/about/controller.nim b/src/app/modules/main/profile_section/about/controller.nim index 792be66311..d21e44247f 100644 --- a/src/app/modules/main/profile_section/about/controller.nim +++ b/src/app/modules/main/profile_section/about/controller.nim @@ -1,4 +1,5 @@ import ./controller_interface +import io_interface import ../../../../../app_service/service/about/service as about_service # import ./item as item @@ -6,23 +7,23 @@ import ../../../../../app_service/service/about/service as about_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface aboutService: about_service.ServiceInterface -proc newController*[T](delegate: T, aboutService: about_service.ServiceInterface): Controller[T] = - result = Controller[T]() +proc newController*(delegate: io_interface.AccessInterface, aboutService: about_service.ServiceInterface): Controller = + result = Controller() result.delegate = delegate result.aboutService = aboutService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard -method getAppVersion*[T](self: Controller[T]): string = +method getAppVersion*(self: Controller): string = return self.aboutService.getAppVersion() -method getNodeVersion*[T](self: Controller[T]): string = +method getNodeVersion*(self: Controller): string = return self.aboutService.getNodeVersion() diff --git a/src/app/modules/main/profile_section/about/io_interface.nim b/src/app/modules/main/profile_section/about/io_interface.nim index 82e7386d34..cb2185ff32 100644 --- a/src/app/modules/main/profile_section/about/io_interface.nim +++ b/src/app/modules/main/profile_section/about/io_interface.nim @@ -17,7 +17,8 @@ method getAppVersion*(self: AccessInterface): string {.base.} = method getNodeVersion*(self: AccessInterface): string {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/profile_section/about/module.nim b/src/app/modules/main/profile_section/about/module.nim index 74dee31767..afdabf33d8 100644 --- a/src/app/modules/main/profile_section/about/module.nim +++ b/src/app/modules/main/profile_section/about/module.nim @@ -1,6 +1,7 @@ import NimQml, Tables import ./io_interface, ./view, ./controller +import ../io_interface as delegate_interface import ../../../../global/global_singleton import ../../../../../app_service/service/about/service as about_service @@ -8,34 +9,38 @@ import ../../../../../app_service/service/about/service as about_service export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface controller: controller.AccessInterface view: View viewVariant: QVariant moduleLoaded: bool -proc newModule*[T](delegate: T, aboutService: about_service.ServiceInterface): Module[T] = - result = Module[T]() +proc newModule*(delegate: delegate_interface.AccessInterface, aboutService: about_service.ServiceInterface): Module = + result = Module() result.delegate = delegate result.view = newView(result) result.viewVariant = newQVariant(result.view) - result.controller = controller.newController[Module[T]](result, aboutService) + result.controller = controller.newController(result, aboutService) result.moduleLoaded = false singletonInstance.engine.setRootContextProperty("aboutModule", result.viewVariant) -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete -method load*[T](self: Module[T]) = - self.moduleLoaded = true +method load*(self: Module) = + self.view.load() -method isLoaded*[T](self: Module[T]): bool = +method isLoaded*(self: Module): bool = return self.moduleLoaded -method getAppVersion*[T](self: Module[T]): string = +method viewDidLoad*(self: Module) = + self.moduleLoaded = true + self.delegate.aboutModuleDidLoad() + +method getAppVersion*(self: Module): string = return self.controller.getAppVersion() -method getNodeVersion*[T](self: Module[T]): string = +method getNodeVersion*(self: Module): string = return self.controller.getNodeVersion() diff --git a/src/app/modules/main/profile_section/about/view.nim b/src/app/modules/main/profile_section/about/view.nim index 2859f5653a..9278a49c45 100644 --- a/src/app/modules/main/profile_section/about/view.nim +++ b/src/app/modules/main/profile_section/about/view.nim @@ -16,6 +16,9 @@ QtObject: result.QObject.setup result.delegate = delegate + proc load*(self: View) = + self.delegate.viewDidLoad() + proc getCurrentVersion*(self: View): string {.slot.} = return self.delegate.getAppVersion() diff --git a/src/app/modules/main/profile_section/contacts/controller.nim b/src/app/modules/main/profile_section/contacts/controller.nim index 02c27f67c7..0d986f115b 100644 --- a/src/app/modules/main/profile_section/contacts/controller.nim +++ b/src/app/modules/main/profile_section/contacts/controller.nim @@ -11,26 +11,26 @@ import eventemitter export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface + Controller* = ref object of controller_interface.AccessInterface delegate: io_interface.AccessInterface events: EventEmitter contactsService: contacts_service.Service accountsService: accounts_service.ServiceInterface -proc newController*[T](delegate: io_interface.AccessInterface, +proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter, contactsService: contacts_service.Service, - accountsService: accounts_service.ServiceInterface): Controller[T] = - result = Controller[T]() + accountsService: accounts_service.ServiceInterface): Controller = + result = Controller() result.delegate = delegate result.events = events result.contactsService = contactsService result.accountsService = accountsService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = self.events.on(SIGNAL_CONTACT_LOOKED_UP) do(e: Args): var args = ContactArgs(e) self.delegate.contactLookedUp(args.contactId) @@ -55,32 +55,32 @@ method init*[T](self: Controller[T]) = var args = ContactNicknameUpdatedArgs(e) self.delegate.contactNicknameChanged(args.contactId, args.nickname) -method getContacts*[T](self: Controller[T]): seq[ContactsDto] = +method getContacts*(self: Controller): seq[ContactsDto] = return self.contactsService.getContacts() -method getContact*[T](self: Controller[T], id: string): ContactsDto = +method getContact*(self: Controller, id: string): ContactsDto = return self.contactsService.getContactById(id) -method generateAlias*[T](self: Controller[T], publicKey: string): string = +method generateAlias*(self: Controller, publicKey: string): string = return self.accountsService.generateAlias(publicKey) -method addContact*[T](self: Controller[T], publicKey: string) = +method addContact*(self: Controller, publicKey: string) = self.contactsService.addContact(publicKey) -method rejectContactRequest*[T](self: Controller[T], publicKey: string) = +method rejectContactRequest*(self: Controller, publicKey: string) = self.contactsService.rejectContactRequest(publicKey) -method unblockContact*[T](self: Controller[T], publicKey: string) = +method unblockContact*(self: Controller, publicKey: string) = self.contactsService.unblockContact(publicKey) -method blockContact*[T](self: Controller[T], publicKey: string) = +method blockContact*(self: Controller, publicKey: string) = self.contactsService.blockContact(publicKey) -method removeContact*[T](self: Controller[T], publicKey: string) = +method removeContact*(self: Controller, publicKey: string) = self.contactsService.removeContact(publicKey) -method changeContactNickname*[T](self: Controller[T], publicKey: string, nickname: string) = +method changeContactNickname*(self: Controller, publicKey: string, nickname: string) = self.contactsService.changeContactNickname(publicKey, nickname) -method lookupContact*[T](self: Controller[T], value: string) = +method lookupContact*(self: Controller, value: string) = self.contactsService.lookupContact(value) \ No newline at end of file diff --git a/src/app/modules/main/profile_section/contacts/io_interface.nim b/src/app/modules/main/profile_section/contacts/io_interface.nim index 73d3b130dd..7489087410 100644 --- a/src/app/modules/main/profile_section/contacts/io_interface.nim +++ b/src/app/modules/main/profile_section/contacts/io_interface.nim @@ -64,7 +64,8 @@ method lookupContact*(self: AccessInterface, value: string) {.base.} = method contactLookedUp*(self: AccessInterface, id: string) {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/profile_section/contacts/module.nim b/src/app/modules/main/profile_section/contacts/module.nim index 3f249166b7..09aa9d7b37 100644 --- a/src/app/modules/main/profile_section/contacts/module.nim +++ b/src/app/modules/main/profile_section/contacts/module.nim @@ -1,6 +1,7 @@ import NimQml, Tables import io_interface, view, controller, model +import ../io_interface as delegate_interface import ../../../../global/global_singleton import ../../../../../app_service/service/contacts/service as contacts_service @@ -12,92 +13,97 @@ import eventemitter export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface controller: controller.AccessInterface view: View viewVariant: QVariant moduleLoaded: bool -proc newModule*[T](delegate: T, +proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, contactsService: contacts_service.Service, accountsService: accounts_service.ServiceInterface): - Module[T] = - result = Module[T]() + Module = + result = Module() result.delegate = delegate result.view = newView(result) result.viewVariant = newQVariant(result.view) - result.controller = controller.newController[Module[T]](result, events, contactsService, accountsService) + result.controller = controller.newController(result, events, contactsService, accountsService) result.moduleLoaded = false singletonInstance.engine.setRootContextProperty("contactsModule", result.viewVariant) -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete -method setContactList*[T](self: Module[T], contacts: seq[ContactsDto]) = +method setContactList*(self: Module, contacts: seq[ContactsDto]) = self.view.model().setContactList(contacts) -method updateContactList*[T](self: Module[T], contacts: seq[ContactsDto]) = +method updateContactList*(self: Module, contacts: seq[ContactsDto]) = self.view.model().updateContactList(contacts) -method load*[T](self: Module[T]) = +method load*(self: Module) = self.controller.init() - let contacts = self.controller.getContacts() - self.setContactList(contacts) - self.moduleLoaded = true - -method isLoaded*[T](self: Module[T]): bool = + self.view.load() + +method isLoaded*(self: Module): bool = return self.moduleLoaded -method getContact*[T](self: Module[T], id: string): ContactsDto = +method viewDidLoad*(self: Module) = + let contacts = self.controller.getContacts() + self.setContactList(contacts) + + self.moduleLoaded = true + self.delegate.contactsModuleDidLoad() + +method getContact*(self: Module, id: string): ContactsDto = self.controller.getContact(id) -method generateAlias*[T](self: Module[T], publicKey: string): string = +method generateAlias*(self: Module, publicKey: string): string = self.controller.generateAlias(publicKey) -method addContact*[T](self: Module[T], publicKey: string) = +method addContact*(self: Module, publicKey: string) = self.controller.addContact(publicKey) -method contactAdded*[T](self: Module[T], contact: ContactsDto) = +method contactAdded*(self: Module, contact: ContactsDto) = self.view.model().contactAdded(contact) -method contactBlocked*[T](self: Module[T], publicKey: string) = +method contactBlocked*(self: Module, publicKey: string) = # once we refactore a model, we should pass only pk from here (like we have for nickname change) let contact = self.controller.getContact(publicKey) self.view.model().contactBlocked(contact) -method contactUnblocked*[T](self: Module[T], publicKey: string) = +method contactUnblocked*(self: Module, publicKey: string) = # once we refactore a model, we should pass only pk from here (like we have for nickname change) let contact = self.controller.getContact(publicKey) self.view.model().contactUnblocked(contact) -method contactRemoved*[T](self: Module[T], publicKey: string) = +method contactRemoved*(self: Module, publicKey: string) = # once we refactore a model, we should pass only pk from here (like we have for nickname change) let contact = self.controller.getContact(publicKey) self.view.model().contactRemoved(contact) -method contactNicknameChanged*[T](self: Module[T], publicKey: string, nickname: string) = +method contactNicknameChanged*(self: Module, publicKey: string, nickname: string) = self.view.model().changeNicknameForContactWithId(publicKey, nickname) -method rejectContactRequest*[T](self: Module[T], publicKey: string) = +method rejectContactRequest*(self: Module, publicKey: string) = self.controller.rejectContactRequest(publicKey) -method unblockContact*[T](self: Module[T], publicKey: string) = +method unblockContact*(self: Module, publicKey: string) = self.controller.unblockContact(publicKey) -method blockContact*[T](self: Module[T], publicKey: string) = +method blockContact*(self: Module, publicKey: string) = self.controller.blockContact(publicKey) -method removeContact*[T](self: Module[T], publicKey: string) = +method removeContact*(self: Module, publicKey: string) = self.controller.removeContact(publicKey) -method changeContactNickname*[T](self: Module[T], publicKey: string, nickname: string) = +method changeContactNickname*(self: Module, publicKey: string, nickname: string) = self.controller.changeContactNickname(publicKey, nickname) -method lookupContact*[T](self: Module[T], value: string) = +method lookupContact*(self: Module, value: string) = self.controller.lookupContact(value) -method contactLookedUp*[T](self: Module[T], id: string) = +method contactLookedUp*(self: Module, id: string) = self.view.contactLookedUp(id) \ No newline at end of file diff --git a/src/app/modules/main/profile_section/contacts/view.nim b/src/app/modules/main/profile_section/contacts/view.nim index 58ba64168d..cfa384149f 100644 --- a/src/app/modules/main/profile_section/contacts/view.nim +++ b/src/app/modules/main/profile_section/contacts/view.nim @@ -33,6 +33,9 @@ QtObject: result.modelVariant = newQVariant(result.model) result.contactToAdd = ContactsDto() + proc load*(self: View) = + self.delegate.viewDidLoad() + proc model*(self: View): Model = return self.model diff --git a/src/app/modules/main/profile_section/io_interface.nim b/src/app/modules/main/profile_section/io_interface.nim index 54d9e2587a..97fe9f5d6f 100644 --- a/src/app/modules/main/profile_section/io_interface.nim +++ b/src/app/modules/main/profile_section/io_interface.nim @@ -23,6 +23,25 @@ method toggleDebug*(self: AccessInterface) {.base.} = method viewDidLoad*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +# Methods called by submodules of this module +method profileModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method contactsModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method languageModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method mnemonicModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method privacyModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method aboutModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + type ## Abstract class (concept) which must be implemented by object/s used in this ## module. diff --git a/src/app/modules/main/profile_section/language/controller.nim b/src/app/modules/main/profile_section/language/controller.nim index 32fac54ff9..5060045c0a 100644 --- a/src/app/modules/main/profile_section/language/controller.nim +++ b/src/app/modules/main/profile_section/language/controller.nim @@ -1,4 +1,5 @@ import ./controller_interface +import io_interface import ../../../../../app_service/service/language/service as language_service # import ./item as item @@ -6,17 +7,21 @@ import ../../../../../app_service/service/language/service as language_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface languageService: language_service.ServiceInterface -proc newController*[T](delegate: T, languageService: language_service.ServiceInterface): Controller[T] = - result = Controller[T]() +method init*(self: Controller) = + discard + +proc newController*(delegate: io_interface.AccessInterface, languageService: language_service.ServiceInterface): + Controller = + result = Controller() result.delegate = delegate result.languageService = languageService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method changeLanguage*[T](self: Controller[T], locale: string) = +method changeLanguage*(self: Controller, locale: string) = self.languageService.setLanguage(locale) diff --git a/src/app/modules/main/profile_section/language/io_interface.nim b/src/app/modules/main/profile_section/language/io_interface.nim index 65aba1872c..699a9dc837 100644 --- a/src/app/modules/main/profile_section/language/io_interface.nim +++ b/src/app/modules/main/profile_section/language/io_interface.nim @@ -14,7 +14,8 @@ method isLoaded*(self: AccessInterface): bool {.base.} = method changeLanguage*(self: AccessInterface, locale: string) {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/profile_section/language/module.nim b/src/app/modules/main/profile_section/language/module.nim index 21c9cfc07c..571493bb57 100644 --- a/src/app/modules/main/profile_section/language/module.nim +++ b/src/app/modules/main/profile_section/language/module.nim @@ -1,6 +1,7 @@ import NimQml, Tables import ./io_interface, ./view, ./controller +import ../io_interface as delegate_interface import ../../../../global/global_singleton import ../../../../../app_service/service/language/service as language_service @@ -8,31 +9,36 @@ import ../../../../../app_service/service/language/service as language_service export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface controller: controller.AccessInterface view: View viewVariant: QVariant moduleLoaded: bool -proc newModule*[T](delegate: T, languageService: language_service.ServiceInterface): Module[T] = - result = Module[T]() +proc newModule*(delegate: delegate_interface.AccessInterface, languageService: language_service.ServiceInterface): Module = + result = Module() result.delegate = delegate result.view = newView(result) result.viewVariant = newQVariant(result.view) - result.controller = controller.newController[Module[T]](result, languageService) + result.controller = controller.newController(result, languageService) result.moduleLoaded = false singletonInstance.engine.setRootContextProperty("languageModule", result.viewVariant) -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete -method load*[T](self: Module[T]) = - self.moduleLoaded = true +method load*(self: Module) = + self.controller.init() + self.view.load() -method isLoaded*[T](self: Module[T]): bool = +method isLoaded*(self: Module): bool = return self.moduleLoaded -method changeLanguage*[T](self: Module[T], locale: string) = +method viewDidLoad*(self: Module) = + self.moduleLoaded = true + self.delegate.languageModuleDidLoad() + +method changeLanguage*(self: Module, locale: string) = self.controller.changeLanguage(locale) diff --git a/src/app/modules/main/profile_section/language/view.nim b/src/app/modules/main/profile_section/language/view.nim index 8257c15e1c..80613f6390 100644 --- a/src/app/modules/main/profile_section/language/view.nim +++ b/src/app/modules/main/profile_section/language/view.nim @@ -16,5 +16,8 @@ QtObject: result.QObject.setup result.delegate = delegate + proc load*(self: View) = + self.delegate.viewDidLoad() + proc changeLocale*(self: View, locale: string) {.slot.} = self.delegate.changeLanguage(locale) diff --git a/src/app/modules/main/profile_section/mnemonic/controller.nim b/src/app/modules/main/profile_section/mnemonic/controller.nim index 691e9c3526..fa3f1d220c 100644 --- a/src/app/modules/main/profile_section/mnemonic/controller.nim +++ b/src/app/modules/main/profile_section/mnemonic/controller.nim @@ -1,32 +1,34 @@ import ./controller_interface +import io_interface import ../../../../../app_service/service/mnemonic/service as mnemonic_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface mnemonicService: mnemonic_service.ServiceInterface -proc newController*[T](delegate: T, mnemonicService: mnemonic_service.ServiceInterface): Controller[T] = - result = Controller[T]() +proc newController*(delegate: io_interface.AccessInterface, mnemonicService: mnemonic_service.ServiceInterface): + Controller = + result = Controller() result.delegate = delegate result.mnemonicService = mnemonicService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard -method isBackedUp*[T](self: Controller[T]): bool = +method isBackedUp*(self: Controller): bool = return self.mnemonicService.isBackedUp() -method getMnemonic*[T](self: Controller[T]): string = +method getMnemonic*(self: Controller): string = return self.mnemonicService.getMnemonic() -method remove*[T](self: Controller[T]) = +method remove*(self: Controller) = self.mnemonicService.remove() -method getWord*[T](self: Controller[T], index: int): string = +method getWord*(self: Controller, index: int): string = return self.mnemonicService.getWord(index) diff --git a/src/app/modules/main/profile_section/mnemonic/io_interface.nim b/src/app/modules/main/profile_section/mnemonic/io_interface.nim index 033425882f..0fa6b9274f 100644 --- a/src/app/modules/main/profile_section/mnemonic/io_interface.nim +++ b/src/app/modules/main/profile_section/mnemonic/io_interface.nim @@ -23,7 +23,8 @@ method remove*(self: AccessInterface) {.base.} = method getWord*(self: AccessInterface, index: int): string {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/profile_section/mnemonic/module.nim b/src/app/modules/main/profile_section/mnemonic/module.nim index 925975a071..c7d7e8ec3c 100644 --- a/src/app/modules/main/profile_section/mnemonic/module.nim +++ b/src/app/modules/main/profile_section/mnemonic/module.nim @@ -1,6 +1,7 @@ import NimQml, Tables import ./io_interface, ./view, ./controller +import ../io_interface as delegate_interface import ../../../../global/global_singleton import ../../../../../app_service/service/mnemonic/service as mnemonic_service @@ -8,40 +9,45 @@ import ../../../../../app_service/service/mnemonic/service as mnemonic_service export io_interface type - Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface controller: controller.AccessInterface view: View viewVariant: QVariant moduleLoaded: bool -proc newModule*[T](delegate: T, mnemonicService: mnemonic_service.ServiceInterface): Module[T] = - result = Module[T]() +proc newModule*(delegate: delegate_interface.AccessInterface, mnemonicService: mnemonic_service.ServiceInterface): Module = + result = Module() result.delegate = delegate result.view = newView(result) result.viewVariant = newQVariant(result.view) - result.controller = controller.newController[Module[T]](result, mnemonicService) + result.controller = controller.newController(result, mnemonicService) result.moduleLoaded = false singletonInstance.engine.setRootContextProperty("mnemonicModule", result.viewVariant) -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete -method load*[T](self: Module[T]) = - self.moduleLoaded = true +method load*(self: Module) = + self.controller.init() + self.view.load() -method isLoaded*[T](self: Module[T]): bool = +method isLoaded*(self: Module): bool = return self.moduleLoaded -method isBackedUp*[T](self: Module[T]): bool = +method viewDidLoad*(self: Module) = + self.moduleLoaded = true + self.delegate.mnemonicModuleDidLoad() + +method isBackedUp*(self: Module): bool = return self.controller.isBackedup() -method getMnemonic*[T](self: Module[T]): string = +method getMnemonic*(self: Module): string = return self.controller.getMnemonic() -method remove*[T](self: Module[T]) = +method remove*(self: Module) = self.controller.remove() -method getWord*[T](self: Module[T], index: int): string = +method getWord*(self: Module, index: int): string = return self.controller.getWord(index) diff --git a/src/app/modules/main/profile_section/mnemonic/view.nim b/src/app/modules/main/profile_section/mnemonic/view.nim index e25390090b..7fc9c7ba97 100644 --- a/src/app/modules/main/profile_section/mnemonic/view.nim +++ b/src/app/modules/main/profile_section/mnemonic/view.nim @@ -15,6 +15,9 @@ QtObject: result.QObject.setup result.delegate = delegate + proc load*(self: View) = + self.delegate.viewDidLoad() + proc isBackedUp*(self: View): bool {.slot.} = return self.delegate.isBackedup() diff --git a/src/app/modules/main/profile_section/module.nim b/src/app/modules/main/profile_section/module.nim index 251a766d29..ed2aa3caba 100644 --- a/src/app/modules/main/profile_section/module.nim +++ b/src/app/modules/main/profile_section/module.nim @@ -78,6 +78,7 @@ method delete*[T](self: Module[T]) = self.controller.delete method load*[T](self: Module[T]) = + self.view.load() self.profileModule.load() self.contactsModule.load() self.languageModule.load() @@ -85,17 +86,53 @@ method load*[T](self: Module[T]) = self.privacyModule.load() self.aboutModule.load() - self.view.setIsTelemetryEnabled(self.controller.isTelemetryEnabled()) - self.view.setIsDebugEnabled(self.controller.isDebugEnabled()) +method isLoaded*[T](self: Module[T]): bool = + return self.moduleLoaded + +proc checkIfModuleDidLoad[T](self: Module[T]) = + if(not self.profileModule.isLoaded()): + return + + if(not self.contactsModule.isLoaded()): + return + + if(not self.languageModule.isLoaded()): + return + + if(not self.mnemonicModule.isLoaded()): + return + + if(not self.privacyModule.isLoaded()): + return + + if(not self.aboutModule.isLoaded()): + return self.moduleLoaded = true self.delegate.profileSectionDidLoad() -method isLoaded*[T](self: Module[T]): bool = - return self.moduleLoaded +method viewDidLoad*[T](self: Module[T]) = + self.view.setIsTelemetryEnabled(self.controller.isTelemetryEnabled()) + self.view.setIsDebugEnabled(self.controller.isDebugEnabled()) + self.checkIfModuleDidLoad() -method viewDidLoad*(self: Module) = - discard +method profileModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +method contactsModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +method languageModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +method mnemonicModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +method privacyModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +method aboutModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() method toggleTelemetry*[T](self: Module[T]) = self.controller.toggleTelemetry() diff --git a/src/app/modules/main/profile_section/privacy/controller.nim b/src/app/modules/main/profile_section/privacy/controller.nim index 2d62d20411..faf5edb0e6 100644 --- a/src/app/modules/main/profile_section/privacy/controller.nim +++ b/src/app/modules/main/profile_section/privacy/controller.nim @@ -1,30 +1,32 @@ import ./controller_interface +import io_interface import ../../../../../app_service/service/accounts/service as accounts_service import ../../../../../app_service/service/privacy/service as privacy_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface accountsService: accounts_service.ServiceInterface privacyService: privacy_service.ServiceInterface -proc newController*[T](delegate: T, privacyService: privacy_service.ServiceInterface, accountsService: accounts_service.ServiceInterface): Controller[T] = - result = Controller[T]() +proc newController*(delegate: io_interface.AccessInterface, privacyService: privacy_service.ServiceInterface, + accountsService: accounts_service.ServiceInterface): Controller = + result = Controller() result.delegate = delegate result.accountsService = accountsService result.privacyService = privacyService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard -method getLinkPreviewWhitelist*[T](self: Controller[T]): string = +method getLinkPreviewWhitelist*(self: Controller): string = return self.privacyService.getLinkPreviewWhitelist() -method changePassword*[T](self: Controller[T], password: string, newPassword: string): bool = +method changePassword*(self: Controller, password: string, newPassword: string): bool = let loggedInAccount = self.accountsService.getLoggedInAccount() return self.privacyService.changePassword(loggedInAccount.keyUid, password, newPassword) diff --git a/src/app/modules/main/profile_section/privacy/io_interface.nim b/src/app/modules/main/profile_section/privacy/io_interface.nim index ea93aec35f..829c6c07f3 100644 --- a/src/app/modules/main/profile_section/privacy/io_interface.nim +++ b/src/app/modules/main/profile_section/privacy/io_interface.nim @@ -17,7 +17,8 @@ method getLinkPreviewWhitelist*(self: AccessInterface): string {.base.} = method changePassword*(self: AccessInterface, password: string, newPassword: string): bool {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/profile_section/privacy/module.nim b/src/app/modules/main/profile_section/privacy/module.nim index 5ec51b1acd..be61150fce 100644 --- a/src/app/modules/main/profile_section/privacy/module.nim +++ b/src/app/modules/main/profile_section/privacy/module.nim @@ -1,6 +1,7 @@ import NimQml, Tables import ./io_interface, ./view, ./controller +import ../io_interface as delegate_interface import ../../../../global/global_singleton import ../../../../../app_service/service/accounts/service as accounts_service @@ -9,34 +10,39 @@ import ../../../../../app_service/service/privacy/service as privacy_service export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface controller: controller.AccessInterface view: View viewVariant: QVariant moduleLoaded: bool -proc newModule*[T](delegate: T, privacyService: privacy_service.ServiceInterface, accountsService: accounts_service.ServiceInterface): Module[T] = - result = Module[T]() +proc newModule*(delegate: delegate_interface.AccessInterface, privacyService: privacy_service.ServiceInterface, accountsService: accounts_service.ServiceInterface): Module = + result = Module() result.delegate = delegate result.view = newView(result) result.viewVariant = newQVariant(result.view) - result.controller = controller.newController[Module[T]](result, privacyService, accountsService) + result.controller = controller.newController(result, privacyService, accountsService) result.moduleLoaded = false singletonInstance.engine.setRootContextProperty("privacyModule", result.viewVariant) -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete -method load*[T](self: Module[T]) = - self.moduleLoaded = true +method load*(self: Module) = + self.controller.init() + self.view.load() -method isLoaded*[T](self: Module[T]): bool = +method isLoaded*(self: Module): bool = return self.moduleLoaded -method getLinkPreviewWhitelist*[T](self: Module[T]): string = +method viewDidLoad*(self: Module) = + self.moduleLoaded = true + self.delegate.privacyModuleDidLoad() + +method getLinkPreviewWhitelist*(self: Module): string = return self.controller.getLinkPreviewWhitelist() -method changePassword*[T](self: Module[T], password: string, newPassword: string): bool = +method changePassword*(self: Module, password: string, newPassword: string): bool = return self.controller.changePassword(password, newPassword) diff --git a/src/app/modules/main/profile_section/privacy/view.nim b/src/app/modules/main/profile_section/privacy/view.nim index 70522d296a..8e7a43f247 100644 --- a/src/app/modules/main/profile_section/privacy/view.nim +++ b/src/app/modules/main/profile_section/privacy/view.nim @@ -16,6 +16,9 @@ QtObject: result.QObject.setup result.delegate = delegate + proc load*(self: View) = + self.delegate.viewDidLoad() + proc getLinkPreviewWhitelist*(self: View): string {.slot.} = return self.delegate.getLinkPreviewWhitelist() diff --git a/src/app/modules/main/profile_section/profile/controller.nim b/src/app/modules/main/profile_section/profile/controller.nim index 320f1633ae..9056750da4 100644 --- a/src/app/modules/main/profile_section/profile/controller.nim +++ b/src/app/modules/main/profile_section/profile/controller.nim @@ -1,5 +1,5 @@ import ./controller_interface - +import io_interface import ../../../../global/global_singleton import ../../../../../app_service/service/profile/service as profile_service import ../../../../../app_service/service/accounts/service as accounts_service @@ -11,27 +11,27 @@ import status/types/identity_image export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface profileService: profile_service.ServiceInterface settingsService: settings_service.ServiceInterface accountsService: accounts_service.ServiceInterface -proc newController*[T](delegate: T, accountsService: accounts_service.ServiceInterface, - settingsService: settings_service.ServiceInterface, profileService: profile_service.ServiceInterface): Controller[T] = - result = Controller[T]() +proc newController*(delegate: io_interface.AccessInterface, accountsService: accounts_service.ServiceInterface, + settingsService: settings_service.ServiceInterface, profileService: profile_service.ServiceInterface): Controller = + result = Controller() result.delegate = delegate result.profileService = profileService result.settingsService = settingsService result.accountsService = accountsService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard -method getProfile*[T](self: Controller[T]): item.Item = +method getProfile*(self: Controller): item.Item = var appearance = self.settingsService.getAppearance() var messagesFromContactsOnly = self.settingsService.getMessagesFromContactsOnly() @@ -60,12 +60,12 @@ method getProfile*[T](self: Controller[T]): item.Item = return item -method storeIdentityImage*[T](self: Controller[T], address: string, image: string, aX: int, aY: int, bX: int, bY: int): identity_image.IdentityImage = +method storeIdentityImage*(self: Controller, address: string, image: string, aX: int, aY: int, bX: int, bY: int): identity_image.IdentityImage = result = self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY) singletonInstance.userProfile.setThumbnailImage(result.thumbnail) singletonInstance.userProfile.setLargeImage(result.large) -method deleteIdentityImage*[T](self: Controller[T], address: string): string = +method deleteIdentityImage*(self: Controller, address: string): string = result = self.profileService.deleteIdentityImage(address) singletonInstance.userProfile.setThumbnailImage("") singletonInstance.userProfile.setLargeImage("") diff --git a/src/app/modules/main/profile_section/profile/io_interface.nim b/src/app/modules/main/profile_section/profile/io_interface.nim index 73a398f9bb..e770f9338e 100644 --- a/src/app/modules/main/profile_section/profile/io_interface.nim +++ b/src/app/modules/main/profile_section/profile/io_interface.nim @@ -13,13 +13,15 @@ method load*(self: AccessInterface) {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") -method storeIdentityImage*(self: AccessInterface, address: string, image: string, aX: int, aY: int, bX: int, bY: int): identity_image.IdentityImage {.base.} = +method storeIdentityImage*(self: AccessInterface, address: string, image: string, aX: int, aY: int, bX: int, bY: int): + identity_image.IdentityImage {.base.} = raise newException(ValueError, "No implementation available") method deleteIdentityImage*(self: AccessInterface, address: string): string {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/profile_section/profile/module.nim b/src/app/modules/main/profile_section/profile/module.nim index 8db45ec071..0e4c81355e 100644 --- a/src/app/modules/main/profile_section/profile/module.nim +++ b/src/app/modules/main/profile_section/profile/module.nim @@ -1,6 +1,7 @@ import NimQml, Tables import ./io_interface, ./view, ./controller, ./item +import ../io_interface as delegate_interface import ../../../../global/global_singleton import ../../../../../app_service/service/profile/service as profile_service @@ -12,37 +13,43 @@ import status/types/identity_image export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface controller: controller.AccessInterface view: View viewVariant: QVariant moduleLoaded: bool -proc newModule*[T](delegate: T, accountsService: accounts_service.ServiceInterface, - settingsService: settings_service.ServiceInterface, profileService: profile_service.ServiceInterface): Module[T] = - result = Module[T]() +proc newModule*(delegate: delegate_interface.AccessInterface, accountsService: accounts_service.ServiceInterface, + settingsService: settings_service.ServiceInterface, profileService: profile_service.ServiceInterface): Module = + result = Module() result.delegate = delegate result.view = newView(result) result.viewVariant = newQVariant(result.view) - result.controller = controller.newController[Module[T]](result, accountsService, settingsService, profileService) + result.controller = controller.newController(result, accountsService, settingsService, profileService) result.moduleLoaded = false singletonInstance.engine.setRootContextProperty("profileModule", result.viewVariant) -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete -method load*[T](self: Module[T]) = - let profile = self.controller.getProfile() - self.view.setProfile(profile) - self.moduleLoaded = true - -method isLoaded*[T](self: Module[T]): bool = +method load*(self: Module) = + self.controller.init() + self.view.load() + +method isLoaded*(self: Module): bool = return self.moduleLoaded -method storeIdentityImage*[T](self: Module[T], address: string, image: string, aX: int, aY: int, bX: int, bY: int): identity_image.IdentityImage = +method viewDidLoad*(self: Module) = + let profile = self.controller.getProfile() + self.view.setProfile(profile) + + self.moduleLoaded = true + self.delegate.profileModuleDidLoad() + +method storeIdentityImage*(self: Module, address: string, image: string, aX: int, aY: int, bX: int, bY: int): identity_image.IdentityImage = self.controller.storeIdentityImage(address, image, aX, aY, bX, bY) -method deleteIdentityImage*[T](self: Module[T], address: string): string = +method deleteIdentityImage*(self: Module, address: string): string = self.controller.deleteIdentityImage(address) diff --git a/src/app/modules/main/profile_section/profile/view.nim b/src/app/modules/main/profile_section/profile/view.nim index bd6a003441..e4192a4dfc 100644 --- a/src/app/modules/main/profile_section/profile/view.nim +++ b/src/app/modules/main/profile_section/profile/view.nim @@ -28,6 +28,9 @@ QtObject: result.model = newModel() result.modelVariant = newQVariant(result.model) + proc load*(self: View) = + self.delegate.viewDidLoad() + proc modelChanged*(self: View) {.signal.} proc getModel*(self: View): QVariant {.slot.} = diff --git a/src/app/modules/main/profile_section/view.nim b/src/app/modules/main/profile_section/view.nim index 74d2ea56d8..2d192669f4 100644 --- a/src/app/modules/main/profile_section/view.nim +++ b/src/app/modules/main/profile_section/view.nim @@ -21,6 +21,9 @@ QtObject: result.delegate = delegate result.setup() + proc load*(self: View) = + self.delegate.viewDidLoad() + proc isTelemetryEnabledChanged*(self: View) {.signal.} proc setIsTelemetryEnabled*(self: View, isTelemetryEnabled: bool) = diff --git a/src/app/modules/main/stickers/io_interface.nim b/src/app/modules/main/stickers/io_interface.nim index 2d2f93f51e..0b185bc861 100644 --- a/src/app/modules/main/stickers/io_interface.nim +++ b/src/app/modules/main/stickers/io_interface.nim @@ -15,6 +15,9 @@ method load*(self: AccessInterface) {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + method buy*(self: AccessInterface, packId: int, address: string, price: string, gas: string, gasPrice: string, maxPriorityFeePerGas: string, maxFeePerGas: string, password: string): tuple[response: string, success: bool] {.base.} = raise newException(ValueError, "No implementation available") @@ -67,3 +70,4 @@ type ## Abstract class (concept) which must be implemented by object/s used in this ## module. DelegateInterface* = concept c + c.stickersDidLoad() diff --git a/src/app/modules/main/stickers/module.nim b/src/app/modules/main/stickers/module.nim index ccda208180..10a2d174a2 100644 --- a/src/app/modules/main/stickers/module.nim +++ b/src/app/modules/main/stickers/module.nim @@ -34,11 +34,15 @@ method delete*[T](self: Module[T]) = method load*[T](self: Module[T]) = self.controller.init() - self.moduleLoaded = true + self.view.load() method isLoaded*[T](self: Module[T]): bool = return self.moduleLoaded +method viewDidLoad*[T](self: Module[T]) = + self.moduleLoaded = true + self.delegate.stickersDidLoad() + method buy*[T](self: Module[T], packId: int, address: string, price: string, gas: string, gasPrice: string, maxPriorityFeePerGas: string, maxFeePerGas: string, password: string): tuple[response: string, success: bool] = return self.controller.buy(packId, address, price, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, password) diff --git a/src/app/modules/main/stickers/view.nim b/src/app/modules/main/stickers/view.nim index c3a2074a8d..f87f2de976 100644 --- a/src/app/modules/main/stickers/view.nim +++ b/src/app/modules/main/stickers/view.nim @@ -22,6 +22,9 @@ QtObject: result.stickerPacks = newStickerPackList() result.recentStickers = newStickerList() + proc load*(self: View) = + self.delegate.viewDidLoad() + proc addStickerPackToList*(self: View, stickerPack: StickerPackDto, isInstalled, isBought, isPending: bool) = self.stickerPacks.addStickerPackToList(stickerPack, newStickerList(stickerPack.stickers), isInstalled, isBought, isPending) diff --git a/src/app/modules/main/wallet_section/account_tokens/controller.nim b/src/app/modules/main/wallet_section/account_tokens/controller.nim index 982cd84771..5d742c966f 100644 --- a/src/app/modules/main/wallet_section/account_tokens/controller.nim +++ b/src/app/modules/main/wallet_section/account_tokens/controller.nim @@ -1,26 +1,27 @@ import ./controller_interface +import io_interface import ../../../../../app_service/service/wallet_account/service as wallet_account_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface walletAccountService: wallet_account_service.ServiceInterface -proc newController*[T]( - delegate: T, +proc newController*( + delegate: io_interface.AccessInterface, walletAccountService: wallet_account_service.ServiceInterface -): Controller[T] = - result = Controller[T]() +): Controller = + result = Controller() result.delegate = delegate result.walletAccountService = walletAccountService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard -method getWalletAccount*[T](self: Controller[T], accountIndex: int): wallet_account_service.WalletAccountDto = +method getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto = return self.walletAccountService.getWalletAccount(accountIndex) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/account_tokens/io_interface.nim b/src/app/modules/main/wallet_section/account_tokens/io_interface.nim index 2510185c3f..77e5080f60 100644 --- a/src/app/modules/main/wallet_section/account_tokens/io_interface.nim +++ b/src/app/modules/main/wallet_section/account_tokens/io_interface.nim @@ -14,7 +14,8 @@ method isLoaded*(self: AccessInterface): bool {.base.} = method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/account_tokens/module.nim b/src/app/modules/main/wallet_section/account_tokens/module.nim index 97d4900ee7..b7e663ed65 100644 --- a/src/app/modules/main/wallet_section/account_tokens/module.nim +++ b/src/app/modules/main/wallet_section/account_tokens/module.nim @@ -1,36 +1,37 @@ import NimQml, sequtils, sugar import eventemitter import ./io_interface, ./view, ./controller, ./item +import ../io_interface as delegate_interface import ../../../../global/global_singleton import ../../../../../app_service/service/wallet_account/service as wallet_account_service export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface events: EventEmitter view: View moduleLoaded: bool controller: controller.AccessInterface currentAccountIndex: int -proc newModule*[T]( - delegate: T, +proc newModule*( + delegate: delegate_interface.AccessInterface, events: EventEmitter, walletAccountService: wallet_account_service.ServiceInterface -): Module[T] = - result = Module[T]() +): Module = + result = Module() result.delegate = delegate result.events = events result.view = newView(result) result.controller = newController(result, walletAccountService) result.moduleLoaded = false -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete -method switchAccount*[T](self: Module[T], accountIndex: int) = +method switchAccount*(self: Module, accountIndex: int) = self.currentAccountIndex = accountIndex let walletAccount = self.controller.getWalletAccount(accountIndex) self.view.setItems( @@ -43,15 +44,22 @@ method switchAccount*[T](self: Module[T], accountIndex: int) = )) ) -method load*[T](self: Module[T]) = +method load*(self: Module) = singletonInstance.engine.setRootContextProperty("walletSectionAccountTokens", newQVariant(self.view)) + + # these connections should be part of the controller's init method self.events.on("walletAccount/currencyUpdated") do(e:Args): self.switchAccount(self.currentAccountIndex) self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args): self.switchAccount(self.currentAccountIndex) - self.moduleLoaded = true + self.controller.init() + self.view.load() -method isLoaded*[T](self: Module[T]): bool = - return self.moduleLoaded \ No newline at end of file +method isLoaded*(self: Module): bool = + return self.moduleLoaded + +method viewDidLoad*(self: Module) = + self.moduleLoaded = true + self.delegate.accountTokensModuleDidLoad() \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/account_tokens/view.nim b/src/app/modules/main/wallet_section/account_tokens/view.nim index 8498ef470a..1d34b64ba2 100644 --- a/src/app/modules/main/wallet_section/account_tokens/view.nim +++ b/src/app/modules/main/wallet_section/account_tokens/view.nim @@ -22,6 +22,9 @@ QtObject: result.model = newModel() result.modelVariant = newQVariant(result.model) + proc load*(self: View) = + self.delegate.viewDidLoad() + proc modelChanged*(self: View) {.signal.} proc getModel(self: View): QVariant {.slot.} = diff --git a/src/app/modules/main/wallet_section/accounts/controller.nim b/src/app/modules/main/wallet_section/accounts/controller.nim index cb25af3d12..d2f4ac1939 100644 --- a/src/app/modules/main/wallet_section/accounts/controller.nim +++ b/src/app/modules/main/wallet_section/accounts/controller.nim @@ -1,41 +1,42 @@ import ./controller_interface +import io_interface import ../../../../../app_service/service/wallet_account/service as wallet_account_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface walletAccountService: wallet_account_service.ServiceInterface -proc newController*[T]( - delegate: T, +proc newController*( + delegate: io_interface.AccessInterface, walletAccountService: wallet_account_service.ServiceInterface -): Controller[T] = - result = Controller[T]() +): Controller = + result = Controller() result.delegate = delegate result.walletAccountService = walletAccountService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard -method getWalletAccounts*[T](self: Controller[T]): seq[wallet_account_service.WalletAccountDto] = +method getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] = return self.walletAccountService.getWalletAccounts() -method generateNewAccount*[T](self: Controller[T], password: string, accountName: string, color: string): string = +method generateNewAccount*(self: Controller, password: string, accountName: string, color: string): string = return self.walletAccountService.generateNewAccount(password, accountName, color) -method addAccountsFromPrivateKey*[T](self: Controller[T], privateKey: string, password: string, accountName: string, color: string): string = +method addAccountsFromPrivateKey*(self: Controller, privateKey: string, password: string, accountName: string, color: string): string = return self.walletAccountService.addAccountsFromPrivateKey(privateKey, password, accountName, color) -method addAccountsFromSeed*[T](self: Controller[T], seedPhrase: string, password: string, accountName: string, color: string): string = +method addAccountsFromSeed*(self: Controller, seedPhrase: string, password: string, accountName: string, color: string): string = return self.walletAccountService.addAccountsFromSeed(seedPhrase, password, accountName, color) -method addWatchOnlyAccount*[T](self: Controller[T], address: string, accountName: string, color: string): string = +method addWatchOnlyAccount*(self: Controller, address: string, accountName: string, color: string): string = return self.walletAccountService.addWatchOnlyAccount(address, accountName, color) -method deleteAccount*[T](self: Controller[T], address: string) = +method deleteAccount*(self: Controller, address: string) = self.walletAccountService.deleteAccount(address) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/accounts/io_interface.nim b/src/app/modules/main/wallet_section/accounts/io_interface.nim index c9ddb67b1d..2969b0d92d 100644 --- a/src/app/modules/main/wallet_section/accounts/io_interface.nim +++ b/src/app/modules/main/wallet_section/accounts/io_interface.nim @@ -29,8 +29,9 @@ method deleteAccount*(self: AccessInterface, address: string) {.base.} = method refreshWalletAccounts*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/accounts/module.nim b/src/app/modules/main/wallet_section/accounts/module.nim index 1b1ba47fcf..2844f1a143 100644 --- a/src/app/modules/main/wallet_section/accounts/module.nim +++ b/src/app/modules/main/wallet_section/accounts/module.nim @@ -2,6 +2,7 @@ import NimQml, sequtils, sugar import eventemitter import ./io_interface, ./view, ./item, ./controller +import ../io_interface as delegate_interface import ../../../../global/global_singleton import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../account_tokens/model as account_tokens @@ -10,34 +11,34 @@ import ../account_tokens/item as account_tokens_item export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface events: EventEmitter view: View controller: controller.AccessInterface moduleLoaded: bool -proc newModule*[T]( - delegate: T, +proc newModule*( + delegate: delegate_interface.AccessInterface, events: EventEmitter, walletAccountService: wallet_account_service.ServiceInterface, -): Module[T] = - result = Module[T]() +): Module = + result = Module() result.delegate = delegate result.events = events result.view = newView(result) - result.controller = controller.newController[Module[T]](result, walletAccountService) + result.controller = controller.newController(result, walletAccountService) result.moduleLoaded = false -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete self.controller.delete -method refreshWalletAccounts*[T](self: Module[T]) = +method refreshWalletAccounts*(self: Module) = let walletAccounts = self.controller.getWalletAccounts() - let items = walletAccounts.map(proc (w: WalletAccountDto): Item = + let items = walletAccounts.map(proc (w: WalletAccountDto): item.Item = let assets = account_tokens.newModel() @@ -66,8 +67,10 @@ method refreshWalletAccounts*[T](self: Module[T]) = self.view.setItems(items) -method load*[T](self: Module[T]) = +method load*(self: Module) = singletonInstance.engine.setRootContextProperty("walletSectionAccounts", newQVariant(self.view)) + + # these connections should be part of the controller's init method self.events.on("walletAccount/accountSaved") do(e:Args): self.refreshWalletAccounts() @@ -82,24 +85,29 @@ method load*[T](self: Module[T]) = self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args): self.refreshWalletAccounts() - - self.refreshWalletAccounts() - self.moduleLoaded = true -method isLoaded*[T](self: Module[T]): bool = + self.controller.init() + self.view.load() + +method isLoaded*(self: Module): bool = return self.moduleLoaded -method generateNewAccount*[T](self: Module[T], password: string, accountName: string, color: string): string = +method viewDidLoad*(self: Module) = + self.refreshWalletAccounts() + self.moduleLoaded = true + self.delegate.accountsModuleDidLoad() + +method generateNewAccount*(self: Module, password: string, accountName: string, color: string): string = return self.controller.generateNewAccount(password, accountName, color) -method addAccountsFromPrivateKey*[T](self: Module[T], privateKey: string, password: string, accountName: string, color: string): string = +method addAccountsFromPrivateKey*(self: Module, privateKey: string, password: string, accountName: string, color: string): string = return self.controller.addAccountsFromPrivateKey(privateKey, password, accountName, color) -method addAccountsFromSeed*[T](self: Module[T], seedPhrase: string, password: string, accountName: string, color: string): string = +method addAccountsFromSeed*(self: Module, seedPhrase: string, password: string, accountName: string, color: string): string = return self.controller.addAccountsFromSeed(seedPhrase, password, accountName, color) -method addWatchOnlyAccount*[T](self: Module[T], address: string, accountName: string, color: string): string = +method addWatchOnlyAccount*(self: Module, address: string, accountName: string, color: string): string = return self.controller.addWatchOnlyAccount(address, accountName, color) -method deleteAccount*[T](self: Module[T], address: string) = +method deleteAccount*(self: Module, address: string) = self.controller.deleteAccount(address) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/accounts/view.nim b/src/app/modules/main/wallet_section/accounts/view.nim index e819c3d37a..fa68d65371 100644 --- a/src/app/modules/main/wallet_section/accounts/view.nim +++ b/src/app/modules/main/wallet_section/accounts/view.nim @@ -23,6 +23,9 @@ QtObject: result.model = newModel() result.modelVariant = newQVariant(result.model) + proc load*(self: View) = + self.delegate.viewDidLoad() + proc modelChanged*(self: View) {.signal.} proc getModel(self: View): QVariant {.slot.} = diff --git a/src/app/modules/main/wallet_section/all_tokens/controller.nim b/src/app/modules/main/wallet_section/all_tokens/controller.nim index 2059ef45ee..0156ce96a1 100644 --- a/src/app/modules/main/wallet_section/all_tokens/controller.nim +++ b/src/app/modules/main/wallet_section/all_tokens/controller.nim @@ -7,43 +7,43 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface + Controller* = ref object of controller_interface.AccessInterface delegate: io_interface.AccessInterface events: EventEmitter tokenService: token_service.Service walletAccountService: wallet_account_service.ServiceInterface -proc newController*[T]( +proc newController*( delegate: io_interface.AccessInterface, events: EventEmitter, tokenService: token_service.Service, walletAccountService: wallet_account_service.ServiceInterface, -): Controller[T] = - result = Controller[T]() +): Controller = + result = Controller() result.events = events result.delegate = delegate result.tokenService = tokenService result.walletAccountService = walletAccountService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = self.events.on(SIGNAL_TOKEN_DETAILS_LOADED) do(e:Args): let args = TokenDetailsLoadedArgs(e) self.delegate.tokenDetailsWereResolved(args.tokenDetails) -method getTokens*[T](self: Controller[T]): seq[token_service.TokenDto] = +method getTokens*(self: Controller): seq[token_service.TokenDto] = return self.tokenService.getTokens() -method addCustomToken*[T](self: Controller[T], address: string, name: string, symbol: string, decimals: int) = +method addCustomToken*(self: Controller, address: string, name: string, symbol: string, decimals: int) = self.tokenService.addCustomToken(address, name, symbol, decimals) -method toggleVisible*[T](self: Controller[T], symbol: string) = +method toggleVisible*(self: Controller, symbol: string) = self.walletAccountService.toggleTokenVisible(symbol) -method removeCustomToken*[T](self: Controller[T], address: string) = +method removeCustomToken*(self: Controller, address: string) = self.tokenService.removeCustomToken(address) -method getTokenDetails*[T](self: Controller[T], address: string) = +method getTokenDetails*(self: Controller, address: string) = self.tokenService.getTokenDetails(address) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/all_tokens/io_interface.nim b/src/app/modules/main/wallet_section/all_tokens/io_interface.nim index 5026e98522..6062ee34d4 100644 --- a/src/app/modules/main/wallet_section/all_tokens/io_interface.nim +++ b/src/app/modules/main/wallet_section/all_tokens/io_interface.nim @@ -29,7 +29,8 @@ method getTokenDetails*(self: AccessInterface, address: string) {.base.} = method tokenDetailsWereResolved*(self: AccessInterface, tokenDetails: string) {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/all_tokens/module.nim b/src/app/modules/main/wallet_section/all_tokens/module.nim index 95280a5c77..347633060e 100644 --- a/src/app/modules/main/wallet_section/all_tokens/module.nim +++ b/src/app/modules/main/wallet_section/all_tokens/module.nim @@ -3,6 +3,7 @@ import NimQml, sequtils, sugar import eventemitter import ./io_interface, ./view, ./controller, ./item +import ../io_interface as delegate_interface import ../../../../global/global_singleton import ../../../../../app_service/service/token/service as token_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service @@ -10,31 +11,31 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface events: EventEmitter view: View controller: controller.AccessInterface moduleLoaded: bool -proc newModule*[T]( - delegate: T, +proc newModule*( + delegate: delegate_interface.AccessInterface, events: EventEmitter, tokenService: token_service.Service, walletAccountService: wallet_account_service.ServiceInterface, -): Module[T] = - result = Module[T]() +): Module = + result = Module() result.delegate = delegate result.events = events result.view = newView(result) - result.controller = controller.newController[Module[T]](result, events, tokenService, walletAccountService) + result.controller = controller.newController(result, events, tokenService, walletAccountService) result.moduleLoaded = false -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete self.controller.delete -method refreshTokens*[T](self: Module[T]) = +method refreshTokens*(self: Module) = let tokens = self.controller.getTokens() self.view.setItems( tokens.map(t => initItem( @@ -48,11 +49,10 @@ method refreshTokens*[T](self: Module[T]) = )) ) -method load*[T](self: Module[T]) = - self.controller.init() +method load*(self: Module) = singletonInstance.engine.setRootContextProperty("walletSectionAllTokens", newQVariant(self.view)) - self.refreshTokens() + # these connections should be part of the controller's init method self.events.on("token/customTokenAdded") do(e:Args): self.refreshTokens() @@ -62,22 +62,28 @@ method load*[T](self: Module[T]) = self.events.on("token/customTokenRemoved") do(e:Args): self.refreshTokens() - self.moduleLoaded = true + self.controller.init() + self.view.load() -method isLoaded*[T](self: Module[T]): bool = +method isLoaded*(self: Module): bool = return self.moduleLoaded -method addCustomToken*[T](self: Module[T], address: string, name: string, symbol: string, decimals: int) = +method viewDidLoad*(self: Module) = + self.refreshTokens() + self.moduleLoaded = true + self.delegate.allTokensModuleDidLoad() + +method addCustomToken*(self: Module, address: string, name: string, symbol: string, decimals: int) = self.controller.addCustomToken(address, name, symbol, decimals) -method toggleVisible*[T](self: Module[T], symbol: string) = +method toggleVisible*(self: Module, symbol: string) = self.controller.toggleVisible(symbol) -method removeCustomToken*[T](self: Module[T], address: string) = +method removeCustomToken*(self: Module, address: string) = self.controller.removeCustomToken(address) -method getTokenDetails*[T](self: Module[T], address: string) = +method getTokenDetails*(self: Module, address: string) = self.controller.getTokenDetails(address) -method tokenDetailsWereResolved*[T](self: Module[T], tokenDetails: string) = +method tokenDetailsWereResolved*(self: Module, tokenDetails: string) = self.view.tokenDetailsWereResolved(tokenDetails) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/all_tokens/view.nim b/src/app/modules/main/wallet_section/all_tokens/view.nim index c92937bf8d..e7251b80f5 100644 --- a/src/app/modules/main/wallet_section/all_tokens/view.nim +++ b/src/app/modules/main/wallet_section/all_tokens/view.nim @@ -26,6 +26,9 @@ QtObject: result.custom = newModel() result.all = newModel() + proc load*(self: View) = + self.delegate.viewDidLoad() + proc allChanged*(self: View) {.signal.} proc getAll(self: View): QVariant {.slot.} = diff --git a/src/app/modules/main/wallet_section/collectibles/collectible/controller.nim b/src/app/modules/main/wallet_section/collectibles/collectible/controller.nim index 272fd10706..7c712cd149 100644 --- a/src/app/modules/main/wallet_section/collectibles/collectible/controller.nim +++ b/src/app/modules/main/wallet_section/collectibles/collectible/controller.nim @@ -1,23 +1,24 @@ import ./controller_interface +import io_interface import ../../../../../../app_service/service/collectible/service as collectible_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface collectibleService: collectible_service.ServiceInterface -proc newController*[T]( - delegate: T, +proc newController*( + delegate: io_interface.AccessInterface, collectibleService: collectible_service.ServiceInterface -): Controller[T] = - result = Controller[T]() +): Controller = + result = Controller() result.delegate = delegate result.collectibleService = collectibleService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/collectible/io_interface.nim b/src/app/modules/main/wallet_section/collectibles/collectible/io_interface.nim index c7ee22a658..4df5c68f1c 100644 --- a/src/app/modules/main/wallet_section/collectibles/collectible/io_interface.nim +++ b/src/app/modules/main/wallet_section/collectibles/collectible/io_interface.nim @@ -11,7 +11,8 @@ method load*(self: AccessInterface) {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/collectibles/collectible/module.nim b/src/app/modules/main/wallet_section/collectibles/collectible/module.nim index fb3b1ecd15..ed5d2824ed 100644 --- a/src/app/modules/main/wallet_section/collectibles/collectible/module.nim +++ b/src/app/modules/main/wallet_section/collectibles/collectible/module.nim @@ -1,30 +1,37 @@ import sequtils, sugar import ./io_interface, ./view, ./controller, ./item +import ../io_interface as delegate_interface import ../../../../../../app_service/service/collectible/service as collectible_service export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface view: View controller: controller.AccessInterface moduleLoaded: bool -proc newModule*[T](delegate: T, collectibleService: collectible_service.ServiceInterface): Module[T] = - result = Module[T]() +proc newModule*(delegate: delegate_interface.AccessInterface, collectibleService: collectible_service.ServiceInterface): + Module = + result = Module() result.delegate = delegate result.view = newView(result) - result.controller = controller.newController[Module[T]](result, collectibleService) + result.controller = controller.newController(result, collectibleService) result.moduleLoaded = false -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete self.controller.delete -method load*[T](self: Module[T]) = - self.moduleLoaded = true +method load*(self: Module) = + self.controller.init() + self.view.load() -method isLoaded*[T](self: Module[T]): bool = +method isLoaded*(self: Module): bool = return self.moduleLoaded + +method viewDidLoad*(self: Module) = + self.moduleLoaded = true + self.delegate.collectibleModuleDidLoad() diff --git a/src/app/modules/main/wallet_section/collectibles/collectible/view.nim b/src/app/modules/main/wallet_section/collectibles/collectible/view.nim index 4bffc4aac7..6799d17f43 100644 --- a/src/app/modules/main/wallet_section/collectibles/collectible/view.nim +++ b/src/app/modules/main/wallet_section/collectibles/collectible/view.nim @@ -23,6 +23,9 @@ QtObject: result.model = newModel() result.modelVariant = newQVariant(result.model) + proc load*(self: View) = + self.delegate.viewDidLoad() + proc modelChanged*(self: View) {.signal.} proc getModel(self: View): QVariant {.slot.} = diff --git a/src/app/modules/main/wallet_section/collectibles/collectibles/controller.nim b/src/app/modules/main/wallet_section/collectibles/collectibles/controller.nim index 6fda112859..b81fb7f858 100644 --- a/src/app/modules/main/wallet_section/collectibles/collectibles/controller.nim +++ b/src/app/modules/main/wallet_section/collectibles/collectibles/controller.nim @@ -1,26 +1,27 @@ import ./controller_interface +import io_interface import ../../../../../../app_service/service/collectible/service as collectible_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface collectibleService: collectible_service.ServiceInterface -proc newController*[T]( - delegate: T, +proc newController*( + delegate: io_interface.AccessInterface, collectibleService: collectible_service.ServiceInterface -): Controller[T] = - result = Controller[T]() +): Controller = + result = Controller() result.delegate = delegate result.collectibleService = collectibleService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard -method fetch*[T](self: Controller[T], address: string, collectionSlug: string): seq[collectible_service.CollectibleDto] = +method fetch*(self: Controller, address: string, collectionSlug: string): seq[collectible_service.CollectibleDto] = return self.collectible_service.getCollectibles(address, collectionSlug) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/collectibles/io_interface.nim b/src/app/modules/main/wallet_section/collectibles/collectibles/io_interface.nim index 69f5c6d027..a03749d78a 100644 --- a/src/app/modules/main/wallet_section/collectibles/collectibles/io_interface.nim +++ b/src/app/modules/main/wallet_section/collectibles/collectibles/io_interface.nim @@ -17,7 +17,8 @@ method fetch*(self: AccessInterface, collectionSlug: string) {.base.} = method setCurrentAddress*(self: AccessInterface, address: string) {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/collectibles/collectibles/module.nim b/src/app/modules/main/wallet_section/collectibles/collectibles/module.nim index 9ee12f3383..ad13b2a281 100644 --- a/src/app/modules/main/wallet_section/collectibles/collectibles/module.nim +++ b/src/app/modules/main/wallet_section/collectibles/collectibles/module.nim @@ -2,42 +2,47 @@ import sequtils, sugar, NimQml import ../../../../../global/global_singleton import ./io_interface, ./view, ./controller, ./item +import ../io_interface as delegate_interface import ../../../../../../app_service/service/collectible/service as collectible_service export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface view: View controller: controller.AccessInterface moduleLoaded: bool currentAddress: string -proc newModule*[T](delegate: T, collectibleService: collectible_service.ServiceInterface): Module[T] = - result = Module[T]() +proc newModule*(delegate: delegate_interface.AccessInterface, collectibleService: collectible_service.ServiceInterface): + Module = + result = Module() result.delegate = delegate result.view = newView(result) - result.controller = controller.newController[Module[T]](result, collectibleService) + result.controller = controller.newController(result, collectibleService) result.moduleLoaded = false -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete self.controller.delete -method load*[T](self: Module[T]) = - singletonInstance.engine.setRootContextProperty( - "walletSectionCollectiblesCollectibles", newQVariant(self.view) - ) - self.moduleLoaded = true +method load*(self: Module) = + singletonInstance.engine.setRootContextProperty("walletSectionCollectiblesCollectibles", newQVariant(self.view)) + self.controller.init() + self.view.load() -method isLoaded*[T](self: Module[T]): bool = +method isLoaded*(self: Module): bool = return self.moduleLoaded -method setCurrentAddress*[T](self: Module[T], address: string) = +method viewDidLoad*(self: Module) = + self.moduleLoaded = true + self.delegate.collectiblesModuleDidLoad() + +method setCurrentAddress*(self: Module, address: string) = self.currentAddress = address -method fetch*[T](self: Module[T], collectionSlug: string) = +method fetch*(self: Module, collectionSlug: string) = let collectibles = self.controller.fetch(self.currentAddress, collectionSlug) let items = collectibles.map(c => initItem( c.id, diff --git a/src/app/modules/main/wallet_section/collectibles/collectibles/view.nim b/src/app/modules/main/wallet_section/collectibles/collectibles/view.nim index acd4ee716b..33ea1cfa8f 100644 --- a/src/app/modules/main/wallet_section/collectibles/collectibles/view.nim +++ b/src/app/modules/main/wallet_section/collectibles/collectibles/view.nim @@ -18,6 +18,9 @@ QtObject: result.QObject.setup result.delegate = delegate result.models = initTable[string, Model]() + + proc load*(self: View) = + self.delegate.viewDidLoad() proc setItems*(self: View, collectionSlug: string, items: seq[Item]) = if not self.models.hasKey(collectionSlug): diff --git a/src/app/modules/main/wallet_section/collectibles/collections/controller.nim b/src/app/modules/main/wallet_section/collectibles/collections/controller.nim index ef21b390ac..b0612c919a 100644 --- a/src/app/modules/main/wallet_section/collectibles/collections/controller.nim +++ b/src/app/modules/main/wallet_section/collectibles/collections/controller.nim @@ -1,26 +1,27 @@ import ./controller_interface +import io_interface import ../../../../../../app_service/service/collectible/service as collectible_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface collectibleService: collectible_service.ServiceInterface -proc newController*[T]( - delegate: T, +proc newController*( + delegate: io_interface.AccessInterface, collectibleService: collectible_service.ServiceInterface -): Controller[T] = - result = Controller[T]() +): Controller = + result = Controller() result.delegate = delegate result.collectibleService = collectibleService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard -method getCollections*[T](self: Controller[T], address: string): seq[collectible_service.CollectionDto] = +method getCollections*(self: Controller, address: string): seq[collectible_service.CollectionDto] = return self.collectibleService.getCollections(address) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/collections/io_interface.nim b/src/app/modules/main/wallet_section/collectibles/collections/io_interface.nim index 961e18392b..aa747f17a2 100644 --- a/src/app/modules/main/wallet_section/collectibles/collections/io_interface.nim +++ b/src/app/modules/main/wallet_section/collectibles/collections/io_interface.nim @@ -14,7 +14,8 @@ method isLoaded*(self: AccessInterface): bool {.base.} = method loadCollections*(self: AccessInterface, address: string) {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/collections/module.nim b/src/app/modules/main/wallet_section/collectibles/collections/module.nim index eb9e2c1cf9..f2ee51019e 100644 --- a/src/app/modules/main/wallet_section/collectibles/collections/module.nim +++ b/src/app/modules/main/wallet_section/collectibles/collections/module.nim @@ -2,38 +2,43 @@ import NimQml, sequtils, sugar import ../../../../../global/global_singleton import ./io_interface, ./view, ./controller, ./item +import ../io_interface as delegate_interface import ../../../../../../app_service/service/collectible/service as collectible_service export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface view: View controller: controller.AccessInterface moduleLoaded: bool -proc newModule*[T](delegate: T, collectibleService: collectible_service.ServiceInterface): Module[T] = - result = Module[T]() +proc newModule*(delegate: delegate_interface.AccessInterface, collectibleService: collectible_service.ServiceInterface): + Module = + result = Module() result.delegate = delegate result.view = newView(result) - result.controller = controller.newController[Module[T]](result, collectibleService) + result.controller = controller.newController(result, collectibleService) result.moduleLoaded = false -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete self.controller.delete -method load*[T](self: Module[T]) = - singletonInstance.engine.setRootContextProperty( - "walletSectionCollectiblesCollections", newQVariant(self.view) - ) - self.moduleLoaded = true +method load*(self: Module) = + singletonInstance.engine.setRootContextProperty("walletSectionCollectiblesCollections", newQVariant(self.view)) + self.controller.init() + self.view.load() -method isLoaded*[T](self: Module[T]): bool = +method isLoaded*(self: Module): bool = return self.moduleLoaded -method loadCollections*[T](self: Module[T], address: string) = +method viewDidLoad*(self: Module) = + self.moduleLoaded = true + self.delegate.collectionsModuleDidLoad() + +method loadCollections*(self: Module, address: string) = let collections = self.controller.getCollections(address) self.view.setItems( collections.map(c => initItem( diff --git a/src/app/modules/main/wallet_section/collectibles/collections/view.nim b/src/app/modules/main/wallet_section/collectibles/collections/view.nim index 4bffc4aac7..6799d17f43 100644 --- a/src/app/modules/main/wallet_section/collectibles/collections/view.nim +++ b/src/app/modules/main/wallet_section/collectibles/collections/view.nim @@ -23,6 +23,9 @@ QtObject: result.model = newModel() result.modelVariant = newQVariant(result.model) + proc load*(self: View) = + self.delegate.viewDidLoad() + proc modelChanged*(self: View) {.signal.} proc getModel(self: View): QVariant {.slot.} = diff --git a/src/app/modules/main/wallet_section/collectibles/controller.nim b/src/app/modules/main/wallet_section/collectibles/controller.nim index 982cd84771..5d742c966f 100644 --- a/src/app/modules/main/wallet_section/collectibles/controller.nim +++ b/src/app/modules/main/wallet_section/collectibles/controller.nim @@ -1,26 +1,27 @@ import ./controller_interface +import io_interface import ../../../../../app_service/service/wallet_account/service as wallet_account_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface walletAccountService: wallet_account_service.ServiceInterface -proc newController*[T]( - delegate: T, +proc newController*( + delegate: io_interface.AccessInterface, walletAccountService: wallet_account_service.ServiceInterface -): Controller[T] = - result = Controller[T]() +): Controller = + result = Controller() result.delegate = delegate result.walletAccountService = walletAccountService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard -method getWalletAccount*[T](self: Controller[T], accountIndex: int): wallet_account_service.WalletAccountDto = +method getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto = return self.walletAccountService.getWalletAccount(accountIndex) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/io_interface.nim b/src/app/modules/main/wallet_section/collectibles/io_interface.nim index 2510185c3f..acfd7ee124 100644 --- a/src/app/modules/main/wallet_section/collectibles/io_interface.nim +++ b/src/app/modules/main/wallet_section/collectibles/io_interface.nim @@ -14,7 +14,12 @@ method isLoaded*(self: AccessInterface): bool {.base.} = method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# Methods called by submodules of this module +method collectibleModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method collectiblesModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method collectionsModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/collectibles/module.nim b/src/app/modules/main/wallet_section/collectibles/module.nim index f43100e9da..5d3f066c69 100644 --- a/src/app/modules/main/wallet_section/collectibles/module.nim +++ b/src/app/modules/main/wallet_section/collectibles/module.nim @@ -1,6 +1,7 @@ import eventemitter import ./io_interface, ./controller +import ../io_interface as delegate_interface import ../../../../../app_service/service/collectible/service as collectible_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service @@ -11,8 +12,8 @@ import ./collectibles/module as collectibles_module export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface moduleLoaded: bool controller: controller.AccessInterface @@ -20,43 +21,58 @@ type collectionsModule: collections_module.AccessInterface collectibleModule: collectible_module.AccessInterface -proc newModule*[T]( - delegate: T, +proc newModule*( + delegate: delegate_interface.AccessInterface, events: EventEmitter, collectibleService: collectible_service.ServiceInterface, walletAccountService: wallet_account_service.ServiceInterface -): Module[T] = - result = Module[T]() +): Module = + result = Module() result.delegate = delegate result.controller = newController(result, walletAccountService) result.moduleLoaded = false - result.collectiblesModule = collectibles_module.newModule[Module[T]]( - result, collectibleService - ) - result.collectionsModule = collectionsModule.newModule[Module[T]]( - result, collectibleService - ) - result.collectibleModule = collectibleModule.newModule[Module[T]]( - result, collectibleService - ) + result.collectiblesModule = collectibles_module.newModule(result, collectibleService) + result.collectionsModule = collectionsModule.newModule(result, collectibleService) + result.collectibleModule = collectibleModule.newModule(result, collectibleService) -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.collectiblesModule.delete self.collectionsModule.delete self.collectibleModule.delete -method load*[T](self: Module[T]) = +method load*(self: Module) = + self.controller.init self.collectiblesModule.load self.collectionsModule.load self.collectibleModule.load - self.moduleLoaded = true - -method isLoaded*[T](self: Module[T]): bool = +method isLoaded*(self: Module): bool = return self.moduleLoaded -method switchAccount*[T](self: Module[T], accountIndex: int) = +proc checkIfModuleDidLoad(self: Module) = + if(not self.collectiblesModule.isLoaded()): + return + + if(not self.collectionsModule.isLoaded()): + return + + if(not self.collectibleModule.isLoaded()): + return + + self.moduleLoaded = true + self.delegate.collectiblesModuleDidLoad() + +method collectibleModuleDidLoad*(self: Module) = + self.checkIfModuleDidLoad() + +method collectiblesModuleDidLoad*(self: Module) = + self.checkIfModuleDidLoad() + +method collectionsModuleDidLoad*(self: Module) = + self.checkIfModuleDidLoad() + +method switchAccount*(self: Module, accountIndex: int) = let account = self.controller.getWalletAccount(accountIndex) self.collectionsModule.loadCollections(account.address) self.collectiblesModule.setCurrentAddress(account.address) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/current_account/controller.nim b/src/app/modules/main/wallet_section/current_account/controller.nim index c3914c17c3..91ec8b460d 100644 --- a/src/app/modules/main/wallet_section/current_account/controller.nim +++ b/src/app/modules/main/wallet_section/current_account/controller.nim @@ -1,29 +1,30 @@ import ./controller_interface +import io_interface import ../../../../../app_service/service/wallet_account/service as wallet_account_service export controller_interface type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface - delegate: T + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface walletAccountService: wallet_account_service.ServiceInterface -proc newController*[T]( - delegate: T, +proc newController*( + delegate: io_interface.AccessInterface, walletAccountService: wallet_account_service.ServiceInterface -): Controller[T] = - result = Controller[T]() +): Controller = + result = Controller() result.delegate = delegate result.walletAccountService = walletAccountService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = discard -method getWalletAccount*[T](self: Controller[T], accountIndex: int): wallet_account_service.WalletAccountDto = +method getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto = return self.walletAccountService.getWalletAccount(accountIndex) -method update*[T](self: Controller[T], address: string, accountName: string, color: string) = +method update*(self: Controller, address: string, accountName: string, color: string) = self.walletAccountService.updateWalletAccount(address, accountName, color) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/current_account/io_interface.nim b/src/app/modules/main/wallet_section/current_account/io_interface.nim index dbc639b9da..68482a9d00 100644 --- a/src/app/modules/main/wallet_section/current_account/io_interface.nim +++ b/src/app/modules/main/wallet_section/current_account/io_interface.nim @@ -17,7 +17,8 @@ method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} = method update*(self: AccessInterface, address: string, accountName: string, color: string) {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/current_account/module.nim b/src/app/modules/main/wallet_section/current_account/module.nim index 719504f562..aa9865344a 100644 --- a/src/app/modules/main/wallet_section/current_account/module.nim +++ b/src/app/modules/main/wallet_section/current_account/module.nim @@ -4,24 +4,25 @@ import ../../../../global/global_singleton import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ./io_interface, ./view, ./controller +import ../io_interface as delegate_interface export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface events: EventEmitter view: View controller: controller.AccessInterface moduleLoaded: bool currentAccountIndex: int -proc newModule*[T]( - delegate: T, +proc newModule*( + delegate: delegate_interface.AccessInterface, events: EventEmitter, walletAccountService: wallet_account_service.ServiceInterface, -): Module[T] = - result = Module[T]() +): Module = + result = Module() result.delegate = delegate result.events = events result.currentAccountIndex = 0 @@ -29,12 +30,13 @@ proc newModule*[T]( result.controller = newController(result, walletAccountService) result.moduleLoaded = false -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete -method load*[T](self: Module[T]) = +method load*(self: Module) = singletonInstance.engine.setRootContextProperty("walletSectionCurrent", newQVariant(self.view)) + # these connections should be part of the controller's init method self.events.on("walletAccount/walletAccountUpdated") do(e:Args): self.switchAccount(self.currentAccountIndex) @@ -44,16 +46,20 @@ method load*[T](self: Module[T]) = self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args): self.switchAccount(self.currentAccountIndex) + self.controller.init() + self.view.load() - self.moduleLoaded = true - -method isLoaded*[T](self: Module[T]): bool = +method isLoaded*(self: Module): bool = return self.moduleLoaded -method switchAccount*[T](self: Module[T], accountIndex: int) = +method viewDidLoad*(self: Module) = + self.moduleLoaded = true + self.delegate.currentAccountModuleDidLoad() + +method switchAccount*(self: Module, accountIndex: int) = self.currentAccountIndex = accountIndex let walletAccount = self.controller.getWalletAccount(accountIndex) self.view.setData(walletAccount) -method update*[T](self: Module[T], address: string, accountName: string, color: string) = +method update*(self: Module, address: string, accountName: string, color: string) = self.controller.update(address, accountName, color) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/current_account/view.nim b/src/app/modules/main/wallet_section/current_account/view.nim index 58b85af9e7..c0c16986da 100644 --- a/src/app/modules/main/wallet_section/current_account/view.nim +++ b/src/app/modules/main/wallet_section/current_account/view.nim @@ -30,6 +30,9 @@ QtObject: result.delegate = delegate result.setup() + proc load*(self: View) = + self.delegate.viewDidLoad() + proc getName(self: View): QVariant {.slot.} = return newQVariant(self.name) diff --git a/src/app/modules/main/wallet_section/io_interface.nim b/src/app/modules/main/wallet_section/io_interface.nim index d8bdf78745..cd9e169d08 100644 --- a/src/app/modules/main/wallet_section/io_interface.nim +++ b/src/app/modules/main/wallet_section/io_interface.nim @@ -19,6 +19,32 @@ method updateCurrency*(self: AccessInterface, currency: string) {.base.} = method setTotalCurrencyBalance*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") + +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +# Methods called by submodules of this module +method accountTokensModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method accountsModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method allTokensModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method collectiblesModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method currentAccountModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method transactionsModuleDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + type ## Abstract class (concept) which must be implemented by object/s used in this ## module. diff --git a/src/app/modules/main/wallet_section/module.nim b/src/app/modules/main/wallet_section/module.nim index 03f03a7722..a1ee556b34 100644 --- a/src/app/modules/main/wallet_section/module.nim +++ b/src/app/modules/main/wallet_section/module.nim @@ -53,12 +53,12 @@ proc newModule*[T]( result.controller = newController(result, settingsService, walletAccountService) result.view = newView(result) - result.accountTokensModule = account_tokens_module.newModule[Module[T]](result, events, walletAccountService) - result.accountsModule = accounts_module.newModule[io_interface.AccessInterface](result, events, walletAccountService) - result.allTokensModule = all_tokens_module.newModule[Module[T]](result, events, tokenService, walletAccountService) - result.collectiblesModule = collectibles_module.newModule[Module[T]](result, events, collectibleService, walletAccountService) - result.currentAccountModule = current_account_module.newModule[Module[T]](result, events, walletAccountService) - result.transactionsModule = transactions_module.newModule[Module[T]](result, events, transactionService, walletAccountService) + result.accountTokensModule = account_tokens_module.newModule(result, events, walletAccountService) + result.accountsModule = accounts_module.newModule(result, events, walletAccountService) + result.allTokensModule = all_tokens_module.newModule(result, events, tokenService, walletAccountService) + result.collectiblesModule = collectibles_module.newModule(result, events, collectibleService, walletAccountService) + result.currentAccountModule = current_account_module.newModule(result, events, walletAccountService) + result.transactionsModule = transactions_module.newModule(result, events, transactionService, walletAccountService) method delete*[T](self: Module[T]) = self.accountTokensModule.delete @@ -94,6 +94,8 @@ method load*[T](self: Module[T]) = self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args): self.setTotalCurrencyBalance() + self.controller.init() + self.view.load() self.accountTokensModule.load() self.accountsModule.load() self.allTokensModule.load() @@ -101,15 +103,55 @@ method load*[T](self: Module[T]) = self.currentAccountModule.load() self.transactionsModule.load() +method isLoaded*[T](self: Module[T]): bool = + return self.moduleLoaded + +proc checkIfModuleDidLoad[T](self: Module[T]) = + if(not self.accountTokensModule.isLoaded()): + return + + if(not self.accountsModule.isLoaded()): + return + + if(not self.allTokensModule.isLoaded()): + return + + if(not self.collectiblesModule.isLoaded()): + return + + if(not self.currentAccountModule.isLoaded()): + return + + if(not self.transactionsModule.isLoaded()): + return + self.switchAccount(0) let currency = self.controller.getCurrency() let signingPhrase = self.controller.getSigningPhrase() let mnemonicBackedUp = self.controller.isMnemonicBackedUp() self.view.setData(currency, signingPhrase, mnemonicBackedUp) self.setTotalCurrencyBalance() + self.moduleLoaded = true self.delegate.walletSectionDidLoad() -method isLoaded*[T](self: Module[T]): bool = - return self.moduleLoaded +method viewDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() +method accountTokensModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +method accountsModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +method allTokensModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +method collectiblesModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +method currentAccountModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() + +method transactionsModuleDidLoad*[T](self: Module[T]) = + self.checkIfModuleDidLoad() diff --git a/src/app/modules/main/wallet_section/transactions/controller.nim b/src/app/modules/main/wallet_section/transactions/controller.nim index a5b8146de0..548be7c60c 100644 --- a/src/app/modules/main/wallet_section/transactions/controller.nim +++ b/src/app/modules/main/wallet_section/transactions/controller.nim @@ -15,32 +15,32 @@ import ../../../../core/[main] import ../../../../core/tasks/[qt, threadpool] type - Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface + Controller* = ref object of controller_interface.AccessInterface delegate: io_interface.AccessInterface events: EventEmitter transactionService: transaction_service.Service walletAccountService: wallet_account_service.ServiceInterface # Forward declaration -method loadTransactions*[T](self: Controller[T], address: string, toBlock: Uint256, limit: int = 20, loadMore: bool = false) -method getWalletAccounts*[T](self: Controller[T]): seq[WalletAccountDto] +method loadTransactions*(self: Controller, address: string, toBlock: Uint256, limit: int = 20, loadMore: bool = false) +method getWalletAccounts*(self: Controller): seq[WalletAccountDto] -proc newController*[T]( +proc newController*( delegate: io_interface.AccessInterface, events: EventEmitter, transactionService: transaction_service.Service, walletAccountService: wallet_account_service.ServiceInterface -): Controller[T] = - result = Controller[T]() +): Controller = + result = Controller() result.events = events result.delegate = delegate result.transactionService = transactionService result.walletAccountService = walletAccountService -method delete*[T](self: Controller[T]) = +method delete*(self: Controller) = discard -method init*[T](self: Controller[T]) = +method init*(self: Controller) = self.events.on(SignalType.Wallet.event) do(e:Args): var data = WalletSignal(e) case data.eventType: @@ -65,17 +65,17 @@ method init*[T](self: Controller[T]) = let args = TransactionsLoadedArgs(e) self.delegate.setTrxHistoryResult(args.transactions, args.address, args.wasFetchMore) -method checkRecentHistory*[T](self: Controller[T]) = +method checkRecentHistory*(self: Controller) = self.transactionService.checkRecentHistory() -method getWalletAccounts*[T](self: Controller[T]): seq[WalletAccountDto] = +method getWalletAccounts*(self: Controller): seq[WalletAccountDto] = self.walletAccountService.getWalletAccounts() -method getWalletAccount*[T](self: Controller[T], accountIndex: int): WalletAccountDto = +method getWalletAccount*(self: Controller, accountIndex: int): WalletAccountDto = return self.walletAccountService.getWalletAccount(accountIndex) -method getAccountByAddress*[T](self: Controller[T], address: string): WalletAccountDto = +method getAccountByAddress*(self: Controller, address: string): WalletAccountDto = self.walletAccountService.getAccountByAddress(address) -method loadTransactions*[T](self: Controller[T], address: string, toBlock: Uint256, limit: int = 20, loadMore: bool = false) = +method loadTransactions*(self: Controller, address: string, toBlock: Uint256, limit: int = 20, loadMore: bool = false) = self.transactionService.loadTransactions(address, toBlock, limit, loadMore) diff --git a/src/app/modules/main/wallet_section/transactions/io_interface.nim b/src/app/modules/main/wallet_section/transactions/io_interface.nim index ff857d90be..1bbd12f6ff 100644 --- a/src/app/modules/main/wallet_section/transactions/io_interface.nim +++ b/src/app/modules/main/wallet_section/transactions/io_interface.nim @@ -37,7 +37,8 @@ method setTrxHistoryResult*(self: AccessInterface, transactions: seq[Transaction method setHistoryFetchState*(self: AccessInterface, addresses: seq[string], isFetching: bool) {.base.} = raise newException(ValueError, "No implementation available") -type - ## Abstract class (concept) which must be implemented by object/s used in this - ## module. - DelegateInterface* = concept c +# View Delegate Interface +# Delegate for the view must be declared here due to use of QtObject and multi +# inheritance, which is not well supported in Nim. +method viewDidLoad*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/transactions/module.nim b/src/app/modules/main/wallet_section/transactions/module.nim index 8be03adf71..95a9b1b34e 100644 --- a/src/app/modules/main/wallet_section/transactions/module.nim +++ b/src/app/modules/main/wallet_section/transactions/module.nim @@ -1,6 +1,7 @@ import NimQml, eventemitter, stint import ./io_interface, ./view, ./controller +import ../io_interface as delegate_interface import ../../../../global/global_singleton import ../../../../../app_service/service/transaction/service as transaction_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service @@ -8,61 +9,62 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou export io_interface type - Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface - delegate: T + Module* = ref object of io_interface.AccessInterface + delegate: delegate_interface.AccessInterface view: View controller: controller.AccessInterface moduleLoaded: bool # Forward declarations -method checkRecentHistory*[T](self: Module[T]) -method getWalletAccounts*[T](self: Module[T]): seq[WalletAccountDto] -method loadTransactions*[T](self: Module[T], address: string, toBlock: string = "0x0", limit: int = 20, loadMore: bool = false) +method checkRecentHistory*(self: Module) +method getWalletAccounts*(self: Module): seq[WalletAccountDto] +method loadTransactions*(self: Module, address: string, toBlock: string = "0x0", limit: int = 20, loadMore: bool = false) -proc newModule*[T]( - delegate: T, +proc newModule*( + delegate: delegate_interface.AccessInterface, events: EventEmitter, transactionService: transaction_service.Service, walletAccountService: wallet_account_service.ServiceInterface -): Module[T] = - result = Module[T]() +): Module = + result = Module() result.delegate = delegate result.view = newView(result) - result.controller = controller.newController[Module[T]](result, events, transactionService, walletAccountService) + result.controller = controller.newController(result, events, transactionService, walletAccountService) result.moduleLoaded = false -method delete*[T](self: Module[T]) = +method delete*(self: Module) = self.view.delete self.controller.delete -method load*[T](self: Module[T]) = +method load*(self: Module) = singletonInstance.engine.setRootContextProperty("walletSectionTransactions", newQVariant(self.view)) - - self.checkRecentHistory() - - let accounts = self.getWalletAccounts() - self.controller.init() - - self.moduleLoaded = true - -method isLoaded*[T](self: Module[T]): bool = + self.view.load() + +method isLoaded*(self: Module): bool = return self.moduleLoaded -method switchAccount*[T](self: Module[T], accountIndex: int) = +method viewDidLoad*(self: Module) = + self.checkRecentHistory() + let accounts = self.getWalletAccounts() + + self.moduleLoaded = true + self.delegate.transactionsModuleDidLoad() + +method switchAccount*(self: Module, accountIndex: int) = let walletAccount = self.controller.getWalletAccount(accountIndex) self.view.switchAccount(walletAccount) -method checkRecentHistory*[T](self: Module[T]) = +method checkRecentHistory*(self: Module) = self.controller.checkRecentHistory() -method getWalletAccounts*[T](self: Module[T]): seq[WalletAccountDto] = +method getWalletAccounts*(self: Module): seq[WalletAccountDto] = self.controller.getWalletAccounts() -method getAccountByAddress*[T](self: Module[T], address: string): WalletAccountDto = +method getAccountByAddress*(self: Module, address: string): WalletAccountDto = self.controller.getAccountByAddress(address) -method loadTransactions*[T](self: Module[T], address: string, toBlock: string = "0x0", limit: int = 20, loadMore: bool = false) = +method loadTransactions*(self: Module, address: string, toBlock: string = "0x0", limit: int = 20, loadMore: bool = false) = let toBlockParsed = stint.fromHex(Uint256, toBlock) let txLimit = if toBlock == "0x0": limit @@ -71,8 +73,8 @@ method loadTransactions*[T](self: Module[T], address: string, toBlock: string = self.controller.loadTransactions(address, toBlockParsed, txLimit, loadMore) -method setTrxHistoryResult*[T](self: Module[T], transactions: seq[TransactionDto], address: string, wasFetchMore: bool) = +method setTrxHistoryResult*(self: Module, transactions: seq[TransactionDto], address: string, wasFetchMore: bool) = self.view.setTrxHistoryResult(transactions, address, wasFetchMore) -method setHistoryFetchState*[T](self: Module[T], addresses: seq[string], isFetching: bool) = +method setHistoryFetchState*(self: Module, addresses: seq[string], isFetching: bool) = self.view.setHistoryFetchStateForAccounts(addresses, isFetching) diff --git a/src/app/modules/main/wallet_section/transactions/view.nim b/src/app/modules/main/wallet_section/transactions/view.nim index 89a5a8ad96..88dfc55e55 100644 --- a/src/app/modules/main/wallet_section/transactions/view.nim +++ b/src/app/modules/main/wallet_section/transactions/view.nim @@ -27,6 +27,9 @@ QtObject: result.model = newModel() result.modelVariant = newQVariant(result.model) + proc load*(self: View) = + self.delegate.viewDidLoad() + proc modelChanged*(self: View) {.signal.} proc getModel(self: View): QVariant {.slot.} = diff --git a/src/app/modules/main/wallet_section/view.nim b/src/app/modules/main/wallet_section/view.nim index 1ce4dc1962..75e1e64699 100644 --- a/src/app/modules/main/wallet_section/view.nim +++ b/src/app/modules/main/wallet_section/view.nim @@ -22,6 +22,9 @@ QtObject: result.delegate = delegate result.setup() + proc load*(self: View) = + self.delegate.viewDidLoad() + proc currentCurrencyChanged*(self: View) {.signal.} proc updateCurrency*(self: View, currency: string) {.slot.} =