Skip to content

Commit bde2e23

Browse files
authored
Merge pull request #9989 from f321x/swap_dialog_followup
qt: SwapDialog: update on changes, don't translate f-str
2 parents 3f755e1 + 7324940 commit bde2e23

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

electrum/gui/qt/swap_dialog.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from electrum.transaction import PartialTxOutput, PartialTransaction
1515
from electrum.fee_policy import FeePolicy
1616
from electrum.crypto import sha256
17+
from electrum.submarine_swaps import NostrTransport
1718

1819
from electrum.gui import messages
1920
from . 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

electrum/submarine_swaps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .util import (
3333
log_exceptions, ignore_exceptions, BelowDustLimit, OldTaskGroup, ca_path, gen_nostr_ann_pow,
3434
get_nostr_ann_pow_amount, make_aiohttp_proxy_connector, get_running_loop, get_asyncio_loop, wait_for2,
35-
run_sync_function_on_asyncio_thread
35+
run_sync_function_on_asyncio_thread, trigger_callback
3636
)
3737
from . import lnutil
3838
from .lnutil import hex_to_bytes, REDEEM_AFTER_DOUBLE_SPENT_DELAY, Keypair
@@ -1648,6 +1648,7 @@ async def get_pairs(self):
16481648
if self.config.SWAPSERVER_NPUB == offer.server_npub:
16491649
self.sm.update_pairs(pairs)
16501650
self._offers[offer.server_npub] = offer
1651+
trigger_callback('swap_offers_changed', self.get_recent_offers())
16511652
# mirror event to other relays
16521653
await self.taskgroup.spawn(self.rebroadcast_event(event, server_relays))
16531654

0 commit comments

Comments
 (0)