Skip to content

Commit

Permalink
Qt: allow to save invoices that have no amount
Browse files Browse the repository at this point in the history
(such invoices are already saved by the QML GUI.)
  • Loading branch information
ecdsa committed Mar 19, 2023
1 parent 5ab3a25 commit c3e52bf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion electrum/gui/qt/invoice_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ def create_menu(self, position):
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:
Expand Down
4 changes: 1 addition & 3 deletions electrum/gui/qt/paytoedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ def get_outputs(self, is_max: bool) -> List[PartialTxOutput]:
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[:]
Expand Down
12 changes: 9 additions & 3 deletions electrum/gui/qt/send_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,6 @@ def read_invoice(self) -> Optional[Invoice]:
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
Expand Down Expand Up @@ -582,7 +579,16 @@ def pay_multiple_invoices(self, invoices):
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:
Expand Down
3 changes: 2 additions & 1 deletion electrum/invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def get_amount_sat(self) -> Union[int, str, None]:
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)
Expand Down

0 comments on commit c3e52bf

Please sign in to comment.