payment_identifier: fix _on_finalize params, fix lnurlp send comment instead of description,
refactor payment_identifier.get_invoice to standalone invoice_from_payment_identifier
This commit is contained in:
@@ -17,7 +17,8 @@ from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates, parse_max_spend
|
||||
from electrum.invoices import PR_PAID, Invoice, PR_BROADCASTING, PR_BROADCAST
|
||||
from electrum.transaction import Transaction, PartialTxInput, PartialTxOutput
|
||||
from electrum.network import TxBroadcastError, BestEffortRequestFailed
|
||||
from electrum.payment_identifier import PaymentIdentifierState, PaymentIdentifierType, PaymentIdentifier
|
||||
from electrum.payment_identifier import PaymentIdentifierState, PaymentIdentifierType, PaymentIdentifier, \
|
||||
invoice_from_payment_identifier
|
||||
|
||||
from .amountedit import AmountEdit, BTCAmountEdit, SizedFreezableLineEdit
|
||||
from .paytoedit import InvalidPaymentIdentifier
|
||||
@@ -25,6 +26,7 @@ from .util import (WaitingDialog, HelpLabel, MessageBoxMixin, EnterButton,
|
||||
char_width_in_lineedit, get_iconname_camera, get_iconname_qrcode,
|
||||
read_QIcon, ColorScheme, icon_path)
|
||||
from .confirm_tx_dialog import ConfirmTxDialog
|
||||
from .invoice_list import InvoiceList
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .main_window import ElectrumWindow
|
||||
@@ -161,7 +163,6 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
self.fiat_send_e.textEdited.connect(reset_max)
|
||||
|
||||
self.invoices_label = QLabel(_('Invoices'))
|
||||
from .invoice_list import InvoiceList
|
||||
self.invoice_list = InvoiceList(self)
|
||||
self.toolbar, menu = self.invoice_list.create_toolbar_with_menu('')
|
||||
|
||||
@@ -469,7 +470,8 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
self.show_error(_('No amount'))
|
||||
return
|
||||
|
||||
invoice = self.payto_e.payment_identifier.get_invoice(amount_sat, self.get_message())
|
||||
invoice = invoice_from_payment_identifier(
|
||||
self.payto_e.payment_identifier, self.wallet, amount_sat, self.get_message())
|
||||
if not invoice:
|
||||
self.show_error('error getting invoice' + self.payto_e.payment_identifier.error)
|
||||
return
|
||||
@@ -517,7 +519,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
pi = self.payto_e.payment_identifier
|
||||
if pi.need_finalize():
|
||||
self.prepare_for_send_tab_network_lookup()
|
||||
pi.finalize(amount_sat=self.get_amount(), comment=self.message_e.text(),
|
||||
pi.finalize(amount_sat=self.get_amount(), comment=self.comment_e.text(),
|
||||
on_finished=self.finalize_done_signal.emit)
|
||||
return
|
||||
self.pending_invoice = self.read_invoice()
|
||||
|
||||
@@ -370,7 +370,7 @@ class PaymentIdentifier(Logger):
|
||||
on_finished: Callable[['PaymentIdentifier'], None] = None,
|
||||
):
|
||||
assert self._state == PaymentIdentifierState.LNURLP_FINALIZE
|
||||
coro = self._do_finalize(amount_sat, comment, on_finished=on_finished)
|
||||
coro = self._do_finalize(amount_sat=amount_sat, comment=comment, on_finished=on_finished)
|
||||
asyncio.run_coroutine_threadsafe(coro, get_asyncio_loop())
|
||||
|
||||
@log_exceptions
|
||||
@@ -665,22 +665,28 @@ class PaymentIdentifier(Logger):
|
||||
return bool(expires) and expires < time.time()
|
||||
return False
|
||||
|
||||
def get_invoice(self, amount_sat, message):
|
||||
# FIXME: this should not be a PI method
|
||||
# ideally, PI should not have a reference to wallet.
|
||||
if self.is_lightning():
|
||||
invoice = self.bolt11
|
||||
if not invoice:
|
||||
return
|
||||
if invoice.amount_msat is None:
|
||||
invoice.amount_msat = int(amount_sat * 1000)
|
||||
return invoice
|
||||
else:
|
||||
outputs = self.get_onchain_outputs(amount_sat)
|
||||
message = self.bip21.get('message') if self.bip21 else message
|
||||
bip70_data = self.bip70_data if self.bip70 else None
|
||||
return self.wallet.create_invoice(
|
||||
outputs=outputs,
|
||||
message=message,
|
||||
pr=bip70_data,
|
||||
URI=self.bip21)
|
||||
|
||||
def invoice_from_payment_identifier(
|
||||
pi: 'PaymentIdentifier',
|
||||
wallet: 'Abstract_Wallet',
|
||||
amount_sat: int,
|
||||
message: str = None
|
||||
):
|
||||
# FIXME: this should not be a PI method
|
||||
# ideally, PI should not have a reference to wallet.
|
||||
if pi.is_lightning():
|
||||
invoice = pi.bolt11
|
||||
if not invoice:
|
||||
return
|
||||
if invoice.amount_msat is None:
|
||||
invoice.amount_msat = int(amount_sat * 1000)
|
||||
return invoice
|
||||
else:
|
||||
outputs = pi.get_onchain_outputs(amount_sat)
|
||||
message = pi.bip21.get('message') if pi.bip21 else message
|
||||
bip70_data = self.bip70_data if self.bip70 else None
|
||||
return wallet.create_invoice(
|
||||
outputs=outputs,
|
||||
message=message,
|
||||
pr=bip70_data,
|
||||
URI=pi.bip21)
|
||||
|
||||
Reference in New Issue
Block a user