2021-04-08 13:43:50 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
2021-09-13 12:35:22 +00:00
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared.status 1.0
|
|
|
|
import shared.controls 1.0
|
2021-04-08 13:43:50 +00:00
|
|
|
|
2021-09-13 12:35:22 +00:00
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
|
|
|
StatusModal {
|
2021-04-08 13:43:50 +00:00
|
|
|
id: addNetworkPopup
|
|
|
|
//% "Add network"
|
2021-09-13 12:35:22 +00:00
|
|
|
header.title: qsTrId("add-network")
|
|
|
|
height: 644
|
2021-04-08 13:43:50 +00:00
|
|
|
|
2021-12-16 10:33:27 +00:00
|
|
|
property var advancedStore
|
|
|
|
|
2021-04-08 13:43:50 +00:00
|
|
|
property string nameValidationError: ""
|
|
|
|
property string rpcValidationError: ""
|
|
|
|
property string networkValidationError: ""
|
|
|
|
property int networkId: 1;
|
|
|
|
property string networkType: Constants.networkMainnet
|
|
|
|
|
|
|
|
function validate() {
|
|
|
|
nameValidationError = ""
|
|
|
|
rpcValidationError = ""
|
|
|
|
networkValidationError = "";
|
|
|
|
|
|
|
|
if (nameInput.text === "") {
|
|
|
|
//% "You need to enter a name"
|
|
|
|
nameValidationError = qsTrId("you-need-to-enter-a-name")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rpcInput.text === "") {
|
|
|
|
//% "You need to enter the RPC endpoint URL"
|
|
|
|
rpcValidationError = qsTrId("you-need-to-enter-the-rpc-endpoint-url")
|
|
|
|
} else if(!Utils.isURL(rpcInput.text)) {
|
|
|
|
//% "Invalid URL"
|
|
|
|
rpcValidationError = qsTrId("invalid-url")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (customRadioBtn.checked) {
|
|
|
|
if (networkInput.text === "") {
|
|
|
|
//% "You need to enter the network id"
|
|
|
|
networkValidationError = qsTrId("you-need-to-enter-the-network-id")
|
|
|
|
} else if (isNaN(networkInput.text)){
|
|
|
|
//% "Should be a number"
|
|
|
|
networkValidationError = qsTrId("should-be-a-number");
|
|
|
|
} else if (parseInt(networkInput.text, 10) <= 4){
|
|
|
|
//% "Invalid network id"
|
|
|
|
networkValidationError = qsTrId("invalid-network-id");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !nameValidationError && !rpcValidationError && !networkValidationError
|
|
|
|
}
|
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
nameInput.text = "";
|
|
|
|
rpcInput.text = "";
|
|
|
|
networkInput.text = "";
|
|
|
|
mainnetRadioBtn.checked = true;
|
|
|
|
addNetworkPopup.networkId = 1;
|
|
|
|
addNetworkPopup.networkType = Constants.networkMainnet;
|
|
|
|
|
|
|
|
nameValidationError = "";
|
|
|
|
rpcValidationError = "";
|
|
|
|
networkValidationError = "";
|
|
|
|
}
|
|
|
|
|
2021-09-13 12:35:22 +00:00
|
|
|
rightButtons: [
|
|
|
|
StatusButton {
|
|
|
|
//% "Save"
|
|
|
|
text: qsTrId("save")
|
|
|
|
enabled: nameInput.text !== "" && rpcInput.text !== ""
|
|
|
|
onClicked: {
|
|
|
|
if (!addNetworkPopup.validate()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-08 13:43:50 +00:00
|
|
|
|
2021-09-13 12:35:22 +00:00
|
|
|
if (customRadioBtn.checked){
|
|
|
|
addNetworkPopup.networkId = parseInt(networkInput.text, 10);
|
|
|
|
}
|
2021-04-08 13:43:50 +00:00
|
|
|
|
2021-12-16 10:33:27 +00:00
|
|
|
addNetworkPopup.advancedStore.addCustomNetwork(nameInput.text,
|
|
|
|
rpcInput.text,
|
|
|
|
addNetworkPopup.networkId,
|
|
|
|
addNetworkPopup.networkType)
|
2021-09-13 12:35:22 +00:00
|
|
|
addNetworkPopup.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
contentItem: Item {
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors {
|
|
|
|
topMargin: (Style.current.padding + addNetworkPopup.topPadding)
|
|
|
|
leftMargin: Style.current.padding
|
|
|
|
rightMargin: Style.current.padding
|
|
|
|
bottomMargin: (Style.current.padding + addNetworkPopup.bottomPadding)
|
|
|
|
}
|
|
|
|
Input {
|
|
|
|
id: nameInput
|
|
|
|
//% "Name"
|
|
|
|
label: qsTrId("name")
|
|
|
|
//% "Specify a name"
|
|
|
|
placeholderText: qsTrId("specify-name")
|
|
|
|
validationError: addNetworkPopup.nameValidationError
|
2021-04-08 13:43:50 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 12:35:22 +00:00
|
|
|
Input {
|
|
|
|
id: rpcInput
|
|
|
|
//% "RPC URL"
|
|
|
|
label: qsTrId("rpc-url")
|
|
|
|
//% "Specify a RPC URL"
|
|
|
|
placeholderText: qsTrId("specify-rpc-url")
|
|
|
|
validationError: addNetworkPopup.rpcValidationError
|
|
|
|
anchors.top: nameInput.bottom
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
}
|
2021-04-08 13:43:50 +00:00
|
|
|
|
2021-09-13 12:35:22 +00:00
|
|
|
StatusSectionHeadline {
|
|
|
|
id: networkChainHeadline
|
|
|
|
//% "Network chain"
|
|
|
|
text: qsTrId("network-chain")
|
|
|
|
anchors.top: rpcInput.bottom
|
|
|
|
anchors.topMargin: Style.current.padding
|
2021-04-08 13:43:50 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 12:35:22 +00:00
|
|
|
Column {
|
|
|
|
id: radioButtonsColumn
|
|
|
|
anchors.top: networkChainHeadline.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
ButtonGroup {
|
|
|
|
id: networkChainGroup
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:37:58 +00:00
|
|
|
RadioButtonSelector {
|
2021-09-13 12:35:22 +00:00
|
|
|
id: mainnetRadioBtn
|
|
|
|
//% "Main network"
|
|
|
|
objectName: "main"
|
2021-10-27 09:37:58 +00:00
|
|
|
title: qsTrId("mainnet-network")
|
2021-09-13 12:35:22 +00:00
|
|
|
buttonGroup: networkChainGroup
|
|
|
|
checked: true
|
2021-10-27 09:37:58 +00:00
|
|
|
onCheckedChanged: {
|
2021-09-13 12:35:22 +00:00
|
|
|
if (checked) {
|
|
|
|
addNetworkPopup.networkId = 1;
|
|
|
|
addNetworkPopup.networkType = Constants.networkMainnet;
|
|
|
|
}
|
2021-04-08 13:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:37:58 +00:00
|
|
|
RadioButtonSelector {
|
2021-09-13 12:35:22 +00:00
|
|
|
//% "Ropsten test network"
|
2021-10-27 09:37:58 +00:00
|
|
|
title: qsTrId("ropsten-network")
|
2021-09-13 12:35:22 +00:00
|
|
|
buttonGroup: networkChainGroup
|
2021-10-27 09:37:58 +00:00
|
|
|
onCheckedChanged: {
|
2021-09-13 12:35:22 +00:00
|
|
|
if (checked) {
|
|
|
|
addNetworkPopup.networkId = 3;
|
|
|
|
addNetworkPopup.networkType = Constants.networkRopsten;
|
|
|
|
}
|
2021-04-08 13:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:37:58 +00:00
|
|
|
RadioButtonSelector {
|
2021-09-13 12:35:22 +00:00
|
|
|
//% "Rinkeby test network"
|
2021-10-27 09:37:58 +00:00
|
|
|
title: qsTrId("rinkeby-network")
|
2021-09-13 12:35:22 +00:00
|
|
|
buttonGroup: networkChainGroup
|
2021-10-27 09:37:58 +00:00
|
|
|
onCheckedChanged: {
|
2021-09-13 12:35:22 +00:00
|
|
|
if (checked) {
|
|
|
|
addNetworkPopup.networkId = 4;
|
|
|
|
addNetworkPopup.networkType = Constants.networkRinkeby;
|
|
|
|
}
|
2021-04-08 13:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 09:37:58 +00:00
|
|
|
RadioButtonSelector {
|
2021-09-13 12:35:22 +00:00
|
|
|
id: customRadioBtn
|
|
|
|
//% "Custom"
|
|
|
|
objectName: "custom"
|
2021-10-27 09:37:58 +00:00
|
|
|
title: qsTrId("custom")
|
2021-09-13 12:35:22 +00:00
|
|
|
buttonGroup: networkChainGroup
|
2021-10-27 09:37:58 +00:00
|
|
|
onCheckedChanged: {
|
2021-09-13 12:35:22 +00:00
|
|
|
if (checked) {
|
|
|
|
addNetworkPopup.networkType = "";
|
|
|
|
}
|
|
|
|
networkInput.visible = checked;
|
2021-04-08 13:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Input {
|
|
|
|
id: networkInput
|
2021-09-13 12:35:22 +00:00
|
|
|
anchors.top: radioButtonsColumn.bottom
|
|
|
|
anchors.topMargin: Style.current.halfPadding
|
|
|
|
visible: false
|
2021-04-08 13:43:50 +00:00
|
|
|
//% "Network Id"
|
|
|
|
label: qsTrId("network-id")
|
|
|
|
//% "Specify the network id"
|
|
|
|
placeholderText: qsTrId("specify-the-network-id")
|
|
|
|
validationError: addNetworkPopup.networkValidationError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|