1
0

use NamedTuple for payment identifier gui fields

This commit is contained in:
Sander van Grieken
2023-06-26 13:50:42 +02:00
parent 3a1e5244b8
commit 0cbf403f8b
2 changed files with 22 additions and 16 deletions

View File

@@ -389,17 +389,17 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
lock_max=lock_max, lock_max=lock_max,
lock_description=False) lock_description=False)
if lock_recipient: if lock_recipient:
recipient, amount, description, comment, validated = pi.get_fields_for_GUI() fields = pi.get_fields_for_GUI()
if recipient: if fields.recipient:
self.payto_e.setText(recipient) self.payto_e.setText(fields.recipient)
if description: if fields.description:
self.message_e.setText(description) self.message_e.setText(fields.description)
self.lock_fields(lock_description=True) self.lock_fields(lock_description=True)
if amount: if fields.amount:
self.amount_e.setAmount(amount) self.amount_e.setAmount(fields.amount)
for w in [self.comment_e, self.comment_label]: for w in [self.comment_e, self.comment_label]:
w.setVisible(bool(comment)) w.setVisible(bool(fields.comment))
self.set_field_validated(self.payto_e, validated=validated) self.set_field_validated(self.payto_e, validated=fields.validated)
self.send_button.setEnabled(bool(self.amount_e.get_amount()) and not pi.has_expired() and not pi.is_error()) self.send_button.setEnabled(bool(self.amount_e.get_amount()) and not pi.has_expired() and not pi.is_error())
self.save_button.setEnabled(not pi.is_error()) self.save_button.setEnabled(not pi.is_error())

View File

@@ -182,6 +182,7 @@ class PaymentIdentifierState(IntEnum):
MERCHANT_ERROR = 52 # PI failed notifying the merchant after broadcasting onchain TX MERCHANT_ERROR = 52 # PI failed notifying the merchant after broadcasting onchain TX
INVALID_AMOUNT = 53 # Specified amount not accepted INVALID_AMOUNT = 53 # Specified amount not accepted
class PaymentIdentifierType(IntEnum): class PaymentIdentifierType(IntEnum):
UNKNOWN = 0 UNKNOWN = 0
SPK = 1 SPK = 1
@@ -194,6 +195,15 @@ class PaymentIdentifierType(IntEnum):
OPENALIAS = 8 OPENALIAS = 8
LNADDR = 9 LNADDR = 9
class FieldsForGUI(NamedTuple):
recipient: Optional[str]
amount: Optional[int]
description: Optional[str]
validated: Optional[bool]
comment: Optional[int]
class PaymentIdentifier(Logger): class PaymentIdentifier(Logger):
""" """
Takes: Takes:
@@ -610,7 +620,7 @@ class PaymentIdentifier(Logger):
assert bitcoin.is_address(address) assert bitcoin.is_address(address)
return address return address
def get_fields_for_GUI(self): def get_fields_for_GUI(self) -> FieldsForGUI:
recipient = None recipient = None
amount = None amount = None
description = None description = None
@@ -646,11 +656,6 @@ class PaymentIdentifier(Logger):
amount = pr.get_amount() amount = pr.get_amount()
description = pr.get_memo() description = pr.get_memo()
validated = not pr.has_expired() validated = not pr.has_expired()
# note: allow saving bip70 reqs, as we save them anyway when paying them
#for btn in [self.send_button, self.clear_button, self.save_button]:
# btn.setEnabled(True)
# signal to set fee
#self.amount_e.textEdited.emit("")
elif self.spk: elif self.spk:
pass pass
@@ -667,7 +672,8 @@ class PaymentIdentifier(Logger):
if label and not description: if label and not description:
description = label description = label
return recipient, amount, description, comment, validated return FieldsForGUI(recipient=recipient, amount=amount, description=description,
comment=comment, validated=validated)
def _get_bolt11_fields(self, bolt11_invoice): def _get_bolt11_fields(self, bolt11_invoice):
"""Parse ln invoice, and prepare the send tab for it.""" """Parse ln invoice, and prepare the send tab for it."""