From e54d57bf734a7309347ef204cfea8179755de942 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Thu, 8 May 2025 19:28:05 +0200 Subject: [PATCH] Qt: improve closing warnings for submarine swaps --- electrum/gui/messages.py | 10 ++++++++++ electrum/gui/qt/main_window.py | 30 +++++++++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/electrum/gui/messages.py b/electrum/gui/messages.py index 9d2fc376d..bdc7f600f 100644 --- a/electrum/gui/messages.py +++ b/electrum/gui/messages.py @@ -74,6 +74,16 @@ MSG_REVERSE_SWAP_FUNDING_MEMPOOL = ( "you will not get back the already pre-paid mining fees.") ) +MSG_FORWARD_SWAP_WARNING = ( + _('You will need to come back online after the funding transaction is confirmed, in order to settle the swap.') + ' ' + + _('If you remain offline for more than {} blocks, your channel will be force closed and you might lose the funds you sent in the swap.') +) + +MSG_REVERSE_SWAP_WARNING = ( + _('You will need to come back online after the funding transaction is confirmed, in order to settle the swap.') + ' ' + + _('If you remain offline for more than {} blocks, the swap will be cancelled and you will lose the prepaid mining fees.') +) + MSG_LN_UTXO_RESERVE = ( _("You do not have enough on-chain funds to protect your Lightning channels.") + ' ' + _("You should have at least {} on-chain in order to be able to sweep channel outputs.") diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 348330836..6aacc4bb7 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -2732,21 +2732,29 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): def _check_ongoing_submarine_swaps_callback(self) -> Optional[str]: """Callback that will return a warning string if there are unconfirmed swap funding txs.""" + from electrum.submarine_swaps import MIN_FINAL_CLTV_DELTA_FOR_CLIENT, LOCKTIME_DELTA_REFUND if not (self.wallet.has_lightning() and self.wallet.lnworker.swap_manager): return None if not self.network: return None - if ongoing_swaps := self.wallet.lnworker.swap_manager.get_pending_swaps(): - return "".join(( - f"{str(len(ongoing_swaps))} ", - _("pending submarine swap") if len(ongoing_swaps) == 1 else _("pending submarine swaps"), - ":\n", - _("Wait until the funding transaction of your swap confirms, otherwise you risk losing your"), - " ", - _("funds") if any(not swap.is_reverse for swap in ongoing_swaps) else _("mining fee prepayment"), - ".", - )) - return None + ongoing_swaps = self.wallet.lnworker.swap_manager.get_pending_swaps() + if not ongoing_swaps: + return None + is_forward = any(not swap.is_reverse for swap in ongoing_swaps) + if is_forward: + # fixme: this is inaccurate, we need local_height - cltv_of_htlc + delta = MIN_FINAL_CLTV_DELTA_FOR_CLIENT + warning = messages.MSG_FORWARD_SWAP_WARNING.format(delta) + else: + locktime = min(swap.locktime for swap in ongoing_swaps) + delta = locktime - self.wallet.adb.get_local_height() + warning = messages.MSG_REVERSE_SWAP_WARNING.format(delta) + return "".join(( + f"{str(len(ongoing_swaps))} ", + _("pending submarine swap") if len(ongoing_swaps) == 1 else _("pending submarine swaps"), + "\n\n", + warning, + )) def closeEvent(self, event): # note that closeEvent is NOT called if the user quits with Ctrl-C