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
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"
2021-03-16 19:19:48 +00:00
type: "secondary"
2021-01-08 22:10:31 +00:00
anchors.verticalCenter: parent . verticalCenter
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +00:00
StyledText {
id: usernameText
2021-02-18 16:36:05 +00:00
//% "Add network"
text: qsTrId ( "add-network" )
2021-01-08 22:10:31 +00:00
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
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
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 === "" ) {
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 22:10:31 +00:00
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +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" )
2021-01-08 22:10:31 +00:00
} else if ( ! Utils . isURL ( rpcInput . text ) ) {
2021-02-18 16:36:05 +00:00
//% "Invalid URL"
rpcValidationError = qsTrId ( "invalid-url" )
2021-01-08 22:10:31 +00:00
}
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 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
}
2021-01-28 11:04:10 +00:00
footer: StatusButton {
2021-01-08 22:10:31 +00:00
anchors.right: parent . right
anchors.rightMargin: Style . current . smallPadding
2021-02-18 16:36:05 +00:00
//% "Save"
text: qsTrId ( "save" )
2021-01-08 22:10:31 +00:00
anchors.bottom: parent . bottom
2021-01-28 11:04:10 +00:00
enabled: nameInput . text !== "" && rpcInput . text !== ""
2021-01-08 22:10:31 +00:00
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
2021-02-18 16:36:05 +00:00
//% "Name"
label: qsTrId ( "name" )
//% "Specify a name"
placeholderText: qsTrId ( "specify-name" )
2021-01-08 22:10:31 +00:00
validationError: addNetworkPopup . nameValidationError
}
2021-01-08 18:08:11 +00:00
2021-01-08 22:10:31 +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" )
2021-01-08 22:10:31 +00:00
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
2021-02-18 16:36:05 +00:00
//% "Network chain"
text: qsTrId ( "network-chain" )
2021-01-08 22:10:31 +00:00
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
2021-03-19 10:25:29 +00:00
anchors.rightMargin: Style . current . padding
anchors.leftMargin: Style . current . padding
2021-01-08 22:10:31 +00:00
2021-03-19 10:25:29 +00:00
ButtonGroup {
id: networkChainGroup
}
2021-01-08 18:08:11 +00:00
2021-03-19 10:25:29 +00:00
StatusRadioButtonRow {
id: mainnetRadioBtn
text: qsTr ( "Main network" )
buttonGroup: networkChainGroup
checked: true
onRadioCheckedChanged: {
if ( checked ) {
2021-01-08 22:10:31 +00:00
addNetworkPopup . networkId = 1 ;
addNetworkPopup . networkType = Constants . networkMainnet ;
}
2021-01-08 18:08:11 +00:00
}
}
2021-03-19 10:25:29 +00:00
StatusRadioButtonRow {
text: qsTr ( "Ropsten test network" )
buttonGroup: networkChainGroup
onRadioCheckedChanged: {
if ( checked ) {
2021-01-08 22:10:31 +00:00
addNetworkPopup . networkId = 3 ;
addNetworkPopup . networkType = Constants . networkRopsten ;
}
2021-01-08 18:08:11 +00:00
}
}
2021-03-19 10:25:29 +00:00
StatusRadioButtonRow {
text: qsTr ( "Rinkeby test network" )
buttonGroup: networkChainGroup
onRadioCheckedChanged: {
if ( checked ) {
2021-01-08 22:10:31 +00:00
addNetworkPopup . networkId = 4 ;
addNetworkPopup . networkType = Constants . networkRinkeby ;
}
2021-01-08 18:08:11 +00:00
}
}
2021-03-19 10:25:29 +00:00
StatusRadioButtonRow {
id: customRadioBtn
text: qsTr ( "Custom" )
buttonGroup: networkChainGroup
onRadioCheckedChanged: {
if ( checked ) {
2021-01-08 22:10:31 +00:00
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
}
}
}
2021-03-19 10:25:29 +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
2021-03-19 10:25:29 +00:00
StatusSectionHeadline {
//% "Main networks"
text: qsTrId ( "main-networks" )
}
2020-11-23 19:14:48 +00:00
2021-03-19 10:25:29 +00:00
NetworkRadioSelector {
network: Constants . networkMainnet
}
2020-11-23 20:41:57 +00:00
2021-03-19 10:25:29 +00:00
NetworkRadioSelector {
network: Constants . networkPOA
}
2020-11-23 19:14:48 +00:00
2021-03-19 10:25:29 +00:00
NetworkRadioSelector {
network: Constants . networkXDai
}
2020-11-23 19:14:48 +00:00
2021-03-19 10:25:29 +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
2021-03-19 10:25:29 +00:00
NetworkRadioSelector {
network: Constants . networkGoerli
}
2021-01-08 18:08:11 +00:00
2021-03-19 10:25:29 +00:00
NetworkRadioSelector {
network: Constants . networkRinkeby
}
NetworkRadioSelector {
network: Constants . networkRopsten
}
2021-01-08 18:08:11 +00:00
2021-03-19 10:25:29 +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 22:10:31 +00:00
}
}
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-" )
}
}