fix(settings): fix saving settings

* fix saveNewWakuNode in the settings
* fix setNimbusProxyConfigEnabled in the settings
* fix setLightMode in the settings
This commit is contained in:
Andrey Bocharnikov 2024-05-23 17:00:02 +04:00
parent 7e166ca9f2
commit 4145be8f76
10 changed files with 81 additions and 73 deletions

View File

@ -61,14 +61,14 @@ proc init*(self: Controller) =
proc sendRPCMessageRaw*(self: Controller, inputJSON: string): string = proc sendRPCMessageRaw*(self: Controller, inputJSON: string): string =
return self.nodeService.sendRPCMessageRaw(inputJSON); return self.nodeService.sendRPCMessageRaw(inputJSON);
proc isV2LightMode*(self: Controller): bool = proc isLightClient*(self: Controller): bool =
return self.nodeConfigurationService.isV2LightMode() return self.nodeConfigurationService.isLightClient()
proc isFullNode*(self: Controller): bool = proc isFullNode*(self: Controller): bool =
return self.nodeConfigurationService.isFullNode() return self.nodeConfigurationService.isFullNode()
proc setV2LightMode*(self: Controller, enabled: bool): bool = proc setLightClient*(self: Controller, enabled: bool): bool =
return self.nodeConfigurationService.setV2LightMode(enabled) return self.nodeConfigurationService.setLightClient(enabled)
proc getWakuVersion*(self: Controller): int = proc getWakuVersion*(self: Controller): int =
return 2 return 2

View File

@ -30,10 +30,10 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
method sendRPCMessageRaw*(self: AccessInterface, inputJSON: string): string {.base.} = method sendRPCMessageRaw*(self: AccessInterface, inputJSON: string): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method setV2LightMode*(self: AccessInterface, enabled: bool) {.base.} = method setLightClient*(self: AccessInterface, enabled: bool) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method isV2LightMode*(self: AccessInterface): bool {.base.} = method isLightClient*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method isFullNode*(self: AccessInterface): bool {.base.} = method isFullNode*(self: AccessInterface): bool {.base.} =

View File

@ -54,12 +54,12 @@ method viewDidLoad*(self: Module) =
method sendRPCMessageRaw*(self: Module, inputJSON: string): string = method sendRPCMessageRaw*(self: Module, inputJSON: string): string =
return self.controller.sendRPCMessageRaw(inputJSON) return self.controller.sendRPCMessageRaw(inputJSON)
method setV2LightMode*(self: Module, enabled: bool) = method setLightClient*(self: Module, enabled: bool) =
if(self.controller.setV2LightMode(enabled)): if(self.controller.setLightClient(enabled)):
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
method isV2LightMode*(self: Module): bool = method isLightClient*(self: Module): bool =
return self.controller.isV2LightMode() return self.controller.isLightClient()
method isFullNode*(self: Module): bool = method isFullNode*(self: Module): bool =
return self.controller.isFullNode() return self.controller.isFullNode()

View File

@ -97,11 +97,11 @@ QtObject:
proc log*(self: View, logContent: string) {.signal.} proc log*(self: View, logContent: string) {.signal.}
proc getWakuV2LightClient(self: View): bool {.slot.} = self.delegate.isV2LightMode() proc getWakuV2LightClient(self: View): bool {.slot.} = self.delegate.isLightClient()
QtProperty[bool] WakuV2LightClient: QtProperty[bool] WakuV2LightClient:
read = getWakuV2LightClient read = getWakuV2LightClient
notify = initialized notify = initialized
proc setWakuV2LightClient*(self: View, enabled: bool) {.slot.} = proc setWakuV2LightClient*(self: View, enabled: bool) {.slot.} =
self.delegate.setV2LightMode(enabled) self.delegate.setLightClient(enabled)

View File

@ -57,10 +57,10 @@ proc setMaxLogBackups*(self: Controller, value: int) =
self.delegate.onLogMaxBackupsChanged() self.delegate.onLogMaxBackupsChanged()
proc getWakuV2LightClientEnabled*(self: Controller): bool = proc getWakuV2LightClientEnabled*(self: Controller): bool =
return self.nodeConfigurationService.getV2LightMode() return self.nodeConfigurationService.isLightClient()
proc setWakuV2LightClientEnabled*(self: Controller, enabled: bool) = proc setWakuV2LightClientEnabled*(self: Controller, enabled: bool) =
if (not self.nodeConfigurationService.setV2LightMode(enabled)): if (not self.nodeConfigurationService.setLightClient(enabled)):
# in the future we may do a call from here to show a popup about this error # in the future we may do a call from here to show a popup about this error
error "an error occurred, we couldn't set WakuV2 light client" error "an error occurred, we couldn't set WakuV2 light client"
return return
@ -122,7 +122,7 @@ proc isNimbusProxyEnabled*(self: Controller): bool =
proc toggleNimbusProxy*(self: Controller) = proc toggleNimbusProxy*(self: Controller) =
let enabled = self.nodeConfigurationService.isNimbusProxyEnabled() let enabled = self.nodeConfigurationService.isNimbusProxyEnabled()
if(not self.nodeConfigurationService.setNimbusProxyConfig(not enabled)): if not self.nodeConfigurationService.setNimbusProxyConfigEnabled(not enabled):
error "an error occurred, we couldn't toggle nimbus proxy" error "an error occurred, we couldn't toggle nimbus proxy"
return return

