feat: cache settings so only retreived when clean
This commit is contained in:
parent
88e5f1a46d
commit
8e6eb65509
|
@ -31,8 +31,8 @@ proc init*(self: ProfileController, account: Account) =
|
||||||
# Ideally, this module should call getSettings once, and fill the
|
# Ideally, this module should call getSettings once, and fill the
|
||||||
# profile with all the information comming from the settings.
|
# profile with all the information comming from the settings.
|
||||||
let response = status_settings.getSettings()
|
let response = status_settings.getSettings()
|
||||||
let pubKey = response["public-key"].getStr
|
let pubKey = status_settings.getSetting[string]("public-key", "0x0")
|
||||||
let mnemonic = response["mnemonic"].getStr
|
let mnemonic = status_settings.getSetting[string]("mnemonic", "")
|
||||||
profile.id = pubKey
|
profile.id = pubKey
|
||||||
|
|
||||||
self.view.setNewProfile(profile)
|
self.view.setNewProfile(profile)
|
||||||
|
|
|
@ -1,22 +1,31 @@
|
||||||
import core, ./types
|
import core, ./types, ../../signals/types as statusgo_types
|
||||||
import json, tables
|
import json, tables
|
||||||
import json_serialization
|
import json_serialization
|
||||||
|
|
||||||
proc saveSettings*(key: string, value: string | JsonNode): string =
|
var settings: JsonNode = %*{}
|
||||||
callPrivateRPC("settings_saveSetting", %* [
|
var dirty: bool = false
|
||||||
|
|
||||||
|
proc saveSettings*(key: string, value: string | JsonNode): StatusGoError =
|
||||||
|
let response = callPrivateRPC("settings_saveSetting", %* [
|
||||||
key, value
|
key, value
|
||||||
])
|
])
|
||||||
|
try:
|
||||||
|
result = Json.decode($response, StatusGoError)
|
||||||
|
except:
|
||||||
|
dirty = true
|
||||||
|
|
||||||
proc getWeb3ClientVersion*(): string =
|
proc getWeb3ClientVersion*(): string =
|
||||||
parseJson(callPrivateRPC("web3_clientVersion"))["result"].getStr
|
parseJson(callPrivateRPC("web3_clientVersion"))["result"].getStr
|
||||||
|
|
||||||
proc getSettings*(): JsonNode =
|
proc getSettings*(useCached: bool = true): JsonNode =
|
||||||
callPrivateRPC("settings_getSettings").parseJSON()["result"]
|
if useCached and not dirty:
|
||||||
# TODO: return an Table/Object instead
|
return settings
|
||||||
|
settings = callPrivateRPC("settings_getSettings").parseJSON()["result"]
|
||||||
|
dirty = false
|
||||||
|
result = settings
|
||||||
|
|
||||||
|
proc getSetting*[T](name: string, defaultValue: T, useCached: bool = true): T =
|
||||||
proc getSetting*[T](name: string, defaultValue: T): T =
|
let settings: JsonNode = getSettings(useCached)
|
||||||
let settings: JsonNode = getSettings()
|
|
||||||
if not settings.contains(name):
|
if not settings.contains(name):
|
||||||
return defaultValue
|
return defaultValue
|
||||||
result = Json.decode($settings{name}, T)
|
result = Json.decode($settings{name}, T)
|
||||||
|
|
Loading…
Reference in New Issue