From d65a7e7efcc868578b6b1c6ea16ea2ba4b52992c Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 27 Sep 2022 17:10:05 +0200 Subject: [PATCH] change address-only handling: create amount=0 onchain invoice invoicedialog auto enables edit mode when amount is 0 --- electrum/gui/qml/components/InvoiceDialog.qml | 2 ++ .../gui/qml/components/WalletMainView.qml | 16 ++++----------- electrum/gui/qml/qeinvoice.py | 20 ++++++++++--------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/electrum/gui/qml/components/InvoiceDialog.qml b/electrum/gui/qml/components/InvoiceDialog.qml index 3509b569e..bdda90aa2 100644 --- a/electrum/gui/qml/components/InvoiceDialog.qml +++ b/electrum/gui/qml/components/InvoiceDialog.qml @@ -325,5 +325,7 @@ ElDialog { if (invoice_key != '') { invoice.initFromKey(invoice_key) } + if (invoice.amount.satsInt == 0) + amountContainer.editmode = true } } diff --git a/electrum/gui/qml/components/WalletMainView.qml b/electrum/gui/qml/components/WalletMainView.qml index c21fb7838..658ec6a73 100644 --- a/electrum/gui/qml/components/WalletMainView.qml +++ b/electrum/gui/qml/components/WalletMainView.qml @@ -142,7 +142,7 @@ Item { id: invoiceParser wallet: Daemon.currentWallet onValidationError: { - var dialog = app.messageDialog.createObject(app, {'text': message }) + var dialog = app.messageDialog.createObject(app, { text: message }) dialog.closed.connect(function() { _sendDialog.restart() }) @@ -150,7 +150,7 @@ Item { } onValidationWarning: { if (code == 'no_channels') { - var dialog = app.messageDialog.createObject(app, {'text': message }) + var dialog = app.messageDialog.createObject(app, { text: message }) dialog.open() // TODO: ask user to open a channel, if funds allow // and maybe store invoice if expiry allows @@ -158,16 +158,8 @@ Item { } onValidationSuccess: { _sendDialog.close() - // address only -> fill form fields and clear this instance - // else -> show invoice confirmation dialog - if (invoiceType == Invoice.OnchainOnlyAddress) { - recipient.text = invoice.recipient - invoiceParser.clear() - } else { - var dialog = invoiceDialog.createObject(app, {'invoice': invoiceParser}) - // dialog.invoice = invoiceParser - dialog.open() - } + var dialog = invoiceDialog.createObject(app, { invoice: invoiceParser }) + dialog.open() } onInvoiceCreateError: console.log(code + ' ' + message) diff --git a/electrum/gui/qml/qeinvoice.py b/electrum/gui/qml/qeinvoice.py index 8abe508cf..b76187743 100644 --- a/electrum/gui/qml/qeinvoice.py +++ b/electrum/gui/qml/qeinvoice.py @@ -288,11 +288,11 @@ class QEInvoiceParser(QEInvoice): def get_max_spendable_lightning(self): return self._wallet.wallet.lnworker.num_sats_can_send() - def setValidAddressOnly(self): - self._logger.debug('setValidAddressOnly') - self.setInvoiceType(QEInvoice.Type.OnchainOnlyAddress) - self._effectiveInvoice = None - self.invoiceChanged.emit() + # def setValidAddressOnly(self): + # self._logger.debug('setValidAddressOnly') + # self.setInvoiceType(QEInvoice.Type.OnchainOnlyAddress) + # self._effectiveInvoice = None + # self.invoiceChanged.emit() def setValidOnchainInvoice(self, invoice: Invoice): self._logger.debug('setValidOnchainInvoice') @@ -335,7 +335,11 @@ class QEInvoiceParser(QEInvoice): return if ':' not in recipient: # address only - self.setValidAddressOnly() + # create bare invoice + outputs = [PartialTxOutput.from_address_and_value(self._bip21['address'], 0)] + invoice = self.create_onchain_invoice(outputs, None, None, None) + self._logger.debug(repr(invoice)) + self.setValidOnchainInvoice(invoice) self.validationSuccess.emit() return else: @@ -387,9 +391,7 @@ class QEInvoiceParser(QEInvoice): self.validationSuccess.emit() else: self._logger.debug('flow without LN but having bip21 uri') - if 'amount' not in self._bip21: #TODO can we have amount-less invoices? - # self.validationError.emit('no_amount', 'no amount in uri') - # return + if 'amount' not in self._bip21: amount = 0 else: amount = self._bip21['amount']