Skip to content

Commit 81c83f8

Browse files
committed
qeinvoice: query self.status once in update_userinfo() and determine_can_pay()
1 parent 5cb0902 commit 81c83f8

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

electrum/gui/qml/qeinvoice.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,12 @@ def update_userinfo(self):
310310
if self.amount.isEmpty:
311311
self.userinfo = _('Enter the amount you want to send')
312312

313-
if amount.isEmpty and self.status == PR_UNPAID: # unspecified amount
313+
status = self.status
314+
315+
if amount.isEmpty and status == PR_UNPAID: # unspecified amount
314316
return
315317

316-
def userinfo_for_invoice_status(status: int) -> str:
318+
def userinfo_for_invoice_status(_status: int) -> str:
317319
return {
318320
PR_EXPIRED: _('This invoice has expired'),
319321
PR_PAID: _('This invoice was already paid'),
@@ -323,10 +325,10 @@ def userinfo_for_invoice_status(status: int) -> str:
323325
PR_BROADCAST: _('Payment in progress...') + ' (' + _('broadcast successfully') + ')',
324326
PR_UNCONFIRMED: _('Payment in progress...') + ' (' + _('waiting for confirmation') + ')',
325327
PR_UNKNOWN: _('Invoice has unknown status'),
326-
}[status]
328+
}[_status]
327329

328330
if self.invoiceType == QEInvoice.Type.LightningInvoice:
329-
if self.status in [PR_UNPAID, PR_FAILED]:
331+
if status in [PR_UNPAID, PR_FAILED]:
330332
if self.get_max_spendable_lightning() >= amount.satsInt:
331333
lnaddr = self._effectiveInvoice._lnaddr
332334
if lnaddr.amount and amount.satsInt < lnaddr.amount * COIN:
@@ -335,13 +337,13 @@ def userinfo_for_invoice_status(status: int) -> str:
335337
# TODO: for onchain: validate address? subtract fee?
336338
self.userinfo = _('Insufficient balance')
337339
else:
338-
self.userinfo = userinfo_for_invoice_status(self.status)
340+
self.userinfo = userinfo_for_invoice_status(status)
339341
elif self.invoiceType == QEInvoice.Type.OnchainInvoice:
340-
if self.status in [PR_UNPAID, PR_FAILED]:
342+
if status in [PR_UNPAID, PR_FAILED]:
341343
if not ((amount.isMax and self.get_max_spendable_onchain() > 0) or (self.get_max_spendable_onchain() >= amount.satsInt)):
342344
self.userinfo = _('Insufficient balance')
343345
else:
344-
self.userinfo = userinfo_for_invoice_status(self.status)
346+
self.userinfo = userinfo_for_invoice_status(status)
345347

346348
def determine_can_pay(self):
347349
self.canPay = False
@@ -357,11 +359,13 @@ def determine_can_pay(self):
357359

358360
self.canSave = not bool(self._wallet.wallet.get_invoice(self._effectiveInvoice.get_id()))
359361

360-
if amount.isEmpty and self.status == PR_UNPAID: # unspecified amount
362+
status = self.status
363+
364+
if amount.isEmpty and status == PR_UNPAID: # unspecified amount
361365
return
362366

363367
if self.invoiceType == QEInvoice.Type.LightningInvoice:
364-
if self.status in [PR_UNPAID, PR_FAILED]:
368+
if status in [PR_UNPAID, PR_FAILED]:
365369
if self.get_max_spendable_lightning() >= amount.satsInt:
366370
lnaddr = self._effectiveInvoice._lnaddr
367371
if not (lnaddr.amount and amount.satsInt < lnaddr.amount * COIN):
@@ -371,7 +375,7 @@ def determine_can_pay(self):
371375
# TODO: subtract fee?
372376
self.canPay = True
373377
elif self.invoiceType == QEInvoice.Type.OnchainInvoice:
374-
if self.status in [PR_UNPAID, PR_FAILED]:
378+
if status in [PR_UNPAID, PR_FAILED]:
375379
if amount.isMax and self.get_max_spendable_onchain() > 0:
376380
# TODO: dust limit?
377381
self.canPay = True

0 commit comments

Comments
 (0)