Browse Source

change address-only handling: create amount=0 onchain invoice

invoicedialog auto enables edit mode when amount is 0
patch-4
Sander van Grieken 2 years ago
parent
commit
d65a7e7efc
  1. 2
      electrum/gui/qml/components/InvoiceDialog.qml
  2. 16
      electrum/gui/qml/components/WalletMainView.qml
  3. 20
      electrum/gui/qml/qeinvoice.py

2
electrum/gui/qml/components/InvoiceDialog.qml

@ -325,5 +325,7 @@ ElDialog {
if (invoice_key != '') { if (invoice_key != '') {
invoice.initFromKey(invoice_key) invoice.initFromKey(invoice_key)
} }
if (invoice.amount.satsInt == 0)
amountContainer.editmode = true
} }
} }

16
electrum/gui/qml/components/WalletMainView.qml

@ -142,7 +142,7 @@ Item {
id: invoiceParser id: invoiceParser
wallet: Daemon.currentWallet wallet: Daemon.currentWallet
onValidationError: { onValidationError: {
var dialog = app.messageDialog.createObject(app, {'text': message }) var dialog = app.messageDialog.createObject(app, { text: message })
dialog.closed.connect(function() { dialog.closed.connect(function() {
_sendDialog.restart() _sendDialog.restart()
}) })
@ -150,7 +150,7 @@ Item {
} }
onValidationWarning: { onValidationWarning: {
if (code == 'no_channels') { if (code == 'no_channels') {
var dialog = app.messageDialog.createObject(app, {'text': message }) var dialog = app.messageDialog.createObject(app, { text: message })
dialog.open() dialog.open()
// TODO: ask user to open a channel, if funds allow // TODO: ask user to open a channel, if funds allow
// and maybe store invoice if expiry allows // and maybe store invoice if expiry allows
@ -158,16 +158,8 @@ Item {
} }
onValidationSuccess: { onValidationSuccess: {
_sendDialog.close() _sendDialog.close()
// address only -> fill form fields and clear this instance var dialog = invoiceDialog.createObject(app, { invoice: invoiceParser })
// else -> show invoice confirmation dialog dialog.open()
if (invoiceType == Invoice.OnchainOnlyAddress) {
recipient.text = invoice.recipient
invoiceParser.clear()
} else {
var dialog = invoiceDialog.createObject(app, {'invoice': invoiceParser})
// dialog.invoice = invoiceParser
dialog.open()
}
} }
onInvoiceCreateError: console.log(code + ' ' + message) onInvoiceCreateError: console.log(code + ' ' + message)

20
electrum/gui/qml/qeinvoice.py

@ -288,11 +288,11 @@ class QEInvoiceParser(QEInvoice):
def get_max_spendable_lightning(self): def get_max_spendable_lightning(self):
return self._wallet.wallet.lnworker.num_sats_can_send() return self._wallet.wallet.lnworker.num_sats_can_send()
def setValidAddressOnly(self): # def setValidAddressOnly(self):
self._logger.debug('setValidAddressOnly') # self._logger.debug('setValidAddressOnly')
self.setInvoiceType(QEInvoice.Type.OnchainOnlyAddress) # self.setInvoiceType(QEInvoice.Type.OnchainOnlyAddress)
self._effectiveInvoice = None # self._effectiveInvoice = None
self.invoiceChanged.emit() # self.invoiceChanged.emit()
def setValidOnchainInvoice(self, invoice: Invoice): def setValidOnchainInvoice(self, invoice: Invoice):
self._logger.debug('setValidOnchainInvoice') self._logger.debug('setValidOnchainInvoice')
@ -335,7 +335,11 @@ class QEInvoiceParser(QEInvoice):
return return
if ':' not in recipient: if ':' not in recipient:
# address only # address only
self.setValidAddressOnly() # create bare invoice
outputs = [PartialTxOutput.from_address_and_value(self._bip21['address'], 0)]
invoice = self.create_onchain_invoice(outputs, None, None, None)
self._logger.debug(repr(invoice))
self.setValidOnchainInvoice(invoice)
self.validationSuccess.emit() self.validationSuccess.emit()
return return
else: else:
@ -387,9 +391,7 @@ class QEInvoiceParser(QEInvoice):
self.validationSuccess.emit() self.validationSuccess.emit()
else: else:
self._logger.debug('flow without LN but having bip21 uri') self._logger.debug('flow without LN but having bip21 uri')
if 'amount' not in self._bip21: #TODO can we have amount-less invoices? if 'amount' not in self._bip21:
# self.validationError.emit('no_amount', 'no amount in uri')
# return
amount = 0 amount = 0
else: else:
amount = self._bip21['amount'] amount = self._bip21['amount']

Loading…
Cancel
Save