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
title: qsTr ( "Network" )
property string newNetwork: "" ;
2020-11-23 20:41:57 +00:00
2021-01-08 22:10:31 +00:00
ScrollView {
id: svNetworks
2020-11-23 19:14:48 +00:00
width: parent . width
2021-01-08 22:10:31 +00:00
height: 300
clip: true
2020-11-23 19:14:48 +00:00
2021-01-08 22:10:31 +00:00
ScrollBar.horizontal.policy: ScrollBar . AlwaysOff
ScrollBar.vertical.policy: ScrollBar . AlwaysOn
2020-11-23 19:14:48 +00:00
2021-01-08 22:10:31 +00:00
Column {
id: column
spacing: Style . current . padding
2021-01-08 18:08:11 +00:00
width: parent . width
2021-01-08 22:10:31 +00:00
ButtonGroup { id: networkSettings }
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
Item {
id: addNetwork
width: parent . width
height: addButton . height
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
StatusRoundButton {
id: addButton
icon.name: "plusSign"
size: "medium"
anchors.verticalCenter: parent . verticalCenter
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
ButtonGroup {
id: networkChainGroup
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
StyledText {
id: usernameText
text: qsTr ( "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
2021-01-08 22:10:31 +00:00
MouseArea {
anchors.fill: parent
cursorShape: Qt . PointingHandCursor
onClicked: addNetworkPopup . open ( )
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
ModalPopup {
id: addNetworkPopup
title: qsTr ( "Add network" )
2021-01-08 23:07:32 +00:00
height: 650
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
property string nameValidationError: ""
property string rpcValidationError: ""
2021-01-08 23:07:32 +00:00
property string networkValidationError: ""
2021-01-08 22:10:31 +00:00
property int networkId: 1 ;
property string networkType: Constants . networkMainnet
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
function validate ( ) {
nameValidationError = ""
rpcValidationError = ""
2021-01-08 23:07:32 +00:00
networkValidationError = "" ;
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
if ( nameInput . text === "" ) {
nameValidationError = qsTr ( "You need to enter a name" )
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
if ( rpcInput . text === "" ) {
rpcValidationError = qsTr ( "You need to enter the RPC endpoint URL" )
} else if ( ! Utils . isURL ( rpcInput . text ) ) {
rpcValidationError = qsTr ( "Invalid URL" )
}
2021-01-08 18:08:11 +00:00
2021-01-08 23:07:32 +00:00
if ( customRadioBtn . checked ) {
if ( networkInput . text === "" ) {
networkValidationError = qsTr ( "You need to enter the network id" )
} else if ( isNaN ( networkInput . text ) ) {
networkValidationError = qsTr ( "Should be a number" ) ;
} else if ( parseInt ( networkInput . text , 10 ) <= 4 ) {
networkValidationError = qsTr ( "Invalid network id" ) ;
}
}
return ! nameValidationError && ! rpcValidationError && ! networkValidationError
2021-01-08 22:10:31 +00:00
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
onOpened: {
nameInput . text = "" ;
rpcInput . text = "" ;
2021-01-08 23:07:32 +00:00
networkInput . text = "" ;
2021-01-08 22:10:31 +00:00
mainnetRadioBtn . checked = true ;
addNetworkPopup . networkId = 1 ;
addNetworkPopup . networkType = Constants . networkMainnet ;
nameValidationError = "" ;
rpcValidationError = "" ;
2021-01-08 23:07:32 +00:00
networkValidationError = "" ;
2021-01-08 22:10:31 +00:00
}
footer: StyledButton {
anchors.right: parent . right
anchors.rightMargin: Style . current . smallPadding
label: qsTr ( "Save" )
anchors.bottom: parent . bottom
disabled: 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 ) ;
}
2021-01-08 22:10:31 +00:00
profileModel . network . add ( nameInput . text , rpcInput . text , addNetworkPopup . networkId , addNetworkPopup . networkType )
profileModel . network . reloadCustomNetworks ( ) ;
addNetworkPopup . close ( )
2021-01-08 18:08:11 +00:00
}
}
2021-01-08 22:10:31 +00:00
Input {
id: nameInput
label: qsTr ( "Name" )
placeholderText: qsTr ( "Specify a name" )
validationError: addNetworkPopup . nameValidationError
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
Input {
id: rpcInput
label: qsTr ( "RPC URL" )
placeholderText: qsTr ( "Specify a RPC URL" )
validationError: addNetworkPopup . rpcValidationError
anchors.top: nameInput . bottom
anchors.topMargin: Style . current . bigPadding
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
StatusSectionHeadline {
id: networkChainHeadline
text: qsTr ( "Network chain" )
anchors.top: rpcInput . bottom
anchors.topMargin: Style . current . bigPadding
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
Column {
spacing: Style . current . padding
anchors.top: networkChainHeadline . bottom
anchors.topMargin: Style . current . smallPadding
anchors.left: parent . left
anchors.right: parent . right
RowLayout {
width: parent . width
StyledText {
text: qsTr ( "Main network" )
font.pixelSize: 15
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
StatusRadioButton {
id: mainnetRadioBtn
Layout.alignment: Qt . AlignRight
ButtonGroup.group: networkChainGroup
rightPadding: 0
checked: true
onClicked: {
addNetworkPopup . networkId = 1 ;
addNetworkPopup . networkType = Constants . networkMainnet ;
}
2021-01-08 18:08:11 +00:00
}
}
2021-01-08 22:10:31 +00:00
RowLayout {
width: parent . width
StyledText {
text: qsTr ( "Ropsten test network" )
font.pixelSize: 15
}
StatusRadioButton {
id: ropstenRadioBtn
Layout.alignment: Qt . AlignRight
ButtonGroup.group: networkChainGroup
rightPadding: 0
onClicked: {
addNetworkPopup . networkId = 3 ;
addNetworkPopup . networkType = Constants . networkRopsten ;
}
2021-01-08 18:08:11 +00:00
}
}
2021-01-08 22:10:31 +00:00
RowLayout {
width: parent . width
StyledText {
text: qsTr ( "Rinkeby test network" )
font.pixelSize: 15
}
StatusRadioButton {
id: rinkebyRadioBtn
Layout.alignment: Qt . AlignRight
ButtonGroup.group: networkChainGroup
rightPadding: 0
onClicked: {
addNetworkPopup . networkId = 4 ;
addNetworkPopup . networkType = Constants . networkRinkeby ;
}
2021-01-08 18:08:11 +00:00
}
}
2021-01-08 22:10:31 +00:00
RowLayout {
width: parent . width
StyledText {
text: qsTr ( "Custom" )
font.pixelSize: 15
}
StatusRadioButton {
id: customRadioBtn
Layout.alignment: Qt . AlignRight
ButtonGroup.group: networkChainGroup
rightPadding: 0
onClicked: {
addNetworkPopup . networkType = "" ;
}
2021-01-08 18:08:11 +00:00
}
}
2021-01-08 23:07:32 +00:00
Input {
id: networkInput
visible: customRadioBtn . checked
label: qsTr ( "Network Id" )
placeholderText: qsTr ( "Specify the network id" )
validationError: addNetworkPopup . networkValidationError
}
2021-01-08 18:08:11 +00:00
}
}
}
2021-01-08 22:10:31 +00:00
StatusSectionHeadline {
text: qsTr ( "Main networks" )
}
2020-11-23 20:41:57 +00:00
2021-01-08 22:10:31 +00:00
NetworkRadioSelector {
network: Constants . networkMainnet
}
2020-11-23 19:14:48 +00:00
2021-01-08 22:10:31 +00:00
NetworkRadioSelector {
network: Constants . networkPOA
}
2020-11-23 19:14:48 +00:00
2021-01-08 22:10:31 +00:00
NetworkRadioSelector {
network: Constants . networkXDai
}
2020-11-23 20:41:57 +00:00
2021-01-08 22:10:31 +00:00
StatusSectionHeadline {
text: qsTr ( "Test networks" )
}
2020-11-23 19:14:48 +00:00
2021-01-08 22:10:31 +00:00
NetworkRadioSelector {
network: Constants . networkGoerli
}
2020-11-23 19:14:48 +00:00
2021-01-08 22:10:31 +00:00
NetworkRadioSelector {
network: Constants . networkRinkeby
}
2020-11-23 19:14:48 +00:00
2021-01-08 22:10:31 +00:00
NetworkRadioSelector {
network: Constants . networkRopsten
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
StatusSectionHeadline {
text: qsTr ( "Custom Networks" )
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
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 {
2021-01-08 22:10:31 +00:00
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-" )
}
}