refactor(@desktop/wallet): Add wallet account service
This commit is contained in:
parent
1828029ab2
commit
a876a4b9ce
|
@ -9,6 +9,7 @@ import ../../app_service/service/community/service as community_service
|
|||
import ../../app_service/service/token/service as token_service
|
||||
import ../../app_service/service/transaction/service as transaction_service
|
||||
import ../../app_service/service/collectible/service as collectible_service
|
||||
import ../../app_service/service/wallet_account/service as wallet_account_service
|
||||
|
||||
|
||||
import ../core/local_account_settings
|
||||
|
@ -64,6 +65,7 @@ type
|
|||
tokenService: token_service.Service
|
||||
transactionService: transaction_service.Service
|
||||
collectibleService: collectible_service.Service
|
||||
walletAccountService: wallet_account_service.Service
|
||||
|
||||
# Core
|
||||
localAccountSettings: LocalAccountSettings
|
||||
|
@ -119,6 +121,8 @@ proc newAppController*(appService: AppService): AppController =
|
|||
result.tokenService = token_service.newService()
|
||||
result.transactionService = transaction_service.newService()
|
||||
result.collectibleService = collectible_service.newService()
|
||||
result.walletAccountService = wallet_account_service.newService()
|
||||
|
||||
|
||||
# Core
|
||||
result.localAccountSettingsVariant = newQVariant(
|
||||
|
@ -136,7 +140,8 @@ proc newAppController*(appService: AppService): AppController =
|
|||
result.communityService,
|
||||
result.tokenService,
|
||||
result.transactionService,
|
||||
result.collectibleService
|
||||
result.collectibleService,
|
||||
result.walletAccountService
|
||||
)
|
||||
|
||||
#################################################
|
||||
|
@ -197,6 +202,7 @@ proc load*(self: AppController) =
|
|||
self.chatService.init()
|
||||
self.communityService.init()
|
||||
self.tokenService.init()
|
||||
self.walletAccountService.init()
|
||||
|
||||
self.mainModule.load()
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import ../../../app_service/service/community/service as community_service
|
|||
import ../../../app_service/service/token/service as token_service
|
||||
import ../../../app_service/service/transaction/service as transaction_service
|
||||
import ../../../app_service/service/collectible/service as collectible_service
|
||||
import ../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
|
||||
import eventemitter
|
||||
|
||||
|
@ -47,7 +48,8 @@ proc newModule*[T](
|
|||
communityService: community_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
transactionService: transaction_service.Service,
|
||||
collectibleService: collectible_service.Service
|
||||
collectibleService: collectible_service.Service,
|
||||
walletAccountService: wallet_account_service.Service
|
||||
): Module[T] =
|
||||
result = Module[T]()
|
||||
result.delegate = delegate
|
||||
|
@ -67,7 +69,7 @@ proc newModule*[T](
|
|||
)
|
||||
|
||||
result.walletSectionModule = wallet_section_module.newModule[Module[T]](
|
||||
result, tokenService, transactionService, collectible_service
|
||||
result, tokenService, transactionService, collectible_service, walletAccountService
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import ./transactions/module as transactions_module
|
|||
import ../../../../app_service/service/token/service as token_service
|
||||
import ../../../../app_service/service/transaction/service as transaction_service
|
||||
import ../../../../app_service/service/collectible/service as collectible_service
|
||||
import ../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
|
||||
import io_interface
|
||||
export io_interface
|
||||
|
@ -33,7 +34,8 @@ proc newModule*[T](
|
|||
delegate: T,
|
||||
tokenService: token_service.Service,
|
||||
transactionService: transaction_service.Service,
|
||||
collectibleService: collectible_service.Service
|
||||
collectibleService: collectible_service.Service,
|
||||
walletAccountService: wallet_account_service.Service
|
||||
): Module[T] =
|
||||
result = Module[T]()
|
||||
result.delegate = delegate
|
||||
|
|
|
@ -20,7 +20,7 @@ type
|
|||
proc newDto*(
|
||||
name: string, chainId: int, address: Address, symbol: string, decimals: int, hasIcon: bool, isCustom: bool = false
|
||||
): Dto =
|
||||
Dto(
|
||||
return Dto(
|
||||
name: name, chainId: chainId, address: address, symbol: symbol, decimals: decimals, hasIcon: hasIcon, isCustom: isCustom
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
import json
|
||||
|
||||
include ../../common/json_utils
|
||||
|
||||
type
|
||||
WalletAccountDto* = ref object of RootObj
|
||||
name*: string
|
||||
address*: string
|
||||
path*: string
|
||||
color*: string
|
||||
publicKey*: string
|
||||
walletType*: string
|
||||
isWallet*: bool
|
||||
isChat*: bool
|
||||
|
||||
proc newDto*(
|
||||
name: string,
|
||||
address: string,
|
||||
path: string,
|
||||
color: string,
|
||||
publicKey: string,
|
||||
walletType: string,
|
||||
isWallet: bool,
|
||||
isChat: bool
|
||||
): WalletAccountDto =
|
||||
return WalletAccountDto(
|
||||
name: name,
|
||||
address: address,
|
||||
path: path,
|
||||
color: color,
|
||||
publicKey: publicKey,
|
||||
walletType: walletType,
|
||||
isWallet: isWallet,
|
||||
isChat: isChat
|
||||
)
|
||||
|
||||
proc toDto*(jsonObj: JsonNode): WalletAccountDto =
|
||||
result = WalletAccountDto()
|
||||
discard jsonObj.getProp("name", result.name)
|
||||
discard jsonObj.getProp("address", result.address)
|
||||
discard jsonObj.getProp("path", result.path)
|
||||
discard jsonObj.getProp("color", result.color)
|
||||
discard jsonObj.getProp("wallet", result.isWallet)
|
||||
discard jsonObj.getProp("chat", result.isChat)
|
||||
discard jsonObj.getProp("public-key", result.publicKey)
|
||||
discard jsonObj.getProp("type", result.walletType)
|
|
@ -0,0 +1,36 @@
|
|||
import Tables, json, sequtils, sugar, chronicles
|
||||
|
||||
import ./service_interface, ./dto
|
||||
import status/statusgo_backend_new/accounts as status_go
|
||||
|
||||
export service_interface
|
||||
|
||||
logScope:
|
||||
topics = "wallet-account-service"
|
||||
|
||||
type
|
||||
Service* = ref object of service_interface.ServiceInterface
|
||||
accounts: Table[string, WalletAccountDto]
|
||||
|
||||
method delete*(self: Service) =
|
||||
discard
|
||||
|
||||
proc newService*(): Service =
|
||||
result = Service()
|
||||
result.accounts = initTable[string, WalletAccountDto]()
|
||||
|
||||
method init*(self: Service) =
|
||||
try:
|
||||
let response = status_go.getAccounts()
|
||||
let accounts = map(response.result.getElems(), proc(x: JsonNode): WalletAccountDto = x.toDto())
|
||||
|
||||
for account in accounts:
|
||||
self.accounts[account.address] = account
|
||||
echo account.address
|
||||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "error: ", errDesription
|
||||
return
|
||||
|
||||
method getAccounts*(self: Service): seq[WalletAccountDto] =
|
||||
return toSeq(self.accounts.values).filter(a => a.isChat)
|
|
@ -0,0 +1,16 @@
|
|||
import ./dto
|
||||
|
||||
export dto
|
||||
|
||||
type
|
||||
ServiceInterface* {.pure inheritable.} = ref object of RootObj
|
||||
## Abstract class for this service access.
|
||||
|
||||
method delete*(self: ServiceInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method init*(self: ServiceInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getAccounts*(self: ServiceInterface): seq[WalletAccountDto] {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
Loading…
Reference in New Issue