feat: choose fleet

This commit is contained in:
Richard Ramos 2020-11-03 17:04:57 -04:00 committed by Iuri Matias
parent 514f6fa31e
commit ea02c7f0b5
10 changed files with 212 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import NimQml, sequtils, strutils, sugar, os, json import NimQml, sequtils, strutils, sugar, os, json
import views/[mailservers_list, ens_manager, contact_list, profile_info, device_list, dapp_list] import views/[mailservers_list, ens_manager, contact_list, fleets, profile_info, device_list, dapp_list]
import ../../status/profile/[mailserver, profile, devices] import ../../status/profile/[mailserver, profile, devices]
import ../../status/profile as status_profile import ../../status/profile as status_profile
import ../../status/contacts as status_contacts import ../../status/contacts as status_contacts
@ -23,6 +23,7 @@ QtObject:
blockedContacts*: ContactList blockedContacts*: ContactList
deviceList*: DeviceList deviceList*: DeviceList
dappList*: DappList dappList*: DappList
fleets*: Fleets
network: string network: string
status*: Status status*: Status
isDeviceSetup: bool isDeviceSetup: bool
@ -42,6 +43,7 @@ QtObject:
if not self.ens.isNil: self.ens.delete if not self.ens.isNil: self.ens.delete
if not self.profile.isNil: self.profile.delete if not self.profile.isNil: self.profile.delete
if not self.dappList.isNil: self.dappList.delete if not self.dappList.isNil: self.dappList.delete
if not self.fleets.isNil: self.fleets.delete
self.QObject.delete self.QObject.delete
proc newProfileView*(status: Status, changeLanguage: proc(locale: string)): ProfileView = proc newProfileView*(status: Status, changeLanguage: proc(locale: string)): ProfileView =
@ -55,6 +57,7 @@ QtObject:
result.deviceList = newDeviceList() result.deviceList = newDeviceList()
result.dappList = newDappList(status) result.dappList = newDappList(status)
result.ens = newEnsManager(status) result.ens = newEnsManager(status)
result.fleets = newFleets(status)
result.network = "" result.network = ""
result.status = status result.status = status
result.isDeviceSetup = false result.isDeviceSetup = false
@ -269,6 +272,12 @@ QtObject:
QtProperty[QVariant] dappList: QtProperty[QVariant] dappList:
read = getDappList read = getDappList
proc getFleets(self: ProfileView): QVariant {.slot.} =
return newQVariant(self.fleets)
QtProperty[QVariant] fleets:
read = getFleets
proc getEnsManager(self: ProfileView): QVariant {.slot.} = proc getEnsManager(self: ProfileView): QVariant {.slot.} =
return newQVariant(self.ens) return newQVariant(self.ens)

View File

@ -0,0 +1,40 @@
import NimQml
import chronicles, strutils
import ../../../status/libstatus/types as status_types
import ../../../status/libstatus/settings as status_settings
import ../../../status/libstatus/accounts as status_accounts
import ../../../status/status
QtObject:
type Fleets * = ref object of QObject
status: Status
proc setup(self: Fleets) =
self.QObject.setup
proc delete*(self: Fleets) =
self.QObject.delete
proc newFleets*(status: Status): Fleets =
new(result, delete)
result = Fleets()
result.status = status
result.setup
proc fleetChanged*(self: Fleets, newFleet: string) {.signal.}
proc setFleet*(self: Fleets, newFleet: string) {.slot.} =
discard status_settings.saveSetting(Setting.Fleet, newFleet)
let fleet = parseEnum[Fleet](newFleet)
let installationId = status_settings.getSetting[string](Setting.InstallationId)
let updatedNodeConfig = status_accounts.getNodeConfig(self.status.fleet.config, installationId, $status_settings.getCurrentNetwork(), fleet)
discard status_settings.saveSetting(Setting.NodeConfig, updatedNodeConfig)
self.fleetChanged(newFleet)
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
proc getFleet*(self: Fleets): string {.slot.} = $status_settings.getFleet()
QtProperty[string] fleet:
read = getFleet
notify = fleetChanged

