Skip to content

Commit

Permalink
swaps: homogenise gui messages
Browse files Browse the repository at this point in the history
see #8940
  • Loading branch information
SomberNight committed Mar 13, 2024
1 parent 4a71032 commit 01155ac
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
20 changes: 20 additions & 0 deletions 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):
Expand Down Expand Up @@ -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.")
)
10 changes: 4 additions & 6 deletions electrum/gui/qml/qeswaphelper.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 7 additions & 4 deletions electrum/gui/qt/main_window.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion electrum/gui/qt/send_tab.py
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions electrum/gui/qt/swap_dialog.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 01155ac

Please sign in to comment.