View File

@ -34,5 +34,5 @@ proc init*(self: Controller) =
proc getAllWakuNodes*(self: Controller): seq[string] = proc getAllWakuNodes*(self: Controller): seq[string] =
return self.nodeConfigurationService.getAllWakuNodes() return self.nodeConfigurationService.getAllWakuNodes()
proc saveNewWakuNode*(self: Controller, nodeAddress: string) = proc saveNewWakuNode*(self: Controller, nodeAddress: string): bool =
self.nodeConfigurationService.saveNewWakuNode(nodeAddress) return self.nodeConfigurationService.saveNewWakuNode(nodeAddress)

View File

@ -61,6 +61,6 @@ method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant return self.viewVariant
method saveNewWakuNode*(self: Module, nodeAddress: string) = method saveNewWakuNode*(self: Module, nodeAddress: string) =
self.controller.saveNewWakuNode(nodeAddress) if self.controller.saveNewWakuNode(nodeAddress):
let item = initItem(nodeAddress) let item = initItem(nodeAddress)
self.view.model().addItem(item) self.view.model().addItem(item)

View File

@ -71,15 +71,6 @@ proc init*(self: Service) =
error "error: ", errDesription error "error: ", errDesription
return return
proc saveConfiguration(self: Service, configuration: NodeConfigDto): bool =
# FIXME: this method should be removed and the configuration should be updated in the status-go
# (see SetLogLevel, #14643)
if(not self.settingsService.saveNodeConfiguration(configuration.toJsonNode())):
error "error saving node configuration "
return false
self.configuration = configuration
return true
proc getWakuVersion*(self: Service): int = proc getWakuVersion*(self: Service): int =
if self.configuration.WakuConfig.Enabled: if self.configuration.WakuConfig.Enabled:
return WAKU_VERSION_1 return WAKU_VERSION_1
@ -143,11 +134,19 @@ proc getFleetAsString*(self: Service): string =
proc getAllWakuNodes*(self: Service): seq[string] = proc getAllWakuNodes*(self: Service): seq[string] =
return self.wakuNodes return self.wakuNodes
proc saveNewWakuNode*(self: Service, nodeAddress: string) = proc saveNewWakuNode*(self: Service, nodeAddress: string): bool =
var newConfiguration = self.configuration try:
newConfiguration.ClusterConfig.WakuNodes.add(nodeAddress) let response = status_node_config.saveNewWakuNode(nodeAddress)
self.configuration = newConfiguration
discard self.saveConfiguration(newConfiguration) if not response.error.isNil:
error "failed to add new waku node: ", errDescription = response.error.message
return false
self.configuration.ClusterConfig.WakuNodes.add(nodeAddress)
except Exception as e:
error "error saving new waku node: ", errDescription = e.msg
return false
return true
proc setFleet*(self: Service, fleet: string): bool = proc setFleet*(self: Service, fleet: string): bool =
if (not self.settingsService.saveFleet(fleet)): if (not self.settingsService.saveFleet(fleet)):
@ -197,13 +196,15 @@ proc setFleet*(self: Service, fleet: string): bool =
error "Could not switch fleet" error "Could not switch fleet"
return false return false
proc getV2LightMode*(self: Service): bool = proc setLightClient*(self: Service, enabled: bool): bool =
return self.configuration.WakuV2Config.LightClient let response = status_node_config.setLightClient(enabled)
proc setV2LightMode*(self: Service, enabled: bool): bool = if not response.error.isNil:
var newConfiguration = self.configuration error "failed to set light client: ", errDescription = response.error.message
newConfiguration.WakuV2Config.LightClient = enabled return false
return self.saveConfiguration(newConfiguration)
self.configuration.WakuV2Config.LightClient = enabled
return true
proc getLogLevel(self: Service): string = proc getLogLevel(self: Service): string =
return self.configuration.LogLevel return self.configuration.LogLevel
@ -231,12 +232,13 @@ proc getNimbusProxyConfig(self: Service): bool =
proc isNimbusProxyEnabled*(self: Service): bool = proc isNimbusProxyEnabled*(self: Service): bool =
return self.getNimbusProxyConfig() return self.getNimbusProxyConfig()
proc setNimbusProxyConfig*(self: Service, value: bool): bool = proc setNimbusProxyConfigEnabled*(self: Service, enabled: bool): bool =
var newConfiguration = self.configuration # FIXME: call status-go API to update NodeConfig
newConfiguration.NimbusProxyConfig.Enabled = value # when this is merged https://github.com/status-im/status-go/pull/4254
return self.saveConfiguration(newConfiguration) self.configuration.NimbusProxyConfig.Enabled = enabled
return true
proc isV2LightMode*(self: Service): bool = proc isLightClient*(self: Service): bool =
return self.configuration.WakuV2Config.LightClient return self.configuration.WakuV2Config.LightClient
proc isFullNode*(self: Service): bool = proc isFullNode*(self: Service): bool =
@ -246,6 +248,12 @@ proc getLogMaxBackups*(self: Service): int =
return self.configuration.LogMaxBackups return self.configuration.LogMaxBackups
proc setMaxLogBackups*(self: Service, value: int): bool = proc setMaxLogBackups*(self: Service, value: int): bool =
var newConfiguration = self.configuration let response = status_node_config.setMaxLogBackups(value)
newConfiguration.LogMaxBackups = value
return self.saveConfiguration(newConfiguration) if not response.error.isNil:
error "failed to set max log backups: ", errDescription = response.error.message
return false
self.configuration.LogMaxBackups = value
return true

