status-desktop/ui/app/AppLayouts/Profile/Sections/NetworksModal.qml

310 lines
12 KiB
QML
Raw Normal View History

2020-11-23 19:14:48 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import "../../../../imports"
import "../../../../shared"
import "../../../../shared/status"
ModalPopup {
id: popup
2021-02-18 16:36:05 +00:00
//% "Network"
title: qsTrId("network")
2020-11-23 19:14:48 +00:00
property string newNetwork: "";
2020-11-23 20:41:57 +00:00
ScrollView {
id: svNetworks
2020-11-23 19:14:48 +00:00
width: parent.width
height: 300
clip: true
2020-11-23 19:14:48 +00:00
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
2020-11-23 19:14:48 +00:00
Column {
id: column
spacing: Style.current.padding
2021-01-08 18:08:11 +00:00
width: parent.width
ButtonGroup { id: networkSettings }
2021-01-08 18:08:11 +00:00
Item {
id: addNetwork
width: parent.width
height: addButton.height
2021-01-08 18:08:11 +00:00
StatusRoundButton {
id: addButton
icon.name: "plusSign"
size: "medium"
type: "secondary"
anchors.verticalCenter: parent.verticalCenter
}
2021-01-08 18:08:11 +00:00
StyledText {
id: usernameText
2021-02-18 16:36:05 +00:00
//% "Add network"
text: qsTrId("add-network")
color: Style.current.blue
anchors.left: addButton.right
anchors.leftMargin: Style.current.padding
anchors.verticalCenter: addButton.verticalCenter
font.pixelSize: 15
}
2021-01-08 18:08:11 +00:00
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: addNetworkPopup.open()
}
2021-01-08 18:08:11 +00:00
ModalPopup {
id: addNetworkPopup
2021-02-18 16:36:05 +00:00
//% "Add network"
title: qsTrId("add-network")
2021-01-08 23:07:32 +00:00
height: 650
2021-01-08 18:08:11 +00:00
property string nameValidationError: ""
property string rpcValidationError: ""
2021-01-08 23:07:32 +00:00
property string networkValidationError: ""
property int networkId: 1;
property string networkType: Constants.networkMainnet
2021-01-08 18:08:11 +00:00
function validate() {
nameValidationError = ""
rpcValidationError = ""
2021-01-08 23:07:32 +00:00
networkValidationError = "";
2021-01-08 18:08:11 +00:00
if (nameInput.text === "") {
2021-02-18 16:36:05 +00:00
//% "You need to enter a name"
nameValidationError = qsTrId("you-need-to-enter-a-name")
}
2021-01-08 18:08:11 +00:00
if (rpcInput.text === "") {
2021-02-18 16:36:05 +00:00
//% "You need to enter the RPC endpoint URL"
rpcValidationError = qsTrId("you-need-to-enter-the-rpc-endpoint-url")
} else if(!Utils.isURL(rpcInput.text)) {
2021-02-18 16:36:05 +00:00
//% "Invalid URL"
rpcValidationError = qsTrId("invalid-url")
}
2021-01-08 18:08:11 +00:00
2021-01-08 23:07:32 +00:00
if (customRadioBtn.checked) {
if (networkInput.text === "") {
2021-02-18 16:36:05 +00:00
//% "You need to enter the network id"
networkValidationError = qsTrId("you-need-to-enter-the-network-id")
2021-01-08 23:07:32 +00:00
} else if (isNaN(networkInput.text)){
2021-02-18 16:36:05 +00:00
//% "Should be a number"
networkValidationError = qsTrId("should-be-a-number");
2021-01-08 23:07:32 +00:00
} else if (parseInt(networkInput.text, 10) <= 4){
2021-02-18 16:36:05 +00:00
//% "Invalid network id"
networkValidationError = qsTrId("invalid-network-id");
2021-01-08 23:07:32 +00:00
}
}
return !nameValidationError && !rpcValidationError && !networkValidationError
}
2021-01-08 18:08:11 +00:00
onOpened: {
nameInput.text = "";
rpcInput.text = "";
2021-01-08 23:07:32 +00:00
networkInput.text = "";
mainnetRadioBtn.checked = true;
addNetworkPopup.networkId = 1;
addNetworkPopup.networkType = Constants.networkMainnet;
nameValidationError = "";
rpcValidationError = "";
2021-01-08 23:07:32 +00:00
networkValidationError = "";
}
footer: StatusButton {
anchors.right: parent.right
anchors.rightMargin: Style.current.smallPadding
2021-02-18 16:36:05 +00:00
//% "Save"
text: qsTrId("save")
anchors.bottom: parent.bottom
enabled: nameInput.text !== "" && rpcInput.text !== ""
onClicked: {
if (!addNetworkPopup.validate()) {
return;
}
2021-01-08 23:07:32 +00:00
if (customRadioBtn.checked){
addNetworkPopup.networkId = parseInt(networkInput.text, 10);
}
profileModel.network.add(nameInput.text, rpcInput.text, addNetworkPopup.networkId, addNetworkPopup.networkType)
profileModel.network.reloadCustomNetworks();
addNetworkPopup.close()
2021-01-08 18:08:11 +00:00
}
}
Input {
id: nameInput
2021-02-18 16:36:05 +00:00
//% "Name"
label: qsTrId("name")
//% "Specify a name"
placeholderText: qsTrId("specify-name")
validationError: addNetworkPopup.nameValidationError
}
2021-01-08 18:08:11 +00:00
Input {
id: rpcInput
2021-02-18 16:36:05 +00:00
//% "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.bigPadding
}
2021-01-08 18:08:11 +00:00
StatusSectionHeadline {
id: networkChainHeadline
2021-02-18 16:36:05 +00:00
//% "Network chain"
text: qsTrId("network-chain")
anchors.top: rpcInput.bottom
anchors.topMargin: Style.current.bigPadding
}
2021-01-08 18:08:11 +00:00
Column {
spacing: Style.current.padding
anchors.top: networkChainHeadline.bottom
anchors.topMargin: Style.current.smallPadding
anchors.left: parent.left
anchors.right: parent.right
anchors.rightMargin: Style.current.padding
anchors.leftMargin: Style.current.padding
ButtonGroup {
id: networkChainGroup
}
2021-01-08 18:08:11 +00:00
StatusRadioButtonRow {
id: mainnetRadioBtn
text: qsTr("Main network")
buttonGroup: networkChainGroup
checked: true
onRadioCheckedChanged: {
if (checked) {
addNetworkPopup.networkId = 1;
addNetworkPopup.networkType = Constants.networkMainnet;
}
2021-01-08 18:08:11 +00:00
}
}
StatusRadioButtonRow {
text: qsTr("Ropsten test network")
buttonGroup: networkChainGroup
onRadioCheckedChanged: {
if (checked) {
addNetworkPopup.networkId = 3;
addNetworkPopup.networkType = Constants.networkRopsten;
}
2021-01-08 18:08:11 +00:00
}
}
StatusRadioButtonRow {
text: qsTr("Rinkeby test network")
buttonGroup: networkChainGroup
onRadioCheckedChanged: {
if (checked) {
addNetworkPopup.networkId = 4;
addNetworkPopup.networkType = Constants.networkRinkeby;
}
2021-01-08 18:08:11 +00:00
}
}
StatusRadioButtonRow {
id: customRadioBtn
text: qsTr("Custom")
buttonGroup: networkChainGroup
onRadioCheckedChanged: {
if (checked) {
addNetworkPopup.networkType = "";
}
2021-01-08 18:08:11 +00:00
}
}
2021-01-08 23:07:32 +00:00
Input {
id: networkInput
visible: customRadioBtn.checked
2021-02-18 16:36:05 +00:00
//% "Network Id"
label: qsTrId("network-id")
//% "Specify the network id"
placeholderText: qsTrId("specify-the-network-id")
2021-01-08 23:07:32 +00:00
validationError: addNetworkPopup.networkValidationError
}
2021-01-08 18:08:11 +00:00
}
}
}
Column {
spacing: Style.current.smallPadding
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Style.current.padding
anchors.rightMargin: Style.current.padding
2021-01-08 18:08:11 +00:00
2020-11-23 20:41:57 +00:00
StatusSectionHeadline {
//% "Main networks"
text: qsTrId("main-networks")
}
2020-11-23 19:14:48 +00:00
NetworkRadioSelector {
network: Constants.networkMainnet
}
2020-11-23 20:41:57 +00:00
NetworkRadioSelector {
network: Constants.networkPOA
}
2020-11-23 19:14:48 +00:00
NetworkRadioSelector {
network: Constants.networkXDai
}
2020-11-23 19:14:48 +00:00
StatusSectionHeadline {
//% "Test networks"
text: qsTrId("test-networks")
anchors.leftMargin: -Style.current.padding
anchors.rightMargin: -Style.current.padding
}
2020-11-23 19:14:48 +00:00
NetworkRadioSelector {
network: Constants.networkGoerli
}
2021-01-08 18:08:11 +00:00
NetworkRadioSelector {
network: Constants.networkRinkeby
}
NetworkRadioSelector {
network: Constants.networkRopsten
}
2021-01-08 18:08:11 +00:00
StatusSectionHeadline {
//% "Custom Networks"
text: qsTrId("custom-networks")
anchors.leftMargin: -Style.current.padding
anchors.rightMargin: -Style.current.padding
}
Repeater {
model: profileModel.network.customNetworkList
delegate: NetworkRadioSelector {
networkName: name
network: customNetworkId
}
}
}
2021-01-08 18:08:11 +00:00
}
2020-11-23 19:14:48 +00:00
}
StyledText {
anchors.top: svNetworks.bottom
2020-11-23 20:41:57 +00:00
anchors.topMargin: Style.current.padding
2020-11-23 19:14:48 +00:00
//% "Under development\nNOTE: You will be logged out and all installed\nsticker packs will be removed and will\nneed to be reinstalled. Purchased sticker\npacks will not need to be re-purchased."
text: qsTrId("under-development-nnote--you-will-be-logged-out-and-all-installed-nsticker-packs-will-be-removed-and-will-nneed-to-be-reinstalled--purchased-sticker-npacks-will-not-need-to-be-re-purchased-")
}
}