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 792397987c
commit 10268ec3c4
76 changed files with 810 additions and 493 deletions

View File

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

View File

@ -33,23 +33,18 @@ method delete*(self: Module) =
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("bookmarkModule", self.viewVariant)
self.view.load()
let bookmarks = self.controller.getBookmarks()
for b in bookmarks:
self.view.addItem(initItem(b.name, b.url, b.imageUrl))
method isLoaded*(self: Module): bool =
return self.moduleLoaded
proc checkIfModuleDidLoad(self: Module) =
method viewDidLoad*(self: Module) =
let bookmarks = self.controller.getBookmarks()
for b in bookmarks:
self.view.addItem(initItem(b.name, b.url, b.imageUrl))
self.moduleLoaded = true
self.delegate.bookmarkDidLoad()
method providerDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method viewDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method storeBookmark*(self: Module, url: string, name: string) =
if url == "":
self.view.addItem(initItem(name, url, "")) # These URLs are not stored but added direclty to the UI

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,6 +29,25 @@ method toggleDebug*(self: AccessInterface) {.base.} =
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# Methods called by submodules of this module
method profileModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method contactsModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method languageModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method mnemonicModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method privacyModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method aboutModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -78,6 +78,7 @@ method delete*[T](self: Module[T]) =
self.controller.delete
method load*[T](self: Module[T]) =
self.view.load()
self.profileModule.load()
self.contactsModule.load()
self.languageModule.load()
@ -85,18 +86,54 @@ method load*[T](self: Module[T]) =
self.privacyModule.load()
self.aboutModule.load()
self.view.setIsTelemetryEnabled(self.controller.isTelemetryEnabled())
self.view.setIsDebugEnabled(self.controller.isDebugEnabled())
self.view.setIsAutoMessageEnabled(self.controller.isAutoMessageEnabled())
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded
proc checkIfModuleDidLoad[T](self: Module[T]) =
if(not self.profileModule.isLoaded()):
return
if(not self.contactsModule.isLoaded()):
return
if(not self.languageModule.isLoaded()):
return
if(not self.mnemonicModule.isLoaded()):
return
if(not self.privacyModule.isLoaded()):
return
if(not self.aboutModule.isLoaded()):
return
self.moduleLoaded = true
self.delegate.profileSectionDidLoad()
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded
method viewDidLoad*[T](self: Module[T]) =
self.view.setIsTelemetryEnabled(self.controller.isTelemetryEnabled())
self.view.setIsDebugEnabled(self.controller.isDebugEnabled())
self.view.setIsAutoMessageEnabled(self.controller.isAutoMessageEnabled())
self.checkIfModuleDidLoad()
method viewDidLoad*(self: Module) =
discard
method profileModuleDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
method contactsModuleDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
method languageModuleDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
method mnemonicModuleDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
method privacyModuleDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
method aboutModuleDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
method enableDeveloperFeatures*[T](self: Module[T]) =
self.controller.enableDeveloperFeatures()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -15,6 +15,9 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method buy*(self: AccessInterface, packId: int, address: string, price: string, gas: string, gasPrice: string, maxPriorityFeePerGas: string, maxFeePerGas: string, password: string): tuple[response: string, success: bool] {.base.} =
raise newException(ValueError, "No implementation available")
@ -67,3 +70,4 @@ type
## Abstract class (concept) which must be implemented by object/s used in this
## module.
DelegateInterface* = concept c
c.stickersDidLoad()

View File

@ -34,11 +34,15 @@ method delete*[T](self: Module[T]) =
method load*[T](self: Module[T]) =
self.controller.init()
self.moduleLoaded = true
self.view.load()
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded
method viewDidLoad*[T](self: Module[T]) =
self.moduleLoaded = true
self.delegate.stickersDidLoad()
method buy*[T](self: Module[T], packId: int, address: string, price: string, gas: string, gasPrice: string, maxPriorityFeePerGas: string, maxFeePerGas: string, password: string): tuple[response: string, success: bool] =
return self.controller.buy(packId, address, price, gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, password)

View File

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

View File

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

View File

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

View File

