From 2d8c26f2117d381fca80ee92a98d903a8246ca43 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 14 Feb 2025 14:33:51 +0000 Subject: [PATCH] qt swaps: fix _spend_max_reverse_swap: round down msats Clicking "max" btn for a reverse swap was setting the text field to a too high value. ``` >>> wallet.lnworker.num_sats_can_send() Decimal('1242647.947') >>> util.format_satoshis_plain(Decimal('1242647.947')) '0.01242648' ``` --- electrum/gui/qt/swap_dialog.py | 1 + electrum/submarine_swaps.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/electrum/gui/qt/swap_dialog.py b/electrum/gui/qt/swap_dialog.py index 473f6c69b..900b9a696 100644 --- a/electrum/gui/qt/swap_dialog.py +++ b/electrum/gui/qt/swap_dialog.py @@ -193,6 +193,7 @@ class SwapDialog(WindowModalDialog, QtEventListener): def _spend_max_reverse_swap(self) -> None: amount = min(self.lnworker.num_sats_can_send(), self.swap_manager.get_max_amount()) + amount = int(amount) # round down msats self.send_amount_e.setAmount(amount) def on_send_edited(self): diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index e3cb4965e..a24ea11ce 100644 --- a/electrum/submarine_swaps.py +++ b/electrum/submarine_swaps.py @@ -967,14 +967,16 @@ class SwapManager(Logger): self._max_amount = pairs.max_amount self.is_initialized.set() - def get_max_amount(self): + def get_max_amount(self) -> int: + """in satoshis""" return self._max_amount - def get_min_amount(self): + def get_min_amount(self) -> int: + """in satoshis""" return self._min_amount - def check_invoice_amount(self, x): - return x >= self.get_min_amount() and x <= self.get_max_amount() + def check_invoice_amount(self, x) -> bool: + return self.get_min_amount() <= x <= self.get_max_amount() def _get_recv_amount(self, send_amount: Optional[int], *, is_reverse: bool) -> Optional[int]: """For a given swap direction and amount we send, returns how much we will receive.