From 35e15f7ed0baf20e4cc0cb8ed313e52f4bc6eb67 Mon Sep 17 00:00:00 2001 From: Khushboo Mehta Date: Tue, 31 Aug 2021 14:06:13 +0200 Subject: [PATCH] feat(desktop/wallet): Adding Setttings tab in wallet 2 Added nim api's to get the account signing phrase fixes #3303 --- src/app/wallet/v2/core.nim | 3 + src/app/wallet/v2/view.nim | 15 +- src/app/wallet/v2/views/settings.nim | 45 +++++ ui/app/AppLayouts/WalletV2/SettingsTab.qml | 164 ++++++++++++++++++ ui/app/AppLayouts/WalletV2/WalletV2Layout.qml | 12 +- ui/app/AppLayouts/WalletV2/qmldir | 1 + 6 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 src/app/wallet/v2/views/settings.nim create mode 100644 ui/app/AppLayouts/WalletV2/SettingsTab.qml diff --git a/src/app/wallet/v2/core.nim b/src/app/wallet/v2/core.nim index c1367bb58e..6b952fc62e 100644 --- a/src/app/wallet/v2/core.nim +++ b/src/app/wallet/v2/core.nim @@ -48,6 +48,9 @@ proc init*(self: WalletController) = var data = WalletSignal(e) debug "TODO: handle wallet signal", signalType=data.eventType + self.view.setSigningPhrase(self.status.settings.getSetting[:string](Setting.SigningPhrase)) + self.view.setEtherscanLink(self.status.settings.getCurrentNetworkDetails().etherscanLink) + self.status.events.on("cryptoServicesFetched") do(e: Args): var args = CryptoServicesArg(e) self.view.onCryptoServicesFetched(args.services) \ No newline at end of file diff --git a/src/app/wallet/v2/view.nim b/src/app/wallet/v2/view.nim index 40dd2a5ad7..98f01828d1 100644 --- a/src/app/wallet/v2/view.nim +++ b/src/app/wallet/v2/view.nim @@ -2,7 +2,7 @@ import atomics, strformat, strutils, sequtils, json, std/wrapnils, parseUtils, t import NimQml, chronicles, stint import status/[status, wallet2] -import views/[accounts, account_list, collectibles] +import views/[accounts, account_list, collectibles, settings] import views/buy_sell_crypto/[service_controller] import ../../../app_service/[main] @@ -13,6 +13,7 @@ QtObject: appService: AppService accountsView: AccountsView collectiblesView: CollectiblesView + settingsView*: SettingsView cryptoServiceController: CryptoServiceController proc delete(self: WalletView) = @@ -20,6 +21,7 @@ QtObject: self.collectiblesView.delete self.cryptoServiceController.delete self.QAbstractListModel.delete + self.settingsView.delete proc setup(self: WalletView) = self.QAbstractListModel.setup @@ -30,6 +32,7 @@ QtObject: result.appService = appService result.accountsView = newAccountsView(status) result.collectiblesView = newCollectiblesView(status, appService) + result.settingsView = newSettingsView() result.cryptoServiceController = newCryptoServiceController(status, appService) result.setup @@ -42,6 +45,10 @@ QtObject: proc getCollectibles(self: WalletView): QVariant {.slot.} = return newQVariant(self.collectiblesView) + proc getSettings(self: WalletView): QVariant {.slot.} = newQVariant(self.settingsView) + QtProperty[QVariant] settingsView: + read = getSettings + QtProperty[QVariant] collectiblesView: read = getCollectibles @@ -61,6 +68,12 @@ QtObject: if (self.accountsView.accounts.rowCount == 1): self.setCurrentAccountByIndex(0) + proc setSigningPhrase*(self: WalletView, signingPhrase: string) = + self.settingsView.setSigningPhrase(signingPhrase) + + proc setEtherscanLink*(self: WalletView, link: string) = + self.settingsView.setEtherscanLink(link) + proc getCryptoServiceController*(self: WalletView): QVariant {.slot.} = newQVariant(self.cryptoServiceController) diff --git a/src/app/wallet/v2/views/settings.nim b/src/app/wallet/v2/views/settings.nim new file mode 100644 index 0000000000..3999e249b1 --- /dev/null +++ b/src/app/wallet/v2/views/settings.nim @@ -0,0 +1,45 @@ +import atomics, strformat, strutils, sequtils, json, std/wrapnils, parseUtils, tables, chronicles, web3/[ethtypes, conversions], stint +import NimQml, json, sequtils, chronicles, strutils, strformat, json + +logScope: + topics = "settings-view" + +QtObject: + type SettingsView* = ref object of QObject + etherscanLink: string + signingPhrase: string + + proc setup(self: SettingsView) = self.QObject.setup + proc delete(self: SettingsView) = self.QObject.delete + + proc newSettingsView*(): SettingsView = + new(result, delete) + result.etherscanLink = "" + result.signingPhrase = "" + result.setup + + proc etherscanLinkChanged*(self: SettingsView) {.signal.} + + proc getEtherscanLink*(self: SettingsView): QVariant {.slot.} = + newQVariant(self.etherscanLink.replace("/address", "/tx")) + + proc setEtherscanLink*(self: SettingsView, link: string) = + self.etherscanLink = link + self.etherscanLinkChanged() + + proc signingPhraseChanged*(self: SettingsView) {.signal.} + + proc getSigningPhrase*(self: SettingsView): QVariant {.slot.} = + newQVariant(self.signingPhrase) + + proc setSigningPhrase*(self: SettingsView, signingPhrase: string) = + self.signingPhrase = signingPhrase + self.signingPhraseChanged() + + QtProperty[QVariant] etherscanLink: + read = getEtherscanLink + notify = etherscanLinkChanged + + QtProperty[QVariant] signingPhrase: + read = getSigningPhrase + notify = signingPhraseChanged diff --git a/ui/app/AppLayouts/WalletV2/SettingsTab.qml b/ui/app/AppLayouts/WalletV2/SettingsTab.qml new file mode 100644 index 0000000000..2ccfa8dd59 --- /dev/null +++ b/ui/app/AppLayouts/WalletV2/SettingsTab.qml @@ -0,0 +1,164 @@ +import QtQuick 2.13 +import QtGraphicalEffects 1.13 + +import StatusQ.Core.Theme 0.1 +import StatusQ.Components 0.1 +import StatusQ.Controls 0.1 +import StatusQ.Core 0.1 + +import "../../../imports" +import "../Profile/Sections" + +Item { + id: root + + Column { + anchors.top:parent.top + leftPadding: 20 + rightPadding: 20 + width: parent.width + spacing: 12 + + StatusExpandableItem { + anchors.left: parent.left + anchors.leftMargin: 20 + anchors.right: parent.right + anchors.rightMargin: 20 + + visible : (walletV2Model.accountsView.currentAccount.walletType !== Constants.seedWalletType) && + (walletV2Model.accountsView.currentAccount.walletType !== Constants.watchWalletType) && + (walletV2Model.accountsView.currentAccount.walletType !== Constants.keyWalletType) + expandable: false + icon.name: "seed-phrase" + primaryText: qsTr("Back up seed phrase") + secondaryText: qsTr("Back up your seed phrase now to secure this account") + button.text: qsTr("Back up seed phrase") + button.enabled: !profileModel.mnemonic.isBackedUp + button.onClicked: backupSeedModal.open() + } + + StatusExpandableItem { + anchors.left: parent.left + anchors.leftMargin: 20 + anchors.right: parent.right + anchors.rightMargin: 20 + + visible : walletV2Model.accountsView.currentAccount.walletType !== Constants.watchWalletType + expandable: true + icon.name: "secret" + primaryText: qsTr("Account signing phrase") + secondaryText: qsTr("View your signing phrase and ensure that you never get scammed") + expandableComponent: showSigningPhraseExpandableRegion + } + + StatusExpandableItem { + anchors.left: parent.left + anchors.leftMargin: 20 + anchors.right: parent.right + anchors.rightMargin: 20 + + visible : (walletV2Model.accountsView.currentAccount.walletType === Constants.keyWalletType) || + (walletV2Model.accountsView.currentAccount.walletType === Constants.seedWalletType) + expandable: true + icon.name: "seed-phrase" + primaryText: qsTr("View private key") + secondaryText: qsTr("View your seed phrase and ensure it's stored in a safe place") + button.text: qsTr("View private key") + expandableComponent: notImplemented + button.onClicked: { + // To-do open enter password Modal + expanded = !expanded + } + } + + StatusExpandableItem { + anchors.left: parent.left + anchors.leftMargin: 20 + anchors.right: parent.right + anchors.rightMargin: 20 + + expandable: true + icon.name: "security" + primaryText: qsTr("Security preferences") + secondaryText: qsTr("View & set security preferences for this wallet") + expandableComponent: notImplemented + } + } + + Component { + id: notImplemented + Rectangle { + anchors.centerIn: parent + width: 654 + height: infoText.implicitHeight + color: Theme.palette.baseColor5 + StatusBaseText { + id: infoText + anchors.centerIn: parent + color: Theme.palette.directColor4 + font.pixelSize: 15 + lineHeight: 22 + lineHeightMode: Text.FixedHeight + font.weight: Font.Medium + text: qsTr("Not Implemented") + } + } + } + + Component { + id: showSigningPhraseExpandableRegion + Row { + spacing: 1 + anchors.centerIn: parent + width: 654 + Rectangle { + id: keyRect + color: Theme.palette.baseColor5 + width: Math.min(keyText.implicitWidth, 200) + keyText.anchors.leftMargin + keyText.anchors.rightMargin + height: Math.max(keyText.implicitHeight, infoText.implicitHeight) + 42 + StatusBaseText { + id: keyText + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 21 + anchors.right: parent.right + anchors.rightMargin: 21 + width: Math.min(implicitWidth, 200) + + color: Theme.palette.dangerColor1 + font.pixelSize: 15 + lineHeight: 22 + lineHeightMode: Text.FixedHeight + elide: Text.ElideRight + wrapMode: Text.Wrap + text: walletV2Model.settingsView.signingPhrase + } + } + Rectangle { + id: infoRect + color: Theme.palette.baseColor5 + width: parent.width - keyRect.width + height: Math.max(keyText.implicitHeight, infoText.implicitHeight) + 42 + StatusBaseText { + id: infoText + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 25 + width: 366 + + color: Theme.palette.directColor4 + font.pixelSize: 12 + lineHeight: 16 + lineHeightMode: Text.FixedHeight + elide: Text.ElideRight + wrapMode: Text.Wrap + text: qsTr("If you see something different, you should immediately sign out and reinstall Status") + } + } + } + } + + BackupSeedModal { + id: backupSeedModal + } +} diff --git a/ui/app/AppLayouts/WalletV2/WalletV2Layout.qml b/ui/app/AppLayouts/WalletV2/WalletV2Layout.qml index 0a89f9899c..7f27e45dd7 100644 --- a/ui/app/AppLayouts/WalletV2/WalletV2Layout.qml +++ b/ui/app/AppLayouts/WalletV2/WalletV2Layout.qml @@ -85,6 +85,12 @@ Item { id: collectiblesBtn btnText: qsTr("Collectibles") } + StatusTabButton { + id: settingsBtn + anchors.left: collectiblesBtn.right + anchors.leftMargin: walletInfoContent.width - collectiblesBtn.width - 100 + btnText: qsTr("Settings") + } } StackLayout { @@ -93,12 +99,16 @@ Item { anchors.right: parent.right anchors.bottom: parent.bottom anchors.left: parent.left - anchors.topMargin: Style.current.bigPadding + anchors.topMargin: Style.current.padding currentIndex: walletTabBar.currentIndex CollectiblesTab { id: collectiblesTab } + + SettingsTab { + id: settingsTab + } } } } diff --git a/ui/app/AppLayouts/WalletV2/qmldir b/ui/app/AppLayouts/WalletV2/qmldir index 2d4d873368..31a3372cf0 100644 --- a/ui/app/AppLayouts/WalletV2/qmldir +++ b/ui/app/AppLayouts/WalletV2/qmldir @@ -2,3 +2,4 @@ LeftTab 1.0 LeftTab.qml WalletHeader 1.0 WalletHeader.qml AssetsTab 1.0 AssetsTab.qml CollectiblesTab 1.0 CollectiblesTab.qml +SettingsTab SettingsTab.qml