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 =
return self.nodeService.sendRPCMessageRaw(inputJSON);
proc isV2LightMode*(self: Controller): bool =
return self.nodeConfigurationService.isV2LightMode()
proc isLightClient*(self: Controller): bool =
return self.nodeConfigurationService.isLightClient()
proc isFullNode*(self: Controller): bool =
return self.nodeConfigurationService.isFullNode()
proc setV2LightMode*(self: Controller, enabled: bool): bool =
return self.nodeConfigurationService.setV2LightMode(enabled)
proc setLightClient*(self: Controller, enabled: bool): bool =
return self.nodeConfigurationService.setLightClient(enabled)
proc getWakuVersion*(self: Controller): int =
return 2

View File

@ -30,10 +30,10 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
method sendRPCMessageRaw*(self: AccessInterface, inputJSON: string): string {.base.} =
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")
method isV2LightMode*(self: AccessInterface): bool {.base.} =
method isLightClient*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method isFullNode*(self: AccessInterface): bool {.base.} =

View File

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

View File

@ -97,11 +97,11 @@ QtObject:
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:
read = getWakuV2LightClient
notify = initialized
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()
proc getWakuV2LightClientEnabled*(self: Controller): bool =
return self.nodeConfigurationService.getV2LightMode()
return self.nodeConfigurationService.isLightClient()
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
error "an error occurred, we couldn't set WakuV2 light client"
return
@ -122,7 +122,7 @@ proc isNimbusProxyEnabled*(self: Controller): bool =
proc toggleNimbusProxy*(self: Controller) =
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"
return

View File

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

View File

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

View File

@ -71,15 +71,6 @@ proc init*(self: Service) =
error "error: ", errDesription
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 =
if self.configuration.WakuConfig.Enabled:
return WAKU_VERSION_1
@ -143,11 +134,19 @@ proc getFleetAsString*(self: Service): string =
proc getAllWakuNodes*(self: Service): seq[string] =
return self.wakuNodes
proc saveNewWakuNode*(self: Service, nodeAddress: string) =
var newConfiguration = self.configuration
newConfiguration.ClusterConfig.WakuNodes.add(nodeAddress)
self.configuration = newConfiguration
discard self.saveConfiguration(newConfiguration)
proc saveNewWakuNode*(self: Service, nodeAddress: string): bool =
try:
let response = status_node_config.saveNewWakuNode(nodeAddress)
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 =
if (not self.settingsService.saveFleet(fleet)):
@ -197,13 +196,15 @@ proc setFleet*(self: Service, fleet: string): bool =
error "Could not switch fleet"
return false
proc getV2LightMode*(self: Service): bool =
return self.configuration.WakuV2Config.LightClient
proc setLightClient*(self: Service, enabled: bool): bool =
let response = status_node_config.setLightClient(enabled)
proc setV2LightMode*(self: Service, enabled: bool): bool =
var newConfiguration = self.configuration
newConfiguration.WakuV2Config.LightClient = enabled
return self.saveConfiguration(newConfiguration)
if not response.error.isNil:
error "failed to set light client: ", errDescription = response.error.message
return false
self.configuration.WakuV2Config.LightClient = enabled
return true
proc getLogLevel(self: Service): string =
return self.configuration.LogLevel
@ -231,12 +232,13 @@ proc getNimbusProxyConfig(self: Service): bool =
proc isNimbusProxyEnabled*(self: Service): bool =
return self.getNimbusProxyConfig()
proc setNimbusProxyConfig*(self: Service, value: bool): bool =
var newConfiguration = self.configuration
newConfiguration.NimbusProxyConfig.Enabled = value
return self.saveConfiguration(newConfiguration)
proc setNimbusProxyConfigEnabled*(self: Service, enabled: bool): bool =
# FIXME: call status-go API to update NodeConfig
# when this is merged https://github.com/status-im/status-go/pull/4254
self.configuration.NimbusProxyConfig.Enabled = enabled
return true
proc isV2LightMode*(self: Service): bool =
proc isLightClient*(self: Service): bool =
return self.configuration.WakuV2Config.LightClient
proc isFullNode*(self: Service): bool =
@ -246,6 +248,12 @@ proc getLogMaxBackups*(self: Service): int =
return self.configuration.LogMaxBackups
proc setMaxLogBackups*(self: Service, value: int): bool =
var newConfiguration = self.configuration
newConfiguration.LogMaxBackups = value
return self.saveConfiguration(newConfiguration)
let response = status_node_config.setMaxLogBackups(value)
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 =
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 =
if(self.saveSetting(KEY_AUTO_MESSAGE_ENABLED, value)):
self.settings.autoMessageEnabled = value

View File

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