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.
This commit is contained in:
Sale Djenic 2021-11-25 14:43:50 +01:00
parent 22595f5032
commit 4c42809a68
76 changed files with 800 additions and 490 deletions

View File

@ -60,7 +60,8 @@ method isLoaded*(self: Module): bool =
return self.moduleLoaded return self.moduleLoaded
method viewDidLoad*(self: Module) = method viewDidLoad*(self: Module) =
self.delegate.chatSectionDidLoad() self.moduleLoaded = true
self.delegate.appSearchDidLoad()
method getModuleAsVariant*(self: Module): QVariant = method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant return self.viewVariant

View File

@ -33,23 +33,18 @@ method delete*(self: Module) =
method load*(self: Module) = method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("bookmarkModule", self.viewVariant) singletonInstance.engine.setRootContextProperty("bookmarkModule", self.viewVariant)
self.view.load() 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 = method isLoaded*(self: Module): bool =
return self.moduleLoaded 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.moduleLoaded = true
self.delegate.bookmarkDidLoad() self.delegate.bookmarkDidLoad()
method providerDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method viewDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method storeBookmark*(self: Module, url: string, name: string) = method storeBookmark*(self: Module, url: string, name: string) =
if url == "": if url == "":
self.view.addItem(initItem(name, url, "")) # These URLs are not stored but added direclty to the UI self.view.addItem(initItem(name, url, "")) # These URLs are not stored but added direclty to the UI

View File

@ -46,21 +46,15 @@ method fetchPermissions(self: Module, dapp: string) =
method load*(self: Module) = method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("dappPermissionsModule", self.viewVariant) singletonInstance.engine.setRootContextProperty("dappPermissionsModule", self.viewVariant)
self.view.load() self.view.load()
self.fetchDapps()
method isLoaded*(self: Module): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded return self.moduleLoaded
proc checkIfModuleDidLoad(self: Module) = method viewDidLoad*(self: Module) =
self.fetchDapps()
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.dappsDidLoad() self.delegate.dappsDidLoad()
method dappsDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method viewDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method hasPermission*(self: Module, hostname: string, permission: string): bool = method hasPermission*(self: Module, hostname: string, permission: string): bool =
self.controller.hasPermission(hostname, permission.toPermission()) self.controller.hasPermission(hostname, permission.toPermission())

View File

@ -48,13 +48,10 @@ method setDappsAddress*(self: Module, value: string) =
method onDappAddressChanged*(self: Module, value: string) = method onDappAddressChanged*(self: Module, value: string) =
self.view.dappsAddress = value self.view.dappsAddress = value
proc checkIfModuleDidLoad(self: Module) = method viewDidLoad*(self: Module) =
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.providerDidLoad() self.delegate.providerDidLoad()
method viewDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method disconnect*(self: Module) = method disconnect*(self: Module) =
self.controller.disconnect() self.controller.disconnect()

View File

@ -10,7 +10,7 @@ include ./private_interfaces/module_controller_delegate_interface
# Defines how submodules of this module communicate with this module # Defines how submodules of this module communicate with this module
include ./private_interfaces/module_chat_section_delegate_interface 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 include ./private_interfaces/module_browser_section_delegate_interface
# This way (using concepts) is used only for the modules managed by AppController # This way (using concepts) is used only for the modules managed by AppController

View File

@ -247,6 +247,9 @@ proc checkIfModuleDidLoad [T](self: Module[T]) =
if(not self.stickersModule.isLoaded()): if(not self.stickersModule.isLoaded()):
return return
if(not self.appSearchModule.isLoaded()):
return
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.mainDidLoad() self.delegate.mainDidLoad()
@ -256,6 +259,12 @@ method chatSectionDidLoad*[T](self: Module[T]) =
method communitySectionDidLoad*[T](self: Module[T]) = method communitySectionDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad() self.checkIfModuleDidLoad()
method appSearchDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
proc stickersDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
proc walletSectionDidLoad*[T](self: Module[T]) = proc walletSectionDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad() self.checkIfModuleDidLoad()

View File

@ -0,0 +1,2 @@
method appSearchDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,5 +1,8 @@
method chatSectionDidLoad*(self: AccessInterface) {.base.} = method chatSectionDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") 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.} = method onActiveChatChange*(self: AccessInterface, sectionId: string, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -1,4 +1,5 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../app_service/service/about/service as about_service import ../../../../../app_service/service/about/service as about_service
# import ./item as item # import ./item as item
@ -6,23 +7,23 @@ import ../../../../../app_service/service/about/service as about_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
aboutService: about_service.ServiceInterface aboutService: about_service.ServiceInterface
proc newController*[T](delegate: T, aboutService: about_service.ServiceInterface): Controller[T] = proc newController*(delegate: io_interface.AccessInterface, aboutService: about_service.ServiceInterface): Controller =
result = Controller[T]() result = Controller()
result.delegate = delegate result.delegate = delegate
result.aboutService = aboutService result.aboutService = aboutService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard discard
method getAppVersion*[T](self: Controller[T]): string = method getAppVersion*(self: Controller): string =
return self.aboutService.getAppVersion() return self.aboutService.getAppVersion()
method getNodeVersion*[T](self: Controller[T]): string = method getNodeVersion*(self: Controller): string =
return self.aboutService.getNodeVersion() return self.aboutService.getNodeVersion()

View File

@ -17,7 +17,8 @@ method getAppVersion*(self: AccessInterface): string {.base.} =
method getNodeVersion*(self: AccessInterface): string {.base.} = method getNodeVersion*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,7 @@
import NimQml, Tables import NimQml, Tables
import ./io_interface, ./view, ./controller import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/about/service as about_service 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 export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
controller: controller.AccessInterface controller: controller.AccessInterface
view: View view: View
viewVariant: QVariant viewVariant: QVariant
moduleLoaded: bool moduleLoaded: bool
proc newModule*[T](delegate: T, aboutService: about_service.ServiceInterface): Module[T] = proc newModule*(delegate: delegate_interface.AccessInterface, aboutService: about_service.ServiceInterface): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) result.view = newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController[Module[T]](result, aboutService) result.controller = controller.newController(result, aboutService)
result.moduleLoaded = false result.moduleLoaded = false
singletonInstance.engine.setRootContextProperty("aboutModule", result.viewVariant) singletonInstance.engine.setRootContextProperty("aboutModule", result.viewVariant)
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
self.moduleLoaded = true self.view.load()
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded 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() return self.controller.getAppVersion()
method getNodeVersion*[T](self: Module[T]): string = method getNodeVersion*(self: Module): string =
return self.controller.getNodeVersion() return self.controller.getNodeVersion()

View File

@ -16,6 +16,9 @@ QtObject:
result.QObject.setup result.QObject.setup
result.delegate = delegate result.delegate = delegate
proc load*(self: View) =
self.delegate.viewDidLoad()
proc getCurrentVersion*(self: View): string {.slot.} = proc getCurrentVersion*(self: View): string {.slot.} =
return self.delegate.getAppVersion() return self.delegate.getAppVersion()

View File

