2023-07-11 15:10:26 +00:00
|
|
|
|
import QtQuick 2.13
|
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
|
|
|
|
|
import shared.panels 1.0
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
property var network
|
|
|
|
|
property var networksModule
|
2023-09-04 15:36:28 +00:00
|
|
|
|
signal evaluateRpcEndPoint(string url, bool isMainUrl)
|
2023-07-11 15:10:26 +00:00
|
|
|
|
signal updateNetworkValues(int chainId, string newMainRpcInput, string newFailoverRpcUrl)
|
|
|
|
|
|
|
|
|
|
enum EvaluationState {
|
|
|
|
|
UnTouched,
|
|
|
|
|
Pending,
|
|
|
|
|
Verified,
|
|
|
|
|
InvalidURL,
|
2023-09-04 15:36:28 +00:00
|
|
|
|
PingUnsuccessful,
|
2023-09-15 08:13:21 +00:00
|
|
|
|
SameAsOther,
|
|
|
|
|
Empty
|
2023-07-11 15:10:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
|
id: d
|
2023-09-04 15:36:28 +00:00
|
|
|
|
property int evaluationStatusMainRpc: EditNetworkForm.UnTouched
|
2023-07-11 15:10:26 +00:00
|
|
|
|
property int evaluationStatusFallBackRpc: EditNetworkForm.UnTouched
|
2023-09-04 15:36:28 +00:00
|
|
|
|
property var evaluateRpcEndPoint: Backpressure.debounce(root, 400, function (value, isMainUrl) {
|
2023-07-18 14:02:03 +00:00
|
|
|
|
if(!Utils.isURL(value)) {
|
2023-09-04 15:36:28 +00:00
|
|
|
|
if(isMainUrl)
|
|
|
|
|
d.evaluationStatusMainRpc = EditNetworkForm.InvalidURL
|
|
|
|
|
else
|
2023-07-18 14:02:03 +00:00
|
|
|
|
d.evaluationStatusFallBackRpc = EditNetworkForm.InvalidURL
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-09-04 15:36:28 +00:00
|
|
|
|
root.evaluateRpcEndPoint(value, isMainUrl)
|
2023-07-11 15:10:26 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function revertValues() {
|
|
|
|
|
warningCheckbox.checked = false
|
2023-09-04 15:36:28 +00:00
|
|
|
|
d.evaluationStatusMainRpc = EditNetworkForm.UnTouched
|
2023-07-11 15:10:26 +00:00
|
|
|
|
d.evaluationStatusFallBackRpc = EditNetworkForm.UnTouched
|
|
|
|
|
if(!!network) {
|
2023-09-19 11:42:25 +00:00
|
|
|
|
mainRpcInput.text = d.mask(network.originalRpcURL)
|
|
|
|
|
failoverRpcUrlInput.text = d.mask(network.originalFallbackURL)
|
2023-07-11 15:10:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getUrlStatusText(status, text) {
|
|
|
|
|
switch(status) {
|
|
|
|
|
case EditNetworkForm.Pending:
|
|
|
|
|
return qsTr("Checking RPC...")
|
|
|
|
|
case EditNetworkForm.InvalidURL:
|
|
|
|
|
return qsTr("What is %1? This isn’t a URL 😒").arg(text)
|
|
|
|
|
case EditNetworkForm.PingUnsuccessful:
|
|
|
|
|
return qsTr("RPC appears to be either offline or this is not a valid JSON RPC endpoint URL")
|
|
|
|
|
case EditNetworkForm.Verified:
|
|
|
|
|
return qsTr("RPC successfully reached")
|
2023-09-04 15:36:28 +00:00
|
|
|
|
case EditNetworkForm.SameAsOther:
|
|
|
|
|
return qsTr("Main and failover JSON RPC URLs are the same")
|
2023-07-11 15:10:26 +00:00
|
|
|
|
default: return ""
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-05 15:27:30 +00:00
|
|
|
|
|
|
|
|
|
function getErrorMessageColor(status) {
|
|
|
|
|
switch(status) {
|
|
|
|
|
case EditNetworkForm.Pending:
|
|
|
|
|
return Theme.palette.baseColor1
|
|
|
|
|
case EditNetworkForm.SameAsOther:
|
|
|
|
|
return Theme.palette.warningColor1
|
|
|
|
|
case EditNetworkForm.Verified:
|
|
|
|
|
return Theme.palette.successColor1
|
|
|
|
|
default: return Theme.palette.dangerColor1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getErrorMessageAlignment(status) {
|
|
|
|
|
switch(status) {
|
|
|
|
|
case EditNetworkForm.Pending:
|
|
|
|
|
case EditNetworkForm.Verified:
|
|
|
|
|
case EditNetworkForm.SameAsOther:
|
|
|
|
|
return Text.AlignLeft
|
|
|
|
|
default: return Text.AlignRight
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-19 11:42:25 +00:00
|
|
|
|
|
|
|
|
|
function mask(rpcUrl) {
|
|
|
|
|
// Mask the last part of the URL
|
|
|
|
|
return rpcUrl.replace(/(\/)([^\/]+)$/, (match, p1, p2) => {
|
|
|
|
|
return p1 + p2.replace(/./g, '*');
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-11 15:10:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onVisibleChanged: if(!visible) {d.revertValues()}
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: networksModule
|
2023-09-04 15:36:28 +00:00
|
|
|
|
function onChainIdFetchedForUrl(url, chainId, success, isMainUrl) {
|
2023-07-12 05:58:33 +00:00
|
|
|
|
let status = EditNetworkForm.PingUnsuccessful
|
|
|
|
|
if(success) {
|
2023-09-04 15:36:28 +00:00
|
|
|
|
if((isMainUrl && url === network.fallbackURL) ||
|
|
|
|
|
(!isMainUrl && url === network.rpcURL)) {
|
|
|
|
|
status = EditNetworkForm.SameAsOther
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
status = EditNetworkForm.Verified
|
2023-07-11 15:10:26 +00:00
|
|
|
|
}
|
2023-09-04 15:36:28 +00:00
|
|
|
|
if(isMainUrl)
|
|
|
|
|
d.evaluationStatusMainRpc = status
|
|
|
|
|
else
|
|
|
|
|
d.evaluationStatusFallBackRpc = status
|
2023-07-11 15:10:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spacing: 20
|
|
|
|
|
|
|
|
|
|
StatusInput {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
label: qsTr("Network name")
|
2023-10-02 12:45:27 +00:00
|
|
|
|
input.edit.objectName: "editNetworkNameInput"
|
2023-07-11 15:10:26 +00:00
|
|
|
|
text: !!network ? network.chainName : ""
|
|
|
|
|
input.enabled: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusInput {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
label: qsTr("Short name")
|
2023-10-02 12:45:27 +00:00
|
|
|
|
input.edit.objectName: "editNetworkShortNameInput"
|
2023-07-11 15:10:26 +00:00
|
|
|
|
text: !!network ? network.shortName : ""
|
|
|
|
|
input.enabled: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusInput {
|
|
|
|
|
Layout.fillWidth: true
|
2023-10-02 12:45:27 +00:00
|
|
|
|
input.edit.objectName: "editNetworkChainIdInput"
|
2023-07-11 15:10:26 +00:00
|
|
|
|
label: qsTr("Chain ID")
|
|
|
|
|
text: !!network ? network.chainId : ""
|
|
|
|
|
input.enabled: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusInput {
|
|
|
|
|
Layout.fillWidth: true
|
2023-10-02 12:45:27 +00:00
|
|
|
|
input.edit.objectName: "editNetworkSymbolInput"
|
2023-07-11 15:10:26 +00:00
|
|
|
|
label: qsTr("Native Token Symbol")
|
|
|
|
|
text: !!network ? network.nativeCurrencySymbol : ""
|
|
|
|
|
input.enabled: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.preferredHeight: childrenRect.height
|
|
|
|
|
StatusBaseText {
|
|
|
|
|
id: requiredText
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: 4
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
elide: Text.ElideRight
|
|
|
|
|
text: qsTr("Required")
|
|
|
|
|
font.pixelSize: 12
|
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
|
}
|
|
|
|
|
StatusInput {
|
|
|
|
|
id: mainRpcInput
|
2023-10-04 11:45:47 +00:00
|
|
|
|
objectName: "mainRpcInputObject"
|
2023-10-02 12:45:27 +00:00
|
|
|
|
input.edit.objectName: "editNetworkMainRpcInput"
|
2023-07-11 15:10:26 +00:00
|
|
|
|
width: parent.width
|
|
|
|
|
label: qsTr("Main JSON RPC URL")
|
2023-08-17 09:38:10 +00:00
|
|
|
|
text: {
|
|
|
|
|
if (!network) {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2023-09-04 15:36:28 +00:00
|
|
|
|
if (network.originalRpcURL === network.rpcURL) {
|
2023-09-19 11:42:25 +00:00
|
|
|
|
return d.mask(network.rpcURL)
|
2023-08-17 09:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
return network.rpcURL
|
|
|
|
|
}
|
2023-07-11 15:10:26 +00:00
|
|
|
|
onTextChanged: {
|
2023-09-15 08:13:21 +00:00
|
|
|
|
if (text === "") {
|
|
|
|
|
d.evaluationStatusMainRpc = EditNetworkForm.Empty
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-09-19 11:42:25 +00:00
|
|
|
|
|
|
|
|
|
if (!!text && d.mask(network.originalRpcURL) === text) {
|
|
|
|
|
d.evaluationStatusMainRpc = EditNetworkForm.Verified
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!!text && d.mask(network.originalRpcURL) !== text) {
|
2023-09-04 15:36:28 +00:00
|
|
|
|
d.evaluationStatusMainRpc = EditNetworkForm.Pending
|
|
|
|
|
Qt.callLater(d.evaluateRpcEndPoint, text, true);
|
2023-07-11 15:10:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-05 15:27:30 +00:00
|
|
|
|
errorMessageCmp.horizontalAlignment: d.getErrorMessageAlignment(d.evaluationStatusMainRpc)
|
2023-09-04 15:36:28 +00:00
|
|
|
|
errorMessageCmp.visible: d.evaluationStatusMainRpc !== EditNetworkForm.UnTouched
|
2023-09-15 08:13:21 +00:00
|
|
|
|
|
2023-09-05 15:27:30 +00:00
|
|
|
|
errorMessageCmp.color: d.getErrorMessageColor(d.evaluationStatusMainRpc)
|
2023-09-15 08:13:21 +00:00
|
|
|
|
errorMessageCmp.text: {
|
|
|
|
|
if (text === "") {
|
|
|
|
|
return qsTr("Main JSON RPC URL is required")
|
|
|
|
|
}
|
|
|
|
|
return d.getUrlStatusText(d.evaluationStatusMainRpc, text)
|
|
|
|
|
}
|
2023-07-11 15:10:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusInput {
|
|
|
|
|
id: failoverRpcUrlInput
|
2023-10-04 11:45:47 +00:00
|
|
|
|
objectName: "failoverRpcUrlInputObject"
|
2023-10-02 12:45:27 +00:00
|
|
|
|
input.edit.objectName: "editNetworkFailoverRpcUrlInput"
|
2023-07-11 15:10:26 +00:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
label: qsTr("Failover JSON RPC URL")
|
2023-08-17 09:38:10 +00:00
|
|
|
|
text: {
|
|
|
|
|
if (!network) {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2023-09-04 15:36:28 +00:00
|
|
|
|
if (network.originalFallbackURL === network.fallbackURL) {
|
2023-09-19 11:42:25 +00:00
|
|
|
|
return d.mask(network.fallbackURL)
|
2023-08-17 09:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
return network.fallbackURL
|
|
|
|
|
}
|
2023-07-11 15:10:26 +00:00
|
|
|
|
onTextChanged: {
|
2023-09-15 08:13:21 +00:00
|
|
|
|
if (text === "") {
|
|
|
|
|
d.evaluationStatusFallBackRpc = EditNetworkForm.Empty
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-19 11:42:25 +00:00
|
|
|
|
if (!!text && d.mask(network.originalFallbackURL) === text) {
|
|
|
|
|
d.evaluationStatusFallBackRpc = EditNetworkForm.Verified
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!!text && d.mask(network.originalFallbackURL) !== text) {
|
2023-07-11 15:10:26 +00:00
|
|
|
|
d.evaluationStatusFallBackRpc = EditNetworkForm.Pending
|
2023-09-04 15:36:28 +00:00
|
|
|
|
Qt.callLater(d.evaluateRpcEndPoint, text, false);
|
2023-07-11 15:10:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-05 15:27:30 +00:00
|
|
|
|
errorMessageCmp.horizontalAlignment: d.getErrorMessageAlignment(d.evaluationStatusFallBackRpc)
|
2023-07-11 15:10:26 +00:00
|
|
|
|
errorMessageCmp.visible: d.evaluationStatusFallBackRpc !== EditNetworkForm.UnTouched
|
|
|
|
|
errorMessageCmp.text: d.getUrlStatusText(d.evaluationStatusFallBackRpc, text)
|
2023-09-05 15:27:30 +00:00
|
|
|
|
errorMessageCmp.color: d.getErrorMessageColor(d.evaluationStatusFallBackRpc)
|
2023-07-11 15:10:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusInput {
|
2023-10-02 12:45:27 +00:00
|
|
|
|
input.edit.objectName: "editNetworkExplorerInput"
|
2023-07-11 15:10:26 +00:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
label: qsTr("Block Explorer")
|
|
|
|
|
text: !!network ? network.blockExplorerURL : ""
|
|
|
|
|
input.enabled: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusCheckBox {
|
|
|
|
|
id: warningCheckbox
|
2023-10-02 12:45:27 +00:00
|
|
|
|
objectName: "editNetworkAknowledgmentCheckbox"
|
2023-07-11 15:10:26 +00:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
text: qsTr("I understand that changing network settings can cause unforeseen issues, errors, security risks and potentially even loss of funds.")
|
|
|
|
|
checkState: Qt.Unchecked
|
|
|
|
|
font.pixelSize: 15
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Separator {}
|
|
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
Layout.alignment: Qt.AlignRight
|
|
|
|
|
spacing: 8
|
|
|
|
|
StatusButton {
|
2023-10-02 12:45:27 +00:00
|
|
|
|
objectName: "editNetworkRevertButton"
|
2023-07-11 15:10:26 +00:00
|
|
|
|
text: qsTr("Revert to default")
|
|
|
|
|
normalColor: "transparent"
|
|
|
|
|
onClicked: d.revertValues()
|
|
|
|
|
}
|
|
|
|
|
StatusButton {
|
2023-10-02 12:45:27 +00:00
|
|
|
|
objectName: "editNetworkSaveButton"
|
2023-07-11 15:10:26 +00:00
|
|
|
|
text: qsTr("Save Changes")
|
2023-09-15 08:13:21 +00:00
|
|
|
|
enabled: (
|
|
|
|
|
d.evaluationStatusMainRpc === EditNetworkForm.Verified ||
|
|
|
|
|
d.evaluationStatusFallBackRpc === EditNetworkForm.Verified ||
|
|
|
|
|
d.evaluationStatusMainRpc === EditNetworkForm.SameAsOther ||
|
|
|
|
|
d.evaluationStatusFallBackRpc === EditNetworkForm.SameAsOther ||
|
|
|
|
|
d.evaluationStatusFallBackRpc === EditNetworkForm.Empty
|
|
|
|
|
) && warningCheckbox.checked
|
|
|
|
|
|
2023-09-19 11:42:25 +00:00
|
|
|
|
onClicked: {
|
|
|
|
|
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)
|
|
|
|
|
}
|
2023-07-11 15:10:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|