Browse Source

UI on Wallets screen. Add active/not active/current indicator tags.

initial wallet delete/change password boilerplate
patch-4
Sander van Grieken 3 years ago
parent
commit
e9a174711b
  1. 3
      electrum/gui/qml/components/Constants.qml
  2. 39
      electrum/gui/qml/components/Wallets.qml
  3. 29
      electrum/gui/qml/components/controls/Tag.qml
  4. 14
      electrum/gui/qml/components/main.qml
  5. 10
      electrum/gui/qml/qedaemon.py
  6. 15
      electrum/gui/qml/qewallet.py

3
electrum/gui/qml/components/Constants.qml

@ -2,7 +2,8 @@ import QtQuick 2.6
import QtQuick.Controls.Material 2.0 import QtQuick.Controls.Material 2.0
Item { 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 paddingXSmall: 6
readonly property int paddingSmall: 8 readonly property int paddingSmall: 8
readonly property int paddingMedium: 12 readonly property int paddingMedium: 12

39
electrum/gui/qml/components/Wallets.qml

@ -35,11 +35,15 @@ Pane {
var dialog = app.messageDialog.createObject(rootItem, var dialog = app.messageDialog.createObject(rootItem,
{'text': qsTr('Really delete this wallet?'), 'yesno': true}) {'text': qsTr('Really delete this wallet?'), 'yesno': true})
dialog.yesClicked.connect(function() { dialog.yesClicked.connect(function() {
Daemon.currentWallet.deleteWallet() Daemon.delete_wallet(Daemon.currentWallet)
}) })
dialog.open() dialog.open()
} }
function changePassword() {
// TODO: show set password dialog
}
property QtObject menu: Menu { property QtObject menu: Menu {
id: menu id: menu
MenuItem { MenuItem {
@ -66,7 +70,7 @@ Pane {
id: deleteWalletComp id: deleteWalletComp
MenuItem { MenuItem {
icon.color: 'transparent' icon.color: 'transparent'
enabled: false enabled: Daemon.currentWallet // != null
action: Action { action: Action {
text: qsTr('Delete Wallet'); text: qsTr('Delete Wallet');
onTriggered: rootItem.deleteWallet() onTriggered: rootItem.deleteWallet()
@ -231,10 +235,14 @@ Pane {
clip: true clip: true
model: Daemon.availableWallets model: Daemon.availableWallets
delegate: AbstractButton { delegate: ItemDelegate {
width: ListView.view.width width: ListView.view.width
height: row.height height: row.height
onClicked: {
Daemon.load_wallet(model.path)
}
RowLayout { RowLayout {
id: row id: row
spacing: 10 spacing: 10
@ -247,19 +255,35 @@ Pane {
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
Layout.preferredWidth: constants.iconSizeLarge Layout.preferredWidth: constants.iconSizeLarge
Layout.preferredHeight: constants.iconSizeLarge Layout.preferredHeight: constants.iconSizeLarge
Layout.topMargin: constants.paddingSmall
Layout.bottomMargin: constants.paddingSmall
} }
Label { Label {
font.pixelSize: constants.fontSizeLarge font.pixelSize: constants.fontSizeLarge
text: model.name text: model.name
color: model.active ? Material.foreground : Qt.darker(Material.foreground, 1.20)
Layout.fillWidth: true Layout.fillWidth: true
} }
Button { Tag {
text: 'Open' visible: Daemon.currentWallet && model.name == Daemon.currentWallet.name
onClicked: { text: qsTr('Current')
Daemon.load_wallet(model.path) 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 { Connections {
target: Daemon target: Daemon
function onWalletLoaded() { function onWalletLoaded() {
Daemon.availableWallets.reload()
app.stack.pop() app.stack.pop()
} }
} }

29
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
}
}
}

14
electrum/gui/qml/components/main.qml

@ -235,4 +235,18 @@ ApplicationWindow
dialog.open() 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()
}
}
} }

10
electrum/gui/qml/qedaemon.py

@ -13,6 +13,7 @@ from electrum.wallet_db import WalletDB
from .qewallet import QEWallet from .qewallet import QEWallet
from .qewalletdb import QEWalletDB from .qewalletdb import QEWalletDB
from .qefx import QEFX from .qefx import QEFX
from .auth import AuthMixin, auth_protect
# wallet list model. supports both wallet basenames (wallet file basenames) # wallet list model. supports both wallet basenames (wallet file basenames)
# and whole Wallet instances (loaded wallets) # and whole Wallet instances (loaded wallets)
@ -84,7 +85,7 @@ class QEAvailableWalletListModel(QEWalletListModel):
wallet = self.daemon.get_wallet(path) wallet = self.daemon.get_wallet(path)
self.add_wallet(wallet_path = path, wallet = wallet) self.add_wallet(wallet_path = path, wallet = wallet)
class QEDaemon(QObject): class QEDaemon(AuthMixin, QObject):
def __init__(self, daemon, parent=None): def __init__(self, daemon, parent=None):
super().__init__(parent) super().__init__(parent)
self.daemon = daemon self.daemon = daemon
@ -145,6 +146,13 @@ class QEDaemon(QObject):
self._logger.error(str(e)) self._logger.error(str(e))
self.walletOpenError.emit(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') @pyqtProperty('QString')
def path(self): def path(self):

15
electrum/gui/qml/qewallet.py

@ -235,7 +235,7 @@ class QEWallet(AuthMixin, QObject):
return self._channelModel return self._channelModel
nameChanged = pyqtSignal() nameChanged = pyqtSignal()
@pyqtProperty('QString', notify=nameChanged) @pyqtProperty(str, notify=nameChanged)
def name(self): def name(self):
return self.wallet.basename() return self.wallet.basename()
@ -252,7 +252,7 @@ class QEWallet(AuthMixin, QObject):
def hasSeed(self): def hasSeed(self):
return self.wallet.has_seed() return self.wallet.has_seed()
@pyqtProperty('QString', notify=dataChanged) @pyqtProperty(str, notify=dataChanged)
def txinType(self): def txinType(self):
return self.wallet.get_txin_type(self.wallet.dummy_address()) return self.wallet.get_txin_type(self.wallet.dummy_address())
@ -272,7 +272,7 @@ class QEWallet(AuthMixin, QObject):
def isHardware(self): def isHardware(self):
return self.wallet.storage.is_encrypted_with_hw_device() return self.wallet.storage.is_encrypted_with_hw_device()
@pyqtProperty('QString', notify=dataChanged) @pyqtProperty(str, notify=dataChanged)
def derivationPrefix(self): def derivationPrefix(self):
keystores = self.wallet.get_keystores() keystores = self.wallet.get_keystores()
if len(keystores) > 1: if len(keystores) > 1:
@ -288,7 +288,6 @@ class QEWallet(AuthMixin, QObject):
@pyqtProperty(QEAmount, notify=balanceChanged) @pyqtProperty(QEAmount, notify=balanceChanged)
def frozenBalance(self): def frozenBalance(self):
c, u, x = self.wallet.get_frozen_balance() 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) self._frozenbalance = QEAmount(amount_sat=c+x)
return self._frozenbalance return self._frozenbalance
@ -300,7 +299,6 @@ class QEWallet(AuthMixin, QObject):
@pyqtProperty(QEAmount, notify=balanceChanged) @pyqtProperty(QEAmount, notify=balanceChanged)
def confirmedBalance(self): def confirmedBalance(self):
c, u, x = self.wallet.get_balance() c, u, x = self.wallet.get_balance()
self._logger.info('balance: ' + str(c) + ' ' + str(u) + ' ' + str(x) + ' ')
self._confirmedbalance = QEAmount(amount_sat=c+x) self._confirmedbalance = QEAmount(amount_sat=c+x)
return self._confirmedbalance return self._confirmedbalance
@ -484,3 +482,10 @@ class QEWallet(AuthMixin, QObject):
@pyqtSlot('QString', result='QVariant') @pyqtSlot('QString', result='QVariant')
def get_invoice(self, key: str): def get_invoice(self, key: str):
return self._invoiceModel.get_model_invoice(key) 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

Loading…
Cancel
Save