@ -14,26 +14,26 @@ import eventemitter
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
events: EventEmitter events: EventEmitter
contactsService: contacts_service.Service contactsService: contacts_service.Service
accountsService: accounts_service.ServiceInterface accountsService: accounts_service.ServiceInterface
proc newController*[T](delegate: io_interface.AccessInterface, proc newController*(delegate: io_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
contactsService: contacts_service.Service, contactsService: contacts_service.Service,
accountsService: accounts_service.ServiceInterface): Controller[T] = accountsService: accounts_service.ServiceInterface): Controller =
result = Controller[T]() result = Controller()
result.delegate = delegate result.delegate = delegate
result.events = events result.events = events
result.contactsService = contactsService result.contactsService = contactsService
result.accountsService = accountsService result.accountsService = accountsService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
self.events.on(SIGNAL_CONTACT_LOOKED_UP) do(e: Args): self.events.on(SIGNAL_CONTACT_LOOKED_UP) do(e: Args):
var args = ContactArgs(e) var args = ContactArgs(e)
self.delegate.contactLookedUp(args.contactId) self.delegate.contactLookedUp(args.contactId)
@ -58,32 +58,32 @@ method init*[T](self: Controller[T]) =
var args = ContactNicknameUpdatedArgs(e) var args = ContactNicknameUpdatedArgs(e)
self.delegate.contactNicknameChanged(args.contactId, args.nickname) 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() 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) 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) return self.accountsService.generateAlias(publicKey)
method addContact*[T](self: Controller[T], publicKey: string) = method addContact*(self: Controller, publicKey: string) =
self.contactsService.addContact(publicKey) self.contactsService.addContact(publicKey)
method rejectContactRequest*[T](self: Controller[T], publicKey: string) = method rejectContactRequest*(self: Controller, publicKey: string) =
self.contactsService.rejectContactRequest(publicKey) self.contactsService.rejectContactRequest(publicKey)
method unblockContact*[T](self: Controller[T], publicKey: string) = method unblockContact*(self: Controller, publicKey: string) =
self.contactsService.unblockContact(publicKey) self.contactsService.unblockContact(publicKey)
method blockContact*[T](self: Controller[T], publicKey: string) = method blockContact*(self: Controller, publicKey: string) =
self.contactsService.blockContact(publicKey) self.contactsService.blockContact(publicKey)
method removeContact*[T](self: Controller[T], publicKey: string) = method removeContact*(self: Controller, publicKey: string) =
self.contactsService.removeContact(publicKey) 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) self.contactsService.changeContactNickname(publicKey, nickname)
method lookupContact*[T](self: Controller[T], value: string) = method lookupContact*(self: Controller, value: string) =
self.contactsService.lookupContact(value) self.contactsService.lookupContact(value)

View File

@ -64,7 +64,8 @@ method lookupContact*(self: AccessInterface, value: string) {.base.} =
method contactLookedUp*(self: AccessInterface, id: string) {.base.} = method contactLookedUp*(self: AccessInterface, id: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,7 @@
import NimQml, Tables import NimQml, Tables
import io_interface, view, controller, model import io_interface, view, controller, model
import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/contacts/service as contacts_service import ../../../../../app_service/service/contacts/service as contacts_service
@ -12,92 +13,97 @@ import eventemitter
export io_interface export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
controller: controller.AccessInterface controller: controller.AccessInterface
view: View view: View
viewVariant: QVariant viewVariant: QVariant
moduleLoaded: bool moduleLoaded: bool
proc newModule*[T](delegate: T, proc newModule*(delegate: delegate_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
contactsService: contacts_service.Service, contactsService: contacts_service.Service,
accountsService: accounts_service.ServiceInterface): accountsService: accounts_service.ServiceInterface):
Module[T] = Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) result.view = newView(result)
result.viewVariant = newQVariant(result.view) 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 result.moduleLoaded = false
singletonInstance.engine.setRootContextProperty("contactsModule", result.viewVariant) singletonInstance.engine.setRootContextProperty("contactsModule", result.viewVariant)
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
method setContactList*[T](self: Module[T], contacts: seq[ContactsDto]) = method setContactList*(self: Module, contacts: seq[ContactsDto]) =
self.view.model().setContactList(contacts) 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) self.view.model().updateContactList(contacts)
method load*[T](self: Module[T]) = method load*(self: Module) =
self.controller.init() self.controller.init()
let contacts = self.controller.getContacts() self.view.load()
self.setContactList(contacts)
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded 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) self.controller.getContact(id)
method generateAlias*[T](self: Module[T], publicKey: string): string = method generateAlias*(self: Module, publicKey: string): string =
self.controller.generateAlias(publicKey) self.controller.generateAlias(publicKey)
method addContact*[T](self: Module[T], publicKey: string) = method addContact*(self: Module, publicKey: string) =
self.controller.addContact(publicKey) self.controller.addContact(publicKey)
method contactAdded*[T](self: Module[T], contact: ContactsDto) = method contactAdded*(self: Module, contact: ContactsDto) =
self.view.model().contactAdded(contact) 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) # once we refactore a model, we should pass only pk from here (like we have for nickname change)
let contact = self.controller.getContact(publicKey) let contact = self.controller.getContact(publicKey)
self.view.model().contactBlocked(contact) 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) # once we refactore a model, we should pass only pk from here (like we have for nickname change)
let contact = self.controller.getContact(publicKey) let contact = self.controller.getContact(publicKey)
self.view.model().contactUnblocked(contact) 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) # once we refactore a model, we should pass only pk from here (like we have for nickname change)
let contact = self.controller.getContact(publicKey) let contact = self.controller.getContact(publicKey)
self.view.model().contactRemoved(contact) 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) self.view.model().changeNicknameForContactWithId(publicKey, nickname)
method rejectContactRequest*[T](self: Module[T], publicKey: string) = method rejectContactRequest*(self: Module, publicKey: string) =
self.controller.rejectContactRequest(publicKey) self.controller.rejectContactRequest(publicKey)
method unblockContact*[T](self: Module[T], publicKey: string) = method unblockContact*(self: Module, publicKey: string) =
self.controller.unblockContact(publicKey) self.controller.unblockContact(publicKey)
method blockContact*[T](self: Module[T], publicKey: string) = method blockContact*(self: Module, publicKey: string) =
self.controller.blockContact(publicKey) self.controller.blockContact(publicKey)
method removeContact*[T](self: Module[T], publicKey: string) = method removeContact*(self: Module, publicKey: string) =
self.controller.removeContact(publicKey) 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) self.controller.changeContactNickname(publicKey, nickname)
method lookupContact*[T](self: Module[T], value: string) = method lookupContact*(self: Module, value: string) =
self.controller.lookupContact(value) self.controller.lookupContact(value)
method contactLookedUp*[T](self: Module[T], id: string) = method contactLookedUp*(self: Module, id: string) =
self.view.contactLookedUp(id) self.view.contactLookedUp(id)

View File

@ -33,6 +33,9 @@ QtObject:
result.modelVariant = newQVariant(result.model) result.modelVariant = newQVariant(result.model)
result.contactToAdd = ContactsDto() result.contactToAdd = ContactsDto()
proc load*(self: View) =
self.delegate.viewDidLoad()
proc model*(self: View): Model = proc model*(self: View): Model =
return self.model return self.model

View File

@ -29,6 +29,25 @@ method toggleDebug*(self: AccessInterface) {.base.} =
method viewDidLoad*(self: AccessInterface) {.base.} = method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") 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 type
## Abstract class (concept) which must be implemented by object/s used in this ## Abstract class (concept) which must be implemented by object/s used in this
## module. ## module.

View File

@ -1,4 +1,5 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../app_service/service/language/service as language_service import ../../../../../app_service/service/language/service as language_service
# import ./item as item # import ./item as item
@ -6,17 +7,21 @@ import ../../../../../app_service/service/language/service as language_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
languageService: language_service.ServiceInterface languageService: language_service.ServiceInterface
proc newController*[T](delegate: T, languageService: language_service.ServiceInterface): Controller[T] = method init*(self: Controller) =
result = Controller[T]() discard
proc newController*(delegate: io_interface.AccessInterface, languageService: language_service.ServiceInterface):
Controller =
result = Controller()
result.delegate = delegate result.delegate = delegate
result.languageService = languageService result.languageService = languageService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method changeLanguage*[T](self: Controller[T], locale: string) = method changeLanguage*(self: Controller, locale: string) =
self.languageService.setLanguage(locale) self.languageService.setLanguage(locale)

View File

@ -14,7 +14,8 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method changeLanguage*(self: AccessInterface, locale: string) {.base.} = method changeLanguage*(self: AccessInterface, locale: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,7 @@
import NimQml, Tables import NimQml, Tables
import ./io_interface, ./view, ./controller import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/language/service as language_service 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 export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
controller: controller.AccessInterface controller: controller.AccessInterface
view: View view: View
viewVariant: QVariant viewVariant: QVariant
moduleLoaded: bool moduleLoaded: bool
proc newModule*[T](delegate: T, languageService: language_service.ServiceInterface): Module[T] = proc newModule*(delegate: delegate_interface.AccessInterface, languageService: language_service.ServiceInterface): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) result.view = newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController[Module[T]](result, languageService) result.controller = controller.newController(result, languageService)
result.moduleLoaded = false result.moduleLoaded = false
singletonInstance.engine.setRootContextProperty("languageModule", result.viewVariant) singletonInstance.engine.setRootContextProperty("languageModule", result.viewVariant)
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
self.moduleLoaded = true self.controller.init()
self.view.load()
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded 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) self.controller.changeLanguage(locale)

