Browse Source

qml: move payment progress info text updates fully into qeinvoice, qeinvoice now updates itself

directly from backend wallet callbacks
master
Sander van Grieken 3 years ago
parent
commit
cc60ab0b20
  1. 25
      electrum/gui/qml/components/InvoiceDialog.qml
  2. 29
      electrum/gui/qml/qeinvoice.py

25
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)

29
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

Loading…
Cancel
Save