From cc60ab0b206ca6c7ce6e66397ee62ebd0c26296b Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 29 Mar 2023 19:06:35 +0200 Subject: [PATCH] qml: move payment progress info text updates fully into qeinvoice, qeinvoice now updates itself directly from backend wallet callbacks --- electrum/gui/qml/components/InvoiceDialog.qml | 25 ++-------------- electrum/gui/qml/qeinvoice.py | 29 +++++++++++++++++-- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/electrum/gui/qml/components/InvoiceDialog.qml b/electrum/gui/qml/components/InvoiceDialog.qml index 20c944905..adff3ca83 100644 --- a/electrum/gui/qml/components/InvoiceDialog.qml +++ b/electrum/gui/qml/components/InvoiceDialog.qml @@ -53,7 +53,9 @@ ElDialog { Layout.bottomMargin: constants.paddingLarge visible: text text: invoice.userinfo - iconStyle: InfoTextArea.IconStyle.Warn + iconStyle: invoice.status == Invoice.Failed || invoice.status == Invoice.Expired + ? InfoTextArea.IconStyle.Warn + : InfoTextArea.IconStyle.Info } Label { @@ -459,33 +461,12 @@ ElDialog { invoice.save_invoice() } doPay() // only signal here - helpText.text = qsTr('Payment in progress...') } } } } - Connections { - target: Daemon.currentWallet - function onPaymentSucceeded(key) { - if (key != invoice.key) { - console.log('wrong invoice ' + key + ' != ' + invoice.key) - return - } - console.log('payment succeeded!') - helpText.text = qsTr('Paid!') - } - function onPaymentFailed(key, reason) { - if (key != invoice.key) { - console.log('wrong invoice ' + key + ' != ' + invoice.key) - return - } - console.log('payment failed: ' + reason) - helpText.text = qsTr('Payment failed: ' + reason) - } - } - Component.onCompleted: { if (invoice_key != '') { invoice.initFromKey(invoice_key) diff --git a/electrum/gui/qml/qeinvoice.py b/electrum/gui/qml/qeinvoice.py index f887b7d0f..d850fd41c 100644 --- a/electrum/gui/qml/qeinvoice.py +++ b/electrum/gui/qml/qeinvoice.py @@ -23,7 +23,7 @@ from electrum.paymentrequest import PaymentRequest from .qetypes import QEAmount from .qewallet import QEWallet -from .util import status_update_timer_interval +from .util import status_update_timer_interval, QtEventListener, event_listener class QEInvoice(QObject): @@ -120,7 +120,7 @@ class QEInvoice(QObject): def get_max_spendable_lightning(self): return self._wallet.wallet.lnworker.num_sats_can_send() if self._wallet.wallet.lnworker else 0 -class QEInvoiceParser(QEInvoice): +class QEInvoiceParser(QEInvoice, QtEventListener): _logger = get_logger(__name__) invoiceChanged = pyqtSignal() @@ -160,6 +160,31 @@ class QEInvoiceParser(QEInvoice): self.clear() + self.register_callbacks() + self.destroyed.connect(lambda: self.on_destroy()) + + def on_destroy(self): + self.unregister_callbacks() + + @event_listener + def on_event_payment_succeeded(self, wallet, key): + if wallet == self._wallet.wallet and key == self.key: + self.statusChanged.emit() + self.userinfo = _('Paid!') + + @event_listener + def on_event_payment_failed(self, wallet, key, reason): + if wallet == self._wallet.wallet and key == self.key: + self.statusChanged.emit() + self.userinfo = _('Payment failed: ') + reason + + @event_listener + def on_event_invoice_status(self, wallet, key, status): + if wallet == self._wallet.wallet and key == self.key: + self.statusChanged.emit() + if status in [PR_INFLIGHT, PR_ROUTING]: + self.userinfo = _('In progress...') + @pyqtProperty(int, notify=invoiceChanged) def invoiceType(self): return self._invoiceType