refactor(@desktop/wallet): init boilerplate code for wallet section

This commit is contained in:
Anthony Laibe 2021-10-13 10:19:14 +02:00 committed by Iuri Matias
parent 7a37c50958
commit ad7b6f7087
23 changed files with 444 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import io_interface, view, controller, item
import ../../core/global_singleton
import chat_section/module as chat_section_module
import wallet_section/module as wallet_section_module
import ../../../app_service/service/keychain/service as keychain_service
import ../../../app_service/service/accounts/service_interface as accounts_service
@ -32,6 +33,7 @@ type
controller: controller.AccessInterface
chatSectionModule: chat_section_module.AccessInterface
communitySectionsModule: OrderedTable[string, chat_section_module.AccessInterface]
walletSectionModule: wallet_section_module.AccessInterface
proc newModule*[T](delegate: T,
events: EventEmitter,
@ -53,14 +55,19 @@ proc newModule*[T](delegate: T,
result.communitySectionsModule = initOrderedTable[string, chat_section_module.AccessInterface]()
let communities = result.controller.getCommunities()
for c in communities:
result.communitySectionsModule[c.id] = chat_section_module.newModule(result,
c.id, true, chatService, communityService)
result.communitySectionsModule[c.id] = chat_section_module.newModule(
result, c.id, true, chatService, communityService
)
result.walletSectionModule = wallet_section_module.newModule[Module[T]](result)
method delete*[T](self: Module[T]) =
self.chatSectionModule.delete
for cModule in self.communitySectionsModule.values:
cModule.delete
self.communitySectionsModule.clear
self.walletSectionModule.delete
self.view.delete
self.viewVariant.delete
self.controller.delete
@ -84,6 +91,9 @@ method load*[T](self: Module[T]) =
for cModule in self.communitySectionsModule.values:
cModule.load()
self.walletSectionModule.load()
proc checkIfModuleDidLoad [T](self: Module[T]) =
if(not self.chatSectionModule.isLoaded()):
return
@ -92,6 +102,10 @@ proc checkIfModuleDidLoad [T](self: Module[T]) =
if(not cModule.isLoaded()):
return
if (not self.walletSectionModule.isLoaded()):
return
self.delegate.mainDidLoad()
method chatSectionDidLoad*[T](self: Module[T]) =
@ -100,6 +114,9 @@ method chatSectionDidLoad*[T](self: Module[T]) =
method communitySectionDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
proc walletSectionDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()
method viewDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()

View File

@ -0,0 +1,17 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
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 File

@ -0,0 +1,24 @@
import ./io_interface, ./view
export io_interface
type
Module* [T: DelegateInterface] = ref object of AccessInterface
delegate: T
view: View
moduleLoaded: bool
proc newModule*[T](delegate: T): Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = newView()
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
self.view.delete
method load*[T](self: Module[T]) =
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded

View File

@ -0,0 +1,15 @@
import NimQml
QtObject:
type
View* = ref object of QObject
proc setup(self: View) =
self.QObject.setup
proc delete*(self: View) =
self.QObject.delete
proc newView*(): View =
new(result, delete)
result.setup()

View File

@ -0,0 +1,17 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
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 File

@ -0,0 +1,24 @@
import ./io_interface, ./view
export io_interface
type
Module* [T: DelegateInterface] = ref object of AccessInterface
delegate: T
view: View
moduleLoaded: bool
proc newModule*[T](delegate: T): Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = newView()
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
self.view.delete
method load*[T](self: Module[T]) =
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded

View File

@ -0,0 +1,15 @@
import NimQml
QtObject:
type
View* = ref object of QObject
proc setup(self: View) =
self.QObject.setup
proc delete*(self: View) =
self.QObject.delete
proc newView*(): View =
new(result, delete)
result.setup()

View File

@ -0,0 +1,17 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
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 File

@ -0,0 +1,24 @@
import ./io_interface, ./view
export io_interface
type
Module* [T: DelegateInterface] = ref object of AccessInterface
delegate: T
view: View
moduleLoaded: bool
proc newModule*[T](delegate: T): Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = newView()
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
self.view.delete
method load*[T](self: Module[T]) =
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded

View File

@ -0,0 +1,15 @@
import NimQml
QtObject:
type
View* = ref object of QObject
proc setup(self: View) =
self.QObject.setup
proc delete*(self: View) =
self.QObject.delete
proc newView*(): View =
new(result, delete)
result.setup()

View File

@ -0,0 +1,17 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
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 File

@ -0,0 +1,24 @@
import ./io_interface, ./view
export io_interface
type
Module* [T: DelegateInterface] = ref object of AccessInterface
delegate: T
view: View
moduleLoaded: bool
proc newModule*[T](delegate: T): Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = newView()
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
self.view.delete
method load*[T](self: Module[T]) =
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded

View File

@ -0,0 +1,15 @@
import NimQml
QtObject:
type
View* = ref object of QObject
proc setup(self: View) =
self.QObject.setup
proc delete*(self: View) =
self.QObject.delete
proc newView*(): View =
new(result, delete)
result.setup()

View File

@ -0,0 +1,18 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
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
c.walletSectionDidLoad()

View File

@ -0,0 +1,17 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
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 File

@ -0,0 +1,24 @@
import ./io_interface, ./view
export io_interface
type
Module* [T: DelegateInterface] = ref object of AccessInterface
delegate: T
view: View
moduleLoaded: bool
proc newModule*[T](delegate: T): Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = newView()
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
self.view.delete
method load*[T](self: Module[T]) =
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded

View File

@ -0,0 +1,15 @@
import NimQml
QtObject:
type
View* = ref object of QObject
proc setup(self: View) =
self.QObject.setup
proc delete*(self: View) =
self.QObject.delete
proc newView*(): View =
new(result, delete)
result.setup()

View File

@ -0,0 +1,55 @@
import ./io_interface as io_ingerface
import ./view
import ./account_tokens/module as account_tokens_module
import ./accounts/module as accountsModule
import ./all_tokens/module as all_tokens_module
import ./collectibles/module as collectibles_module
import ./main_account/module as main_account_module
import ./transactions/module as transactions_module
import io_interface
export io_interface
type
Module* [T: io_ingerface.DelegateInterface] = ref object of io_ingerface.AccessInterface
delegate: T
view: View
moduleLoaded: bool
accountTokensModule: account_tokens_module.AccessInterface
accountsModule: accounts_module.AccessInterface
allTokensModule: all_tokens_module.AccessInterface
collectiblesModule: collectibles_module.AccessInterface
mainAccountModule: main_account_module.AccessInterface
transactionsModule: transactions_module.AccessInterface
proc newModule*[T](delegate: T): Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = newView()
result.moduleLoaded = false
result.accountTokensModule = account_tokens_module.newModule(result)
result.accountsModule = accounts_module.newModule(result)
result.allTokensModule = all_tokens_module.newModule(result)
result.collectiblesModule = collectibles_module.newModule(result)
result.mainAccountModule = main_account_module.newModule(result)
result.transactionsModule = transactions_module.newModule(result)
method delete*[T](self: Module[T]) =
self.view.delete
method load*[T](self: Module[T]) =
self.accountTokensModule.load()
self.accountsModule.load()
self.allTokensModule.load()
self.collectiblesModule.load()
self.mainAccountModule.load()
self.transactionsModule.load()
self.moduleLoaded = true
self.delegate.walletSectionDidLoad()
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded

View File

@ -0,0 +1,17 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
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 File

@ -0,0 +1,24 @@
import ./io_interface, ./view
export io_interface
type
Module* [T: DelegateInterface] = ref object of AccessInterface
delegate: T
view: View
moduleLoaded: bool
proc newModule*[T](delegate: T): Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = newView()
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
self.view.delete
method load*[T](self: Module[T]) =
self.moduleLoaded = true
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded

View File

@ -0,0 +1,15 @@
import NimQml
QtObject:
type
View* = ref object of QObject
proc setup(self: View) =
self.QObject.setup
proc delete*(self: View) =
self.QObject.delete
proc newView*(): View =
new(result, delete)
result.setup()

View File

@ -0,0 +1,15 @@
import NimQml
QtObject:
type
View* = ref object of QObject
proc setup(self: View) =
self.QObject.setup
proc delete*(self: View) =
self.QObject.delete
proc newView*(): View =
new(result, delete)
result.setup()

2
vendor/status-lib vendored

@ -1 +1 @@
Subproject commit 47553f4fc8ffb3456af1190f0c3fb47d6eb91d2e
Subproject commit 2a3f48f46979b6300160e9fd982dd678a1ad2a58