mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-26 13:36:04 +00:00
feat: select bloom filter level
This commit is contained in:
parent
f4da94af6a
commit
c21f80e7da
@ -10,6 +10,7 @@ QtObject:
|
|||||||
callResult: string
|
callResult: string
|
||||||
lastMessage*: string
|
lastMessage*: string
|
||||||
wakuBloomFilterMode*: bool
|
wakuBloomFilterMode*: bool
|
||||||
|
fullNode*: bool
|
||||||
|
|
||||||
proc setup(self: NodeView) =
|
proc setup(self: NodeView) =
|
||||||
self.QObject.setup
|
self.QObject.setup
|
||||||
@ -20,6 +21,7 @@ QtObject:
|
|||||||
result.callResult = "Use this tool to call JSONRPC methods"
|
result.callResult = "Use this tool to call JSONRPC methods"
|
||||||
result.lastMessage = ""
|
result.lastMessage = ""
|
||||||
result.wakuBloomFilterMode = false
|
result.wakuBloomFilterMode = false
|
||||||
|
result.fullNode = false
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
proc delete*(self: NodeView) =
|
proc delete*(self: NodeView) =
|
||||||
@ -69,9 +71,20 @@ QtObject:
|
|||||||
proc getWakuBloomFilterMode*(self: NodeView): bool {.slot.} =
|
proc getWakuBloomFilterMode*(self: NodeView): bool {.slot.} =
|
||||||
result = self.wakuBloomFilterMode
|
result = self.wakuBloomFilterMode
|
||||||
|
|
||||||
|
proc getBloomLevel*(self: NodeView): string {.slot.} =
|
||||||
|
if self.wakuBloomFilterMode and not self.fullNode:
|
||||||
|
return "normal"
|
||||||
|
if self.wakuBloomFilterMode and self.fullNode:
|
||||||
|
return "full"
|
||||||
|
return "light"
|
||||||
|
|
||||||
QtProperty[bool] wakuBloomFilterMode:
|
QtProperty[bool] wakuBloomFilterMode:
|
||||||
read = getWakuBloomFilterMode
|
read = getWakuBloomFilterMode
|
||||||
notify = receivedMessage
|
notify = initialized
|
||||||
|
|
||||||
|
QtProperty[string] bloomLevel:
|
||||||
|
read = getBloomLevel
|
||||||
|
notify = initialized
|
||||||
|
|
||||||
proc setWakuBloomFilterMode*(self: NodeView, bloomFilterMode: bool) {.slot.} =
|
proc setWakuBloomFilterMode*(self: NodeView, bloomFilterMode: bool) {.slot.} =
|
||||||
let statusGoResult = self.status.settings.setBloomFilterMode(bloomFilterMode)
|
let statusGoResult = self.status.settings.setBloomFilterMode(bloomFilterMode)
|
||||||
@ -80,7 +93,10 @@ QtObject:
|
|||||||
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
|
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
|
||||||
|
|
||||||
proc init*(self: NodeView) {.slot.} =
|
proc init*(self: NodeView) {.slot.} =
|
||||||
|
let nodeConfig = self.status.settings.getNodeConfig()
|
||||||
self.wakuBloomFilterMode = self.status.settings.getSetting[:bool](Setting.WakuBloomFilterMode)
|
self.wakuBloomFilterMode = self.status.settings.getSetting[:bool](Setting.WakuBloomFilterMode)
|
||||||
|
self.fullNode = nodeConfig["WakuConfig"]["FullNode"].getBool()
|
||||||
|
self.initialized()
|
||||||
|
|
||||||
proc wakuVersion*(self: NodeView): int {.slot.} =
|
proc wakuVersion*(self: NodeView): int {.slot.} =
|
||||||
var fleetStr = self.status.settings.getSetting[:string](Setting.Fleet)
|
var fleetStr = self.status.settings.getSetting[:string](Setting.Fleet)
|
||||||
@ -88,3 +104,22 @@ QtObject:
|
|||||||
let isWakuV2 = if fleet == WakuV2Prod or fleet == WakuV2Test: true else: false
|
let isWakuV2 = if fleet == WakuV2Prod or fleet == WakuV2Test: true else: false
|
||||||
if isWakuV2: return 2
|
if isWakuV2: return 2
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
proc setBloomLevel*(self: NodeView, level: string) {.slot.} =
|
||||||
|
var FullNode = false
|
||||||
|
var BloomFilterMode = false
|
||||||
|
case level:
|
||||||
|
of "light":
|
||||||
|
BloomFilterMode = false
|
||||||
|
FullNode = false
|
||||||
|
of "full":
|
||||||
|
BloomFilterMode = true
|
||||||
|
FullNode = true
|
||||||
|
else:
|
||||||
|
BloomFilterMode = true
|
||||||
|
FullNode = false
|
||||||
|
|
||||||
|
let statusGoResult = self.status.settings.setBloomLevel(BloomFilterMode, FullNode)
|
||||||
|
if statusGoResult.error != "":
|
||||||
|
error "Error saving updated node config", msg=statusGoResult.error
|
||||||
|
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
|
@ -161,9 +161,9 @@ var NODE_CONFIG* = %* {
|
|||||||
"URL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED
|
"URL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED
|
||||||
},
|
},
|
||||||
"WakuConfig": {
|
"WakuConfig": {
|
||||||
"BloomFilterMode": nil,
|
"BloomFilterMode": false,
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"LightClient": true,
|
"LightClient": false,
|
||||||
"MinimumPoW": 0.001
|
"MinimumPoW": 0.001
|
||||||
},
|
},
|
||||||
"WakuV2Config": {
|
"WakuV2Config": {
|
||||||
|
@ -175,10 +175,17 @@ proc setBloomFilterMode*(bloomFilterMode: bool): StatusGoError =
|
|||||||
let statusGoResult = saveSetting(Setting.WakuBloomFilterMode, bloomFilterMode)
|
let statusGoResult = saveSetting(Setting.WakuBloomFilterMode, bloomFilterMode)
|
||||||
if statusGoResult.error != "":
|
if statusGoResult.error != "":
|
||||||
return statusGoResult
|
return statusGoResult
|
||||||
|
|
||||||
var nodeConfig = getNodeConfig()
|
var nodeConfig = getNodeConfig()
|
||||||
nodeConfig["WakuConfig"]["BloomFilterMode"] = newJBool(bloomFilterMode)
|
nodeConfig["WakuConfig"]["BloomFilterMode"] = newJBool(bloomFilterMode)
|
||||||
|
return saveSetting(Setting.NodeConfig, nodeConfig)
|
||||||
|
|
||||||
|
proc setBloomLevel*(bloomFilterMode: bool, fullNode: bool): StatusGoError =
|
||||||
|
let statusGoResult = saveSetting(Setting.WakuBloomFilterMode, bloomFilterMode)
|
||||||
|
if statusGoResult.error != "":
|
||||||
|
return statusGoResult
|
||||||
|
var nodeConfig = getNodeConfig()
|
||||||
|
nodeConfig["WakuConfig"]["BloomFilterMode"] = newJBool(bloomFilterMode)
|
||||||
|
nodeConfig["WakuConfig"]["FullNode"] = newJBool(fullNode)
|
||||||
return saveSetting(Setting.NodeConfig, nodeConfig)
|
return saveSetting(Setting.NodeConfig, nodeConfig)
|
||||||
|
|
||||||
proc setFleet*(fleetConfig: FleetConfig, fleet: Fleet): StatusGoError =
|
proc setFleet*(fleetConfig: FleetConfig, fleet: Fleet): StatusGoError =
|
||||||
|
@ -69,3 +69,6 @@ proc setFleet*(self: SettingsModel, fleetConfig: FleetConfig, fleet: Fleet): Sta
|
|||||||
|
|
||||||
proc getNodeConfig*(self: SettingsModel): JsonNode =
|
proc getNodeConfig*(self: SettingsModel): JsonNode =
|
||||||
libstatus_settings.getNodeConfig()
|
libstatus_settings.getNodeConfig()
|
||||||
|
|
||||||
|
proc setBloomLevel*(self: SettingsModel, bloomFilterMode: bool, fullNode: bool): StatusGoError =
|
||||||
|
libstatus_settings.setBloomLevel(bloomFilterMode, fullNode)
|
@ -135,33 +135,83 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusSettingsLineButton {
|
StatusSectionHeadline {
|
||||||
//% "Waku Bloom Mode"
|
text: qsTr("Bloom filter level")
|
||||||
visible: profileModel.fleets.fleet != Constants.waku_prod && profileModel.fleets.fleet != Constants.waku_test
|
topPadding: Style.current.bigPadding
|
||||||
text: qsTrId("waku-bloom-mode")
|
bottomPadding: Style.current.padding
|
||||||
isSwitch: true
|
}
|
||||||
switchChecked: nodeModel.wakuBloomFilterMode
|
|
||||||
onClicked: function (checked) {
|
Row {
|
||||||
openPopup(bloomConfirmationDialogComponent, {bloomFilterMode: checked})
|
spacing: 11
|
||||||
}
|
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: bloomConfirmationDialogComponent
|
id: bloomConfirmationDialogComponent
|
||||||
ConfirmationDialog {
|
ConfirmationDialog {
|
||||||
property bool bloomFilterMode: false
|
property string mode: "normal"
|
||||||
|
|
||||||
id: confirmDialog
|
id: confirmDialog
|
||||||
//% "Warning!"
|
//% "Warning!"
|
||||||
title: qsTrId("close-app-title")
|
title: qsTrId("close-app-title")
|
||||||
confirmationText: qsTr("The account will be logged out. When you login again, the selected mode will be enabled")
|
confirmationText: qsTr("The account will be logged out. When you login again, the selected mode will be enabled")
|
||||||
onConfirmButtonClicked: {
|
onConfirmButtonClicked: {
|
||||||
nodeModel.setWakuBloomFilterMode(bloomFilterMode)
|
nodeModel.setBloomLevel(mode)
|
||||||
}
|
}
|
||||||
onClosed: {
|
onClosed: {
|
||||||
|
switch(nodeModel.bloomLevel){
|
||||||
|
case "light": btnBloomLight.click(); break;
|
||||||
|
case "normal": btnBloomNormal.click(); break;
|
||||||
|
case "full": btnBloomFull.click(); break;
|
||||||
|
}
|
||||||
destroy()
|
destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ButtonGroup {
|
||||||
|
id: bloomGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
BloomSelectorButton {
|
||||||
|
id: btnBloomLight
|
||||||
|
buttonGroup: bloomGroup
|
||||||
|
checkedByDefault: nodeModel.bloomLevel == "light"
|
||||||
|
btnText: qsTr("Light Node")
|
||||||
|
onToggled: {
|
||||||
|
if (nodeModel.bloomLevel != "light") {
|
||||||
|
openPopup(bloomConfirmationDialogComponent, {mode: "light"})
|
||||||
|
} else {
|
||||||
|
btnBloomLight.click()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BloomSelectorButton {
|
||||||
|
id: btnBloomNormal
|
||||||
|
buttonGroup: bloomGroup
|
||||||
|
checkedByDefault: nodeModel.bloomLevel == "normal"
|
||||||
|
btnText: qsTr("Normal")
|
||||||
|
onToggled: {
|
||||||
|
if (nodeModel.bloomLevel != "normal") {
|
||||||
|
openPopup(bloomConfirmationDialogComponent, {mode: "normal"})
|
||||||
|
} else {
|
||||||
|
btnBloomNormal.click()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BloomSelectorButton {
|
||||||
|
id: btnBloomFull
|
||||||
|
buttonGroup: bloomGroup
|
||||||
|
checkedByDefault: nodeModel.bloomLevel == "full"
|
||||||
|
btnText: qsTr("Full Node")
|
||||||
|
onToggled: {
|
||||||
|
if (nodeModel.bloomLevel != "full") {
|
||||||
|
openPopup(bloomConfirmationDialogComponent, {mode: "full"})
|
||||||
|
} else {
|
||||||
|
btnBloomFull.click()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusSettingsLineButton {
|
// StatusSettingsLineButton {
|
||||||
|
66
ui/app/AppLayouts/Profile/Sections/BloomSelectorButton.qml
Normal file
66
ui/app/AppLayouts/Profile/Sections/BloomSelectorButton.qml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import QtQuick 2.13
|
||||||
|
import QtQuick.Controls 2.13
|
||||||
|
import QtQuick.Layouts 1.13
|
||||||
|
import "../../../../imports"
|
||||||
|
import "../../../../shared"
|
||||||
|
import "../../../../shared/status"
|
||||||
|
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
property var buttonGroup
|
||||||
|
property string btnText: qsTr("TODO")
|
||||||
|
property bool hovered: false
|
||||||
|
property bool checkedByDefault: false
|
||||||
|
|
||||||
|
signal checked()
|
||||||
|
signal toggled(bool checked)
|
||||||
|
|
||||||
|
function click(){
|
||||||
|
radioBtn.toggle()
|
||||||
|
}
|
||||||
|
|
||||||
|
id: root
|
||||||
|
border.color: hovered || radioBtn.checked ? Style.current.primary : Style.current.border
|
||||||
|
border.width: 1
|
||||||
|
color: Style.current.transparent
|
||||||
|
width: 130
|
||||||
|
height: 120
|
||||||
|
clip: true
|
||||||
|
radius: Style.current.radius
|
||||||
|
|
||||||
|
StatusRadioButton {
|
||||||
|
id: radioBtn
|
||||||
|
ButtonGroup.group: buttonGroup
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.topMargin: 14
|
||||||
|
checked: root.checkedByDefault
|
||||||
|
onCheckedChanged: {
|
||||||
|
if (checked) {
|
||||||
|
root.checked()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
id: txt
|
||||||
|
text: btnText
|
||||||
|
font.pixelSize: 15
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
anchors.top: radioBtn.bottom
|
||||||
|
anchors.topMargin: 6
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: mouseArea
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
onEntered: root.hovered = true
|
||||||
|
onExited: root.hovered = false
|
||||||
|
onClicked: {
|
||||||
|
radioBtn.toggle()
|
||||||
|
root.toggled(radioBtn.checked)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user