From e9a174711be4f0f885e3cf7853dd42b57d7ff770 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 21 Jun 2022 00:01:30 +0200 Subject: [PATCH] UI on Wallets screen. Add active/not active/current indicator tags. initial wallet delete/change password boilerplate --- electrum/gui/qml/components/Constants.qml | 3 +- electrum/gui/qml/components/Wallets.qml | 41 ++++++++++++++++---- electrum/gui/qml/components/controls/Tag.qml | 29 ++++++++++++++ electrum/gui/qml/components/main.qml | 14 +++++++ electrum/gui/qml/qedaemon.py | 10 ++++- electrum/gui/qml/qewallet.py | 15 ++++--- 6 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 electrum/gui/qml/components/controls/Tag.qml diff --git a/electrum/gui/qml/components/Constants.qml b/electrum/gui/qml/components/Constants.qml index da633b95b..f6eb7293d 100644 --- a/electrum/gui/qml/components/Constants.qml +++ b/electrum/gui/qml/components/Constants.qml @@ -2,7 +2,8 @@ import QtQuick 2.6 import QtQuick.Controls.Material 2.0 Item { - readonly property int paddingTiny: 4 + readonly property int paddingTiny: 4 //deprecated + readonly property int paddingXXSmall: 4 readonly property int paddingXSmall: 6 readonly property int paddingSmall: 8 readonly property int paddingMedium: 12 diff --git a/electrum/gui/qml/components/Wallets.qml b/electrum/gui/qml/components/Wallets.qml index 9cc941bf3..f38fe29ae 100644 --- a/electrum/gui/qml/components/Wallets.qml +++ b/electrum/gui/qml/components/Wallets.qml @@ -35,11 +35,15 @@ Pane { var dialog = app.messageDialog.createObject(rootItem, {'text': qsTr('Really delete this wallet?'), 'yesno': true}) dialog.yesClicked.connect(function() { - Daemon.currentWallet.deleteWallet() + Daemon.delete_wallet(Daemon.currentWallet) }) dialog.open() } + function changePassword() { + // TODO: show set password dialog + } + property QtObject menu: Menu { id: menu MenuItem { @@ -66,7 +70,7 @@ Pane { id: deleteWalletComp MenuItem { icon.color: 'transparent' - enabled: false + enabled: Daemon.currentWallet // != null action: Action { text: qsTr('Delete Wallet'); onTriggered: rootItem.deleteWallet() @@ -231,10 +235,14 @@ Pane { clip: true model: Daemon.availableWallets - delegate: AbstractButton { + delegate: ItemDelegate { width: ListView.view.width height: row.height + onClicked: { + Daemon.load_wallet(model.path) + } + RowLayout { id: row spacing: 10 @@ -247,19 +255,35 @@ Pane { fillMode: Image.PreserveAspectFit Layout.preferredWidth: constants.iconSizeLarge Layout.preferredHeight: constants.iconSizeLarge + Layout.topMargin: constants.paddingSmall + Layout.bottomMargin: constants.paddingSmall } Label { font.pixelSize: constants.fontSizeLarge text: model.name + color: model.active ? Material.foreground : Qt.darker(Material.foreground, 1.20) Layout.fillWidth: true } - Button { - text: 'Open' - onClicked: { - Daemon.load_wallet(model.path) - } + Tag { + visible: Daemon.currentWallet && model.name == Daemon.currentWallet.name + text: qsTr('Current') + border.color: Material.foreground + font.bold: true + labelcolor: Material.foreground + } + Tag { + visible: model.active + text: qsTr('Active') + border.color: 'green' + labelcolor: 'green' + } + Tag { + visible: !model.active + text: qsTr('Not loaded') + border.color: 'grey' + labelcolor: 'grey' } } } @@ -279,6 +303,7 @@ Pane { Connections { target: Daemon function onWalletLoaded() { + Daemon.availableWallets.reload() app.stack.pop() } } diff --git a/electrum/gui/qml/components/controls/Tag.qml b/electrum/gui/qml/components/controls/Tag.qml new file mode 100644 index 000000000..510e059d0 --- /dev/null +++ b/electrum/gui/qml/components/controls/Tag.qml @@ -0,0 +1,29 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 2.3 +import QtQuick.Controls.Material 2.0 + +Rectangle { + radius: constants.paddingXSmall + width: layout.width + height: layout.height + color: 'transparent' + border.color: Material.accentColor + + property alias text: label.text + property alias font: label.font + property alias labelcolor: label.color + + RowLayout { + id: layout + + Label { + id: label + Layout.leftMargin: constants.paddingSmall + Layout.rightMargin: constants.paddingSmall + Layout.topMargin: constants.paddingXXSmall + Layout.bottomMargin: constants.paddingXXSmall + font.pixelSize: constants.fontSizeXSmall + } + } +} diff --git a/electrum/gui/qml/components/main.qml b/electrum/gui/qml/components/main.qml index 775b735a4..606f2aa1d 100644 --- a/electrum/gui/qml/components/main.qml +++ b/electrum/gui/qml/components/main.qml @@ -235,4 +235,18 @@ ApplicationWindow dialog.open() } } + + Connections { + target: Daemon + function onAuthRequired() { + var dialog = app.messageDialog.createObject(app, {'text': 'Auth placeholder', 'yesno': true}) + dialog.yesClicked.connect(function() { + Daemon.authProceed() + }) + dialog.noClicked.connect(function() { + Daemon.authCancel() + }) + dialog.open() + } + } } diff --git a/electrum/gui/qml/qedaemon.py b/electrum/gui/qml/qedaemon.py index 8d049b31a..28d602477 100644 --- a/electrum/gui/qml/qedaemon.py +++ b/electrum/gui/qml/qedaemon.py @@ -13,6 +13,7 @@ from electrum.wallet_db import WalletDB from .qewallet import QEWallet from .qewalletdb import QEWalletDB from .qefx import QEFX +from .auth import AuthMixin, auth_protect # wallet list model. supports both wallet basenames (wallet file basenames) # and whole Wallet instances (loaded wallets) @@ -84,7 +85,7 @@ class QEAvailableWalletListModel(QEWalletListModel): wallet = self.daemon.get_wallet(path) self.add_wallet(wallet_path = path, wallet = wallet) -class QEDaemon(QObject): +class QEDaemon(AuthMixin, QObject): def __init__(self, daemon, parent=None): super().__init__(parent) self.daemon = daemon @@ -145,6 +146,13 @@ class QEDaemon(QObject): self._logger.error(str(e)) self.walletOpenError.emit(str(e)) + @pyqtSlot(QEWallet) + @auth_protect + def delete_wallet(self, wallet): + path = wallet.wallet.storage.path + self._logger.debug('Ok to delete wallet with path %s' % path) + # TODO checks, e.g. existing LN channels, unpaid requests, etc + self.daemon.stop_wallet(path) @pyqtProperty('QString') def path(self): diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index 98467a73b..8333ac501 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -235,7 +235,7 @@ class QEWallet(AuthMixin, QObject): return self._channelModel nameChanged = pyqtSignal() - @pyqtProperty('QString', notify=nameChanged) + @pyqtProperty(str, notify=nameChanged) def name(self): return self.wallet.basename() @@ -252,7 +252,7 @@ class QEWallet(AuthMixin, QObject): def hasSeed(self): return self.wallet.has_seed() - @pyqtProperty('QString', notify=dataChanged) + @pyqtProperty(str, notify=dataChanged) def txinType(self): return self.wallet.get_txin_type(self.wallet.dummy_address()) @@ -272,7 +272,7 @@ class QEWallet(AuthMixin, QObject): def isHardware(self): return self.wallet.storage.is_encrypted_with_hw_device() - @pyqtProperty('QString', notify=dataChanged) + @pyqtProperty(str, notify=dataChanged) def derivationPrefix(self): keystores = self.wallet.get_keystores() if len(keystores) > 1: @@ -288,7 +288,6 @@ class QEWallet(AuthMixin, QObject): @pyqtProperty(QEAmount, notify=balanceChanged) def frozenBalance(self): c, u, x = self.wallet.get_frozen_balance() - self._logger.info('frozen balance: ' + str(c) + ' ' + str(u) + ' ' + str(x) + ' ') self._frozenbalance = QEAmount(amount_sat=c+x) return self._frozenbalance @@ -300,7 +299,6 @@ class QEWallet(AuthMixin, QObject): @pyqtProperty(QEAmount, notify=balanceChanged) def confirmedBalance(self): c, u, x = self.wallet.get_balance() - self._logger.info('balance: ' + str(c) + ' ' + str(u) + ' ' + str(x) + ' ') self._confirmedbalance = QEAmount(amount_sat=c+x) return self._confirmedbalance @@ -484,3 +482,10 @@ class QEWallet(AuthMixin, QObject): @pyqtSlot('QString', result='QVariant') def get_invoice(self, key: str): return self._invoiceModel.get_model_invoice(key) + + @pyqtSlot(str) + @auth_protect + def set_password(self, password): + storage = self.wallet.storage + self._logger.debug('Ok to set password for wallet with path %s' % storage.path) + # TODO