@ -1,36 +1,37 @@
import NimQml, sequtils, sugar
import eventemitter
import ./io_interface, ./view, ./controller, ./item
import ../io_interface as delegate_interface
import ../../../../global/global_singleton
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export io_interface
type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
delegate: T
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
events: EventEmitter
view: View
moduleLoaded: bool
controller: controller.AccessInterface
currentAccountIndex: int
proc newModule*[T](
delegate: T,
proc newModule*(
delegate: delegate_interface.AccessInterface,
events: EventEmitter,
walletAccountService: wallet_account_service.ServiceInterface
): Module[T] =
result = Module[T]()
): Module =
result = Module()
result.delegate = delegate
result.events = events
result.view = newView(result)
result.controller = newController(result, walletAccountService)
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
method delete*(self: Module) =
self.view.delete
method switchAccount*[T](self: Module[T], accountIndex: int) =
method switchAccount*(self: Module, accountIndex: int) =
self.currentAccountIndex = accountIndex
let walletAccount = self.controller.getWalletAccount(accountIndex)
self.view.setItems(
@ -43,15 +44,22 @@ method switchAccount*[T](self: Module[T], accountIndex: int) =
))
)
method load*[T](self: Module[T]) =
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionAccountTokens", newQVariant(self.view))
# these connections should be part of the controller's init method
self.events.on("walletAccount/currencyUpdated") do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args):
self.switchAccount(self.currentAccountIndex)
self.moduleLoaded = true
self.controller.init()
self.view.load()
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.accountTokensModuleDidLoad()

View File

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

View File

@ -1,41 +1,42 @@
import ./controller_interface
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export controller_interface
type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface
delegate: T
Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.ServiceInterface
proc newController*[T](
delegate: T,
proc newController*(
delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.ServiceInterface
): Controller[T] =
result = Controller[T]()
): Controller =
result = Controller()
result.delegate = delegate
result.walletAccountService = walletAccountService
method delete*[T](self: Controller[T]) =
method delete*(self: Controller) =
discard
method init*[T](self: Controller[T]) =
method init*(self: Controller) =
discard
method getWalletAccounts*[T](self: Controller[T]): seq[wallet_account_service.WalletAccountDto] =
method getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] =
return self.walletAccountService.getWalletAccounts()
method generateNewAccount*[T](self: Controller[T], password: string, accountName: string, color: string): string =
method generateNewAccount*(self: Controller, password: string, accountName: string, color: string): string =
return self.walletAccountService.generateNewAccount(password, accountName, color)
method addAccountsFromPrivateKey*[T](self: Controller[T], privateKey: string, password: string, accountName: string, color: string): string =
method addAccountsFromPrivateKey*(self: Controller, privateKey: string, password: string, accountName: string, color: string): string =
return self.walletAccountService.addAccountsFromPrivateKey(privateKey, password, accountName, color)
method addAccountsFromSeed*[T](self: Controller[T], seedPhrase: string, password: string, accountName: string, color: string): string =
method addAccountsFromSeed*(self: Controller, seedPhrase: string, password: string, accountName: string, color: string): string =
return self.walletAccountService.addAccountsFromSeed(seedPhrase, password, accountName, color)
method addWatchOnlyAccount*[T](self: Controller[T], address: string, accountName: string, color: string): string =
method addWatchOnlyAccount*(self: Controller, address: string, accountName: string, color: string): string =
return self.walletAccountService.addWatchOnlyAccount(address, accountName, color)
method deleteAccount*[T](self: Controller[T], address: string) =
method deleteAccount*(self: Controller, address: string) =
self.walletAccountService.deleteAccount(address)

View File

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

View File