View File

@ -16,5 +16,8 @@ QtObject:
result.QObject.setup result.QObject.setup
result.delegate = delegate result.delegate = delegate
proc load*(self: View) =
self.delegate.viewDidLoad()
proc changeLocale*(self: View, locale: string) {.slot.} = proc changeLocale*(self: View, locale: string) {.slot.} =
self.delegate.changeLanguage(locale) self.delegate.changeLanguage(locale)

View File

@ -1,32 +1,34 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../app_service/service/mnemonic/service as mnemonic_service import ../../../../../app_service/service/mnemonic/service as mnemonic_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
mnemonicService: mnemonic_service.ServiceInterface mnemonicService: mnemonic_service.ServiceInterface
proc newController*[T](delegate: T, mnemonicService: mnemonic_service.ServiceInterface): Controller[T] = proc newController*(delegate: io_interface.AccessInterface, mnemonicService: mnemonic_service.ServiceInterface):
result = Controller[T]() Controller =
result = Controller()
result.delegate = delegate result.delegate = delegate
result.mnemonicService = mnemonicService result.mnemonicService = mnemonicService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard discard
method isBackedUp*[T](self: Controller[T]): bool = method isBackedUp*(self: Controller): bool =
return self.mnemonicService.isBackedUp() return self.mnemonicService.isBackedUp()
method getMnemonic*[T](self: Controller[T]): string = method getMnemonic*(self: Controller): string =
return self.mnemonicService.getMnemonic() return self.mnemonicService.getMnemonic()
method remove*[T](self: Controller[T]) = method remove*(self: Controller) =
self.mnemonicService.remove() self.mnemonicService.remove()
method getWord*[T](self: Controller[T], index: int): string = method getWord*(self: Controller, index: int): string =
return self.mnemonicService.getWord(index) return self.mnemonicService.getWord(index)

View File

@ -23,7 +23,8 @@ method remove*(self: AccessInterface) {.base.} =
method getWord*(self: AccessInterface, index: int): string {.base.} = method getWord*(self: AccessInterface, index: int): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,7 @@
import NimQml, Tables import NimQml, Tables
import ./io_interface, ./view, ./controller import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/mnemonic/service as mnemonic_service 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 export io_interface
type type
Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
controller: controller.AccessInterface controller: controller.AccessInterface
view: View view: View
viewVariant: QVariant viewVariant: QVariant
moduleLoaded: bool moduleLoaded: bool
proc newModule*[T](delegate: T, mnemonicService: mnemonic_service.ServiceInterface): Module[T] = proc newModule*(delegate: delegate_interface.AccessInterface, mnemonicService: mnemonic_service.ServiceInterface): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) result.view = newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController[Module[T]](result, mnemonicService) result.controller = controller.newController(result, mnemonicService)
result.moduleLoaded = false result.moduleLoaded = false
singletonInstance.engine.setRootContextProperty("mnemonicModule", result.viewVariant) singletonInstance.engine.setRootContextProperty("mnemonicModule", result.viewVariant)
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
self.moduleLoaded = true self.controller.init()
self.view.load()
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded 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() return self.controller.isBackedup()
method getMnemonic*[T](self: Module[T]): string = method getMnemonic*(self: Module): string =
return self.controller.getMnemonic() return self.controller.getMnemonic()
method remove*[T](self: Module[T]) = method remove*(self: Module) =
self.controller.remove() self.controller.remove()
method getWord*[T](self: Module[T], index: int): string = method getWord*(self: Module, index: int): string =
return self.controller.getWord(index) return self.controller.getWord(index)

View File

@ -15,6 +15,9 @@ QtObject:
result.QObject.setup result.QObject.setup
result.delegate = delegate result.delegate = delegate
proc load*(self: View) =
self.delegate.viewDidLoad()
proc isBackedUp*(self: View): bool {.slot.} = proc isBackedUp*(self: View): bool {.slot.} =
return self.delegate.isBackedup() return self.delegate.isBackedup()

View File

@ -78,6 +78,7 @@ method delete*[T](self: Module[T]) =
self.controller.delete self.controller.delete
method load*[T](self: Module[T]) = method load*[T](self: Module[T]) =
self.view.load()
self.profileModule.load() self.profileModule.load()
self.contactsModule.load() self.contactsModule.load()
self.languageModule.load() self.languageModule.load()
@ -85,6 +86,32 @@ method load*[T](self: Module[T]) =
self.privacyModule.load() self.privacyModule.load()
self.aboutModule.load() self.aboutModule.load()
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 viewDidLoad*[T](self: Module[T]) =
self.view.setIsTelemetryEnabled(self.controller.isTelemetryEnabled()) self.view.setIsTelemetryEnabled(self.controller.isTelemetryEnabled())
self.view.setIsDebugEnabled(self.controller.isDebugEnabled()) self.view.setIsDebugEnabled(self.controller.isDebugEnabled())
self.view.setIsAutoMessageEnabled(self.controller.isAutoMessageEnabled()) self.view.setIsAutoMessageEnabled(self.controller.isAutoMessageEnabled())
@ -99,14 +126,14 @@ method contactsModuleDidLoad*[T](self: Module[T]) =
method languageModuleDidLoad*[T](self: Module[T]) = method languageModuleDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad() self.checkIfModuleDidLoad()
self.moduleLoaded = true method mnemonicModuleDidLoad*[T](self: Module[T]) =
self.delegate.profileSectionDidLoad() self.checkIfModuleDidLoad()
method isLoaded*[T](self: Module[T]): bool = method privacyModuleDidLoad*[T](self: Module[T]) =
return self.moduleLoaded self.checkIfModuleDidLoad()
method viewDidLoad*(self: Module) = method aboutModuleDidLoad*[T](self: Module[T]) =
discard self.checkIfModuleDidLoad()
method enableDeveloperFeatures*[T](self: Module[T]) = method enableDeveloperFeatures*[T](self: Module[T]) =
self.controller.enableDeveloperFeatures() self.controller.enableDeveloperFeatures()

View File

@ -1,30 +1,32 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../app_service/service/accounts/service as accounts_service import ../../../../../app_service/service/accounts/service as accounts_service
import ../../../../../app_service/service/privacy/service as privacy_service import ../../../../../app_service/service/privacy/service as privacy_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
accountsService: accounts_service.ServiceInterface accountsService: accounts_service.ServiceInterface
privacyService: privacy_service.ServiceInterface privacyService: privacy_service.ServiceInterface
proc newController*[T](delegate: T, privacyService: privacy_service.ServiceInterface, accountsService: accounts_service.ServiceInterface): Controller[T] = proc newController*(delegate: io_interface.AccessInterface, privacyService: privacy_service.ServiceInterface,
result = Controller[T]() accountsService: accounts_service.ServiceInterface): Controller =
result = Controller()
result.delegate = delegate result.delegate = delegate
result.accountsService = accountsService result.accountsService = accountsService
result.privacyService = privacyService result.privacyService = privacyService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard discard
method getLinkPreviewWhitelist*[T](self: Controller[T]): string = method getLinkPreviewWhitelist*(self: Controller): string =
return self.privacyService.getLinkPreviewWhitelist() 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() let loggedInAccount = self.accountsService.getLoggedInAccount()
return self.privacyService.changePassword(loggedInAccount.keyUid, password, newPassword) return self.privacyService.changePassword(loggedInAccount.keyUid, password, newPassword)

View File

@ -17,7 +17,8 @@ method getLinkPreviewWhitelist*(self: AccessInterface): string {.base.} =
method changePassword*(self: AccessInterface, password: string, newPassword: string): bool {.base.} = method changePassword*(self: AccessInterface, password: string, newPassword: string): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,7 @@
import NimQml, Tables import NimQml, Tables
import ./io_interface, ./view, ./controller import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/accounts/service as accounts_service 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 export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
controller: controller.AccessInterface controller: controller.AccessInterface
view: View view: View
viewVariant: QVariant viewVariant: QVariant
moduleLoaded: bool moduleLoaded: bool
proc newModule*[T](delegate: T, privacyService: privacy_service.ServiceInterface, accountsService: accounts_service.ServiceInterface): Module[T] = proc newModule*(delegate: delegate_interface.AccessInterface, privacyService: privacy_service.ServiceInterface, accountsService: accounts_service.ServiceInterface): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) result.view = newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController[Module[T]](result, privacyService, accountsService) result.controller = controller.newController(result, privacyService, accountsService)
result.moduleLoaded = false result.moduleLoaded = false
singletonInstance.engine.setRootContextProperty("privacyModule", result.viewVariant) singletonInstance.engine.setRootContextProperty("privacyModule", result.viewVariant)
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
self.moduleLoaded = true self.controller.init()
self.view.load()
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded 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() 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) return self.controller.changePassword(password, newPassword)

