Browse Source

qml: add lnurl-pay comment feature

patch-4
Sander van Grieken 2 years ago
parent
commit
8538bfe49b
  1. 22
      electrum/gui/qml/components/LnurlPayRequestDialog.qml
  2. 16
      electrum/gui/qml/qeinvoice.py

22
electrum/gui/qml/components/LnurlPayRequestDialog.qml

@ -11,10 +11,9 @@ ElDialog {
id: dialog
title: qsTr('LNURL Payment request')
iconSource: '../../../icons/link.png'
// property var lnurlData
property InvoiceParser invoiceParser
// property alias lnurlData: dialog.invoiceParser.lnurlData
standardButtons: Dialog.Cancel
@ -26,24 +25,30 @@ ElDialog {
GridLayout {
columns: 2
implicitWidth: parent.width
width: parent.width
Label {
text: qsTr('Provider')
color: Material.accentColor
}
Label {
text: invoiceParser.lnurlData['domain']
}
Label {
text: qsTr('Description')
color: Material.accentColor
}
Label {
text: invoiceParser.lnurlData['metadata_plaintext']
Layout.fillWidth: true
wrapMode: Text.Wrap
}
Label {
text: invoiceParser.lnurlData['min_sendable_sat'] == invoiceParser.lnurlData['max_sendable_sat']
? qsTr('Amount')
: qsTr('Amount range')
color: Material.accentColor
}
Label {
text: invoiceParser.lnurlData['min_sendable_sat'] == invoiceParser.lnurlData['max_sendable_sat']
@ -53,12 +58,21 @@ ElDialog {
: invoiceParser.lnurlData['min_sendable_sat'] + ' < amount < ' + invoiceParser.lnurlData['max_sendable_sat']
}
TextArea {
id: comment
Layout.columnSpan: 2
Layout.preferredWidth: parent.width
Layout.minimumHeight: 80
wrapMode: TextEdit.Wrap
placeholderText: qsTr('Enter an (optional) message for the receiver')
}
Button {
Layout.columnSpan: 2
Layout.alignment: Qt.AlignHCenter
text: qsTr('Proceed')
onClicked: {
invoiceParser.lnurlGetInvoice(invoiceParser.lnurlData['min_sendable_sat'])
invoiceParser.lnurlGetInvoice(invoiceParser.lnurlData['min_sendable_sat'], comment.text)
dialog.close()
}
}

16
electrum/gui/qml/qeinvoice.py

@ -450,21 +450,27 @@ class QEInvoiceParser(QEInvoice):
'callback_url' : lnurldata.callback_url,
'min_sendable_sat': lnurldata.min_sendable_sat,
'max_sendable_sat': lnurldata.max_sendable_sat,
'metadata_plaintext': lnurldata.metadata_plaintext
'metadata_plaintext': lnurldata.metadata_plaintext,
'comment_allowed': lnurldata.comment_allowed
}
self.setValidLNURLPayRequest()
self.lnurlRetrieved.emit()
@pyqtSlot('quint64')
def lnurlGetInvoice(self, amount):
@pyqtSlot('quint64', str)
def lnurlGetInvoice(self, amount, comment=None):
assert self._lnurlData
if self._lnurlData['comment_allowed'] == 0:
comment = None
self._logger.debug(f'fetching callback url {self._lnurlData["callback_url"]}')
def fetch_invoice_task():
try:
coro = callback_lnurl(self._lnurlData['callback_url'], {
'amount': amount * 1000 # msats
})
params = { 'amount': amount * 1000 }
if comment:
params['comment'] = comment
coro = callback_lnurl(self._lnurlData['callback_url'], params)
fut = asyncio.run_coroutine_threadsafe(coro, self._wallet.wallet.network.asyncio_loop)
self.on_lnurl_invoice(fut.result())
except Exception as e:

Loading…
Cancel
Save