View File

@ -1,6 +1,4 @@
import libstatus/core as status
import ../eventemitter import ../eventemitter
import tables
import json import json
import libstatus/types import libstatus/types

View File

@ -1,4 +1,4 @@
import json, os, nimcrypto, uuids, json_serialization, chronicles, strutils, sequtils, random, sugar import json, os, nimcrypto, uuids, json_serialization, chronicles, strutils
from nim_status import multiAccountGenerateAndDeriveAddresses, generateAlias, identicon, saveAccountAndLogin, login, openAccounts from nim_status import multiAccountGenerateAndDeriveAddresses, generateAlias, identicon, saveAccountAndLogin, login, openAccounts
import core import core
@ -19,6 +19,7 @@ proc getNodeConfig*(fleetConfig: FleetConfig, installationId: string, currentNet
newDataDir.removeSuffix("_rpc") newDataDir.removeSuffix("_rpc")
result = constants.NODE_CONFIG.copy() result = constants.NODE_CONFIG.copy()
result["ClusterConfig"]["Fleet"] = newJString($fleet)
result["ClusterConfig"]["BootNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Bootnodes) result["ClusterConfig"]["BootNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Bootnodes)
result["ClusterConfig"]["TrustedMailServers"] = %* fleetConfig.getNodes(fleet, FleetNodes.Mailservers) result["ClusterConfig"]["TrustedMailServers"] = %* fleetConfig.getNodes(fleet, FleetNodes.Mailservers)
result["ClusterConfig"]["StaticNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Whisper) result["ClusterConfig"]["StaticNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Whisper)

View File

@ -100,8 +100,7 @@ var NODE_CONFIG* = %* {
"Enabled": true "Enabled": true
}, },
"ClusterConfig": { "ClusterConfig": {
"Enabled": true, "Enabled": true
"Fleet": "eth.prod"
}, },
"DataDir": "./ethereum/mainnet", "DataDir": "./ethereum/mainnet",
"EnableNTPSync": true, "EnableNTPSync": true,

View File

@ -1,5 +1,5 @@
import core, ./types, ../signals/types as statusgo_types, ./accounts/constants, ./utils import core, ./types, ../signals/types as statusgo_types, ./accounts/constants, ./utils
import json, tables, sugar, sequtils import json, tables, sugar, sequtils, strutils
import json_serialization import json_serialization
import locks import locks
@ -69,3 +69,7 @@ proc getCurrentNetworkDetails*(): NetworkDetails =
proc getLinkPreviewWhitelist*(): JsonNode = proc getLinkPreviewWhitelist*(): JsonNode =
result = callPrivateRPC("getLinkPreviewWhitelist".prefix, %* []).parseJSON()["result"] result = callPrivateRPC("getLinkPreviewWhitelist".prefix, %* []).parseJSON()["result"]
proc getFleet*(): Fleet =
let fleet = getSetting[string](Setting.Fleet, $Fleet.PROD)
result = parseEnum[Fleet](fleet)

View File

@ -166,6 +166,7 @@ type
PreferredUsername = "preferred-name" PreferredUsername = "preferred-name"
Usernames = "usernames" Usernames = "usernames"
SigningPhrase = "signing-phrase" SigningPhrase = "signing-phrase"
Fleet = "fleet"
VisibleTokens = "wallet/visible-tokens" VisibleTokens = "wallet/visible-tokens"
UpstreamConfig* = ref object UpstreamConfig* = ref object

View File