View File

@ -16,6 +16,9 @@ QtObject:
result.QObject.setup result.QObject.setup
result.delegate = delegate result.delegate = delegate
proc load*(self: View) =
self.delegate.viewDidLoad()
proc getLinkPreviewWhitelist*(self: View): string {.slot.} = proc getLinkPreviewWhitelist*(self: View): string {.slot.} =
return self.delegate.getLinkPreviewWhitelist() return self.delegate.getLinkPreviewWhitelist()

View File

@ -1,5 +1,5 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/profile/service as profile_service import ../../../../../app_service/service/profile/service as profile_service
import ../../../../../app_service/service/accounts/service as accounts_service import ../../../../../app_service/service/accounts/service as accounts_service
@ -11,27 +11,27 @@ import status/types/identity_image
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
profileService: profile_service.ServiceInterface profileService: profile_service.ServiceInterface
settingsService: settings_service.ServiceInterface settingsService: settings_service.ServiceInterface
accountsService: accounts_service.ServiceInterface accountsService: accounts_service.ServiceInterface
proc newController*[T](delegate: T, accountsService: accounts_service.ServiceInterface, proc newController*(delegate: io_interface.AccessInterface, accountsService: accounts_service.ServiceInterface,
settingsService: settings_service.ServiceInterface, profileService: profile_service.ServiceInterface): Controller[T] = settingsService: settings_service.ServiceInterface, profileService: profile_service.ServiceInterface): Controller =
result = Controller[T]() result = Controller()
result.delegate = delegate result.delegate = delegate
result.profileService = profileService result.profileService = profileService
result.settingsService = settingsService result.settingsService = settingsService
result.accountsService = accountsService result.accountsService = accountsService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard discard
method getProfile*[T](self: Controller[T]): item.Item = method getProfile*(self: Controller): item.Item =
var appearance = self.settingsService.getAppearance() var appearance = self.settingsService.getAppearance()
var messagesFromContactsOnly = self.settingsService.getMessagesFromContactsOnly() var messagesFromContactsOnly = self.settingsService.getMessagesFromContactsOnly()
@ -60,12 +60,12 @@ method getProfile*[T](self: Controller[T]): item.Item =
return 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) result = self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY)
singletonInstance.userProfile.setThumbnailImage(result.thumbnail) singletonInstance.userProfile.setThumbnailImage(result.thumbnail)
singletonInstance.userProfile.setLargeImage(result.large) 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) result = self.profileService.deleteIdentityImage(address)
singletonInstance.userProfile.setThumbnailImage("") singletonInstance.userProfile.setThumbnailImage("")
singletonInstance.userProfile.setLargeImage("") singletonInstance.userProfile.setLargeImage("")

View File

@ -13,13 +13,15 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") 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") raise newException(ValueError, "No implementation available")
method deleteIdentityImage*(self: AccessInterface, address: string): string {.base.} = method deleteIdentityImage*(self: AccessInterface, address: string): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,7 @@
import NimQml, Tables import NimQml, Tables
import ./io_interface, ./view, ./controller, ./item import ./io_interface, ./view, ./controller, ./item
import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/profile/service as profile_service import ../../../../../app_service/service/profile/service as profile_service
@ -12,37 +13,43 @@ import status/types/identity_image
export io_interface export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
controller: controller.AccessInterface controller: controller.AccessInterface
view: View view: View
viewVariant: QVariant viewVariant: QVariant
moduleLoaded: bool moduleLoaded: bool
proc newModule*[T](delegate: T, accountsService: accounts_service.ServiceInterface, proc newModule*(delegate: delegate_interface.AccessInterface, accountsService: accounts_service.ServiceInterface,
settingsService: settings_service.ServiceInterface, profileService: profile_service.ServiceInterface): Module[T] = settingsService: settings_service.ServiceInterface, profileService: profile_service.ServiceInterface): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) result.view = newView(result)
result.viewVariant = newQVariant(result.view) 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 result.moduleLoaded = false
singletonInstance.engine.setRootContextProperty("profileModule", result.viewVariant) singletonInstance.engine.setRootContextProperty("profileModule", result.viewVariant)
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
let profile = self.controller.getProfile() self.controller.init()
self.view.setProfile(profile) self.view.load()
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded 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) 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) self.controller.deleteIdentityImage(address)

View File

@ -28,6 +28,9 @@ QtObject:
result.model = newModel() result.model = newModel()
result.modelVariant = newQVariant(result.model) result.modelVariant = newQVariant(result.model)
proc load*(self: View) =
self.delegate.viewDidLoad()
proc modelChanged*(self: View) {.signal.} proc modelChanged*(self: View) {.signal.}
proc getModel*(self: View): QVariant {.slot.} = proc getModel*(self: View): QVariant {.slot.} =

View File

@ -22,6 +22,9 @@ QtObject:
result.delegate = delegate result.delegate = delegate
result.setup() result.setup()
proc load*(self: View) =
self.delegate.viewDidLoad()
proc isTelemetryEnabledChanged*(self: View) {.signal.} proc isTelemetryEnabledChanged*(self: View) {.signal.}
proc setIsTelemetryEnabled*(self: View, isTelemetryEnabled: bool) = proc setIsTelemetryEnabled*(self: View, isTelemetryEnabled: bool) =

View File

@ -15,6 +15,9 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") 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.} = 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") raise newException(ValueError, "No implementation available")
@ -73,3 +76,4 @@ type
## Abstract class (concept) which must be implemented by object/s used in this ## Abstract class (concept) which must be implemented by object/s used in this
## module. ## module.
DelegateInterface* = concept c DelegateInterface* = concept c
c.stickersDidLoad()

View File

@ -34,11 +34,15 @@ method delete*[T](self: Module[T]) =
method load*[T](self: Module[T]) = method load*[T](self: Module[T]) =
self.controller.init() self.controller.init()
self.moduleLoaded = true self.view.load()
method isLoaded*[T](self: Module[T]): bool = method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded 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] = 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) return self.controller.buy(packId, address, price, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, password)

View File

@ -21,6 +21,9 @@ QtObject:
result.stickerPacks = newStickerPackList(result.delegate) result.stickerPacks = newStickerPackList(result.delegate)
result.recentStickers = newStickerList(result.delegate) result.recentStickers = newStickerList(result.delegate)
proc load*(self: View) =
self.delegate.viewDidLoad()
proc addStickerPackToList*(self: View, stickerPack: StickerPackDto, isInstalled, isBought, isPending: bool) = proc addStickerPackToList*(self: View, stickerPack: StickerPackDto, isInstalled, isBought, isPending: bool) =
self.stickerPacks.addStickerPackToList( self.stickerPacks.addStickerPackToList(
stickerPack, stickerPack,

View File

@ -1,26 +1,27 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
proc newController*[T]( proc newController*(
delegate: T, delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
): Controller[T] = ): Controller =
result = Controller[T]() result = Controller()
result.delegate = delegate result.delegate = delegate
result.walletAccountService = walletAccountService result.walletAccountService = walletAccountService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard 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) return self.walletAccountService.getWalletAccount(accountIndex)

View File

@ -14,7 +14,8 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} = method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,36 +1,37 @@
import NimQml, sequtils, sugar import NimQml, sequtils, sugar
import eventemitter import eventemitter
import ./io_interface, ./view, ./controller, ./item import ./io_interface, ./view, ./controller, ./item
import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export io_interface export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
events: EventEmitter events: EventEmitter
view: View view: View
moduleLoaded: bool moduleLoaded: bool
controller: controller.AccessInterface controller: controller.AccessInterface
currentAccountIndex: int currentAccountIndex: int
proc newModule*[T]( proc newModule*(
delegate: T, delegate: delegate_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
): Module[T] = ): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.events = events result.events = events
result.view = newView(result) result.view = newView(result)
result.controller = newController(result, walletAccountService) result.controller = newController(result, walletAccountService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
method switchAccount*[T](self: Module[T], accountIndex: int) = method switchAccount*(self: Module, accountIndex: int) =
self.currentAccountIndex = accountIndex self.currentAccountIndex = accountIndex
let walletAccount = self.controller.getWalletAccount(accountIndex) let walletAccount = self.controller.getWalletAccount(accountIndex)
self.view.setItems( 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)) 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.events.on("walletAccount/currencyUpdated") do(e:Args):
self.switchAccount(self.currentAccountIndex) self.switchAccount(self.currentAccountIndex)
self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args): self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args):
self.switchAccount(self.currentAccountIndex) self.switchAccount(self.currentAccountIndex)
self.moduleLoaded = true self.controller.init()
self.view.load()
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded return self.moduleLoaded
method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.accountTokensModuleDidLoad()

