qml: add lnurl-pay comment feature
This commit is contained in:
@@ -11,10 +11,9 @@ ElDialog {
|
|||||||
id: dialog
|
id: dialog
|
||||||
|
|
||||||
title: qsTr('LNURL Payment request')
|
title: qsTr('LNURL Payment request')
|
||||||
|
iconSource: '../../../icons/link.png'
|
||||||
|
|
||||||
// property var lnurlData
|
|
||||||
property InvoiceParser invoiceParser
|
property InvoiceParser invoiceParser
|
||||||
// property alias lnurlData: dialog.invoiceParser.lnurlData
|
|
||||||
|
|
||||||
standardButtons: Dialog.Cancel
|
standardButtons: Dialog.Cancel
|
||||||
|
|
||||||
@@ -26,24 +25,30 @@ ElDialog {
|
|||||||
|
|
||||||
GridLayout {
|
GridLayout {
|
||||||
columns: 2
|
columns: 2
|
||||||
implicitWidth: parent.width
|
|
||||||
|
width: parent.width
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: qsTr('Provider')
|
text: qsTr('Provider')
|
||||||
|
color: Material.accentColor
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: invoiceParser.lnurlData['domain']
|
text: invoiceParser.lnurlData['domain']
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: qsTr('Description')
|
text: qsTr('Description')
|
||||||
|
color: Material.accentColor
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: invoiceParser.lnurlData['metadata_plaintext']
|
text: invoiceParser.lnurlData['metadata_plaintext']
|
||||||
|
Layout.fillWidth: true
|
||||||
|
wrapMode: Text.Wrap
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: invoiceParser.lnurlData['min_sendable_sat'] == invoiceParser.lnurlData['max_sendable_sat']
|
text: invoiceParser.lnurlData['min_sendable_sat'] == invoiceParser.lnurlData['max_sendable_sat']
|
||||||
? qsTr('Amount')
|
? qsTr('Amount')
|
||||||
: qsTr('Amount range')
|
: qsTr('Amount range')
|
||||||
|
color: Material.accentColor
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: invoiceParser.lnurlData['min_sendable_sat'] == invoiceParser.lnurlData['max_sendable_sat']
|
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']
|
: 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 {
|
Button {
|
||||||
Layout.columnSpan: 2
|
Layout.columnSpan: 2
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
text: qsTr('Proceed')
|
text: qsTr('Proceed')
|
||||||
onClicked: {
|
onClicked: {
|
||||||
invoiceParser.lnurlGetInvoice(invoiceParser.lnurlData['min_sendable_sat'])
|
invoiceParser.lnurlGetInvoice(invoiceParser.lnurlData['min_sendable_sat'], comment.text)
|
||||||
dialog.close()
|
dialog.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -450,21 +450,27 @@ class QEInvoiceParser(QEInvoice):
|
|||||||
'callback_url' : lnurldata.callback_url,
|
'callback_url' : lnurldata.callback_url,
|
||||||
'min_sendable_sat': lnurldata.min_sendable_sat,
|
'min_sendable_sat': lnurldata.min_sendable_sat,
|
||||||
'max_sendable_sat': lnurldata.max_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.setValidLNURLPayRequest()
|
||||||
self.lnurlRetrieved.emit()
|
self.lnurlRetrieved.emit()
|
||||||
|
|
||||||
@pyqtSlot('quint64')
|
@pyqtSlot('quint64')
|
||||||
def lnurlGetInvoice(self, amount):
|
@pyqtSlot('quint64', str)
|
||||||
|
def lnurlGetInvoice(self, amount, comment=None):
|
||||||
assert self._lnurlData
|
assert self._lnurlData
|
||||||
|
|
||||||
|
if self._lnurlData['comment_allowed'] == 0:
|
||||||
|
comment = None
|
||||||
|
|
||||||
self._logger.debug(f'fetching callback url {self._lnurlData["callback_url"]}')
|
self._logger.debug(f'fetching callback url {self._lnurlData["callback_url"]}')
|
||||||
def fetch_invoice_task():
|
def fetch_invoice_task():
|
||||||
try:
|
try:
|
||||||
coro = callback_lnurl(self._lnurlData['callback_url'], {
|
params = { 'amount': amount * 1000 }
|
||||||
'amount': amount * 1000 # msats
|
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)
|
fut = asyncio.run_coroutine_threadsafe(coro, self._wallet.wallet.network.asyncio_loop)
|
||||||
self.on_lnurl_invoice(fut.result())
|
self.on_lnurl_invoice(fut.result())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user