refactor(@desktop/wallet): Add settings service and to module
This commit is contained in:
parent
5d523b739e
commit
0d129fa7fd
|
@ -10,7 +10,7 @@ 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 ../../app_service/service/setting/service as setting_service
|
||||
|
||||
import ../core/local_account_settings
|
||||
import ../modules/startup/module as startup_module
|
||||
|
@ -66,6 +66,7 @@ type
|
|||
transactionService: transaction_service.Service
|
||||
collectibleService: collectible_service.Service
|
||||
walletAccountService: wallet_account_service.Service
|
||||
settingService: setting_service.Service
|
||||
|
||||
# Core
|
||||
localAccountSettings: LocalAccountSettings
|
||||
|
@ -123,7 +124,7 @@ proc newAppController*(appService: AppService): AppController =
|
|||
result.transactionService = transaction_service.newService()
|
||||
result.collectibleService = collectible_service.newService()
|
||||
result.walletAccountService = wallet_account_service.newService()
|
||||
|
||||
result.settingService = setting_service.newService()
|
||||
|
||||
# Core
|
||||
result.localAccountSettingsVariant = newQVariant(
|
||||
|
@ -146,7 +147,8 @@ proc newAppController*(appService: AppService): AppController =
|
|||
result.tokenService,
|
||||
result.transactionService,
|
||||
result.collectibleService,
|
||||
result.walletAccountService
|
||||
result.walletAccountService,
|
||||
result.settingService
|
||||
)
|
||||
|
||||
#################################################
|
||||
|
@ -212,7 +214,8 @@ proc load*(self: AppController) =
|
|||
self.communityService.init()
|
||||
self.tokenService.init()
|
||||
self.walletAccountService.init()
|
||||
|
||||
self.settingService.init()
|
||||
|
||||
self.mainModule.load()
|
||||
|
||||
proc userLoggedIn*(self: AppController) =
|
||||
|
|
|
@ -14,6 +14,7 @@ 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 ../../../app_service/service/setting/service as setting_service
|
||||
|
||||
import eventemitter
|
||||
|
||||
|
@ -49,7 +50,8 @@ proc newModule*[T](
|
|||
tokenService: token_service.Service,
|
||||
transactionService: transaction_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
walletAccountService: wallet_account_service.Service
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
settingService: setting_service.Service
|
||||
): Module[T] =
|
||||
result = Module[T]()
|
||||
result.delegate = delegate
|
||||
|
@ -74,7 +76,8 @@ proc newModule*[T](
|
|||
tokenService,
|
||||
transactionService,
|
||||
collectible_service,
|
||||
walletAccountService
|
||||
walletAccountService,
|
||||
settingService
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ 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 ../../../../app_service/service/setting/service as setting_service
|
||||
|
||||
import io_interface
|
||||
export io_interface
|
||||
|
@ -38,7 +39,8 @@ proc newModule*[T](
|
|||
tokenService: token_service.Service,
|
||||
transactionService: transaction_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
walletAccountService: wallet_account_service.Service
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
settingService: setting_service.Service
|
||||
): Module[T] =
|
||||
result = Module[T]()
|
||||
result.delegate = delegate
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
import json
|
||||
|
||||
include ../../common/json_utils
|
||||
|
||||
const DEFAULT_NETWORK_ID = "mainnet_rpc"
|
||||
|
||||
type NetworkDto* = ref object of RootObj
|
||||
id*: string
|
||||
etherscanLink*: string
|
||||
name*: string
|
||||
|
||||
type
|
||||
SettingDto* = ref object of RootObj
|
||||
currentNetwork*: NetworkDto
|
||||
signingPhrase*: string
|
||||
currency*: string
|
||||
|
||||
proc toDto*(jsonObj: JsonNode): SettingDto =
|
||||
result = SettingDto()
|
||||
discard jsonObj.getProp("signing-phrase", result.signingPhrase)
|
||||
discard jsonObj.getProp("currency", result.currency)
|
||||
|
||||
var currentNetworkId: string
|
||||
if not jsonObj.getProp("networks/current-network", currentNetworkId):
|
||||
currentNetworkId = DEFAULT_NETWORK_ID
|
||||
|
||||
var networks: JsonNode
|
||||
discard jsonObj.getProp("networks/networks", networks)
|
||||
for networkJson in networks.getElems():
|
||||
if networkJson{"id"}.getStr != currentNetworkId:
|
||||
continue
|
||||
|
||||
var networkDto = NetworkDto()
|
||||
discard networkJson.getProp("id", networkDto.id)
|
||||
discard networkJson.getProp("name", networkDto.name)
|
||||
discard networkJson.getProp("etherscan-link", networkDto.etherscanLink)
|
||||
result.currentNetwork = networkDto
|
||||
break
|
|
@ -0,0 +1,32 @@
|
|||
import chronicles
|
||||
|
||||
import ./service_interface, ./dto
|
||||
import status/statusgo_backend_new/settings as status_go
|
||||
|
||||
export service_interface
|
||||
|
||||
logScope:
|
||||
topics = "setting-service"
|
||||
|
||||
type
|
||||
Service* = ref object of service_interface.ServiceInterface
|
||||
setting: SettingDto
|
||||
|
||||
method delete*(self: Service) =
|
||||
discard
|
||||
|
||||
proc newService*(): Service =
|
||||
result = Service()
|
||||
|
||||
method init*(self: Service) =
|
||||
try:
|
||||
let response = status_go.getSettings()
|
||||
self.setting = response.result.toDto()
|
||||
echo self.setting.currentNetwork.etherscanLink
|
||||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "error: ", errDesription
|
||||
return
|
||||
|
||||
method getSetting*(self: Service): SettingDto =
|
||||
return self.setting
|
|
@ -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 getSetting*(self: ServiceInterface): seq[SettingDto] {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
|
@ -26,7 +26,6 @@ method init*(self: Service) =
|
|||
|
||||
for account in accounts:
|
||||
self.accounts[account.address] = account
|
||||
echo account.address
|
||||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "error: ", errDesription
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit a507f8b579756e149c09bec026dccb3e687d024a
|
||||
Subproject commit f320378bd5fee8fa4b1af66e608ef352bbf0a215
|
Loading…
Reference in New Issue