View File

@ -22,6 +22,9 @@ QtObject:
result.model = newModel() result.model = newModel()
result.modelVariant = newQVariant(result.model) result.modelVariant = newQVariant(result.model)
proc load*(self: View) =
self.delegate.viewDidLoad()
proc modelChanged*(self: View) {.signal.} proc modelChanged*(self: View) {.signal.}
proc getModel(self: View): QVariant {.slot.} = proc getModel(self: View): QVariant {.slot.} =

View File

@ -1,41 +1,42 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
proc newController*[T]( proc newController*(
delegate: T, delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
): Controller[T] = ): Controller =
result = Controller[T]() result = Controller()
result.delegate = delegate result.delegate = delegate
result.walletAccountService = walletAccountService result.walletAccountService = walletAccountService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard 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() 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) 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) 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) 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) 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) self.walletAccountService.deleteAccount(address)

View File

@ -29,8 +29,9 @@ method deleteAccount*(self: AccessInterface, address: string) {.base.} =
method refreshWalletAccounts*(self: AccessInterface) {.base.} = method refreshWalletAccounts*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -2,6 +2,7 @@ import NimQml, sequtils, sugar
import eventemitter import eventemitter
import ./io_interface, ./view, ./item, ./controller import ./io_interface, ./view, ./item, ./controller
import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../account_tokens/model as account_tokens import ../account_tokens/model as account_tokens
@ -10,34 +11,34 @@ import ../account_tokens/item as account_tokens_item
export io_interface export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
events: EventEmitter events: EventEmitter
view: View view: View
controller: controller.AccessInterface controller: controller.AccessInterface
moduleLoaded: bool moduleLoaded: bool
proc newModule*[T]( proc newModule*(
delegate: T, delegate: delegate_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
walletAccountService: wallet_account_service.ServiceInterface, walletAccountService: wallet_account_service.ServiceInterface,
): Module[T] = ): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.events = events result.events = events
result.view = newView(result) result.view = newView(result)
result.controller = controller.newController[Module[T]](result, walletAccountService) result.controller = controller.newController(result, walletAccountService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
self.controller.delete self.controller.delete
method refreshWalletAccounts*[T](self: Module[T]) = method refreshWalletAccounts*(self: Module) =
let walletAccounts = self.controller.getWalletAccounts() 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() let assets = account_tokens.newModel()
@ -66,8 +67,10 @@ method refreshWalletAccounts*[T](self: Module[T]) =
self.view.setItems(items) self.view.setItems(items)
method load*[T](self: Module[T]) = method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionAccounts", newQVariant(self.view)) 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.events.on("walletAccount/accountSaved") do(e:Args):
self.refreshWalletAccounts() self.refreshWalletAccounts()
@ -83,23 +86,28 @@ method load*[T](self: Module[T]) =
self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args): self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args):
self.refreshWalletAccounts() self.refreshWalletAccounts()
self.refreshWalletAccounts() self.controller.init()
self.moduleLoaded = true self.view.load()
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded 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) 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) 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) 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) 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) self.controller.deleteAccount(address)

View File

@ -23,6 +23,9 @@ QtObject:
result.model = newModel() result.model = newModel()
result.modelVariant = newQVariant(result.model) result.modelVariant = newQVariant(result.model)
proc load*(self: View) =
self.delegate.viewDidLoad()
proc modelChanged*(self: View) {.signal.} proc modelChanged*(self: View) {.signal.}
proc getModel(self: View): QVariant {.slot.} = proc getModel(self: View): QVariant {.slot.} =

View File

@ -7,43 +7,43 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
events: EventEmitter events: EventEmitter
tokenService: token_service.Service tokenService: token_service.Service
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
proc newController*[T]( proc newController*(
delegate: io_interface.AccessInterface, delegate: io_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
tokenService: token_service.Service, tokenService: token_service.Service,
walletAccountService: wallet_account_service.ServiceInterface, walletAccountService: wallet_account_service.ServiceInterface,
): Controller[T] = ): Controller =
result = Controller[T]() result = Controller()
result.events = events result.events = events
result.delegate = delegate result.delegate = delegate
result.tokenService = tokenService result.tokenService = tokenService
result.walletAccountService = walletAccountService result.walletAccountService = walletAccountService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
self.events.on(SIGNAL_TOKEN_DETAILS_LOADED) do(e:Args): self.events.on(SIGNAL_TOKEN_DETAILS_LOADED) do(e:Args):
let args = TokenDetailsLoadedArgs(e) let args = TokenDetailsLoadedArgs(e)
self.delegate.tokenDetailsWereResolved(args.tokenDetails) 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() 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) 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) self.walletAccountService.toggleTokenVisible(symbol)
method removeCustomToken*[T](self: Controller[T], address: string) = method removeCustomToken*(self: Controller, address: string) =
self.tokenService.removeCustomToken(address) self.tokenService.removeCustomToken(address)
method getTokenDetails*[T](self: Controller[T], address: string) = method getTokenDetails*(self: Controller, address: string) =
self.tokenService.getTokenDetails(address) self.tokenService.getTokenDetails(address)

View File

@ -29,7 +29,8 @@ method getTokenDetails*(self: AccessInterface, address: string) {.base.} =
method tokenDetailsWereResolved*(self: AccessInterface, tokenDetails: string) {.base.} = method tokenDetailsWereResolved*(self: AccessInterface, tokenDetails: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -3,6 +3,7 @@ import NimQml, sequtils, sugar
import eventemitter import eventemitter
import ./io_interface, ./view, ./controller, ./item import ./io_interface, ./view, ./controller, ./item
import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/token/service as token_service import ../../../../../app_service/service/token/service as token_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_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 export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
events: EventEmitter events: EventEmitter
view: View view: View
controller: controller.AccessInterface controller: controller.AccessInterface
moduleLoaded: bool moduleLoaded: bool
proc newModule*[T]( proc newModule*(
delegate: T, delegate: delegate_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
tokenService: token_service.Service, tokenService: token_service.Service,
walletAccountService: wallet_account_service.ServiceInterface, walletAccountService: wallet_account_service.ServiceInterface,
): Module[T] = ): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.events = events result.events = events
result.view = newView(result) 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 result.moduleLoaded = false
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
self.controller.delete self.controller.delete
method refreshTokens*[T](self: Module[T]) = method refreshTokens*(self: Module) =
let tokens = self.controller.getTokens() let tokens = self.controller.getTokens()
self.view.setItems( self.view.setItems(
tokens.map(t => initItem( tokens.map(t => initItem(
@ -48,11 +49,10 @@ method refreshTokens*[T](self: Module[T]) =
)) ))
) )
method load*[T](self: Module[T]) = method load*(self: Module) =
self.controller.init()
singletonInstance.engine.setRootContextProperty("walletSectionAllTokens", newQVariant(self.view)) 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.events.on("token/customTokenAdded") do(e:Args):
self.refreshTokens() self.refreshTokens()
@ -62,22 +62,28 @@ method load*[T](self: Module[T]) =
self.events.on("token/customTokenRemoved") do(e:Args): self.events.on("token/customTokenRemoved") do(e:Args):
self.refreshTokens() 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 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) 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) self.controller.toggleVisible(symbol)
method removeCustomToken*[T](self: Module[T], address: string) = method removeCustomToken*(self: Module, address: string) =
self.controller.removeCustomToken(address) self.controller.removeCustomToken(address)
method getTokenDetails*[T](self: Module[T], address: string) = method getTokenDetails*(self: Module, address: string) =
self.controller.getTokenDetails(address) self.controller.getTokenDetails(address)
method tokenDetailsWereResolved*[T](self: Module[T], tokenDetails: string) = method tokenDetailsWereResolved*(self: Module, tokenDetails: string) =
self.view.tokenDetailsWereResolved(tokenDetails) self.view.tokenDetailsWereResolved(tokenDetails)

