1414from electrum .transaction import PartialTxOutput , PartialTransaction
1515from electrum .fee_policy import FeePolicy
1616from electrum .crypto import sha256
17+ from electrum .submarine_swaps import NostrTransport
1718
1819from electrum .gui import messages
1920from . import util
@@ -54,8 +55,10 @@ def __init__(self, window: 'ElectrumWindow', transport: 'SwapServerTransport', i
5455 self .is_reverse = is_reverse if is_reverse is not None else True
5556 vbox = QVBoxLayout (self )
5657
57- recent_offers = transport .get_recent_offers () if not self .config .SWAPSERVER_URL else []
58- self .server_button = QPushButton (_ (f' { len (recent_offers )} providers' ))
58+ self .server_button = QPushButton ()
59+ self .set_server_button_text (len (transport .get_recent_offers ()) \
60+ if not self .config .SWAPSERVER_URL and isinstance (transport , NostrTransport ) else 0
61+ )
5962 self .server_button .clicked .connect (lambda : self .choose_swap_server (transport ))
6063 self .server_button .setEnabled (not self .config .SWAPSERVER_URL )
6164 self .description_label = WWLabel (self .get_description ())
@@ -142,6 +145,15 @@ def on_event_fee(self, *args):
142145 self .on_send_edited ()
143146 self .on_recv_edited ()
144147
148+ @qt_event_listener
149+ def on_event_swap_offers_changed (self , recent_offers : Sequence ['SwapOffer' ]):
150+ self .set_server_button_text (len (recent_offers ))
151+ self .update ()
152+
153+ def set_server_button_text (self , offer_count : int ):
154+ button_text = f' { offer_count } ' + (_ ('providers' ) if offer_count != 1 else _ ('provider' ))
155+ self .server_button .setText (button_text )
156+
145157 def timer_actions (self ):
146158 if self .needs_tx_update :
147159 self .update_tx ()
@@ -471,6 +483,7 @@ def __init__(self, window: 'ElectrumWindow', servers: Sequence['SwapOffer']):
471483 self .ok_button = OkButton (self )
472484 vbox .addLayout (Buttons (CancelButton (self ), self .ok_button ))
473485 self .setMinimumWidth (650 )
486+ self .register_callbacks ()
474487
475488 def run (self ):
476489 if self .exec () != 1 :
@@ -479,6 +492,14 @@ def run(self):
479492 return item .data (self .Columns .PUBKEY , ROLE_NPUB )
480493 return None
481494
495+ def closeEvent (self , event ):
496+ self .unregister_callbacks ()
497+ event .accept ()
498+
499+ @qt_event_listener
500+ def on_event_swap_offers_changed (self , recent_offers : Sequence ['SwapOffer' ]):
501+ self .update_servers_list (recent_offers )
502+
482503 def update_servers_list (self , servers : Sequence ['SwapOffer' ]):
483504 self .servers_list .clear ()
484505 from electrum .util import age
0 commit comments