Qt: allow to save invoices that have no amount
(such invoices are already saved by the QML GUI.)
This commit is contained in:
@@ -179,7 +179,10 @@ class InvoiceList(MyTreeView):
|
||||
copy_menu.addAction(_("Address"), lambda: self.main_window.do_copy(invoice.get_address(), title='Bitcoin Address'))
|
||||
status = wallet.get_invoice_status(invoice)
|
||||
if status == PR_UNPAID:
|
||||
menu.addAction(_("Pay") + "...", lambda: self.send_tab.do_pay_invoice(invoice))
|
||||
if bool(invoice.get_amount_sat()):
|
||||
menu.addAction(_("Pay") + "...", lambda: self.send_tab.do_pay_invoice(invoice))
|
||||
else:
|
||||
menu.addAction(_("Edit amount") + "...", lambda: self.send_tab.do_edit_invoice(invoice))
|
||||
if status == PR_FAILED:
|
||||
menu.addAction(_("Retry"), lambda: self.send_tab.do_pay_invoice(invoice))
|
||||
if self.wallet.lnworker:
|
||||
|
||||
@@ -364,9 +364,7 @@ class PayToEdit(Logger, GenericInputHandler):
|
||||
if is_max:
|
||||
amount = '!'
|
||||
else:
|
||||
amount = self.amount_edit.get_amount()
|
||||
if amount is None:
|
||||
return []
|
||||
amount = self.amount_edit.get_amount() or 0
|
||||
self.outputs = [PartialTxOutput(scriptpubkey=self.payto_scriptpubkey, value=amount)]
|
||||
|
||||
return self.outputs[:]
|
||||
|
||||
@@ -500,9 +500,6 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
amount_sat = self.amount_e.get_amount()
|
||||
if amount_sat:
|
||||
invoice.amount_msat = int(amount_sat * 1000)
|
||||
else:
|
||||
self.show_error(_('No amount'))
|
||||
return
|
||||
if not self.wallet.has_lightning() and not invoice.can_be_paid_onchain():
|
||||
self.show_error(_('Lightning is disabled'))
|
||||
return
|
||||
@@ -582,7 +579,16 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
outputs += invoice.outputs
|
||||
self.pay_onchain_dialog(outputs)
|
||||
|
||||
def do_edit_invoice(self, invoice: 'Invoice'):
|
||||
assert not bool(invoice.get_amount_sat())
|
||||
text = invoice.lightning_invoice if invoice.is_lightning() else invoice.get_address()
|
||||
self.payto_e._on_input_btn(text)
|
||||
self.amount_e.setFocus()
|
||||
|
||||
def do_pay_invoice(self, invoice: 'Invoice'):
|
||||
if not bool(invoice.get_amount_sat()):
|
||||
self.show_error(_('No amount'))
|
||||
return
|
||||
if invoice.is_lightning():
|
||||
self.pay_lightning_invoice(invoice)
|
||||
else:
|
||||
|
||||
@@ -161,7 +161,8 @@ class BaseInvoice(StoredObject):
|
||||
Returns an integer satoshi amount, or '!' or None.
|
||||
Callers who need msat precision should call get_amount_msat()
|
||||
"""
|
||||
amount_msat = self.amount_msat
|
||||
# return strictly positive value or None
|
||||
amount_msat = self.amount_msat or None
|
||||
if amount_msat in [None, "!"]:
|
||||
return amount_msat
|
||||
return int(amount_msat // 1000)
|
||||
|
||||
Reference in New Issue
Block a user