View File

@ -26,6 +26,9 @@ QtObject:
result.custom = newModel() result.custom = newModel()
result.all = newModel() result.all = newModel()
proc load*(self: View) =
self.delegate.viewDidLoad()
proc allChanged*(self: View) {.signal.} proc allChanged*(self: View) {.signal.}
proc getAll(self: View): QVariant {.slot.} = proc getAll(self: View): QVariant {.slot.} =

View File

@ -1,23 +1,24 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../../app_service/service/collectible/service as collectible_service import ../../../../../../app_service/service/collectible/service as collectible_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
collectibleService: collectible_service.ServiceInterface collectibleService: collectible_service.ServiceInterface
proc newController*[T]( proc newController*(
delegate: T, delegate: io_interface.AccessInterface,
collectibleService: collectible_service.ServiceInterface collectibleService: collectible_service.ServiceInterface
): Controller[T] = ): Controller =
result = Controller[T]() result = Controller()
result.delegate = delegate result.delegate = delegate
result.collectibleService = collectibleService result.collectibleService = collectibleService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard discard

View File

@ -11,7 +11,8 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,30 +1,37 @@
import sequtils, sugar import sequtils, sugar
import ./io_interface, ./view, ./controller, ./item import ./io_interface, ./view, ./controller, ./item
import ../io_interface as delegate_interface
import ../../../../../../app_service/service/collectible/service as collectible_service import ../../../../../../app_service/service/collectible/service as collectible_service
export io_interface export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
view: View view: View
controller: controller.AccessInterface controller: controller.AccessInterface
moduleLoaded: bool moduleLoaded: bool
proc newModule*[T](delegate: T, collectibleService: collectible_service.ServiceInterface): Module[T] = proc newModule*(delegate: delegate_interface.AccessInterface, collectibleService: collectible_service.ServiceInterface):
result = Module[T]() Module =
result = Module()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) result.view = newView(result)
result.controller = controller.newController[Module[T]](result, collectibleService) result.controller = controller.newController(result, collectibleService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
self.controller.delete self.controller.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
self.moduleLoaded = true self.controller.init()
self.view.load()
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded return self.moduleLoaded
method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.collectibleModuleDidLoad()

View File

@ -23,6 +23,9 @@ QtObject:
result.model = newModel() result.model = newModel()
result.modelVariant = newQVariant(result.model) result.modelVariant = newQVariant(result.model)
proc load*(self: View) =
self.delegate.viewDidLoad()
proc modelChanged*(self: View) {.signal.} proc modelChanged*(self: View) {.signal.}
proc getModel(self: View): QVariant {.slot.} = proc getModel(self: View): QVariant {.slot.} =

View File

@ -1,26 +1,27 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../../app_service/service/collectible/service as collectible_service import ../../../../../../app_service/service/collectible/service as collectible_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
collectibleService: collectible_service.ServiceInterface collectibleService: collectible_service.ServiceInterface
proc newController*[T]( proc newController*(
delegate: T, delegate: io_interface.AccessInterface,
collectibleService: collectible_service.ServiceInterface collectibleService: collectible_service.ServiceInterface
): Controller[T] = ): Controller =
result = Controller[T]() result = Controller()
result.delegate = delegate result.delegate = delegate
result.collectibleService = collectibleService result.collectibleService = collectibleService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard 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) return self.collectible_service.getCollectibles(address, collectionSlug)

View File

