refactor(@desktop/wallet): Add walletaccount to more module
This commit is contained in:
parent
4bc61134c4
commit
6a1923abcf
|
@ -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)
|
|
@ -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
|
||||||
|
|
|
@ -11,6 +11,9 @@ method load*(self: AccessInterface) {.base.} =
|
||||||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
type
|
type
|
||||||
## Abstract class (concept) which must be implemented by object/s used in this
|
## Abstract class (concept) which must be implemented by object/s used in this
|
||||||
## module.
|
## module.
|
||||||
|
|
|
@ -1,18 +1,27 @@
|
||||||
|
import NimQml
|
||||||
import eventemitter
|
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
|
export io_interface
|
||||||
|
|
||||||
type
|
type
|
||||||
Module* [T: DelegateInterface] = ref object of AccessInterface
|
Module* [T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
|
||||||
delegate: T
|
delegate: T
|
||||||
view: View
|
view: View
|
||||||
moduleLoaded: bool
|
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 = Module[T]()
|
||||||
result.delegate = delegate
|
result.delegate = delegate
|
||||||
result.view = newView(result)
|
result.view = newView(result)
|
||||||
|
result.controller = newController(result, walletAccountService)
|
||||||
result.moduleLoaded = false
|
result.moduleLoaded = false
|
||||||
|
|
||||||
method delete*[T](self: Module[T]) =
|
method delete*[T](self: Module[T]) =
|
||||||
|
@ -23,3 +32,6 @@ method load*[T](self: Module[T]) =
|
||||||
|
|
||||||
method isLoaded*[T](self: Module[T]): bool =
|
method isLoaded*[T](self: Module[T]): bool =
|
||||||
return self.moduleLoaded
|
return self.moduleLoaded
|
||||||
|
|
||||||
|
method switchAccount*[T](self: Module[T], accountIndex: int) =
|
||||||
|
discard
|
|
@ -11,6 +11,9 @@ method load*(self: AccessInterface) {.base.} =
|
||||||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
type
|
type
|
||||||
## Abstract class (concept) which must be implemented by object/s used in this
|
## Abstract class (concept) which must be implemented by object/s used in this
|
||||||
## module.
|
## module.
|
||||||
|
|
|
@ -2,6 +2,7 @@ import eventemitter
|
||||||
|
|
||||||
import ./io_interface, ./view
|
import ./io_interface, ./view
|
||||||
import ../../../../../app_service/service/collectible/service as collectible_service
|
import ../../../../../app_service/service/collectible/service as collectible_service
|
||||||
|
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||||
|
|
||||||
import ./collectible/module as collectible_module
|
import ./collectible/module as collectible_module
|
||||||
import ./collections/module as collections_module
|
import ./collections/module as collections_module
|
||||||
|
@ -22,7 +23,8 @@ type
|
||||||
proc newModule*[T](
|
proc newModule*[T](
|
||||||
delegate: T,
|
delegate: T,
|
||||||
events: EventEmitter,
|
events: EventEmitter,
|
||||||
collectibleService: collectible_service.ServiceInterface
|
collectibleService: collectible_service.ServiceInterface,
|
||||||
|
walletAccountService: wallet_account_service.ServiceInterface
|
||||||
): Module[T] =
|
): Module[T] =
|
||||||
result = Module[T]()
|
result = Module[T]()
|
||||||
result.delegate = delegate
|
result.delegate = delegate
|
||||||
|
@ -54,3 +56,6 @@ method load*[T](self: Module[T]) =
|
||||||
|
|
||||||
method isLoaded*[T](self: Module[T]): bool =
|
method isLoaded*[T](self: Module[T]): bool =
|
||||||
return self.moduleLoaded
|
return self.moduleLoaded
|
||||||
|
|
||||||
|
method switchAccount*[T](self: Module[T], accountIndex: int) =
|
||||||
|
discard
|
|
@ -11,6 +11,9 @@ method load*(self: AccessInterface) {.base.} =
|
||||||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
type
|
type
|
||||||
## Abstract class (concept) which must be implemented by object/s used in this
|
## Abstract class (concept) which must be implemented by object/s used in this
|
||||||
## module.
|
## module.
|
||||||
|
|
|
@ -34,22 +34,22 @@ type
|
||||||
proc newModule*[T](
|
proc newModule*[T](
|
||||||
delegate: T,
|
delegate: T,
|
||||||
events: EventEmitter,
|
events: EventEmitter,
|
||||||
tokenService: token_service.Service,
|
tokenService: token_service.ServiceInterface,
|
||||||
transactionService: transaction_service.Service,
|
transactionService: transaction_service.ServiceInterface,
|
||||||
collectibleService: collectible_service.Service,
|
collectibleService: collectible_service.ServiceInterface,
|
||||||
walletAccountService: wallet_account_service.Service,
|
walletAccountService: wallet_account_service.ServiceInterface,
|
||||||
settingService: setting_service.Service
|
settingService: setting_service.ServiceInterface
|
||||||
): Module[T] =
|
): Module[T] =
|
||||||
result = Module[T]()
|
result = Module[T]()
|
||||||
result.delegate = delegate
|
result.delegate = delegate
|
||||||
result.moduleLoaded = false
|
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.accountsModule = accounts_module.newModule(result, events, walletAccountService)
|
||||||
result.allTokensModule = all_tokens_module.newModule(result, events, tokenService)
|
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.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]) =
|
method delete*[T](self: Module[T]) =
|
||||||
self.accountTokensModule.delete
|
self.accountTokensModule.delete
|
||||||
|
@ -59,6 +59,11 @@ method delete*[T](self: Module[T]) =
|
||||||
self.mainAccountModule.delete
|
self.mainAccountModule.delete
|
||||||
self.transactionsModule.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]) =
|
method load*[T](self: Module[T]) =
|
||||||
self.accountTokensModule.load()
|
self.accountTokensModule.load()
|
||||||
self.accountsModule.load()
|
self.accountsModule.load()
|
||||||
|
@ -67,6 +72,7 @@ method load*[T](self: Module[T]) =
|
||||||
self.mainAccountModule.load()
|
self.mainAccountModule.load()
|
||||||
self.transactionsModule.load()
|
self.transactionsModule.load()
|
||||||
|
|
||||||
|
self.switchAccount(0)
|
||||||
self.moduleLoaded = true
|
self.moduleLoaded = true
|
||||||
self.delegate.walletSectionDidLoad()
|
self.delegate.walletSectionDidLoad()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import ./controller_interface
|
import ./controller_interface
|
||||||
import ../../../../../app_service/service/transaction/service as transaction_service
|
import ../../../../../app_service/service/transaction/service as transaction_service
|
||||||
|
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||||
|
|
||||||
export controller_interface
|
export controller_interface
|
||||||
|
|
||||||
|
@ -7,14 +8,17 @@ type
|
||||||
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface
|
Controller*[T: controller_interface.DelegateInterface] = ref object of controller_interface.AccessInterface
|
||||||
delegate: T
|
delegate: T
|
||||||
transactionService: transaction_service.ServiceInterface
|
transactionService: transaction_service.ServiceInterface
|
||||||
|
walletAccountService: wallet_account_service.ServiceInterface
|
||||||
|
|
||||||
proc newController*[T](
|
proc newController*[T](
|
||||||
delegate: T,
|
delegate: T,
|
||||||
transactionService: transaction_service.ServiceInterface,
|
transactionService: transaction_service.ServiceInterface,
|
||||||
|
walletAccountService: wallet_account_service.ServiceInterface
|
||||||
): Controller[T] =
|
): Controller[T] =
|
||||||
result = Controller[T]()
|
result = Controller[T]()
|
||||||
result.delegate = delegate
|
result.delegate = delegate
|
||||||
result.transactionService = transactionService
|
result.transactionService = transactionService
|
||||||
|
result.walletAccountService = walletAccountService
|
||||||
|
|
||||||
method delete*[T](self: Controller[T]) =
|
method delete*[T](self: Controller[T]) =
|
||||||
discard
|
discard
|
||||||
|
|
|
@ -11,6 +11,9 @@ method load*(self: AccessInterface) {.base.} =
|
||||||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
type
|
type
|
||||||
## Abstract class (concept) which must be implemented by object/s used in this
|
## Abstract class (concept) which must be implemented by object/s used in this
|
||||||
## module.
|
## module.
|
||||||
|
|
|
@ -2,6 +2,7 @@ import eventemitter
|
||||||
|
|
||||||
import ./io_interface, ./view, ./controller
|
import ./io_interface, ./view, ./controller
|
||||||
import ../../../../../app_service/service/transaction/service as transaction_service
|
import ../../../../../app_service/service/transaction/service as transaction_service
|
||||||
|
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||||
|
|
||||||
export io_interface
|
export io_interface
|
||||||
|
|
||||||
|
@ -15,12 +16,13 @@ type
|
||||||
proc newModule*[T](
|
proc newModule*[T](
|
||||||
delegate: T,
|
delegate: T,
|
||||||
events: EventEmitter,
|
events: EventEmitter,
|
||||||
transactionService: transaction_service.ServiceInterface
|
transactionService: transaction_service.ServiceInterface,
|
||||||
|
walletAccountService: wallet_account_service.ServiceInterface
|
||||||
): Module[T] =
|
): Module[T] =
|
||||||
result = Module[T]()
|
result = Module[T]()
|
||||||
result.delegate = delegate
|
result.delegate = delegate
|
||||||
result.view = newView(result)
|
result.view = newView(result)
|
||||||
result.controller = controller.newController[Module[T]](result, transactionService)
|
result.controller = controller.newController[Module[T]](result, transactionService, walletAccountService)
|
||||||
result.moduleLoaded = false
|
result.moduleLoaded = false
|
||||||
|
|
||||||
method delete*[T](self: Module[T]) =
|
method delete*[T](self: Module[T]) =
|
||||||
|
@ -34,3 +36,6 @@ method load*[T](self: Module[T]) =
|
||||||
|
|
||||||
method isLoaded*[T](self: Module[T]): bool =
|
method isLoaded*[T](self: Module[T]): bool =
|
||||||
return self.moduleLoaded
|
return self.moduleLoaded
|
||||||
|
|
||||||
|
method switchAccount*[T](self: Module[T], accountIndex: int) =
|
||||||
|
discard
|
|
@ -120,5 +120,8 @@ method init*(self: Service) =
|
||||||
method getWalletAccounts*(self: Service): seq[WalletAccountDto] =
|
method getWalletAccounts*(self: Service): seq[WalletAccountDto] =
|
||||||
return toSeq(self.accounts.values).filter(a => a.isChat)
|
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 =
|
method getCurrencyBalance*(self: Service): float64 =
|
||||||
return self.getWalletAccounts().map(a => a.getCurrencyBalance()).foldl(a + b, 0.0)
|
return self.getWalletAccounts().map(a => a.getCurrencyBalance()).foldl(a + b, 0.0)
|
|
@ -14,3 +14,6 @@ method init*(self: ServiceInterface) {.base.} =
|
||||||
|
|
||||||
method getWalletAccounts*(self: ServiceInterface): seq[WalletAccountDto] {.base.} =
|
method getWalletAccounts*(self: ServiceInterface): seq[WalletAccountDto] {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method getWalletAccount*(self: ServiceInterface, accountIndex: int): WalletAccountDto {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
Loading…
Reference in New Issue