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