Browse Source

add RequestDialog, open request on create, and implement UI delete request

master
Sander van Grieken 4 years ago
parent
commit
490862d096
  1. 176
      electrum/gui/qml/components/Receive.qml
  2. 19
      electrum/gui/qml/qerequestlistmodel.py
  3. 7
      electrum/gui/qml/qewallet.py

176
electrum/gui/qml/components/Receive.qml

@ -2,6 +2,7 @@ import QtQuick 2.6
import QtQuick.Layouts 1.0 import QtQuick.Layouts 1.0
import QtQuick.Controls 2.14 import QtQuick.Controls 2.14
import QtQuick.Controls.Material 2.0 import QtQuick.Controls.Material 2.0
import QtQml.Models 2.1
import org.electrum 1.0 import org.electrum 1.0
@ -182,91 +183,99 @@ Pane {
} }
ListView { ListView {
id: listview
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
clip: true clip: true
model: Daemon.currentWallet.requestModel model: DelegateModel {
id: delegateModel
model: Daemon.currentWallet.requestModel
delegate: ItemDelegate { delegate: ItemDelegate {
id: root id: root
height: item.height height: item.height
width: ListView.view.width width: ListView.view.width
onClicked: console.log('Request ' + index + ' clicked') onClicked: {
var dialog = requestdialog.createObject(app, {'modelItem': model})
font.pixelSize: constants.fontSizeSmall // set default font size for child controls dialog.open()
GridLayout {
id: item
anchors {
left: parent.left
right: parent.right
leftMargin: constants.paddingSmall
rightMargin: constants.paddingSmall
}
columns: 5
Rectangle {
Layout.columnSpan: 5
Layout.fillWidth: true
Layout.preferredHeight: constants.paddingTiny
color: 'transparent'
}
Image {
Layout.rowSpan: 2
Layout.preferredWidth: 32
Layout.preferredHeight: 32
source: model.type == 0 ? "../../icons/bitcoin.png" : "../../icons/lightning.png"
}
Label {
Layout.fillWidth: true
Layout.columnSpan: 2
text: model.message
elide: Text.ElideRight
font.pixelSize: constants.fontSizeLarge
} }
Label { font.pixelSize: constants.fontSizeSmall // set default font size for child controls
text: qsTr('Amount: ')
} GridLayout {
Label { id: item
id: amount
text: Config.formatSats(model.amount, true) anchors {
font.family: FixedFont left: parent.left
right: parent.right
leftMargin: constants.paddingSmall
rightMargin: constants.paddingSmall
}
columns: 5
Rectangle {
Layout.columnSpan: 5
Layout.fillWidth: true
Layout.preferredHeight: constants.paddingTiny
color: 'transparent'
}
Image {
Layout.rowSpan: 2
Layout.preferredWidth: constants.iconSizeLarge
Layout.preferredHeight: constants.iconSizeLarge
source: model.type == 0 ? "../../icons/bitcoin.png" : "../../icons/lightning.png"
}
Label {
Layout.fillWidth: true
Layout.columnSpan: 2
text: model.message
elide: Text.ElideRight
font.pixelSize: constants.fontSizeLarge
}
Label {
text: qsTr('Amount: ')
}
Label {
id: amount
text: Config.formatSats(model.amount, true)
font.family: FixedFont
}
Label {
text: qsTr('Timestamp: ')
}
Label {
text: model.timestamp
}
Label {
text: qsTr('Status: ')
}
Label {
text: model.status
}
Rectangle {
Layout.columnSpan: 5
Layout.fillWidth: true
Layout.preferredHeight: constants.paddingTiny
color: 'transparent'
}
} }
Label { Connections {
text: qsTr('Timestamp: ') target: Config
} function onBaseUnitChanged() {
Label { amount.text = Config.formatSats(model.amount, true)
text: model.timestamp }
function onThousandsSeparatorChanged() {
amount.text = Config.formatSats(model.amount, true)
}
} }
Label {
text: qsTr('Status: ')
}
Label {
text: model.status
}
Rectangle {
Layout.columnSpan: 5
Layout.fillWidth: true
Layout.preferredHeight: constants.paddingTiny
color: 'transparent'
}
}
Connections {
target: Config
function onBaseUnitChanged() {
amount.text = Config.formatSats(model.amount, true)
}
function onThousandsSeparatorChanged() {
amount.text = Config.formatSats(model.amount, true)
}
} }
} }
@ -280,6 +289,14 @@ Pane {
NumberAnimation { properties: 'opacity'; to: 1.0; duration: 700 * (1-from) } NumberAnimation { properties: 'opacity'; to: 1.0; duration: 700 * (1-from) }
} }
remove: Transition {
NumberAnimation { properties: 'scale'; to: 0; duration: 400 }
NumberAnimation { properties: 'opacity'; to: 0; duration: 300 }
}
removeDisplaced: Transition {
SpringAnimation { properties: 'y'; duration: 100; spring: 5; damping: 0.5; mass: 2 }
}
ScrollIndicator.vertical: ScrollIndicator { } ScrollIndicator.vertical: ScrollIndicator { }
} }
} }
@ -294,9 +311,14 @@ Pane {
FocusScope { id: parkFocus } FocusScope { id: parkFocus }
} }
Component {
id: requestdialog
RequestDialog {}
}
function createRequest(ignoreGaplimit = false) { function createRequest(ignoreGaplimit = false) {
var a = Config.unitsToSats(amount.text) var a = Config.unitsToSats(amount.text)
Daemon.currentWallet.create_invoice(a, message.text, expires.currentValue, false, ignoreGaplimit) Daemon.currentWallet.create_request(a, message.text, expires.currentValue, false, ignoreGaplimit)
} }
Connections { Connections {
@ -304,8 +326,10 @@ Pane {
function onRequestCreateSuccess() { function onRequestCreateSuccess() {
message.text = '' message.text = ''
amount.text = '' amount.text = ''
// var dialog = app.showAsQrDialog.createObject(app, {'text': 'test'}) var dialog = requestdialog.createObject(app, {
// dialog.open() 'modelItem': delegateModel.items.get(0).model
})
dialog.open()
} }
function onRequestCreateError(code, error) { function onRequestCreateError(code, error) {
if (code == 'gaplimit') { if (code == 'gaplimit') {

19
electrum/gui/qml/qerequestlistmodel.py

@ -14,7 +14,7 @@ class QERequestListModel(QAbstractListModel):
_logger = get_logger(__name__) _logger = get_logger(__name__)
# define listmodel rolemap # define listmodel rolemap
_ROLE_NAMES=('type','timestamp','message','amount','status') _ROLE_NAMES=('key','type','timestamp','message','amount','status','address')
_ROLE_KEYS = range(Qt.UserRole + 1, Qt.UserRole + 1 + len(_ROLE_NAMES)) _ROLE_KEYS = range(Qt.UserRole + 1, Qt.UserRole + 1 + len(_ROLE_NAMES))
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES])) _ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES]))
@ -49,8 +49,11 @@ class QERequestListModel(QAbstractListModel):
item['timestamp'] = format_time(timestamp) item['timestamp'] = format_time(timestamp)
item['amount'] = req.get_amount_sat() item['amount'] = req.get_amount_sat()
item['message'] = req.message item['message'] = req.message
if req.type == 0: # OnchainInvoice
#amount_str = self.parent.format_amount(amount) if amount else "" item['key'] = item['address'] = req.get_address()
elif req.type == 2: # LNInvoice
#item['key'] = req.getrhash()
pass
return item return item
@ -74,3 +77,13 @@ class QERequestListModel(QAbstractListModel):
self.beginInsertRows(QModelIndex(), 0, 0) self.beginInsertRows(QModelIndex(), 0, 0)
self.requests.insert(0, item) self.requests.insert(0, item)
self.endInsertRows() self.endInsertRows()
def delete_request(self, key: str):
i = 0
for request in self.requests:
if request['key'] == key:
self.beginRemoveRows(QModelIndex(), i, i)
self.requests.pop(i)
self.endRemoveRows()
break
i = i + 1

