diff --git a/electrum/gui/qt/send_tab.py b/electrum/gui/qt/send_tab.py index 5709c0a2c..71e93d832 100644 --- a/electrum/gui/qt/send_tab.py +++ b/electrum/gui/qt/send_tab.py @@ -389,17 +389,17 @@ class SendTab(QWidget, MessageBoxMixin, Logger): lock_max=lock_max, lock_description=False) if lock_recipient: - recipient, amount, description, comment, validated = pi.get_fields_for_GUI() - if recipient: - self.payto_e.setText(recipient) - if description: - self.message_e.setText(description) + fields = pi.get_fields_for_GUI() + if fields.recipient: + self.payto_e.setText(fields.recipient) + if fields.description: + self.message_e.setText(fields.description) self.lock_fields(lock_description=True) - if amount: - self.amount_e.setAmount(amount) + if fields.amount: + self.amount_e.setAmount(fields.amount) for w in [self.comment_e, self.comment_label]: - w.setVisible(bool(comment)) - self.set_field_validated(self.payto_e, validated=validated) + w.setVisible(bool(fields.comment)) + 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.save_button.setEnabled(not pi.is_error()) diff --git a/electrum/payment_identifier.py b/electrum/payment_identifier.py index 837780815..2dd35b2b2 100644 --- a/electrum/payment_identifier.py +++ b/electrum/payment_identifier.py @@ -182,6 +182,7 @@ class PaymentIdentifierState(IntEnum): MERCHANT_ERROR = 52 # PI failed notifying the merchant after broadcasting onchain TX INVALID_AMOUNT = 53 # Specified amount not accepted + class PaymentIdentifierType(IntEnum): UNKNOWN = 0 SPK = 1 @@ -194,6 +195,15 @@ class PaymentIdentifierType(IntEnum): OPENALIAS = 8 LNADDR = 9 + +class FieldsForGUI(NamedTuple): + recipient: Optional[str] + amount: Optional[int] + description: Optional[str] + validated: Optional[bool] + comment: Optional[int] + + class PaymentIdentifier(Logger): """ Takes: @@ -610,7 +620,7 @@ class PaymentIdentifier(Logger): assert bitcoin.is_address(address) return address - def get_fields_for_GUI(self): + def get_fields_for_GUI(self) -> FieldsForGUI: recipient = None amount = None description = None @@ -646,11 +656,6 @@ class PaymentIdentifier(Logger): amount = pr.get_amount() description = pr.get_memo() 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: pass @@ -667,7 +672,8 @@ class PaymentIdentifier(Logger): if label and not description: 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): """Parse ln invoice, and prepare the send tab for it."""