1
0

Qt: improve closing warnings for submarine swaps

This commit is contained in:
ThomasV
2025-05-08 19:28:05 +02:00
parent 05e395018c
commit e54d57bf73
2 changed files with 29 additions and 11 deletions

View File

@@ -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