Skip to content

Commit

Permalink
fix(settings): fix saveNewWakuNode in the settings
Browse files Browse the repository at this point in the history
fixes #12918 (part 4/4)
  • Loading branch information
friofry committed May 30, 2024
1 parent c47f51a commit 66189dc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/app/modules/main/profile_section/waku/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions src/app/modules/main/profile_section/waku/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
27 changes: 13 additions & 14 deletions src/app_service/service/node_configuration/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down
6 changes: 0 additions & 6 deletions src/app_service/service/settings/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,6 @@ QtObject:
proc unpinMailserver*(self: Service, fleet: Fleet): bool =
return self.pinMailserver("", 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
Expand Down
23 changes: 11 additions & 12 deletions src/backend/node_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,32 @@ proc switchFleet*(fleet: string, nodeConfig: JsonNode): RpcResponse[JsonNode] =
error "error doing rpc request", methodName = "switchFleet", exception=e.msg
raise newException(RpcException, e.msg)

proc callRPCMethod*(methodName: string, payload: JsonNode): RpcResponse[JsonNode] =
try:
result = core.callPrivateRPC(methodName.prefix, payload)
except RpcException as e:
error "error doing rpc request", methodName=methodName, exception=e.msg
raise newException(RpcException, e.msg)

proc enableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] =
result = callRPCMethod("enableCommunityHistoryArchiveProtocol", %* [])
return core.callPrivateRPC("enableCommunityHistoryArchiveProtocol".prefix, %* [])

proc disableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] =
result = callRPCMethod("disableCommunityHistoryArchiveProtocol", %* [])
return core.callPrivateRPC("disableCommunityHistoryArchiveProtocol".prefix, %* [])

proc setLogLevel*(logLevel: LogLevel): RpcResponse[JsonNode] =
let payload = %*[{
"logLevel": $logLevel
}]
result = callRPCMethod("setLogLevel", payload)
result = core.callPrivateRPC("setLogLevel".prefix, payload)

proc setMaxLogBackups*(maxLogBackups: int): RpcResponse[JsonNode] =
let payload = %*[{
"maxLogBackups": maxLogBackups
}]
result = callRPCMethod("setMaxLogBackups", payload)
return core.callPrivateRPC("setMaxLogBackups".prefix, payload)

proc setLightClient*(enabled: bool): RpcResponse[JsonNode] =
let payload = %*[{
"enabled": enabled
}]
result = callRPCMethod("setLightClient", payload)
return core.callPrivateRPC("setLightClient".prefix, payload)

proc saveNewWakuNode*(nodeAddress: string): RpcResponse[JsonNode] =
let payload = %*[{
"nodeAddress": nodeAddress
}]
return core.callPrivateRPC("saveNewWakuNode".prefix, payload)

0 comments on commit 66189dc

Please sign in to comment.