1
0

qml: allow user to delete invoices and requests from the list screen

also, delete expired requests before loading list
This commit is contained in:
ThomasV
2023-03-31 07:56:10 +02:00
parent d4aeeaf541
commit 986955a6e8
4 changed files with 71 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ import "controls"
Pane {
id: root
property string selected_key
ColumnLayout {
anchors.fill: parent
@@ -39,7 +40,11 @@ Pane {
dialog.invoiceAmountChanged.connect(function () {
Daemon.currentWallet.invoiceModel.init_model()
})
selected_key = ''
}
onPressAndHold: {
selected_key = model.key
}
}
}
@@ -65,5 +70,33 @@ Pane {
ScrollIndicator.vertical: ScrollIndicator { }
}
}
ButtonContainer {
Layout.fillWidth: true
FlatButton {
Layout.fillWidth: true
Layout.preferredWidth: 1
text: qsTr('Delete')
icon.source: '../../icons/delete.png'
visible: selected_key != ''
onClicked: {
Daemon.currentWallet.delete_invoice(selected_key)
selected_key = ''
}
}
FlatButton {
Layout.fillWidth: true
Layout.preferredWidth: 1
text: qsTr('View')
icon.source: '../../icons/tab_receive.png'
visible: selected_key != ''
onClicked: {
var dialog = app.stack.getRoot().openInvoice(selected_key)
dialog.invoiceAmountChanged.connect(function () {
Daemon.currentWallet.invoiceModel.init_model()
})
selected_key = ''
}
}
}
}
}

View File

@@ -12,6 +12,7 @@ import "controls"
Pane {
id: root
objectName: 'ReceiveRequests'
property string selected_key
ColumnLayout {
anchors.fill: parent
@@ -38,14 +39,14 @@ Pane {
model: Daemon.currentWallet.requestModel
delegate: InvoiceDelegate {
onClicked: {
// TODO: only open unpaid?
if (model.status == Invoice.Unpaid) {
app.stack.getRoot().openRequest(model.key)
}
app.stack.getRoot().openRequest(model.key)
selected_key = ''
}
onPressAndHold: {
selected_key = model.key
}
}
}
add: Transition {
NumberAnimation { properties: 'scale'; from: 0.75; to: 1; duration: 500 }
NumberAnimation { properties: 'opacity'; from: 0; to: 1; duration: 500 }
@@ -68,5 +69,30 @@ Pane {
ScrollIndicator.vertical: ScrollIndicator { }
}
}
ButtonContainer {
Layout.fillWidth: true
FlatButton {
Layout.fillWidth: true
Layout.preferredWidth: 1
text: qsTr('Delete')
icon.source: '../../icons/delete.png'
visible: selected_key != ''
onClicked: {
Daemon.currentWallet.delete_request(selected_key)
selected_key = ''
}
}
FlatButton {
Layout.fillWidth: true
Layout.preferredWidth: 1
text: qsTr('View')
icon.source: '../../icons/tab_receive.png'
visible: selected_key != ''
onClicked: {
app.stack.getRoot().openRequest(selected_key)
selected_key = ''
}
}
}
}
}

View File

@@ -192,6 +192,7 @@ Item {
dialog.open()
}
onPressAndHold: {
Daemon.currentWallet.delete_expired_requests()
app.stack.push(Qt.resolvedUrl('ReceiveRequests.qml'))
}
}

View File

@@ -608,17 +608,18 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
threading.Thread(target=pay_thread, daemon=True).start()
@pyqtSlot()
def delete_expired_requests(self):
keys = self.wallet.delete_expired_requests()
for key in keys:
self.requestModel.delete_invoice(key)
@pyqtSlot(QEAmount, str, int)
@pyqtSlot(QEAmount, str, int, bool)
@pyqtSlot(QEAmount, str, int, bool, bool)
@pyqtSlot(QEAmount, str, int, bool, bool, bool)
def createRequest(self, amount: QEAmount, message: str, expiration: int, lightning_only: bool = False, reuse_address: bool = False):
# delete expired_requests
keys = self.wallet.delete_expired_requests()
for key in keys:
self.requestModel.delete_invoice(key)
self.delete_expired_requests()
try:
amount = amount.satsInt
addr = self.wallet.get_unused_address()