@ -2,6 +2,7 @@ import NimQml, sequtils, sugar
import eventemitter
import ./io_interface, ./view, ./item, ./controller
import ../io_interface as delegate_interface
import ../../../../global/global_singleton
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../account_tokens/model as account_tokens
@ -10,34 +11,34 @@ import ../account_tokens/item as account_tokens_item
export io_interface
type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
delegate: T
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
events: EventEmitter
view: View
controller: controller.AccessInterface
moduleLoaded: bool
proc newModule*[T](
delegate: T,
proc newModule*(
delegate: delegate_interface.AccessInterface,
events: EventEmitter,
walletAccountService: wallet_account_service.ServiceInterface,
): Module[T] =
result = Module[T]()
): Module =
result = Module()
result.delegate = delegate
result.events = events
result.view = newView(result)
result.controller = controller.newController[Module[T]](result, walletAccountService)
result.controller = controller.newController(result, walletAccountService)
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
method delete*(self: Module) =
self.view.delete
self.controller.delete
method refreshWalletAccounts*[T](self: Module[T]) =
method refreshWalletAccounts*(self: Module) =
let walletAccounts = self.controller.getWalletAccounts()
let items = walletAccounts.map(proc (w: WalletAccountDto): Item =
let items = walletAccounts.map(proc (w: WalletAccountDto): item.Item =
let assets = account_tokens.newModel()
@ -66,8 +67,10 @@ method refreshWalletAccounts*[T](self: Module[T]) =
self.view.setItems(items)
method load*[T](self: Module[T]) =
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionAccounts", newQVariant(self.view))
# these connections should be part of the controller's init method
self.events.on("walletAccount/accountSaved") do(e:Args):
self.refreshWalletAccounts()
@ -82,24 +85,29 @@ method load*[T](self: Module[T]) =
self.events.on("walletAccount/tokenVisibilityToggled") do(e:Args):
self.refreshWalletAccounts()
self.refreshWalletAccounts()
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool =
self.controller.init()
self.view.load()
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method generateNewAccount*[T](self: Module[T], password: string, accountName: string, color: string): string =
method viewDidLoad*(self: Module) =
self.refreshWalletAccounts()
self.moduleLoaded = true
self.delegate.accountsModuleDidLoad()
method generateNewAccount*(self: Module, password: string, accountName: string, color: string): string =
return self.controller.generateNewAccount(password, accountName, color)
method addAccountsFromPrivateKey*[T](self: Module[T], privateKey: string, password: string, accountName: string, color: string): string =
method addAccountsFromPrivateKey*(self: Module, privateKey: string, password: string, accountName: string, color: string): string =
return self.controller.addAccountsFromPrivateKey(privateKey, password, accountName, color)
method addAccountsFromSeed*[T](self: Module[T], seedPhrase: string, password: string, accountName: string, color: string): string =
method addAccountsFromSeed*(self: Module, seedPhrase: string, password: string, accountName: string, color: string): string =
return self.controller.addAccountsFromSeed(seedPhrase, password, accountName, color)
method addWatchOnlyAccount*[T](self: Module[T], address: string, accountName: string, color: string): string =
method addWatchOnlyAccount*(self: Module, address: string, accountName: string, color: string): string =
return self.controller.addWatchOnlyAccount(address, accountName, color)
method deleteAccount*[T](self: Module[T], address: string) =
method deleteAccount*(self: Module, address: string) =
self.controller.deleteAccount(address)

View File

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

View File

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

View File

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

View File

@ -3,6 +3,7 @@ import NimQml, sequtils, sugar
import eventemitter
import ./io_interface, ./view, ./controller, ./item
import ../io_interface as delegate_interface
import ../../../../global/global_singleton
import ../../../../../app_service/service/token/service as token_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
@ -10,31 +11,31 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou
export io_interface
type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
delegate: T
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
events: EventEmitter
view: View
controller: controller.AccessInterface
moduleLoaded: bool
proc newModule*[T](
delegate: T,
proc newModule*(
delegate: delegate_interface.AccessInterface,
events: EventEmitter,
tokenService: token_service.Service,
walletAccountService: wallet_account_service.ServiceInterface,
): Module[T] =
result = Module[T]()
): Module =
result = Module()
result.delegate = delegate
result.events = events
result.view = newView(result)
result.controller = controller.newController[Module[T]](result, events, tokenService, walletAccountService)
result.controller = controller.newController(result, events, tokenService, walletAccountService)
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
method delete*(self: Module) =
self.view.delete
self.controller.delete
method refreshTokens*[T](self: Module[T]) =
method refreshTokens*(self: Module) =
let tokens = self.controller.getTokens()
self.view.setItems(
tokens.map(t => initItem(
@ -48,11 +49,10 @@ method refreshTokens*[T](self: Module[T]) =
))
)
method load*[T](self: Module[T]) =
self.controller.init()
method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionAllTokens", newQVariant(self.view))
self.refreshTokens()
# these connections should be part of the controller's init method
self.events.on("token/customTokenAdded") do(e:Args):
self.refreshTokens()
@ -62,22 +62,28 @@ method load*[T](self: Module[T]) =
self.events.on("token/customTokenRemoved") do(e:Args):
self.refreshTokens()
self.moduleLoaded = true
self.controller.init()
self.view.load()
method isLoaded*[T](self: Module[T]): bool =
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method addCustomToken*[T](self: Module[T], address: string, name: string, symbol: string, decimals: int) =
method viewDidLoad*(self: Module) =
self.refreshTokens()
self.moduleLoaded = true
self.delegate.allTokensModuleDidLoad()
method addCustomToken*(self: Module, address: string, name: string, symbol: string, decimals: int) =
self.controller.addCustomToken(address, name, symbol, decimals)
method toggleVisible*[T](self: Module[T], symbol: string) =
method toggleVisible*(self: Module, symbol: string) =
self.controller.toggleVisible(symbol)
method removeCustomToken*[T](self: Module[T], address: string) =
method removeCustomToken*(self: Module, address: string) =
self.controller.removeCustomToken(address)
method getTokenDetails*[T](self: Module[T], address: string) =
method getTokenDetails*(self: Module, address: string) =
self.controller.getTokenDetails(address)
method tokenDetailsWereResolved*[T](self: Module[T], tokenDetails: string) =
method tokenDetailsWereResolved*(self: Module, tokenDetails: string) =
self.view.tokenDetailsWereResolved(tokenDetails)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
import eventemitter
import ./io_interface, ./controller
import ../io_interface as delegate_interface
import ../../../../../app_service/service/collectible/service as collectible_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
@ -11,8 +12,8 @@ import ./collectibles/module as collectibles_module
export io_interface
type
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
delegate: T
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
moduleLoaded: bool
controller: controller.AccessInterface
@ -20,43 +21,58 @@ type
collectionsModule: collections_module.AccessInterface
collectibleModule: collectible_module.AccessInterface
proc newModule*[T](
delegate: T,
proc newModule*(
delegate: delegate_interface.AccessInterface,
events: EventEmitter,
collectibleService: collectible_service.ServiceInterface,
walletAccountService: wallet_account_service.ServiceInterface
): Module[T] =
result = Module[T]()
): Module =
result = Module()
result.delegate = delegate
result.controller = newController(result, walletAccountService)
result.moduleLoaded = false
result.collectiblesModule = collectibles_module.newModule[Module[T]](
result, collectibleService
)
result.collectionsModule = collectionsModule.newModule[Module[T]](
result, collectibleService
)
result.collectibleModule = collectibleModule.newModule[Module[T]](
result, collectibleService
)
result.collectiblesModule = collectibles_module.newModule(result, collectibleService)
result.collectionsModule = collectionsModule.newModule(result, collectibleService)
result.collectibleModule = collectibleModule.newModule(result, collectibleService)
method delete*[T](self: Module[T]) =
method delete*(self: Module) =
self.collectiblesModule.delete
self.collectionsModule.delete
self.collectibleModule.delete
method load*[T](self: Module[T]) =
method load*(self: Module) =
self.controller.init
self.collectiblesModule.load
self.collectionsModule.load
self.collectibleModule.load
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool =
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method switchAccount*[T](self: Module[T], accountIndex: int) =
proc checkIfModuleDidLoad(self: Module) =
if(not self.collectiblesModule.isLoaded()):
return
if(not self.collectionsModule.isLoaded()):
return
if(not self.collectibleModule.isLoaded()):
return
self.moduleLoaded = true
self.delegate.collectiblesModuleDidLoad()
method collectibleModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method collectiblesModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method collectionsModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method switchAccount*(self: Module, accountIndex: int) =
let account = self.controller.getWalletAccount(accountIndex)
self.collectionsModule.loadCollections(account.address)
self.collectiblesModule.setCurrentAddress(account.address)

View File

@ -1,29 +1,30 @@
import ./controller_interface
import io_interface
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export controller_interface
type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface
delegate: T
Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface
walletAccountService: wallet_account_service.ServiceInterface
proc newController*[T](
delegate: T,
proc newController*(
delegate: io_interface.AccessInterface,
walletAccountService: wallet_account_service.ServiceInterface
): Controller[T] =
result = Controller[T]()
): Controller =
result = Controller()
result.delegate = delegate
result.walletAccountService = walletAccountService
method delete*[T](self: Controller[T]) =
method delete*(self: Controller) =
discard
method init*[T](self: Controller[T]) =
method init*(self: Controller) =
discard
method getWalletAccount*[T](self: Controller[T], accountIndex: int): wallet_account_service.WalletAccountDto =
method getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getWalletAccount(accountIndex)
method update*[T](self: Controller[T], address: string, accountName: string, color: string) =
method update*(self: Controller, address: string, accountName: string, color: string) =
self.walletAccountService.updateWalletAccount(address, accountName, color)

View File

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

View File

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

View File

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

View File

@ -19,6 +19,32 @@ method updateCurrency*(self: AccessInterface, currency: string) {.base.} =
method setTotalCurrencyBalance*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# Methods called by submodules of this module
method accountTokensModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method accountsModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method allTokensModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method collectiblesModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method currentAccountModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method transactionsModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.

View File

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

View File

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

View File

@ -37,10 +37,8 @@ method setTrxHistoryResult*(self: AccessInterface, transactions: seq[Transaction
method setHistoryFetchState*(self: AccessInterface, addresses: seq[string], isFetching: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method setIsNonArchivalNode*(self: AccessInterface, isNonArchivalNode: bool) {.base.} =
# 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")
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.
DelegateInterface* = concept c

View File

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

View File

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

View File

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