qml: handle invoice validation errors on save
This commit is contained in:
@@ -470,9 +470,10 @@ ElDialog {
|
|||||||
if (amountMax.checked)
|
if (amountMax.checked)
|
||||||
invoice.amountOverride.isMax = true
|
invoice.amountOverride.isMax = true
|
||||||
}
|
}
|
||||||
invoice.saveInvoice()
|
if (invoice.saveInvoice()) {
|
||||||
app.stack.push(Qt.resolvedUrl('Invoices.qml'))
|
app.stack.push(Qt.resolvedUrl('Invoices.qml'))
|
||||||
dialog.close()
|
dialog.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FlatButton {
|
FlatButton {
|
||||||
|
|||||||
@@ -114,7 +114,8 @@ Item {
|
|||||||
var canComplete = !Daemon.currentWallet.isWatchOnly && Daemon.currentWallet.canSignWithoutCosigner
|
var canComplete = !Daemon.currentWallet.isWatchOnly && Daemon.currentWallet.canSignWithoutCosigner
|
||||||
dialog.accepted.connect(function() {
|
dialog.accepted.connect(function() {
|
||||||
if (invoice.canSave)
|
if (invoice.canSave)
|
||||||
invoice.saveInvoice()
|
if (!invoice.saveInvoice())
|
||||||
|
return
|
||||||
if (!canComplete) {
|
if (!canComplete) {
|
||||||
if (Daemon.currentWallet.isWatchOnly) {
|
if (Daemon.currentWallet.isWatchOnly) {
|
||||||
dialog.finalizer.saveOrShow()
|
dialog.finalizer.saveOrShow()
|
||||||
@@ -413,7 +414,11 @@ Item {
|
|||||||
dialog.open()
|
dialog.open()
|
||||||
}
|
}
|
||||||
onInvoiceCreateError: (code, message) => {
|
onInvoiceCreateError: (code, message) => {
|
||||||
console.log(code + ' ' + message)
|
var msg = qsTr('Cannot save invoice') + ': ' + message
|
||||||
|
var dialog = app.messageDialog.createObject(app, {
|
||||||
|
text: msg
|
||||||
|
})
|
||||||
|
dialog.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
onLnurlRetrieved: {
|
onLnurlRetrieved: {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from .qetypes import QEAmount
|
|||||||
from .qewallet import QEWallet
|
from .qewallet import QEWallet
|
||||||
from .util import status_update_timer_interval, QtEventListener, event_listener
|
from .util import status_update_timer_interval, QtEventListener, event_listener
|
||||||
from ...fee_policy import FeePolicy
|
from ...fee_policy import FeePolicy
|
||||||
|
from ...util import InvoiceError
|
||||||
|
|
||||||
|
|
||||||
class QEInvoice(QObject, QtEventListener):
|
class QEInvoice(QObject, QtEventListener):
|
||||||
@@ -690,18 +691,22 @@ class QEInvoiceParser(QEInvoice):
|
|||||||
|
|
||||||
self.recipient = invoice.lightning_invoice
|
self.recipient = invoice.lightning_invoice
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot(result=bool)
|
||||||
def saveInvoice(self):
|
def saveInvoice(self) -> bool:
|
||||||
if not self._effectiveInvoice:
|
if not self._effectiveInvoice:
|
||||||
return
|
return False
|
||||||
if self.isSaved:
|
if self.isSaved:
|
||||||
return
|
return False
|
||||||
|
|
||||||
if not self._effectiveInvoice.amount_msat and not self.amountOverride.isEmpty:
|
try:
|
||||||
if self.invoiceType == QEInvoice.Type.OnchainInvoice and self.amountOverride.isMax:
|
if not self._effectiveInvoice.amount_msat and not self.amountOverride.isEmpty:
|
||||||
self._effectiveInvoice.set_amount_msat('!')
|
if self.invoiceType == QEInvoice.Type.OnchainInvoice and self.amountOverride.isMax:
|
||||||
else:
|
self._effectiveInvoice.set_amount_msat('!')
|
||||||
self._effectiveInvoice.set_amount_msat(self.amountOverride.satsInt * 1000)
|
else:
|
||||||
|
self._effectiveInvoice.set_amount_msat(self.amountOverride.satsInt * 1000)
|
||||||
|
except InvoiceError as e:
|
||||||
|
self.invoiceCreateError.emit('validation', str(e))
|
||||||
|
return False
|
||||||
|
|
||||||
self.canSave = False
|
self.canSave = False
|
||||||
|
|
||||||
@@ -709,3 +714,5 @@ class QEInvoiceParser(QEInvoice):
|
|||||||
self._key = self._effectiveInvoice.get_id()
|
self._key = self._effectiveInvoice.get_id()
|
||||||
self._wallet.invoiceModel.addInvoice(self._key)
|
self._wallet.invoiceModel.addInvoice(self._key)
|
||||||
self.invoiceSaved.emit(self._key)
|
self.invoiceSaved.emit(self._key)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user