@@ -205,9 +205,14 @@ def showSpinner(self, b):
205
205
206
206
def on_amount_changed (self , text ):
207
207
# FIXME: implement full valid amount check to enable/disable Pay button
208
- pi_valid = self .payto_e .payment_identifier .is_valid () if self .payto_e .payment_identifier else False
209
- pi_error = self .payto_e .payment_identifier .is_error () if pi_valid else False
210
- self .send_button .setEnabled (bool (self .amount_e .get_amount ()) and pi_valid and not pi_error )
208
+ pi = self .payto_e .payment_identifier
209
+ if not pi :
210
+ self .send_button .setEnabled (False )
211
+ return
212
+ pi_error = pi .is_error () if pi .is_valid () else False
213
+ is_spk_script = pi .type == PaymentIdentifierType .SPK and not pi .spk_is_address
214
+ valid_amount = is_spk_script or bool (self .amount_e .get_amount ())
215
+ self .send_button .setEnabled (pi .is_valid () and not pi_error and valid_amount )
211
216
212
217
def do_paste (self ):
213
218
self .logger .debug ('do_paste' )
@@ -224,16 +229,20 @@ def set_payment_identifier(self, text):
224
229
self .show_error (_ ('Invalid payment identifier' ))
225
230
226
231
def spend_max (self ):
227
- if self .payto_e .payment_identifier is None :
232
+ pi = self .payto_e .payment_identifier
233
+
234
+ if pi is None or pi .type == PaymentIdentifierType .UNKNOWN :
228
235
return
229
236
230
- assert self .payto_e .payment_identifier .type in [PaymentIdentifierType .SPK , PaymentIdentifierType .MULTILINE ,
231
- PaymentIdentifierType .BIP21 , PaymentIdentifierType .OPENALIAS ]
232
- assert not self .payto_e .payment_identifier .is_amount_locked ()
237
+ assert pi .type in [PaymentIdentifierType .SPK , PaymentIdentifierType .MULTILINE ,
238
+ PaymentIdentifierType .BIP21 , PaymentIdentifierType .OPENALIAS ]
239
+
240
+ if pi .type == PaymentIdentifierType .BIP21 :
241
+ assert 'amount' not in pi .bip21
233
242
234
243
if run_hook ('abort_send' , self ):
235
244
return
236
- outputs = self . payto_e . payment_identifier .get_onchain_outputs ('!' )
245
+ outputs = pi .get_onchain_outputs ('!' )
237
246
if not outputs :
238
247
return
239
248
make_tx = lambda fee_est , * , confirmed_only = False : self .wallet .make_unsigned_transaction (
@@ -446,10 +455,13 @@ def update_fields(self):
446
455
self .spend_max ()
447
456
448
457
pi_unusable = pi .is_error () or (not self .wallet .has_lightning () and not pi .is_onchain ())
458
+ is_spk_script = pi .type == PaymentIdentifierType .SPK and not pi .spk_is_address
459
+
460
+ amount_valid = is_spk_script or bool (self .amount_e .get_amount ())
449
461
450
- self .send_button .setEnabled (not pi_unusable and bool ( self . amount_e . get_amount ()) and not pi .has_expired ())
451
- self .save_button .setEnabled (not pi_unusable and pi . type not in [ PaymentIdentifierType . LNURLP ,
452
- PaymentIdentifierType .LNADDR ])
462
+ self .send_button .setEnabled (not pi_unusable and amount_valid and not pi .has_expired ())
463
+ self .save_button .setEnabled (not pi_unusable and not is_spk_script and \
464
+ pi . type not in [ PaymentIdentifierType . LNURLP , PaymentIdentifierType .LNADDR ])
453
465
454
466
def _handle_payment_identifier (self ):
455
467
self .update_fields ()
@@ -479,11 +491,8 @@ def get_message(self):
479
491
def read_invoice (self ) -> Optional [Invoice ]:
480
492
if self .check_payto_line_and_show_errors ():
481
493
return
482
- amount_sat = self .read_amount ()
483
- if not amount_sat :
484
- self .show_error (_ ('No amount' ))
485
- return
486
494
495
+ amount_sat = self .read_amount ()
487
496
invoice = invoice_from_payment_identifier (
488
497
self .payto_e .payment_identifier , self .wallet , amount_sat , self .get_message ())
489
498
if not invoice :
@@ -551,15 +560,19 @@ def pay_multiple_invoices(self, invoices):
551
560
def do_edit_invoice (self , invoice : 'Invoice' ): # FIXME broken
552
561
assert not bool (invoice .get_amount_sat ())
553
562
text = invoice .lightning_invoice if invoice .is_lightning () else invoice .get_address ()
554
- self .payto_e . _on_input_btn (text )
563
+ self .set_payment_identifier (text )
555
564
self .amount_e .setFocus ()
556
565
# disable save button, because it would create a new invoice
557
566
self .save_button .setEnabled (False )
558
567
559
568
def do_pay_invoice (self , invoice : 'Invoice' ):
560
569
if not bool (invoice .get_amount_sat ()):
561
- self .show_error (_ ('No amount' ))
562
- return
570
+ pi = self .payto_e .payment_identifier
571
+ if pi .type == PaymentIdentifierType .SPK and not pi .spk_is_address :
572
+ pass
573
+ else :
574
+ self .show_error (_ ('No amount' ))
575
+ return
563
576
if invoice .is_lightning ():
564
577
self .pay_lightning_invoice (invoice )
565
578
else :
0 commit comments