7
electrum/gui/qml/qewallet.py

@ -164,7 +164,7 @@ class QEWallet(QObject):
@pyqtSlot(int, 'QString', int) @pyqtSlot(int, 'QString', int)
@pyqtSlot(int, 'QString', int, bool) @pyqtSlot(int, 'QString', int, bool)
@pyqtSlot(int, 'QString', int, bool, bool) @pyqtSlot(int, 'QString', int, bool, bool)
def create_invoice(self, amount: int, message: str, expiration: int, is_lightning: bool = False, ignore_gap: bool = False): def create_request(self, amount: int, message: str, expiration: int, is_lightning: bool = False, ignore_gap: bool = False):
expiry = expiration #TODO: self.config.get('request_expiry', PR_DEFAULT_EXPIRATION_WHEN_CREATING) expiry = expiration #TODO: self.config.get('request_expiry', PR_DEFAULT_EXPIRATION_WHEN_CREATING)
try: try:
if is_lightning: if is_lightning:
@ -190,3 +190,8 @@ class QEWallet(QObject):
#content = r.invoice if r.is_lightning() else r.get_address() #content = r.invoice if r.is_lightning() else r.get_address()
#title = _('Invoice') if is_lightning else _('Address') #title = _('Invoice') if is_lightning else _('Address')
#self.do_copy(content, title=title) #self.do_copy(content, title=title)
@pyqtSlot('QString')
def delete_request(self, key: str):
self.wallet.delete_request(key)
self._requestModel.delete_request(key)

Loading…
Cancel
Save