View File

@ -446,12 +446,6 @@ QtObject:
proc unpinMailserver*(self: Service, fleet: Fleet): bool = proc unpinMailserver*(self: Service, fleet: Fleet): bool =
return self.setPinnedMailserverId("", fleet) return self.setPinnedMailserverId("", fleet)
proc saveNodeConfiguration*(self: Service, value: JsonNode): bool =
if(self.saveSetting(KEY_NODE_CONFIG, value)):
self.settings.nodeConfig = value
return true
return false
proc saveAutoMessageEnabled*(self: Service, value: bool): bool = proc saveAutoMessageEnabled*(self: Service, value: bool): bool =
if(self.saveSetting(KEY_AUTO_MESSAGE_ENABLED, value)): if(self.saveSetting(KEY_AUTO_MESSAGE_ENABLED, value)):
self.settings.autoMessageEnabled = value self.settings.autoMessageEnabled = value

View File

@ -29,25 +29,31 @@ proc switchFleet*(fleet: string, nodeConfig: JsonNode): RpcResponse[JsonNode] =
raise newException(RpcException, e.msg) raise newException(RpcException, e.msg)
proc enableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] = proc enableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] =
try: return core.callPrivateRPC("enableCommunityHistoryArchiveProtocol".prefix, %* [])
result = core.callPrivateRPC("enableCommunityHistoryArchiveProtocol".prefix)
except RpcException as e:
error "error doing rpc request", methodName = "enableCommunityHistoryArchiveProtocol", exception=e.msg
raise newException(RpcException, e.msg)
proc disableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] = proc disableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] =
try: return core.callPrivateRPC("disableCommunityHistoryArchiveProtocol".prefix, %* [])
result = core.callPrivateRPC("disableCommunityHistoryArchiveProtocol".prefix)
except RpcException as e:
error "error doing rpc request", methodName = "disableCommunityHistoryArchiveProtocol", exception=e.msg
raise newException(RpcException, e.msg)
proc setLogLevel*(logLevel: LogLevel): RpcResponse[JsonNode] = proc setLogLevel*(logLevel: LogLevel): RpcResponse[JsonNode] =
try:
let payload = %*[{ let payload = %*[{
"logLevel": $logLevel "logLevel": $logLevel
}] }]
result = core.callPrivateRPC("setLogLevel".prefix, payload) result = core.callPrivateRPC("setLogLevel".prefix, payload)
except RpcException as e:
error "error doing rpc request", methodName = "setLogLevel", exception=e.msg proc setMaxLogBackups*(maxLogBackups: int): RpcResponse[JsonNode] =
raise newException(RpcException, e.msg) let payload = %*[{
"maxLogBackups": maxLogBackups
}]
return core.callPrivateRPC("setMaxLogBackups".prefix, payload)
proc setLightClient*(enabled: bool): RpcResponse[JsonNode] =
let payload = %*[{
"enabled": enabled
}]
return core.callPrivateRPC("setLightClient".prefix, payload)
proc saveNewWakuNode*(nodeAddress: string): RpcResponse[JsonNode] =
let payload = %*[{
"nodeAddress": nodeAddress
}]
return core.callPrivateRPC("saveNewWakuNode".prefix, payload)