feat(@wallet): confirmation and restart when changing rpc endpoint

This commit is contained in:
Anthony Laibe 2024-01-16 13:47:23 +01:00 committed by Anthony Laibe
parent 2b6f2229c7
commit a6be5bd4fb
1 changed files with 112 additions and 33 deletions

View File

@ -2,6 +2,7 @@ import QtQuick 2.13
import QtQuick.Layouts 1.13 import QtQuick.Layouts 1.13
import StatusQ.Core 0.1 import StatusQ.Core 0.1
import StatusQ.Popups 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
import StatusQ.Controls 0.1 import StatusQ.Controls 0.1
@ -96,6 +97,19 @@ ColumnLayout {
return p1 + p2.replace(/./g, '*'); return p1 + p2.replace(/./g, '*');
}); });
} }
function save() {
let main = mainRpcInput.text
let fallback = failoverRpcUrlInput.text
if (main === d.mask(network.originalRpcURL)) {
main = network.originalRpcURL
}
if (fallback === d.mask(network.originalFallbackURL)) {
fallback = network.originalFallbackURL
}
root.updateNetworkValues(network.chainId, main, fallback, false)
}
} }
Connections { Connections {
@ -163,7 +177,7 @@ ColumnLayout {
anchors.topMargin: 4 anchors.topMargin: 4
anchors.right: parent.right anchors.right: parent.right
elide: Text.ElideRight elide: Text.ElideRight
text: qsTr("Required") text: qsTr("Required (changes require restart)")
font.pixelSize: 12 font.pixelSize: 12
color: Theme.palette.baseColor1 color: Theme.palette.baseColor1
} }
@ -210,11 +224,24 @@ ColumnLayout {
} }
} }
Item {
Layout.fillWidth: true
Layout.preferredHeight: childrenRect.height
StatusBaseText {
id: optionalText
anchors.top: parent.top
anchors.topMargin: 4
anchors.right: parent.right
elide: Text.ElideRight
text: qsTr("Optional (changes require restart)")
font.pixelSize: 12
color: Theme.palette.baseColor1
}
StatusInput { StatusInput {
id: failoverRpcUrlInput id: failoverRpcUrlInput
objectName: "failoverRpcUrlInputObject" objectName: "failoverRpcUrlInputObject"
input.edit.objectName: "editNetworkFailoverRpcUrlInput" input.edit.objectName: "editNetworkFailoverRpcUrlInput"
Layout.fillWidth: true width: parent.width
label: qsTr("Failover JSON RPC URL") label: qsTr("Failover JSON RPC URL")
text: { text: {
if (!network) { if (!network) {
@ -230,7 +257,7 @@ ColumnLayout {
d.evaluationStatusFallBackRpc = EditNetworkForm.Empty d.evaluationStatusFallBackRpc = EditNetworkForm.Empty
return return
} }
else {
if ((d.mask(network.originalFallbackURL) === text) || if ((d.mask(network.originalFallbackURL) === text) ||
(network.fallbackURL === text)) { (network.fallbackURL === text)) {
d.evaluationStatusFallBackRpc = EditNetworkForm.UnTouched d.evaluationStatusFallBackRpc = EditNetworkForm.UnTouched
@ -239,12 +266,12 @@ ColumnLayout {
Qt.callLater(d.evaluateRpcEndPoint, text, false); Qt.callLater(d.evaluateRpcEndPoint, text, false);
} }
} }
}
errorMessageCmp.horizontalAlignment: d.getErrorMessageAlignment(d.evaluationStatusFallBackRpc) errorMessageCmp.horizontalAlignment: d.getErrorMessageAlignment(d.evaluationStatusFallBackRpc)
errorMessageCmp.visible: d.evaluationStatusFallBackRpc !== EditNetworkForm.UnTouched errorMessageCmp.visible: d.evaluationStatusFallBackRpc !== EditNetworkForm.UnTouched
errorMessageCmp.text: d.getUrlStatusText(d.evaluationStatusFallBackRpc, text) errorMessageCmp.text: d.getUrlStatusText(d.evaluationStatusFallBackRpc, text)
errorMessageCmp.color: d.getErrorMessageColor(d.evaluationStatusFallBackRpc) errorMessageCmp.color: d.getErrorMessageColor(d.evaluationStatusFallBackRpc)
} }
}
StatusInput { StatusInput {
input.edit.objectName: "editNetworkExplorerInput" input.edit.objectName: "editNetworkExplorerInput"
@ -291,17 +318,69 @@ ColumnLayout {
) && warningCheckbox.checked ) && warningCheckbox.checked
onClicked: { onClicked: {
let main = mainRpcInput.text Global.openPopup(confirmationDialogComponent)
let fallback = failoverRpcUrlInput.text }
if (main === d.mask(network.originalRpcURL)) { }
main = network.originalRpcURL
} }
if (fallback === d.mask(network.originalFallbackURL)) { Component {
fallback = network.originalFallbackURL id: confirmationDialogComponent
StatusModal {
headerSettings.title: qsTr("RPC URL change requires app restart")
contentItem: Item {
width: parent.width
implicitHeight: childrenRect.height
Column {
width: parent.width - 32
anchors.horizontalCenter: parent.horizontalCenter
Item {
width: parent.width
height: 16
} }
root.updateNetworkValues(network.chainId, main, fallback, false)
StatusBaseText {
text: qsTr("For new JSON RPC URLs to take effect, Status must be restarted. Are you ready to do this now?")
font.pixelSize: 15
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
color: Theme.palette.directColor1
}
Item {
width: parent.width
height: 16
} }
} }
} }
rightButtons: [
StatusFlatButton {
id: laterButton
text: qsTr("Save and restart later")
type: StatusBaseButton.Type.Normal
onClicked: {
close()
d.save()
}
},
StatusButton {
id: saveButton
type: StatusBaseButton.Type.Normal
text: qsTr("Save and restart Status")
focus: true
Keys.onReturnPressed: function(event) {
saveButton.clicked()
}
onClicked: {
close()
d.save()
Qt.quit()
}
}
]
}
}
} }