1
0

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'
```
This commit is contained in:
SomberNight
2025-02-14 14:33:51 +00:00
parent 6749468866
commit 2d8c26f211
2 changed files with 7 additions and 4 deletions

View File

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

View File

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