refactor(@desktop/wallet): Add walletaccount to more module

This commit is contained in:
Anthony Laibe 2021-10-20 15:50:06 +02:00 committed by Iuri Matias
parent 4bc61134c4
commit 6a1923abcf
13 changed files with 110 additions and 14 deletions

View File

@ -0,0 +1,26 @@
import ./controller_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
walletAccountService: wallet_account_service.ServiceInterface
proc newController*[T](
delegate: T,
walletAccountService: wallet_account_service.ServiceInterface
): Controller[T] =
result = Controller[T]()
result.delegate = delegate
result.walletAccountService = walletAccountService
method delete*[T](self: Controller[T]) =
discard
method init*[T](self: Controller[T]) =
discard
method getWalletAccount*[T](self: Controller[T], accountIndex: int): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getWalletAccount(accountIndex)

View File

@ -0,0 +1,20 @@
import ../../../../../app_service/service/wallet_account/service_interface as wallet_account_service
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 init*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getWalletAccount*(self: AccessInterface, accountIndex: int): wallet_account_service.WalletAccountDto {.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

@ -11,6 +11,9 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
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.

View File

@ -1,18 +1,27 @@
import NimQml
import eventemitter
import ./io_interface, ./view
import ./io_interface, ./view, ./controller
import ../../../../core/global_singleton
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export io_interface
type
Module* [T: DelegateInterface] = ref object of AccessInterface
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
delegate: T
view: View
moduleLoaded: bool
controller: controller.AccessInterface
proc newModule*[T](delegate: T, events: EventEmitter): Module[T] =
proc newModule*[T](
delegate: T,
events: EventEmitter,
walletAccountService: wallet_account_service.ServiceInterface
): Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = newView(result)
result.controller = newController(result, walletAccountService)
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
@ -23,3 +32,6 @@ method load*[T](self: Module[T]) =
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded
method switchAccount*[T](self: Module[T], accountIndex: int) =
discard

View File

@ -11,6 +11,9 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
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.

View File

@ -2,6 +2,7 @@ import eventemitter
import ./io_interface, ./view
import ../../../../../app_service/service/collectible/service as collectible_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ./collectible/module as collectible_module
import ./collections/module as collections_module
@ -22,7 +23,8 @@ type
proc newModule*[T](
delegate: T,
events: EventEmitter,
collectibleService: collectible_service.ServiceInterface
collectibleService: collectible_service.ServiceInterface,
walletAccountService: wallet_account_service.ServiceInterface
): Module[T] =
result = Module[T]()
result.delegate = delegate
@ -54,3 +56,6 @@ method load*[T](self: Module[T]) =
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded
method switchAccount*[T](self: Module[T], accountIndex: int) =
discard

View File

@ -11,6 +11,9 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
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.

View File

@ -34,22 +34,22 @@ type
proc newModule*[T](
delegate: T,
events: EventEmitter,
tokenService: token_service.Service,
transactionService: transaction_service.Service,
collectibleService: collectible_service.Service,
walletAccountService: wallet_account_service.Service,
settingService: setting_service.Service
tokenService: token_service.ServiceInterface,
transactionService: transaction_service.ServiceInterface,
collectibleService: collectible_service.ServiceInterface,
walletAccountService: wallet_account_service.ServiceInterface,
settingService: setting_service.ServiceInterface
): Module[T] =
result = Module[T]()
result.delegate = delegate
result.moduleLoaded = false
result.accountTokensModule = account_tokens_module.newModule(result, events)
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)
result.collectiblesModule = collectibles_module.newModule(result, events, collectibleService)
result.collectiblesModule = collectibles_module.newModule(result, events, collectibleService, walletAccountService)
result.mainAccountModule = main_account_module.newModule(result, events)
result.transactionsModule = transactions_module.newModule(result, events, transactionService)
result.transactionsModule = transactions_module.newModule(result, events, transactionService, walletAccountService)
method delete*[T](self: Module[T]) =
self.accountTokensModule.delete
@ -59,6 +59,11 @@ method delete*[T](self: Module[T]) =
self.mainAccountModule.delete
self.transactionsModule.delete
method switchAccount*[T](self: Module[T], accountIndex: int) =
self.collectiblesModule.switchAccount(accountIndex)
self.accountTokensModule.switchAccount(accountIndex)
self.transactionsModule.switchAccount(accountIndex)
method load*[T](self: Module[T]) =
self.accountTokensModule.load()
self.accountsModule.load()
@ -67,6 +72,7 @@ method load*[T](self: Module[T]) =
self.mainAccountModule.load()
self.transactionsModule.load()
self.switchAccount(0)
self.moduleLoaded = true
self.delegate.walletSectionDidLoad()

View File

@ -1,5 +1,6 @@
import ./controller_interface
import ../../../../../app_service/service/transaction/service as transaction_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export controller_interface
@ -7,14 +8,17 @@ type
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface
delegate: T
transactionService: transaction_service.ServiceInterface
walletAccountService: wallet_account_service.ServiceInterface
proc newController*[T](
delegate: T,
transactionService: transaction_service.ServiceInterface,
walletAccountService: wallet_account_service.ServiceInterface
): Controller[T] =
result = Controller[T]()
result.delegate = delegate
result.transactionService = transactionService
result.walletAccountService = walletAccountService
method delete*[T](self: Controller[T]) =
discard

View File

@ -11,6 +11,9 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
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.

View File

@ -2,6 +2,7 @@ import eventemitter
import ./io_interface, ./view, ./controller
import ../../../../../app_service/service/transaction/service as transaction_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
export io_interface
@ -15,12 +16,13 @@ type
proc newModule*[T](
delegate: T,
events: EventEmitter,
transactionService: transaction_service.ServiceInterface
transactionService: transaction_service.ServiceInterface,
walletAccountService: wallet_account_service.ServiceInterface
): Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = newView(result)
result.controller = controller.newController[Module[T]](result, transactionService)
result.controller = controller.newController[Module[T]](result, transactionService, walletAccountService)
result.moduleLoaded = false
method delete*[T](self: Module[T]) =
@ -34,3 +36,6 @@ method load*[T](self: Module[T]) =
method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded
method switchAccount*[T](self: Module[T], accountIndex: int) =
discard

View File

@ -120,5 +120,8 @@ method init*(self: Service) =
method getWalletAccounts*(self: Service): seq[WalletAccountDto] =
return toSeq(self.accounts.values).filter(a => a.isChat)
method getWalletAccount*(self: Service, accountIndex: int): WalletAccountDto =
return self.getWalletAccounts()[accountIndex]
method getCurrencyBalance*(self: Service): float64 =
return self.getWalletAccounts().map(a => a.getCurrencyBalance()).foldl(a + b, 0.0)

View File

@ -14,3 +14,6 @@ method init*(self: ServiceInterface) {.base.} =
method getWalletAccounts*(self: ServiceInterface): seq[WalletAccountDto] {.base.} =
raise newException(ValueError, "No implementation available")
method getWalletAccount*(self: ServiceInterface, accountIndex: int): WalletAccountDto {.base.} =
raise newException(ValueError, "No implementation available")