@ -17,7 +17,8 @@ method fetch*(self: AccessInterface, collectionSlug: string) {.base.} =
method setCurrentAddress*(self: AccessInterface, address: string) {.base.} = method setCurrentAddress*(self: AccessInterface, address: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -2,42 +2,47 @@ import sequtils, sugar, NimQml
import ../../../../../global/global_singleton import ../../../../../global/global_singleton
import ./io_interface, ./view, ./controller, ./item import ./io_interface, ./view, ./controller, ./item
import ../io_interface as delegate_interface
import ../../../../../../app_service/service/collectible/service as collectible_service import ../../../../../../app_service/service/collectible/service as collectible_service
export io_interface export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
view: View view: View
controller: controller.AccessInterface controller: controller.AccessInterface
moduleLoaded: bool moduleLoaded: bool
currentAddress: string currentAddress: string
proc newModule*[T](delegate: T, collectibleService: collectible_service.ServiceInterface): Module[T] = proc newModule*(delegate: delegate_interface.AccessInterface, collectibleService: collectible_service.ServiceInterface):
result = Module[T]() Module =
result = Module()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) result.view = newView(result)
result.controller = controller.newController[Module[T]](result, collectibleService) result.controller = controller.newController(result, collectibleService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
self.controller.delete self.controller.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
singletonInstance.engine.setRootContextProperty( singletonInstance.engine.setRootContextProperty("walletSectionCollectiblesCollectibles", newQVariant(self.view))
"walletSectionCollectiblesCollectibles", newQVariant(self.view) self.controller.init()
) self.view.load()
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded 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 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 collectibles = self.controller.fetch(self.currentAddress, collectionSlug)
let items = collectibles.map(c => initItem( let items = collectibles.map(c => initItem(
c.id, c.id,

View File

@ -19,6 +19,9 @@ QtObject:
result.delegate = delegate result.delegate = delegate
result.models = initTable[string, Model]() result.models = initTable[string, Model]()
proc load*(self: View) =
self.delegate.viewDidLoad()
proc setItems*(self: View, collectionSlug: string, items: seq[Item]) = proc setItems*(self: View, collectionSlug: string, items: seq[Item]) =
if not self.models.hasKey(collectionSlug): if not self.models.hasKey(collectionSlug):
self.models[collectionSlug] = newModel() self.models[collectionSlug] = newModel()

View File

@ -1,26 +1,27 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../../app_service/service/collectible/service as collectible_service import ../../../../../../app_service/service/collectible/service as collectible_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
collectibleService: collectible_service.ServiceInterface collectibleService: collectible_service.ServiceInterface
proc newController*[T]( proc newController*(
delegate: T, delegate: io_interface.AccessInterface,
collectibleService: collectible_service.ServiceInterface collectibleService: collectible_service.ServiceInterface
): Controller[T] = ): Controller =
result = Controller[T]() result = Controller()
result.delegate = delegate result.delegate = delegate
result.collectibleService = collectibleService result.collectibleService = collectibleService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard 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) return self.collectibleService.getCollections(address)

View File

@ -14,7 +14,8 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method loadCollections*(self: AccessInterface, address: string) {.base.} = method loadCollections*(self: AccessInterface, address: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -2,38 +2,43 @@ import NimQml, sequtils, sugar
import ../../../../../global/global_singleton import ../../../../../global/global_singleton
import ./io_interface, ./view, ./controller, ./item import ./io_interface, ./view, ./controller, ./item
import ../io_interface as delegate_interface
import ../../../../../../app_service/service/collectible/service as collectible_service import ../../../../../../app_service/service/collectible/service as collectible_service
export io_interface export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
view: View view: View
controller: controller.AccessInterface controller: controller.AccessInterface
moduleLoaded: bool moduleLoaded: bool
proc newModule*[T](delegate: T, collectibleService: collectible_service.ServiceInterface): Module[T] = proc newModule*(delegate: delegate_interface.AccessInterface, collectibleService: collectible_service.ServiceInterface):
result = Module[T]() Module =
result = Module()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) result.view = newView(result)
result.controller = controller.newController[Module[T]](result, collectibleService) result.controller = controller.newController(result, collectibleService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
self.controller.delete self.controller.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
singletonInstance.engine.setRootContextProperty( singletonInstance.engine.setRootContextProperty("walletSectionCollectiblesCollections", newQVariant(self.view))
"walletSectionCollectiblesCollections", newQVariant(self.view) self.controller.init()
) self.view.load()
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool = method isLoaded*(self: Module): bool =
return self.moduleLoaded 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) let collections = self.controller.getCollections(address)
self.view.setItems( self.view.setItems(
collections.map(c => initItem( collections.map(c => initItem(

View File

@ -23,6 +23,9 @@ QtObject:
result.model = newModel() result.model = newModel()
result.modelVariant = newQVariant(result.model) result.modelVariant = newQVariant(result.model)
proc load*(self: View) =
self.delegate.viewDidLoad()
proc modelChanged*(self: View) {.signal.} proc modelChanged*(self: View) {.signal.}
proc getModel(self: View): QVariant {.slot.} = proc getModel(self: View): QVariant {.slot.} =

View File

@ -1,26 +1,27 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
proc newController*[T]( proc newController*(
delegate: T, delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
): Controller[T] = ): Controller =
result = Controller[T]() result = Controller()
result.delegate = delegate result.delegate = delegate
result.walletAccountService = walletAccountService result.walletAccountService = walletAccountService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard 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) return self.walletAccountService.getWalletAccount(accountIndex)

View File

@ -14,7 +14,12 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} = method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # Methods called by submodules of this module
## Abstract class (concept) which must be implemented by object/s used in this method collectibleModuleDidLoad*(self: AccessInterface) {.base.} =
## module. raise newException(ValueError, "No implementation available")
DelegateInterface* = concept c
method collectiblesModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method collectionsModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,7 @@
import eventemitter import eventemitter
import ./io_interface, ./controller import ./io_interface, ./controller
import ../io_interface as delegate_interface
import ../../../../../app_service/service/collectible/service as collectible_service import ../../../../../app_service/service/collectible/service as collectible_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_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 export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
moduleLoaded: bool moduleLoaded: bool
controller: controller.AccessInterface controller: controller.AccessInterface
@ -20,43 +21,58 @@ type
collectionsModule: collections_module.AccessInterface collectionsModule: collections_module.AccessInterface
collectibleModule: collectible_module.AccessInterface collectibleModule: collectible_module.AccessInterface
proc newModule*[T]( proc newModule*(
delegate: T, delegate: delegate_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
collectibleService: collectible_service.ServiceInterface, collectibleService: collectible_service.ServiceInterface,
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
): Module[T] = ): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.controller = newController(result, walletAccountService) result.controller = newController(result, walletAccountService)
result.moduleLoaded = false result.moduleLoaded = false
result.collectiblesModule = collectibles_module.newModule[Module[T]]( result.collectiblesModule = collectibles_module.newModule(result, collectibleService)
result, collectibleService result.collectionsModule = collectionsModule.newModule(result, collectibleService)
) result.collectibleModule = collectibleModule.newModule(result, collectibleService)
result.collectionsModule = collectionsModule.newModule[Module[T]](
result, collectibleService
)
result.collectibleModule = collectibleModule.newModule[Module[T]](
result, collectibleService
)
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.collectiblesModule.delete self.collectiblesModule.delete
self.collectionsModule.delete self.collectionsModule.delete
self.collectibleModule.delete self.collectibleModule.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
self.controller.init
self.collectiblesModule.load self.collectiblesModule.load
self.collectionsModule.load self.collectionsModule.load
self.collectibleModule.load self.collectibleModule.load
self.moduleLoaded = true method isLoaded*(self: Module): bool =
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded 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) let account = self.controller.getWalletAccount(accountIndex)
self.collectionsModule.loadCollections(account.address) self.collectionsModule.loadCollections(account.address)
self.collectiblesModule.setCurrentAddress(account.address) self.collectiblesModule.setCurrentAddress(account.address)

View File

@ -1,29 +1,30 @@
import ./controller_interface import ./controller_interface
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export controller_interface export controller_interface
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: T delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
proc newController*[T]( proc newController*(
delegate: T, delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
): Controller[T] = ): Controller =
result = Controller[T]() result = Controller()
result.delegate = delegate result.delegate = delegate
result.walletAccountService = walletAccountService result.walletAccountService = walletAccountService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
discard 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) 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) self.walletAccountService.updateWalletAccount(address, accountName, color)

View File

@ -17,7 +17,8 @@ method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
method update*(self: AccessInterface, address: string, accountName: string, color: string) {.base.} = method update*(self: AccessInterface, address: string, accountName: string, color: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -4,24 +4,25 @@ import ../../../../global/global_singleton
import ../../../../../app_service/service/wallet_account/service as wallet_account_service import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ./io_interface, ./view, ./controller import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
export io_interface export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
events: EventEmitter events: EventEmitter
view: View view: View
controller: controller.AccessInterface controller: controller.AccessInterface
moduleLoaded: bool moduleLoaded: bool
currentAccountIndex: int currentAccountIndex: int
proc newModule*[T]( proc newModule*(
delegate: T, delegate: delegate_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
walletAccountService: wallet_account_service.ServiceInterface, walletAccountService: wallet_account_service.ServiceInterface,
): Module[T] = ): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.events = events result.events = events
result.currentAccountIndex = 0 result.currentAccountIndex = 0
@ -29,12 +30,13 @@ proc newModule*[T](
result.controller = newController(result, walletAccountService) result.controller = newController(result, walletAccountService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionCurrent", newQVariant(self.view)) 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.events.on("walletAccount/walletAccountUpdated") do(e:Args):
self.switchAccount(self.currentAccountIndex) self.switchAccount(self.currentAccountIndex)
@ -44,16 +46,20 @@ method load*[T](self: Module[T]) =
self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args): self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args):
self.switchAccount(self.currentAccountIndex) self.switchAccount(self.currentAccountIndex)
self.controller.init()
self.view.load()
self.moduleLoaded = true method isLoaded*(self: Module): bool =
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded 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 self.currentAccountIndex = accountIndex
let walletAccount = self.controller.getWalletAccount(accountIndex) let walletAccount = self.controller.getWalletAccount(accountIndex)
self.view.setData(walletAccount) 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) self.controller.update(address, accountName, color)

View File

@ -30,6 +30,9 @@ QtObject:
result.delegate = delegate result.delegate = delegate
result.setup() result.setup()
proc load*(self: View) =
self.delegate.viewDidLoad()
proc getName(self: View): QVariant {.slot.} = proc getName(self: View): QVariant {.slot.} =
return newQVariant(self.name) return newQVariant(self.name)

View File

@ -19,6 +19,32 @@ method updateCurrency*(self: AccessInterface, currency: string) {.base.} =
method setTotalCurrencyBalance*(self: AccessInterface) {.base.} = method setTotalCurrencyBalance*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") 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 type
## Abstract class (concept) which must be implemented by object/s used in this ## Abstract class (concept) which must be implemented by object/s used in this
## module. ## module.

View File

@ -53,12 +53,12 @@ proc newModule*[T](
result.controller = newController(result, settingsService, walletAccountService) result.controller = newController(result, settingsService, walletAccountService)
result.view = newView(result) result.view = newView(result)
result.accountTokensModule = account_tokens_module.newModule[Module[T]](result, events, walletAccountService) result.accountTokensModule = account_tokens_module.newModule(result, events, walletAccountService)
result.accountsModule = accounts_module.newModule[io_interface.AccessInterface](result, events, walletAccountService) result.accountsModule = accounts_module.newModule(result, events, walletAccountService)
result.allTokensModule = all_tokens_module.newModule[Module[T]](result, events, tokenService, walletAccountService) result.allTokensModule = all_tokens_module.newModule(result, events, tokenService, walletAccountService)
result.collectiblesModule = collectibles_module.newModule[Module[T]](result, events, collectibleService, walletAccountService) result.collectiblesModule = collectibles_module.newModule(result, events, collectibleService, walletAccountService)
result.currentAccountModule = current_account_module.newModule[Module[T]](result, events, walletAccountService) result.currentAccountModule = current_account_module.newModule(result, events, walletAccountService)
result.transactionsModule = transactions_module.newModule[Module[T]](result, events, transactionService, walletAccountService) result.transactionsModule = transactions_module.newModule(result, events, transactionService, walletAccountService)
method delete*[T](self: Module[T]) = method delete*[T](self: Module[T]) =
self.accountTokensModule.delete self.accountTokensModule.delete
@ -94,6 +94,8 @@ method load*[T](self: Module[T]) =
self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args): self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args):
self.setTotalCurrencyBalance() self.setTotalCurrencyBalance()
self.controller.init()
self.view.load()
self.accountTokensModule.load() self.accountTokensModule.load()
self.accountsModule.load() self.accountsModule.load()
self.allTokensModule.load() self.allTokensModule.load()
@ -101,15 +103,55 @@ method load*[T](self: Module[T]) =
self.currentAccountModule.load() self.currentAccountModule.load()
self.transactionsModule.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) self.switchAccount(0)
let currency = self.controller.getCurrency() let currency = self.controller.getCurrency()
let signingPhrase = self.controller.getSigningPhrase() let signingPhrase = self.controller.getSigningPhrase()
let mnemonicBackedUp = self.controller.isMnemonicBackedUp() let mnemonicBackedUp = self.controller.isMnemonicBackedUp()
self.view.setData(currency, signingPhrase, mnemonicBackedUp) self.view.setData(currency, signingPhrase, mnemonicBackedUp)
self.setTotalCurrencyBalance() self.setTotalCurrencyBalance()
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.walletSectionDidLoad() self.delegate.walletSectionDidLoad()
method isLoaded*[T](self: Module[T]): bool = method viewDidLoad*[T](self: Module[T]) =
return self.moduleLoaded 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()

View File

@ -15,32 +15,32 @@ import ../../../../core/[main]
import ../../../../core/tasks/[qt, threadpool] import ../../../../core/tasks/[qt, threadpool]
type type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
events: EventEmitter events: EventEmitter
transactionService: transaction_service.Service transactionService: transaction_service.Service
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
# Forward declaration # Forward declaration
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)
method getWalletAccounts*[T](self: Controller[T]): seq[WalletAccountDto] method getWalletAccounts*(self: Controller): seq[WalletAccountDto]
proc newController*[T]( proc newController*(
delegate: io_interface.AccessInterface, delegate: io_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
transactionService: transaction_service.Service, transactionService: transaction_service.Service,
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
): Controller[T] = ): Controller =
result = Controller[T]() result = Controller()
result.events = events result.events = events
result.delegate = delegate result.delegate = delegate
result.transactionService = transactionService result.transactionService = transactionService
result.walletAccountService = walletAccountService result.walletAccountService = walletAccountService
method delete*[T](self: Controller[T]) = method delete*(self: Controller) =
discard discard
method init*[T](self: Controller[T]) = method init*(self: Controller) =
self.events.on(SignalType.Wallet.event) do(e:Args): self.events.on(SignalType.Wallet.event) do(e:Args):
var data = WalletSignal(e) var data = WalletSignal(e)
case data.eventType: case data.eventType:
@ -66,17 +66,17 @@ method init*[T](self: Controller[T]) =
let args = TransactionsLoadedArgs(e) let args = TransactionsLoadedArgs(e)
self.delegate.setTrxHistoryResult(args.transactions, args.address, args.wasFetchMore) self.delegate.setTrxHistoryResult(args.transactions, args.address, args.wasFetchMore)
method checkRecentHistory*[T](self: Controller[T]) = method checkRecentHistory*(self: Controller) =
self.transactionService.checkRecentHistory() self.transactionService.checkRecentHistory()
method getWalletAccounts*[T](self: Controller[T]): seq[WalletAccountDto] = method getWalletAccounts*(self: Controller): seq[WalletAccountDto] =
self.walletAccountService.getWalletAccounts() self.walletAccountService.getWalletAccounts()
method getWalletAccount*[T](self: Controller[T], accountIndex: int): WalletAccountDto = method getWalletAccount*(self: Controller, accountIndex: int): WalletAccountDto =
return self.walletAccountService.getWalletAccount(accountIndex) 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) 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) self.transactionService.loadTransactions(address, toBlock, limit, loadMore)

