@@ -2619,8 +2619,46 @@ def settings_dialog(self):
2619
2619
if d .need_restart :
2620
2620
self .show_warning (_ ('Please restart Electrum to activate the new GUI settings' ), title = _ ('Success' ))
2621
2621
2622
+ def _show_closing_warnings (self ) -> bool :
2623
+ """Show any closing warnings and return True if the user chose to quit anyways."""
2624
+ for callback in self .wallet .closing_warning_callbacks :
2625
+ try :
2626
+ warning : Optional [str ] = callback ()
2627
+ except Exception :
2628
+ self .logger .exception ("Closing warning callback failed: " )
2629
+ continue
2630
+ if warning :
2631
+ # build custom QMessageBox to change button strings and color
2632
+ box = QMessageBox ()
2633
+ box .setWindowTitle (_ ("Don't close Electrum yet!" ))
2634
+ box .setText (_ ("An ongoing operation may get interrupted!" ))
2635
+ box .setInformativeText (str (warning ))
2636
+ box .setMaximumWidth (400 )
2637
+ box .setIcon (QMessageBox .Icon .Warning )
2638
+ box .setStyleSheet ("QMessageBox { border: 3px solid #d9534f; }" )
2639
+
2640
+ # Add custom buttons
2641
+ cancel_button = box .addButton (_ ("Cancel" ), QMessageBox .ButtonRole .RejectRole )
2642
+ box .setDefaultButton (cancel_button )
2643
+ close_anyway_button = box .addButton (_ ("Close anyways" ), QMessageBox .ButtonRole .AcceptRole )
2644
+ close_anyway_button .setStyleSheet ("background-color: #d9534f;" )
2645
+
2646
+ if text_label := box .findChild (QLabel ):
2647
+ text_label .setWordWrap (True )
2648
+
2649
+ box .exec ()
2650
+ if box .clickedButton () == cancel_button :
2651
+ break
2652
+ else :
2653
+ # user chose to cancel all warnings or there were no warnings
2654
+ return True
2655
+ return False
2656
+
2622
2657
def closeEvent (self , event ):
2623
2658
# note that closeEvent is NOT called if the user quits with Ctrl-C
2659
+ if not self ._show_closing_warnings ():
2660
+ event .ignore ()
2661
+ return
2624
2662
self .clean_up ()
2625
2663
event .accept ()
2626
2664
@@ -2809,7 +2847,16 @@ def on_swap_result(self, txid: Optional[str], *, is_reverse: bool):
2809
2847
if is_reverse :
2810
2848
msg += messages .MSG_REVERSE_SWAP_FUNDING_MEMPOOL
2811
2849
else :
2812
- msg += messages .MSG_FORWARD_SWAP_FUNDING_MEMPOOL
2850
+ msg += messages .MSG_FORWARD_SWAP_FUNDING_MEMPOOL + messages .MSG_FORWARD_SWAP_HTLC_EXPIRY
2851
+
2852
+ def wallet_closing_warning_callback () -> Optional [str ]:
2853
+ # gets called when the wallet GUI is closed
2854
+ warning = messages .MSG_REVERSE_SWAP_FUNDING_MEMPOOL if is_reverse \
2855
+ else messages .MSG_FORWARD_SWAP_FUNDING_MEMPOOL
2856
+ if self .wallet .adb .get_tx_height (txid ).height < 1 :
2857
+ return _ ("Ongoing submarine swap" ) + ": " + warning
2858
+ self .wallet .register_closing_warning_callback (wallet_closing_warning_callback )
2859
+
2813
2860
self .show_message_signal .emit (msg )
2814
2861
else :
2815
2862
msg += _ ("Lightning funds were not received." ) # FIXME should this not depend on is_reverse?
0 commit comments