Browse Source

qml: disable pay button while editing amount, perform minimum amount check for lightning invoices, update amount in invoice list.

patch-4
Sander van Grieken 2 years ago
parent
commit
3ace53391f
  1. 27
      electrum/gui/qml/components/InvoiceDialog.qml
  2. 7
      electrum/gui/qml/components/Invoices.qml
  3. 8
      electrum/gui/qml/components/LightningPaymentProgressDialog.qml
  4. 8
      electrum/gui/qml/qeinvoice.py

27
electrum/gui/qml/components/InvoiceDialog.qml

@ -14,6 +14,7 @@ ElDialog {
property string invoice_key
signal doPay
signal invoiceAmountChanged
title: qsTr('Invoice')
standardButtons: invoice_key != '' ? Dialog.Close : Dialog.Cancel
@ -121,6 +122,29 @@ ElDialog {
}
}
Label {
visible: invoice.invoiceType == Invoice.LightningInvoice
text: qsTr('Payment hash')
color: Material.accentColor
}
TextHighlightPane {
visible: invoice.invoiceType == Invoice.LightningInvoice
Layout.columnSpan: 2
Layout.fillWidth: true
padding: 0
leftPadding: constants.paddingMedium
Label {
width: parent.width
text: 'payment_hash' in invoice.lnprops ? invoice.lnprops.payment_hash : ''
font.family: FixedFont
wrapMode: Text.Wrap
}
}
Label {
text: qsTr('Description')
visible: invoice.message
@ -278,6 +302,7 @@ ElDialog {
onClicked: {
amountContainer.editmode = false
invoice.amount = amountMax.checked ? MAX : Config.unitsToSats(amountBtc.text)
invoiceAmountChanged()
}
}
ToolButton {
@ -308,7 +333,7 @@ ElDialog {
Layout.fillWidth: true
text: qsTr('Pay')
icon.source: '../../icons/confirmed.png'
enabled: invoice.invoiceType != Invoice.Invalid && invoice.canPay
enabled: invoice.invoiceType != Invoice.Invalid && invoice.canPay && !amountContainer.editmode
onClicked: {
if (invoice_key == '') // save invoice if not retrieved from key
invoice.save_invoice()

7
electrum/gui/qml/components/Invoices.qml

@ -42,7 +42,12 @@ Pane {
id: delegateModel
model: Daemon.currentWallet.invoiceModel
delegate: InvoiceDelegate {
onClicked: app.stack.getRoot().openInvoice(model.key)
onClicked: {
var dialog = app.stack.getRoot().openInvoice(model.key)
dialog.invoiceAmountChanged.connect(function () {
Daemon.currentWallet.invoiceModel.init_model()
})
}
}
}

8
electrum/gui/qml/components/LightningPaymentProgressDialog.qml

@ -70,6 +70,7 @@ ElDialog {
ColumnLayout {
id: content
anchors.centerIn: parent
width: parent.width
Item {
Layout.alignment: Qt.AlignHCenter
@ -92,15 +93,18 @@ ElDialog {
Label {
id: helpText
Layout.alignment: Qt.AlignHCenter
text: qsTr('Paying...')
font.pixelSize: constants.fontSizeXXLarge
Layout.alignment: Qt.AlignHCenter
}
Label {
id: errorText
font.pixelSize: constants.fontSizeLarge
Layout.preferredWidth: parent.width
Layout.alignment: Qt.AlignHCenter
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap
font.pixelSize: constants.fontSizeLarge
}
}

8
electrum/gui/qml/qeinvoice.py

@ -16,6 +16,7 @@ from electrum.transaction import PartialTxOutput
from electrum.util import (parse_URI, InvalidBitcoinURI, InvoiceError,
maybe_extract_lightning_payment_identifier)
from electrum.lnurl import decode_lnurl, request_lnurl, callback_lnurl
from electrum.bitcoin import COIN
from .qetypes import QEAmount
from .qewallet import QEWallet
@ -226,6 +227,7 @@ class QEInvoiceParser(QEInvoice):
self._logger.debug(str(lnaddr.get_routing_info('t')))
return {
'pubkey': lnaddr.pubkey.serialize().hex(),
'payment_hash': lnaddr.paymenthash.hex(),
't': '', #lnaddr.get_routing_info('t')[0][0].hex(),
'r': '' #lnaddr.get_routing_info('r')[0][0][0].hex()
}
@ -277,7 +279,11 @@ class QEInvoiceParser(QEInvoice):
if self.invoiceType == QEInvoice.Type.LightningInvoice:
if self.status in [PR_UNPAID, PR_FAILED]:
if self.get_max_spendable_lightning() >= self.amount.satsInt:
self.canPay = True
lnaddr = self._effectiveInvoice._lnaddr
if self.amount.satsInt < lnaddr.amount * COIN:
self.userinfo = _('Cannot pay less than the amount specified in the invoice')
else:
self.canPay = True
else:
self.userinfo = _('Insufficient balance')
else:

Loading…
Cancel
Save