@ -1,6 +1,7 @@
import QtQuick 2.13 import QtQuick 2.13
import QtQuick.Controls 2.13 import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13 import QtQuick.Layouts 1.13
import QtGraphicalEffects 1.13
import "../../../../imports" import "../../../../imports"
import "../../../../shared" import "../../../../shared"
import "../../../../shared/status" import "../../../../shared/status"
@ -114,9 +115,58 @@ Item {
} }
} }
Item {
id: fleetSetting
anchors.top: networkTabSettings.bottom
anchors.topMargin: Style.current.padding
width: parent.width
height: fleetText.height
StyledText {
id: fleetText
text: qsTr("Fleet")
font.pixelSize: 15
}
StyledText {
text: profileModel.fleets.fleet
font.pixelSize: 15
anchors.right: caret2.left
anchors.rightMargin: Style.current.padding
}
SVGImage {
id: caret2
anchors.right: parent.right
anchors.rightMargin: 0
anchors.verticalCenter: fleetText.verticalCenter
source: "../../../img/caret.svg"
width: 13
height: 7
rotation: -90
}
ColorOverlay {
anchors.fill: caret2
source: caret2
color: Style.current.darkGrey
rotation: -90
}
FleetsModal {
id: fleetModal
}
MouseArea {
anchors.fill: parent
onClicked: fleetModal.open()
cursorShape: Qt.PointingHandCursor
}
}
RowLayout { RowLayout {
id: uiCatalog id: uiCatalog
anchors.top: networkTabSettings.bottom anchors.top: fleetSetting.bottom
anchors.topMargin: 20 anchors.topMargin: 20
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 24 anchors.leftMargin: 24
@ -140,7 +190,6 @@ Item {
text: qsTrId("developer-setting") text: qsTrId("developer-setting")
} }
} }
} }
/*##^## /*##^##

View File

@ -0,0 +1,97 @@
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("Fleet")
property string newFleet: "";
Column {
id: column
spacing: Style.current.padding
width: parent.width
ConfirmationDialog {
id: confirmDialog
title: qsTr("Warning!")
confirmationText: qsTr("Change fleet to %1").arg(newFleet)
onConfirmButtonClicked: profileModel.fleets.setFleet(newFleet)
onClosed: {
let currFleet = profileModel.fleets.fleet
radioProd.checked = currFleet == Constants.eth_prod
radioStaging.checked = currFleet == Constants.eth_staging
radioTest.checked = currFleet == Constants.eth_test
}
}
ButtonGroup { id: fleetSettings }
RowLayout {
width: parent.width
StyledText {
text: Constants.eth_prod
font.pixelSize: 15
}
StatusRadioButton {
id: radioProd
Layout.alignment: Qt.AlignRight
ButtonGroup.group: fleetSettings
rightPadding: 0
checked: profileModel.fleets.fleet == Constants.eth_prod
onClicked: {
if (profileModel.fleets.fleet === Constants.eth_prod) return;
newFleet = Constants.eth_prod;
confirmDialog.open();
}
}
}
RowLayout {
width: parent.width
StyledText {
text: Constants.eth_staging
font.pixelSize: 15
}
StatusRadioButton {
id: radioStaging
Layout.alignment: Qt.AlignRight
ButtonGroup.group: fleetSettings
rightPadding: 0
checked: profileModel.fleets.fleet === Constants.eth_staging
onClicked: {
if (profileModel.fleets.fleet === Constants.eth_staging) return;
newFleet = Constants.eth_staging;
confirmDialog.open();
}
}
}
RowLayout {
width: parent.width
StyledText {
text: Constants.eth_test
font.pixelSize: 15
}
StatusRadioButton {
id: radioTest
Layout.alignment: Qt.AlignRight
ButtonGroup.group: fleetSettings
rightPadding: 0
checked: profileModel.fleets.fleet === Constants.eth_test
onClicked: {
if (profileModel.fleets.fleet === Constants.eth_test) {
return;
}
newFleet = Constants.eth_test;
confirmDialog.open();
}
}
}
}
}

View File

@ -78,4 +78,8 @@ QtObject {
readonly property string eth_sign: "eth_sign" readonly property string eth_sign: "eth_sign"
readonly property string eth_signTypedData: "eth_signTypedData" readonly property string eth_signTypedData: "eth_signTypedData"
readonly property string eth_signTypedData_v3: "eth_signTypedData_v3" readonly property string eth_signTypedData_v3: "eth_signTypedData_v3"
readonly property string eth_prod: "eth.prod"
readonly property string eth_staging: "eth.staging"
readonly property string eth_test: "eth.test"
} }