From 01155ac6f5526458df57138d36b7896dcc22a1cc Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 13 Mar 2024 13:44:36 +0000 Subject: [PATCH] swaps: homogenise gui messages see https://github.com/spesmilo/electrum/issues/8940 --- electrum/gui/messages.py | 20 ++++++++++++++++++++ electrum/gui/qml/qeswaphelper.py | 10 ++++------ electrum/gui/qt/main_window.py | 11 +++++++---- electrum/gui/qt/send_tab.py | 2 +- electrum/gui/qt/swap_dialog.py | 7 +++++-- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/electrum/gui/messages.py b/electrum/gui/messages.py index 922679efebd2..0d78d7907658 100644 --- a/electrum/gui/messages.py +++ b/electrum/gui/messages.py @@ -1,4 +1,5 @@ from electrum.i18n import _ +from electrum.submarine_swaps import MIN_FINAL_CLTV_DELTA_FOR_CLIENT def to_rtf(msg): @@ -47,3 +48,22 @@ def to_rtf(msg): MSG_FREEZE_ADDRESS = _("When you freeze an address, the funds in that address will not be used for sending bitcoins.") MSG_FREEZE_COIN = _("When you freeze a coin, it will not be used for sending bitcoins.") + +MSG_FORWARD_SWAP_FUNDING_MEMPOOL = ( + _('Your funding transaction has been broadcast.') + " " + + _('The swap will be finalized once your transaction is confirmed.') + " " + + _("After the funding transaction is mined, the server will reveal the preimage needed to " + "fulfill the pending received lightning HTLCs. The HTLCs expire in {} blocks. " + "You will need to be online after the funding transaction is confirmed but before the HTLCs expire, " + "to claim your money. If you go offline for several days while the swap is pending, " + "you risk losing the swap amount!").format(MIN_FINAL_CLTV_DELTA_FOR_CLIENT) + " " + + _("Please remain online until the funding transaction is confirmed.") +) + +MSG_REVERSE_SWAP_FUNDING_MEMPOOL = ( + _('The funding transaction has been detected.') + " " + + _('Your claiming transaction will be broadcast when the funding transaction is confirmed.') + " " + + _('You may choose to broadcast it earlier, although that would not be trustless.') + " " + + _("If you go offline before broadcasting the claiming transaction and let the swap time out, " + "you will not get back the already pre-paid mining fees.") +) diff --git a/electrum/gui/qml/qeswaphelper.py b/electrum/gui/qml/qeswaphelper.py index a85030e391f2..ccc262ca6c7c 100644 --- a/electrum/gui/qml/qeswaphelper.py +++ b/electrum/gui/qml/qeswaphelper.py @@ -12,6 +12,8 @@ from electrum.transaction import PartialTxOutput, PartialTransaction from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates, profiler, get_asyncio_loop +from electrum.gui import messages + from .auth import AuthMixin, auth_protect from .qetypes import QEAmount from .qewallet import QEWallet @@ -386,9 +388,7 @@ def swap_task(): try: # swaphelper might be destroyed at this point self.userinfo = ' '.join([ _('Success!'), - _('Your funding transaction has been broadcast.'), - _('The swap will be finalized once your transaction is confirmed.'), - _('You will need to be online to finalize the swap, or the transaction will be refunded to you after some delay.'), + messages.MSG_FORWARD_SWAP_FUNDING_MEMPOOL, ]) self.state = QESwapHelper.State.Success except RuntimeError: @@ -459,9 +459,7 @@ def swap_task(): if txid: self.userinfo = ' '.join([ _('Success!'), - _('The funding transaction has been detected.'), - _('Your claiming transaction will be broadcast when the funding transaction is confirmed.'), - _('You may choose to broadcast it earlier, although that would not be trustless.'), + messages.MSG_REVERSE_SWAP_FUNDING_MEMPOOL, ]) self.state = QESwapHelper.State.Success else: diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index c6f993a37a95..0c60312a9e69 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -2686,14 +2686,17 @@ def rebalance_dialog(self, chan1, chan2, amount_sat=None): d = RebalanceDialog(self, chan1, chan2, amount_sat) d.run() - def on_swap_result(self, txid): + def on_swap_result(self, txid: Optional[str], *, is_reverse: bool): msg = _("Submarine swap") + ': ' + (_("Success") if txid else _("Expired")) + '\n\n' if txid: - msg += _("Funding transaction") + ': ' + txid + '\n' - msg += _("Please remain online until the funding transaction is confirmed.") + msg += _("Funding transaction") + ': ' + txid + '\n\n' + if is_reverse: + msg += messages.MSG_REVERSE_SWAP_FUNDING_MEMPOOL + else: + msg += messages.MSG_FORWARD_SWAP_FUNDING_MEMPOOL self.show_message_signal.emit(msg) else: - msg += _("Lightning funds were not received.") + msg += _("Lightning funds were not received.") # FIXME should this not depend on is_reverse? self.show_error_signal.emit(msg) def set_payment_identifier(self, pi: str): diff --git a/electrum/gui/qt/send_tab.py b/electrum/gui/qt/send_tab.py index 4fbd4745c2a6..8566b6a79436 100644 --- a/electrum/gui/qt/send_tab.py +++ b/electrum/gui/qt/send_tab.py @@ -741,7 +741,7 @@ def broadcast_transaction(self, tx: Transaction, *, payment_identifier: PaymentI coro = sm.wait_for_htlcs_and_broadcast(swap=swap, invoice=tx.swap_invoice, tx=tx) self.window.run_coroutine_dialog( coro, _('Awaiting swap payment...'), - on_result=self.window.on_swap_result, + on_result=lambda funding_txid: self.window.on_swap_result(funding_txid, is_reverse=False), on_cancelled=lambda: sm.cancel_normal_swap(swap)) return diff --git a/electrum/gui/qt/swap_dialog.py b/electrum/gui/qt/swap_dialog.py index 7a35a2e40782..08edcd6f2a0f 100644 --- a/electrum/gui/qt/swap_dialog.py +++ b/electrum/gui/qt/swap_dialog.py @@ -255,7 +255,10 @@ def run(self): lightning_amount_sat=lightning_amount, expected_onchain_amount_sat=onchain_amount + self.swap_manager.get_claim_fee(), ) - self.window.run_coroutine_from_thread(coro, _('Swapping funds'), on_result=self.window.on_swap_result) + self.window.run_coroutine_from_thread( + coro, _('Swapping funds'), + on_result=lambda funding_txid: self.window.on_swap_result(funding_txid, is_reverse=True), + ) return True else: lightning_amount = self.recv_amount_e.get_amount() @@ -334,7 +337,7 @@ def do_normal_swap(self, lightning_amount, onchain_amount, password): coro2 = sm.wait_for_htlcs_and_broadcast(swap=swap, invoice=invoice, tx=tx) self.window.run_coroutine_dialog( coro2, _('Awaiting swap payment...'), - on_result=self.window.on_swap_result, + on_result=lambda funding_txid: self.window.on_swap_result(funding_txid, is_reverse=False), on_cancelled=lambda: sm.cancel_normal_swap(swap)) def get_description(self):