diff --git a/src/app/modules/main/profile_section/controller.nim b/src/app/modules/main/profile_section/controller.nim index c3deaf1cce..b62e99126f 100644 --- a/src/app/modules/main/profile_section/controller.nim +++ b/src/app/modules/main/profile_section/controller.nim @@ -37,3 +37,9 @@ method delete*[T](self: Controller[T]) = method init*[T](self: Controller[T]) = discard + +method toggleTelemetry*[T](self: Controller[T]) = + self.settingsService.toggleTelemetry() + +method isTelemetryEnabled*[T](self: Controller[T]): bool = + return self.settingsService.isTelemetryEnabled() diff --git a/src/app/modules/main/profile_section/controller_interface.nim b/src/app/modules/main/profile_section/controller_interface.nim index 95e9646a9c..0c1e58f8e3 100644 --- a/src/app/modules/main/profile_section/controller_interface.nim +++ b/src/app/modules/main/profile_section/controller_interface.nim @@ -9,6 +9,12 @@ method delete*(self: AccessInterface) {.base.} = method init*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") +method toggleTelemetry*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method isTelemetryEnabled*(self: AccessInterface): bool {.base.} = + raise newException(ValueError, "No implementation available") + type ## Abstract class (concept) which must be implemented by object/s used in this ## module. diff --git a/src/app/modules/main/profile_section/io_interface.nim b/src/app/modules/main/profile_section/io_interface.nim index 7dcd09fb2e..11824342f9 100644 --- a/src/app/modules/main/profile_section/io_interface.nim +++ b/src/app/modules/main/profile_section/io_interface.nim @@ -11,6 +11,9 @@ method load*(self: AccessInterface) {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") +method toggleTelemetry*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + # View Delegate Interface # Delegate for the view must be declared here due to use of QtObject and multi # inheritance, which is not well supported in Nim. diff --git a/src/app/modules/main/profile_section/module.nim b/src/app/modules/main/profile_section/module.nim index a042899f0b..f6112fc4eb 100644 --- a/src/app/modules/main/profile_section/module.nim +++ b/src/app/modules/main/profile_section/module.nim @@ -51,7 +51,7 @@ proc newModule*[T](delegate: T, Module[T] = result = Module[T]() result.delegate = delegate - result.view = view.newView() + result.view = view.newView(result) result.viewVariant = newQVariant(result.view) result.controller = controller.newController[Module[T]](result, accountsService, settingsService, profileService, languageService, mnemonicService, privacyService) result.moduleLoaded = false @@ -85,6 +85,8 @@ method load*[T](self: Module[T]) = self.privacyModule.load() self.aboutModule.load() + self.view.setIsTelemetryEnabled(self.controller.isTelemetryEnabled()) + self.moduleLoaded = true self.delegate.profileSectionDidLoad() @@ -93,3 +95,6 @@ method isLoaded*[T](self: Module[T]): bool = method viewDidLoad*(self: Module) = discard + +method toggleTelemetry*[T](self: Module[T]) = + self.controller.toggleTelemetry() diff --git a/src/app/modules/main/profile_section/view.nim b/src/app/modules/main/profile_section/view.nim index f8caffbd63..ed2eaf0889 100644 --- a/src/app/modules/main/profile_section/view.nim +++ b/src/app/modules/main/profile_section/view.nim @@ -1,8 +1,13 @@ import NimQml +import ./io_interface + QtObject: type View* = ref object of QObject + delegate: io_interface.AccessInterface + # TODO: move to the correct module once all have been merged + isTelemetryEnabled: bool proc setup(self: View) = self.QObject.setup @@ -10,6 +15,24 @@ QtObject: proc delete*(self: View) = self.QObject.delete - proc newView*(): View = + proc newView*(delegate: io_interface.AccessInterface): View = new(result, delete) + result.delegate = delegate result.setup() + + proc isTelemetryEnabledChanged*(self: View) {.signal.} + + proc setIsTelemetryEnabled*(self: View, isTelemetryEnabled: bool) = + self.isTelemetryEnabled = isTelemetryEnabled + self.isTelemetryEnabledChanged() + + proc getIsTelemetryEnabled*(self: View): QVariant {.slot.} = + return newQVariant(self.isTelemetryEnabled) + + QtProperty[QVariant] isTelemetryEnabled: + read = getIsTelemetryEnabled + notify = isTelemetryEnabledChanged + + proc toggleTelemetry*(self: View) {.slot.} = + self.delegate.toggleTelemetry() + self.setIsTelemetryEnabled(not self.isTelemetryEnabled) \ No newline at end of file diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index 9be919cd34..0c78348940 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -75,4 +75,16 @@ method getCurrentNetworkDetails*(self: Service): NetworkDetails = let networks = getSetting[seq[NetworkDetails]](Setting.Networks_Networks) for n in networks: if n.id == currNetwork: - return n \ No newline at end of file + return n + +method toggleTelemetry*(self: Service) = + let telemetryServerUrl = status_go_settings.getSetting[string](Setting.TelemetryServerUrl) + var newValue = "" + if telemetryServerUrl == "": + newValue = "https://telemetry.status.im" + + discard status_go_settings.saveSetting(Setting.TelemetryServerUrl, newValue) + +method isTelemetryEnabled*(self: Service): bool = + let telemetryServerUrl = status_go_settings.getSetting[string](Setting.TelemetryServerUrl) + return telemetryServerUrl != "" \ No newline at end of file diff --git a/src/app_service/service/settings/service_interface.nim b/src/app_service/service/settings/service_interface.nim index 5c42c8ae22..d5b8188908 100644 --- a/src/app_service/service/settings/service_interface.nim +++ b/src/app_service/service/settings/service_interface.nim @@ -47,3 +47,9 @@ method setDappsAddress*(self: ServiceInterface, address: string): bool {.base.} method getCurrentNetworkDetails*(self: ServiceInterface): NetworkDetails {.base.} = raise newException(ValueError, "No implementation available") + +method toggleTelemetry*(self: ServiceInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method isTelemetryEnabled*(self: ServiceInterface): bool {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/ui/app/AppLayouts/Profile/views/AdvancedView.qml b/ui/app/AppLayouts/Profile/views/AdvancedView.qml index 8d88b1b46f..8941e504bf 100644 --- a/ui/app/AppLayouts/Profile/views/AdvancedView.qml +++ b/ui/app/AppLayouts/Profile/views/AdvancedView.qml @@ -406,6 +406,16 @@ ScrollView { localAccountSensitiveSettings.stickersEnsRopsten = !localAccountSensitiveSettings.stickersEnsRopsten } } + + // TODO: replace with StatusQ component + StatusSettingsLineButton { + text: qsTr("Enable Telemetry") + isSwitch: true + switchChecked: root.store.profileModuleInst.isTelemetryEnabled + onClicked: { + openPopup(enableTelemetryConfirmationDialogComponent, {light: false}) + } + } } NetworksModal { @@ -416,6 +426,24 @@ ScrollView { id: fleetModal } + Component { + id: enableTelemetryConfirmationDialogComponent + ConfirmationDialog { + property bool mode: false + + id: confirmDialog + showCancelButton: true + confirmationText: qsTr("Are you sure you want to enable telemetry? This will reduce your privacy level while using Status. You need to restart the app for this change to take effect.") + onConfirmButtonClicked: { + root.store.profileModuleInst.toggleTelemetry() + close() + } + onCancelButtonClicked: { + close() + } + } + } + ConfirmationDialog { id: confirmationPopup property string settingsProp: "" diff --git a/vendor/status-lib b/vendor/status-lib index 1aba03aed6..5417274a3b 160000 --- a/vendor/status-lib +++ b/vendor/status-lib @@ -1 +1 @@ -Subproject commit 1aba03aed619b605a2f41eb02765d65756fff817 +Subproject commit 5417274a3bb83645725bdc9dcad3e6d5af4b269c