add getSettings methods to src/status

This commit is contained in:
Iuri Matias 2021-06-08 08:48:31 -04:00
parent 933dbe9586
commit 09f77177b0
4 changed files with 37 additions and 7 deletions

View File

@ -3,10 +3,10 @@ import NimQml, strformat, strutils, chronicles, sugar, sequtils
import view
import views/[asset_list, account_list, account_item]
import ../../status/libstatus/wallet as status_wallet
import ../../status/libstatus/settings as status_settings
# import ../../status/libstatus/settings as status_settings
import ../../status/libstatus/types as status_types
import ../../status/signals/types
import ../../status/[status, wallet]
import ../../status/[status, wallet, settings]
import ../../status/wallet/account as WalletTypes
import ../../eventemitter
@ -48,8 +48,8 @@ proc init*(self: WalletController) =
self.status.events.on("assetChanged") do(e: Args):
self.view.updateView()
self.view.setEtherscanLink(status_settings.getCurrentNetworkDetails().etherscanLink)
self.view.setSigningPhrase(status_settings.getSetting[string](Setting.SigningPhrase))
self.view.setSigningPhrase(self.status.settings.getSetting[string](Setting.SigningPhrase))
self.view.setEtherscanLink(self.status.settings.getCurrentNetworkDetails().etherscanLink)
self.status.events.on(SignalType.Wallet.event) do(e:Args):
var data = WalletSignal(e)

View File

@ -73,12 +73,12 @@ proc getCurrentNetwork*(): Network =
result = Network.Poa
else:
result = Network.Other
proc getCurrentNetworkDetails*(): NetworkDetails =
let currNetwork = getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME)
let networks = getSetting[seq[NetworkDetails]](Setting.Networks_Networks)
networks.find((network: NetworkDetails) => network.id == currNetwork)
proc getLinkPreviewWhitelist*(): JsonNode =
result = callPrivateRPC("getLinkPreviewWhitelist".prefix, %* []).parseJSON()["result"]

27
src/status/settings.nim Normal file
View File

@ -0,0 +1,27 @@
import json, json_serialization
import
sugar, sequtils, strutils, atomics
import libstatus/settings as status_settings
import ../eventemitter
#TODO: temporary?
import libstatus/types as LibStatusTypes
type
SettingsModel* = ref object
events*: EventEmitter
proc newSettingsModel*(events: EventEmitter): SettingsModel =
result = SettingsModel()
result.events = events
proc getSetting*[T](self: SettingsModel, name: Setting, defaultValue: T, useCached: bool = true): T =
result = status_settings.getSetting(name, defaultValue, useCached)
proc getSetting*[T](self: SettingsModel, name: Setting, useCached: bool = true): T =
result = status_settings.getSetting[T](name, useCached)
proc getCurrentNetworkDetails*(self: SettingsModel): LibStatusTypes.NetworkDetails =
result = status_settings.getCurrentNetworkDetails()

View File

@ -2,7 +2,7 @@ import libstatus/accounts as libstatus_accounts
import libstatus/core as libstatus_core
import libstatus/settings as libstatus_settings
import libstatus/types as libstatus_types
import chat, accounts, wallet, node, network, messages, contacts, profile, stickers, permissions, fleet
import chat, accounts, wallet, node, network, messages, contacts, profile, stickers, permissions, fleet, settings
import ../eventemitter
import ./tasks/task_runner_impl
@ -22,6 +22,7 @@ type Status* = ref object
stickers*: StickersModel
permissions*: PermissionsModel
tasks*: TaskRunner
settings*: SettingsModel
proc newStatusInstance*(fleetConfig: string): Status =
result = Status()
@ -39,6 +40,7 @@ proc newStatusInstance*(fleetConfig: string): Status =
result.network = network.newNetworkModel(result.events)
result.stickers = stickers.newStickersModel(result.events)
result.permissions = permissions.newPermissionsModel(result.events)
result.settings = settings.newSettingsModel(result.events)
proc initNode*(self: Status) =
self.tasks.init()
@ -62,5 +64,6 @@ proc reset*(self: Status) =
proc getNodeVersion*(self: Status): string =
libstatus_settings.getWeb3ClientVersion()
# TODO: duplicated??
proc saveSetting*(self: Status, setting: Setting, value: string | bool) =
discard libstatus_settings.saveSetting(setting, value)