feat: choose network
This commit is contained in:
parent
2c42ebf923
commit
159c82c329
|
@ -152,6 +152,9 @@ QtObject:
|
|||
|
||||
proc networkChanged*(self: ProfileView) {.signal.}
|
||||
|
||||
proc triggerNetworkChange*(self: ProfileView) {.slot.} =
|
||||
self.networkChanged()
|
||||
|
||||
proc getNetwork*(self: ProfileView): QVariant {.slot.} =
|
||||
return newQVariant(self.network)
|
||||
|
||||
|
|
|
@ -57,8 +57,10 @@ proc decodeContentHash*(value: string): string =
|
|||
# See https://notes.status.im/Q-sQmQbpTOOWCQcYiXtf5g#Read-Sticker-Packs-owned-by-a-user
|
||||
# for more details
|
||||
proc getBalance*(address: Address): int =
|
||||
let
|
||||
contract = contracts.getContract("sticker-pack")
|
||||
let contract = contracts.getContract("sticker-pack")
|
||||
if contract == nil: return 0
|
||||
|
||||
let
|
||||
balanceOf = BalanceOf(address: address)
|
||||
payload = %* [{
|
||||
"to": $contract.address,
|
||||
|
@ -76,6 +78,8 @@ proc getBalance*(address: Address): int =
|
|||
# Gets number of sticker packs
|
||||
proc getPackCount*(): int =
|
||||
let contract = contracts.getContract("stickers")
|
||||
if contract == nil: return 0
|
||||
|
||||
let payload = %* [{
|
||||
"to": $contract.address,
|
||||
"data": contract.methods["packCount"].encodeAbi()
|
||||
|
|
|
@ -36,7 +36,7 @@ proc getCustomTokens*(useCached: bool = true): seq[Erc20Contract] =
|
|||
|
||||
proc visibleTokensSNTDefault(): JsonNode =
|
||||
let currentNetwork = getCurrentNetwork()
|
||||
let SNT = if currentNetwork == Network.Testnet: "STT" else: "SNT"
|
||||
let SNT = if currentNetwork == Network.Mainnet: "SNT" else: "STT"
|
||||
let response = getSetting[string](Setting.VisibleTokens, "{}").parseJSON
|
||||
|
||||
if not response.hasKey($currentNetwork):
|
||||
|
|
|
@ -320,7 +320,8 @@ proc validateMnemonic*(self: WalletModel, mnemonic: string): string =
|
|||
result = status_wallet.validateMnemonic(mnemonic).parseJSON()["error"].getStr
|
||||
|
||||
proc getGasPricePredictions*(self: WalletModel): GasPricePrediction =
|
||||
if status_settings.getCurrentNetwork() == Network.Testnet:
|
||||
if status_settings.getCurrentNetwork() != Network.Mainnet:
|
||||
# TODO: what about other chains like xdai?
|
||||
return GasPricePrediction(safeLow: 1.0, standard: 2.0, fast: 3.0, fastest: 4.0)
|
||||
try:
|
||||
let url: string = fmt"https://etherchain.org/api/gasPriceOracle"
|
||||
|
|
|
@ -90,36 +90,64 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Item {
|
||||
id: networkTabSettings
|
||||
anchors.top: nodeTabSettings.bottom
|
||||
anchors.topMargin: 20
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 24
|
||||
width: parent.width - 20
|
||||
height: networkText.height
|
||||
|
||||
StyledText {
|
||||
//% "Enable testnet (Ropsten)\nCurrent network: %1"
|
||||
text: qsTrId("enable-testnet--ropsten--ncurrent-network---1").arg(profileModel.network)
|
||||
}
|
||||
StatusSwitch {
|
||||
checked: profileModel.network === Constants.networkRopsten
|
||||
onCheckedChanged: {
|
||||
if (checked && profileModel.network === Constants.networkRopsten || !checked && profileModel.network === Constants.networkMainnet){
|
||||
return;
|
||||
}
|
||||
profileModel.network = checked ? Constants.networkRopsten : Constants.networkMainnet;
|
||||
}
|
||||
id: networkText
|
||||
text: qsTr("Network")
|
||||
font.pixelSize: 15
|
||||
}
|
||||
|
||||
StyledText {
|
||||
//% "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-")
|
||||
text: qsTrId(profileModel.network)
|
||||
font.pixelSize: 15
|
||||
anchors.right: caret3.left
|
||||
anchors.rightMargin: Style.current.padding
|
||||
}
|
||||
|
||||
SVGImage {
|
||||
id: caret3
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 0
|
||||
anchors.verticalCenter: networkText.verticalCenter
|
||||
source: "../../../img/caret.svg"
|
||||
width: 13
|
||||
height: 7
|
||||
rotation: -90
|
||||
}
|
||||
|
||||
ColorOverlay {
|
||||
anchors.fill: caret3
|
||||
source: caret2
|
||||
color: Style.current.darkGrey
|
||||
rotation: -90
|
||||
}
|
||||
|
||||
NetworksModal {
|
||||
id: networksModal
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: networksModal.open()
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: fleetSetting
|
||||
anchors.top: networkTabSettings.bottom
|
||||
anchors.topMargin: Style.current.padding
|
||||
width: parent.width
|
||||
anchors.topMargin: 20
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 24
|
||||
width: parent.width - 20
|
||||
height: fleetText.height
|
||||
|
||||
StyledText {
|
||||
|
|
|
@ -282,7 +282,7 @@ Item {
|
|||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: Style.current.padding
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
disabled: profileModel.network !== "mainnet_rpc" // Comment this to use on testnet
|
||||
disabled: profileModel.network !== Constants.networkMainnet // Comment this to use on testnet
|
||||
//% "Start"
|
||||
label: !disabled ?
|
||||
qsTrId("start") :
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
import QtQuick 2.13
|
||||
import QtQuick.Controls 2.13
|
||||
import QtQuick.Layouts 1.13
|
||||
import "../../../../imports"
|
||||
import "../../../../shared"
|
||||
import "../../../../shared/status"
|
||||
|
||||
RowLayout {
|
||||
property string networkName: ""
|
||||
property string newNetwork: ""
|
||||
|
||||
ConfirmationDialog {
|
||||
id: confirmDialog
|
||||
title: qsTr("Warning!")
|
||||
confirmationText: qsTr("The account will be logged out. When you unlock it again, the selected network will be used")
|
||||
onConfirmButtonClicked: {
|
||||
profileModel.network = newNetwork;
|
||||
}
|
||||
onClosed: profileModel.triggerNetworkChange()
|
||||
}
|
||||
|
||||
width: parent.width
|
||||
StyledText {
|
||||
text: qsTrId(networkName)
|
||||
font.pixelSize: 15
|
||||
}
|
||||
StatusRadioButton {
|
||||
id: radioProd
|
||||
Layout.alignment: Qt.AlignRight
|
||||
ButtonGroup.group: networkSettings
|
||||
rightPadding: 0
|
||||
checked: profileModel.network === networkName
|
||||
onClicked: {
|
||||
if (profileModel.network === networkName) return;
|
||||
newNetwork = networkName;
|
||||
confirmDialog.open();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
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: "";
|
||||
|
||||
Column {
|
||||
id: column
|
||||
spacing: Style.current.padding
|
||||
width: parent.width
|
||||
|
||||
ButtonGroup { id: networkSettings }
|
||||
|
||||
NetworkRadioSelector {
|
||||
networkName: Constants.networkMainnet
|
||||
}
|
||||
|
||||
NetworkRadioSelector {
|
||||
networkName: Constants.networkPOA
|
||||
}
|
||||
|
||||
NetworkRadioSelector {
|
||||
networkName: Constants.networkXDai
|
||||
}
|
||||
|
||||
NetworkRadioSelector {
|
||||
networkName: Constants.networkGoerli
|
||||
}
|
||||
|
||||
NetworkRadioSelector {
|
||||
networkName: Constants.networkRinkeby
|
||||
}
|
||||
|
||||
NetworkRadioSelector {
|
||||
networkName: Constants.networkRopsten
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
StyledText {
|
||||
anchors.top: column.bottom
|
||||
anchors.topMargin: Style.current.padding * 2
|
||||
//% "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-")
|
||||
}
|
||||
}
|
|
@ -75,8 +75,12 @@ QtObject {
|
|||
"#8B3131"
|
||||
]
|
||||
|
||||
readonly property string networkRopsten: "testnet_rpc"
|
||||
readonly property string networkMainnet: "mainnet_rpc"
|
||||
readonly property string networkPOA: "poa_rpc"
|
||||
readonly property string networkXDai: "xdai_rpc"
|
||||
readonly property string networkGoerli: "goerli_rpc"
|
||||
readonly property string networkRinkeby: "rinkeby_rpc"
|
||||
readonly property string networkRopsten: "testnet_rpc"
|
||||
|
||||
readonly property string api_request: "api-request"
|
||||
readonly property string web3SendAsyncReadOnly: "web3-send-async-read-only"
|
||||
|
|
|
@ -725,6 +725,8 @@ Rectangle {
|
|||
anchors.leftMargin: 2
|
||||
anchors.bottom: parent.bottom
|
||||
icon.name: "stickers_icon"
|
||||
visible: profileModel.network === Constants.networkMainnet
|
||||
width: visible ? 32 : 0
|
||||
type: "secondary"
|
||||
onClicked: {
|
||||
emojiPopup.close()
|
||||
|
|
Loading…
Reference in New Issue