From a8623f63bbc31989dd18f1b57540685a235fb2b1 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sun, 23 Apr 2023 16:42:08 +0000 Subject: [PATCH] qml: fix send "flow with LN but not LN enabled AND having bip21 uri" closes https://github.com/spesmilo/electrum/issues/8334 --- electrum/gui/qml/qeinvoice.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/electrum/gui/qml/qeinvoice.py b/electrum/gui/qml/qeinvoice.py index fbd31db76..3b40ee596 100644 --- a/electrum/gui/qml/qeinvoice.py +++ b/electrum/gui/qml/qeinvoice.py @@ -1,5 +1,5 @@ import threading -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, Optional, Dict, Any import asyncio from urllib.parse import urlparse @@ -552,7 +552,7 @@ class QEInvoiceParser(QEInvoice): self.validationError.emit('no_lightning',_('Detected valid Lightning invoice, but Lightning not enabled for wallet and no fallback address found.')) else: self._logger.debug('flow with LN but not LN enabled AND having bip21 uri') - self.setValidOnchainInvoice(bip21['address']) + self._validateRecipient_bip21_onchain(bip21) else: self.setValidLightningInvoice(lninvoice) if not self._wallet.wallet.lnworker.channels: @@ -561,17 +561,20 @@ class QEInvoiceParser(QEInvoice): self.validationSuccess.emit() else: self._logger.debug('flow without LN but having bip21 uri') - if 'amount' not in bip21: - amount = 0 - else: - amount = bip21['amount'] - outputs = [PartialTxOutput.from_address_and_value(bip21['address'], amount)] - self._logger.debug(outputs) - message = bip21['message'] if 'message' in bip21 else '' - invoice = self.create_onchain_invoice(outputs, message, None, bip21) - self._logger.debug(repr(invoice)) - self.setValidOnchainInvoice(invoice) - self.validationSuccess.emit() + self._validateRecipient_bip21_onchain(bip21) + + def _validateRecipient_bip21_onchain(self, bip21: Dict[str, Any]) -> None: + if 'amount' not in bip21: + amount = 0 + else: + amount = bip21['amount'] + outputs = [PartialTxOutput.from_address_and_value(bip21['address'], amount)] + self._logger.debug(outputs) + message = bip21['message'] if 'message' in bip21 else '' + invoice = self.create_onchain_invoice(outputs, message, None, bip21) + self._logger.debug(repr(invoice)) + self.setValidOnchainInvoice(invoice) + self.validationSuccess.emit() def resolve_lnurl(self, lnurl): self._logger.debug('resolve_lnurl')