From ea02c7f0b5924b66465787845633a685ec0a2bea Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 3 Nov 2020 17:04:57 -0400 Subject: [PATCH] feat: choose fleet --- src/app/profile/view.nim | 11 ++- src/app/profile/views/fleets.nim | 40 ++++++++ src/status/fleet.nim | 2 - src/status/libstatus/accounts.nim | 3 +- src/status/libstatus/accounts/constants.nim | 3 +- src/status/libstatus/settings.nim | 8 +- src/status/libstatus/types.nim | 1 + .../Profile/Sections/AdvancedContainer.qml | 53 +++++++++- .../Profile/Sections/FleetsModal.qml | 97 +++++++++++++++++++ ui/imports/Constants.qml | 4 + 10 files changed, 212 insertions(+), 10 deletions(-) create mode 100644 src/app/profile/views/fleets.nim create mode 100644 ui/app/AppLayouts/Profile/Sections/FleetsModal.qml diff --git a/src/app/profile/view.nim b/src/app/profile/view.nim index d341fd6923..5f76c3bb22 100644 --- a/src/app/profile/view.nim +++ b/src/app/profile/view.nim @@ -1,5 +1,5 @@ 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 as status_profile import ../../status/contacts as status_contacts @@ -23,6 +23,7 @@ QtObject: blockedContacts*: ContactList deviceList*: DeviceList dappList*: DappList + fleets*: Fleets network: string status*: Status isDeviceSetup: bool @@ -42,6 +43,7 @@ QtObject: if not self.ens.isNil: self.ens.delete if not self.profile.isNil: self.profile.delete if not self.dappList.isNil: self.dappList.delete + if not self.fleets.isNil: self.fleets.delete self.QObject.delete proc newProfileView*(status: Status, changeLanguage: proc(locale: string)): ProfileView = @@ -55,6 +57,7 @@ QtObject: result.deviceList = newDeviceList() result.dappList = newDappList(status) result.ens = newEnsManager(status) + result.fleets = newFleets(status) result.network = "" result.status = status result.isDeviceSetup = false @@ -269,6 +272,12 @@ QtObject: QtProperty[QVariant] dappList: read = getDappList + proc getFleets(self: ProfileView): QVariant {.slot.} = + return newQVariant(self.fleets) + + QtProperty[QVariant] fleets: + read = getFleets + proc getEnsManager(self: ProfileView): QVariant {.slot.} = return newQVariant(self.ens) diff --git a/src/app/profile/views/fleets.nim b/src/app/profile/views/fleets.nim new file mode 100644 index 0000000000..4b87642fb5 --- /dev/null +++ b/src/app/profile/views/fleets.nim @@ -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 diff --git a/src/status/fleet.nim b/src/status/fleet.nim index b4f2af6548..befc08711c 100644 --- a/src/status/fleet.nim +++ b/src/status/fleet.nim @@ -1,6 +1,4 @@ -import libstatus/core as status import ../eventemitter -import tables import json import libstatus/types diff --git a/src/status/libstatus/accounts.nim b/src/status/libstatus/accounts.nim index 72ce76877f..667e62b0e2 100644 --- a/src/status/libstatus/accounts.nim +++ b/src/status/libstatus/accounts.nim @@ -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 import core @@ -19,6 +19,7 @@ proc getNodeConfig*(fleetConfig: FleetConfig, installationId: string, currentNet newDataDir.removeSuffix("_rpc") result = constants.NODE_CONFIG.copy() + result["ClusterConfig"]["Fleet"] = newJString($fleet) result["ClusterConfig"]["BootNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Bootnodes) result["ClusterConfig"]["TrustedMailServers"] = %* fleetConfig.getNodes(fleet, FleetNodes.Mailservers) result["ClusterConfig"]["StaticNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Whisper) diff --git a/src/status/libstatus/accounts/constants.nim b/src/status/libstatus/accounts/constants.nim index 8ba98eede2..3fd1ee836a 100644 --- a/src/status/libstatus/accounts/constants.nim +++ b/src/status/libstatus/accounts/constants.nim @@ -100,8 +100,7 @@ var NODE_CONFIG* = %* { "Enabled": true }, "ClusterConfig": { - "Enabled": true, - "Fleet": "eth.prod" + "Enabled": true }, "DataDir": "./ethereum/mainnet", "EnableNTPSync": true, diff --git a/src/status/libstatus/settings.nim b/src/status/libstatus/settings.nim index 22f9113f95..9bea2a5be0 100644 --- a/src/status/libstatus/settings.nim +++ b/src/status/libstatus/settings.nim @@ -1,5 +1,5 @@ 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 locks @@ -68,4 +68,8 @@ proc getCurrentNetworkDetails*(): NetworkDetails = networks.find((network: NetworkDetails) => network.id == currNetwork) proc getLinkPreviewWhitelist*(): JsonNode = - result = callPrivateRPC("getLinkPreviewWhitelist".prefix, %* []).parseJSON()["result"] \ No newline at end of file + result = callPrivateRPC("getLinkPreviewWhitelist".prefix, %* []).parseJSON()["result"] + +proc getFleet*(): Fleet = + let fleet = getSetting[string](Setting.Fleet, $Fleet.PROD) + result = parseEnum[Fleet](fleet) diff --git a/src/status/libstatus/types.nim b/src/status/libstatus/types.nim index 5e1985f115..5eb8b0a6fa 100644 --- a/src/status/libstatus/types.nim +++ b/src/status/libstatus/types.nim @@ -166,6 +166,7 @@ type PreferredUsername = "preferred-name" Usernames = "usernames" SigningPhrase = "signing-phrase" + Fleet = "fleet" VisibleTokens = "wallet/visible-tokens" UpstreamConfig* = ref object diff --git a/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml b/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml index aa361c9749..42d0af77d9 100644 --- a/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml +++ b/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml @@ -1,6 +1,7 @@ import QtQuick 2.13 import QtQuick.Controls 2.13 import QtQuick.Layouts 1.13 +import QtGraphicalEffects 1.13 import "../../../../imports" import "../../../../shared" 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 { id: uiCatalog - anchors.top: networkTabSettings.bottom + anchors.top: fleetSetting.bottom anchors.topMargin: 20 anchors.left: parent.left anchors.leftMargin: 24 @@ -140,7 +190,6 @@ Item { text: qsTrId("developer-setting") } } - } /*##^## diff --git a/ui/app/AppLayouts/Profile/Sections/FleetsModal.qml b/ui/app/AppLayouts/Profile/Sections/FleetsModal.qml new file mode 100644 index 0000000000..045f29be7f --- /dev/null +++ b/ui/app/AppLayouts/Profile/Sections/FleetsModal.qml @@ -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(); + } + } + } + } +} diff --git a/ui/imports/Constants.qml b/ui/imports/Constants.qml index fa0aff5a76..5dbd5dbde9 100644 --- a/ui/imports/Constants.qml +++ b/ui/imports/Constants.qml @@ -78,4 +78,8 @@ QtObject { readonly property string eth_sign: "eth_sign" readonly property string eth_signTypedData: "eth_signTypedData" 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" }