From d7c5c40c1da4c455d60cac571f10a60130614e3b Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 18 Mar 2023 16:46:20 +0100 Subject: [PATCH] Save user-entered amount in invoice. fixes #8252. Note that this allows users to save invoices that have an empty amount, which is not allowed by the Qt GUI. Qt will complain at pay time about empty amount if a lightning invoice without amount is saved. With onchain invoices, Qt will create an onchain tx with a zero output. --- electrum/gui/qml/components/InvoiceDialog.qml | 15 ++++++++++++++- electrum/gui/qml/qeinvoice.py | 8 +++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/electrum/gui/qml/components/InvoiceDialog.qml b/electrum/gui/qml/components/InvoiceDialog.qml index c559801cc..a240a632a 100644 --- a/electrum/gui/qml/components/InvoiceDialog.qml +++ b/electrum/gui/qml/components/InvoiceDialog.qml @@ -435,6 +435,9 @@ ElDialog { enabled: invoice.canSave onClicked: { app.stack.push(Qt.resolvedUrl('Invoices.qml')) + if (invoice.amount.isEmpty) { + invoice.amount = amountMax.checked ? MAX : Config.unitsToSats(amountBtc.text) + } invoice.save_invoice() dialog.close() } @@ -446,8 +449,18 @@ ElDialog { icon.source: '../../icons/confirmed.png' enabled: invoice.invoiceType != Invoice.Invalid && invoice.canPay onClicked: { - if (invoice_key == '') // save invoice if not retrieved from key + if (invoice.amount.isEmpty) { + invoice.amount = amountMax.checked ? MAX : Config.unitsToSats(amountBtc.text) + if (invoice_key != '') { + // delete the existing invoice because this affects get_id() + invoice.wallet.delete_invoice(invoice_key) + invoice_key = '' + } + } + if (invoice_key == '') { + // save invoice if new or modified invoice.save_invoice() + } dialog.close() doPay() // only signal here } diff --git a/electrum/gui/qml/qeinvoice.py b/electrum/gui/qml/qeinvoice.py index 7188eda36..b60da544e 100644 --- a/electrum/gui/qml/qeinvoice.py +++ b/electrum/gui/qml/qeinvoice.py @@ -313,8 +313,6 @@ class QEInvoiceParser(QEInvoice): self.set_lnprops() - self.canSave = True - self.determine_can_pay() self.invoiceChanged.emit() @@ -339,6 +337,7 @@ class QEInvoiceParser(QEInvoice): def determine_can_pay(self): self.canPay = False + self.canSave = False self.userinfo = '' if not self.amountOverride.isEmpty: @@ -346,6 +345,8 @@ class QEInvoiceParser(QEInvoice): else: amount = self.amount + self.canSave = True + if amount.isEmpty: # unspecified amount return @@ -652,6 +653,8 @@ class QEUserEnteredPayment(QEInvoice): self.validationError.emit('recipient', _('Invalid Bitcoin address')) return + self.canSave = True + if self._amount.isEmpty: self.validationError.emit('amount', _('Invalid amount')) return @@ -659,7 +662,6 @@ class QEUserEnteredPayment(QEInvoice): if self._amount.isMax: self.canPay = True else: - self.canSave = True if self.get_max_spendable_onchain() >= self._amount.satsInt: self.canPay = True