From f2367824901e738300c7540fed2bf20c415d6a47 Mon Sep 17 00:00:00 2001 From: Godfrain Jacques Date: Tue, 20 Feb 2024 11:07:22 -0800 Subject: [PATCH] (feat/desktop) Add toggle for mainnet transaction validation with nimbus (#13227) - Adds the View for the toogle button --- .../profile_section/advanced/controller.nim | 12 +++++++ .../profile_section/advanced/io_interface.nim | 9 ++++++ .../main/profile_section/advanced/module.nim | 9 ++++++ .../main/profile_section/advanced/view.nim | 10 ++++++ .../node_configuration/dto/node_config.nim | 11 +++++++ .../service/node_configuration/service.nim | 11 +++++++ .../Profile/stores/AdvancedStore.qml | 8 +++++ .../AppLayouts/Profile/views/AdvancedView.qml | 32 +++++++++++++++++++ 8 files changed, 102 insertions(+) diff --git a/src/app/modules/main/profile_section/advanced/controller.nim b/src/app/modules/main/profile_section/advanced/controller.nim index db79c49c3a..130ef6392c 100644 --- a/src/app/modules/main/profile_section/advanced/controller.nim +++ b/src/app/modules/main/profile_section/advanced/controller.nim @@ -116,6 +116,18 @@ proc toggleDebug*(self: Controller) = self.delegate.onDebugToggled() +proc isNimbusProxyEnabled*(self: Controller): bool = + return self.nodeConfigurationService.isNimbusProxyEnabled() + +proc toggleNimbusProxy*(self: Controller) = + let enabled = self.nodeConfigurationService.isNimbusProxyEnabled() + + if(not self.nodeConfigurationService.setNimbusProxyConfig(not enabled)): + error "an error occurred, we couldn't toggle nimbus proxy" + return + + self.delegate.onNimbusProxyToggled() + proc toggleCommunitiesPortalSection*(self: Controller) = self.events.emit(TOGGLE_SECTION, ToggleSectionArgs(sectionType: SectionType.CommunitiesPortal)) diff --git a/src/app/modules/main/profile_section/advanced/io_interface.nim b/src/app/modules/main/profile_section/advanced/io_interface.nim index 937400b872..a771a993c7 100644 --- a/src/app/modules/main/profile_section/advanced/io_interface.nim +++ b/src/app/modules/main/profile_section/advanced/io_interface.nim @@ -30,6 +30,9 @@ method onAutoMessageToggled*(self: AccessInterface) {.base.} = method onDebugToggled*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method onNimbusProxyToggled*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + method viewDidLoad*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") @@ -69,6 +72,12 @@ method isRuntimeLogLevelSet*(self: AccessInterface): bool {.base.} = method toggleDebug*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method isNimbusProxyEnabled*(self: AccessInterface): bool {.base.} = + raise newException(ValueError, "No implementation available") + +method toggleNimbusProxy*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + method toggleCommunitiesPortalSection*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/profile_section/advanced/module.nim b/src/app/modules/main/profile_section/advanced/module.nim index 0628ceb8e1..4616495fe2 100644 --- a/src/app/modules/main/profile_section/advanced/module.nim +++ b/src/app/modules/main/profile_section/advanced/module.nim @@ -105,6 +105,15 @@ method toggleDebug*(self: Module) = method onDebugToggled*(self: Module) = self.view.isDebugEnabledChanged() +method isNimbusProxyEnabled*(self: Module): bool = + self.controller.isNimbusProxyEnabled() + +method toggleNimbusProxy*(self: Module) = + self.controller.toggleNimbusProxy() + +method onNimbusProxyToggled*(self: Module) = + self.view.isNimbusProxyEnabledChanged() + method isRuntimeLogLevelSet*(self: Module): bool = return constants.runtimeLogLevelSet() diff --git a/src/app/modules/main/profile_section/advanced/view.nim b/src/app/modules/main/profile_section/advanced/view.nim index 15c64cb2e3..ef822e6137 100644 --- a/src/app/modules/main/profile_section/advanced/view.nim +++ b/src/app/modules/main/profile_section/advanced/view.nim @@ -88,6 +88,16 @@ QtObject: proc toggleDebug*(self: View) {.slot.} = self.delegate.toggleDebug() + proc isNimbusProxyEnabledChanged*(self: View) {.signal.} + proc getIsNimbusProxyEnabled*(self: View): bool {.slot.} = + return self.delegate.isNimbusProxyEnabled() + QtProperty[bool] isNimbusProxyEnabled: + read = getIsNimbusProxyEnabled + notify = isNimbusProxyEnabledChanged + + proc toggleNimbusProxy*(self: View) {.slot.} = + self.delegate.toggleNimbusProxy() + proc getIsRuntimeLogLevelSet*(self: View): bool {.slot.} = return self.delegate.isRuntimeLogLevelSet() QtProperty[bool] isRuntimeLogLevelSet: diff --git a/src/app_service/service/node_configuration/dto/node_config.nim b/src/app_service/service/node_configuration/dto/node_config.nim index 37acacf2cc..b4d709af79 100644 --- a/src/app_service/service/node_configuration/dto/node_config.nim +++ b/src/app_service/service/node_configuration/dto/node_config.nim @@ -107,6 +107,9 @@ type EnableFilterFullNode*: bool UseShardAsDefaultTopic*: bool + NimbusProxyConfig* = object + Enabled*: bool + ShhextConfig* = object PFSEnabled*: bool BackupDisabledDataDir*: string @@ -230,11 +233,15 @@ type RequireTopics*: RequireTopics MailServerRegistryAddress*: string PushNotificationServerConfig*: PushNotificationServerConfig # not used in the app yet + NimbusProxyConfig*: NimbusProxyConfig proc toUpstreamConfig*(jsonObj: JsonNode): UpstreamConfig = discard jsonObj.getProp("Enabled", result.Enabled) discard jsonObj.getProp("URL", result.URL) +proc toNimbusProxyConfig*(jsonObj: JsonNode): NimbusProxyConfig = + discard jsonObj.getProp("Enabled", result.Enabled) + proc toNetwork*(jsonObj: JsonNode): Network = discard jsonObj.getProp("chainId", result.chainId) discard jsonObj.getProp("chainName", result.chainName) @@ -484,6 +491,10 @@ proc toNodeConfigDto*(jsonObj: JsonNode): NodeConfigDto = discard jsonObj.getProp("EnableNTPSync", result.EnableNTPSync) discard jsonObj.getProp("MailServerRegistryAddress", result.MailServerRegistryAddress) + var nimbusProxyConfigObj: JsonNode + if(jsonObj.getProp("NimbusProxyConfig", nimbusProxyConfigObj)): + result.NimbusProxyConfig = toNimbusProxyConfig(nimbusProxyConfigObj) + var upstreamConfigObj: JsonNode if(jsonObj.getProp("UpstreamConfig", upstreamConfigObj)): result.UpstreamConfig = toUpstreamConfig(upstreamConfigObj) diff --git a/src/app_service/service/node_configuration/service.nim b/src/app_service/service/node_configuration/service.nim index 4d0f5065b9..8b5f3025dc 100644 --- a/src/app_service/service/node_configuration/service.nim +++ b/src/app_service/service/node_configuration/service.nim @@ -211,6 +211,17 @@ proc setLogLevel*(self: Service, logLevel: LogLevel): bool = else: return false +proc getNimbusProxyConfig(self: Service): bool = + return self.configuration.NimbusProxyConfig.Enabled + +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 isV2LightMode*(self: Service): bool = return self.configuration.WakuV2Config.LightClient diff --git a/ui/app/AppLayouts/Profile/stores/AdvancedStore.qml b/ui/app/AppLayouts/Profile/stores/AdvancedStore.qml index b6b850470c..7570594283 100644 --- a/ui/app/AppLayouts/Profile/stores/AdvancedStore.qml +++ b/ui/app/AppLayouts/Profile/stores/AdvancedStore.qml @@ -13,6 +13,7 @@ QtObject { property bool wakuV2LightClientEnabled: advancedModule? advancedModule.wakuV2LightClientEnabled : false property bool isTelemetryEnabled: advancedModule? advancedModule.isTelemetryEnabled : false property bool isAutoMessageEnabled: advancedModule? advancedModule.isAutoMessageEnabled : false + property bool isNimbusProxyEnabled: advancedModule? advancedModule.isNimbusProxyEnabled : false property bool isDebugEnabled: advancedModule? advancedModule.isDebugEnabled : false readonly property bool isWakuV2ShardedCommunitiesEnabled: localAppSettings.wakuV2ShardedCommunitiesEnabled ?? false property int logMaxBackups: advancedModule ? advancedModule.logMaxBackups : 1 @@ -89,6 +90,13 @@ QtObject { root.advancedModule.toggleDebug() } + function toggleNimbusProxy() { + if(!root.advancedModule) + return + + root.advancedModule.toggleNimbusProxy() + } + function setMaxLogBackups(value) { if(!root.advancedModule) return diff --git a/ui/app/AppLayouts/Profile/views/AdvancedView.qml b/ui/app/AppLayouts/Profile/views/AdvancedView.qml index cb9d8dd261..9c740d0113 100644 --- a/ui/app/AppLayouts/Profile/views/AdvancedView.qml +++ b/ui/app/AppLayouts/Profile/views/AdvancedView.qml @@ -82,6 +82,17 @@ SettingsContentBase { } } + StatusSettingsLineButton { + anchors.leftMargin: 0 + anchors.rightMargin: 0 + text: qsTr("Mainnet data verified by Nimbus") + isSwitch: true + switchChecked: root.advancedStore.isNimbusProxyEnabled + onClicked: { + Global.openPopup(enableNimbusProxyComponent) + } + } + StatusBaseText { anchors.left: parent.left anchors.right: parent.right @@ -551,6 +562,27 @@ SettingsContentBase { } } + Component { + id: enableNimbusProxyComponent + ConfirmationDialog { + property bool mode: false + + id: confirmDialog + destroyOnClose: true + showCancelButton: true + confirmationText: qsTr("Are you sure you want to %1 Nimbus proxy? You need to restart the app for this change to take effect.").arg(root.advancedStore.isNimbusProxyEnabled ? + qsTr("disable") : + qsTr("enable")) + onConfirmButtonClicked: { + root.advancedStore.toggleNimbusProxy() + close() + } + onCancelButtonClicked: { + close() + } + } + } + Component { id: changeNumberOfLogsArchived