1
0

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.
This commit is contained in:
ThomasV
2023-03-18 16:46:20 +01:00
parent dd2dced296
commit d7c5c40c1d
2 changed files with 19 additions and 4 deletions

View File

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

View File

@@ -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