View File

@ -37,7 +37,8 @@ method setTrxHistoryResult*(self: AccessInterface, transactions: seq[Transaction
method setHistoryFetchState*(self: AccessInterface, addresses: seq[string], isFetching: bool) {.base.} = method setHistoryFetchState*(self: AccessInterface, addresses: seq[string], isFetching: bool) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
type # View Delegate Interface
## Abstract class (concept) which must be implemented by object/s used in this # Delegate for the view must be declared here due to use of QtObject and multi
## module. # inheritance, which is not well supported in Nim.
DelegateInterface* = concept c method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,7 @@
import NimQml, eventemitter, stint import NimQml, eventemitter, stint
import ./io_interface, ./view, ./controller import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/transaction/service as transaction_service import ../../../../../app_service/service/transaction/service as transaction_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_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 export io_interface
type type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: T delegate: delegate_interface.AccessInterface
view: View view: View
controller: controller.AccessInterface controller: controller.AccessInterface
moduleLoaded: bool moduleLoaded: bool
# Forward declarations # Forward declarations
method checkRecentHistory*[T](self: Module[T]) method checkRecentHistory*(self: Module)
method getWalletAccounts*[T](self: Module[T]): seq[WalletAccountDto] method getWalletAccounts*(self: Module): seq[WalletAccountDto]
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)
proc newModule*[T]( proc newModule*(
delegate: T, delegate: delegate_interface.AccessInterface,
events: EventEmitter, events: EventEmitter,
transactionService: transaction_service.Service, transactionService: transaction_service.Service,
walletAccountService: wallet_account_service.ServiceInterface walletAccountService: wallet_account_service.ServiceInterface
): Module[T] = ): Module =
result = Module[T]() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) 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 result.moduleLoaded = false
method delete*[T](self: Module[T]) = method delete*(self: Module) =
self.view.delete self.view.delete
self.controller.delete self.controller.delete
method load*[T](self: Module[T]) = method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionTransactions", newQVariant(self.view)) singletonInstance.engine.setRootContextProperty("walletSectionTransactions", newQVariant(self.view))
self.checkRecentHistory()
let accounts = self.getWalletAccounts()
self.controller.init() self.controller.init()
self.view.load()
self.moduleLoaded = true method isLoaded*(self: Module): bool =
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded 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) let walletAccount = self.controller.getWalletAccount(accountIndex)
self.view.switchAccount(walletAccount) self.view.switchAccount(walletAccount)
method checkRecentHistory*[T](self: Module[T]) = method checkRecentHistory*(self: Module) =
self.controller.checkRecentHistory() self.controller.checkRecentHistory()
method getWalletAccounts*[T](self: Module[T]): seq[WalletAccountDto] = method getWalletAccounts*(self: Module): seq[WalletAccountDto] =
self.controller.getWalletAccounts() self.controller.getWalletAccounts()
method getAccountByAddress*[T](self: Module[T], address: string): WalletAccountDto = method getAccountByAddress*(self: Module, address: string): WalletAccountDto =
self.controller.getAccountByAddress(address) 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 toBlockParsed = stint.fromHex(Uint256, toBlock)
let txLimit = if toBlock == "0x0": let txLimit = if toBlock == "0x0":
limit limit
@ -71,10 +73,10 @@ method loadTransactions*[T](self: Module[T], address: string, toBlock: string =
self.controller.loadTransactions(address, toBlockParsed, txLimit, loadMore) 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) 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) self.view.setHistoryFetchStateForAccounts(addresses, isFetching)
method setIsNonArchivalNode*[T](self: Module[T], isNonArchivalNode: bool) = method setIsNonArchivalNode*[T](self: Module[T], isNonArchivalNode: bool) =

View File

@ -28,6 +28,9 @@ QtObject:
result.model = newModel() result.model = newModel()
result.modelVariant = newQVariant(result.model) result.modelVariant = newQVariant(result.model)
proc load*(self: View) =
self.delegate.viewDidLoad()
proc modelChanged*(self: View) {.signal.} proc modelChanged*(self: View) {.signal.}
proc getModel(self: View): QVariant {.slot.} = proc getModel(self: View): QVariant {.slot.} =

View File

@ -22,6 +22,9 @@ QtObject:
result.delegate = delegate result.delegate = delegate
result.setup() result.setup()
proc load*(self: View) =
self.delegate.viewDidLoad()
proc currentCurrencyChanged*(self: View) {.signal.} proc currentCurrencyChanged*(self: View) {.signal.}
proc updateCurrency*(self: View, currency: string) {.slot.} = proc updateCurrency*(self: View, currency: string) {.slot.} =