From 4145be8f7698e381325c8501269b2fd2a275d780 Mon Sep 17 00:00:00 2001 From: Andrey Bocharnikov Date: Thu, 23 May 2024 17:00:02 +0400 Subject: [PATCH] fix(settings): fix saving settings * fix saveNewWakuNode in the settings * fix setNimbusProxyConfigEnabled in the settings * fix setLightMode in the settings --- .../modules/main/node_section/controller.nim | 8 +-- .../main/node_section/io_interface.nim | 4 +- src/app/modules/main/node_section/module.nim | 8 +-- src/app/modules/main/node_section/view.nim | 4 +- .../profile_section/advanced/controller.nim | 6 +- .../main/profile_section/waku/controller.nim | 4 +- .../main/profile_section/waku/module.nim | 6 +- .../service/node_configuration/service.nim | 64 +++++++++++-------- src/app_service/service/settings/service.nim | 6 -- src/backend/node_config.nim | 44 +++++++------ 10 files changed, 81 insertions(+), 73 deletions(-) diff --git a/src/app/modules/main/node_section/controller.nim b/src/app/modules/main/node_section/controller.nim index 0146290939..87346b1dba 100644 --- a/src/app/modules/main/node_section/controller.nim +++ b/src/app/modules/main/node_section/controller.nim @@ -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 diff --git a/src/app/modules/main/node_section/io_interface.nim b/src/app/modules/main/node_section/io_interface.nim index 8f942af01d..90ee649044 100644 --- a/src/app/modules/main/node_section/io_interface.nim +++ b/src/app/modules/main/node_section/io_interface.nim @@ -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.} = diff --git a/src/app/modules/main/node_section/module.nim b/src/app/modules/main/node_section/module.nim index 112b6a9bd8..5bd8383d25 100644 --- a/src/app/modules/main/node_section/module.nim +++ b/src/app/modules/main/node_section/module.nim @@ -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() diff --git a/src/app/modules/main/node_section/view.nim b/src/app/modules/main/node_section/view.nim index f5fc03db38..f3f1d480af 100644 --- a/src/app/modules/main/node_section/view.nim +++ b/src/app/modules/main/node_section/view.nim @@ -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) diff --git a/src/app/modules/main/profile_section/advanced/controller.nim b/src/app/modules/main/profile_section/advanced/controller.nim index 69d11952ed..61ad5f28fc 100644 --- a/src/app/modules/main/profile_section/advanced/controller.nim +++ b/src/app/modules/main/profile_section/advanced/controller.nim @@ -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 diff --git a/src/app/modules/main/profile_section/waku/controller.nim b/src/app/modules/main/profile_section/waku/controller.nim index 5f002b7d8c..99756754e3 100644 --- a/src/app/modules/main/profile_section/waku/controller.nim +++ b/src/app/modules/main/profile_section/waku/controller.nim @@ -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) diff --git a/src/app/modules/main/profile_section/waku/module.nim b/src/app/modules/main/profile_section/waku/module.nim index f4f3d13ddb..ec61143a59 100644 --- a/src/app/modules/main/profile_section/waku/module.nim +++ b/src/app/modules/main/profile_section/waku/module.nim @@ -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) diff --git a/src/app_service/service/node_configuration/service.nim b/src/app_service/service/node_configuration/service.nim index 68de9fcd93..dad51eec72 100644 --- a/src/app_service/service/node_configuration/service.nim +++ b/src/app_service/service/node_configuration/service.nim @@ -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 + diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index 0e8ce0146e..0940fdae88 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -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 diff --git a/src/backend/node_config.nim b/src/backend/node_config.nim index 6a5b25026f..05ddd6e99e 100644 --- a/src/backend/node_config.nim +++ b/src/backend/node_config.nim @@ -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)