qt swap_dialog: "max" now takes into account the server-provided value
This commit is contained in:
@@ -5,7 +5,6 @@ from PyQt5.QtWidgets import QLabel, QVBoxLayout, QGridLayout, QPushButton
|
|||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.lnutil import ln_dummy_address
|
from electrum.lnutil import ln_dummy_address
|
||||||
from electrum.transaction import PartialTxOutput, PartialTransaction
|
from electrum.transaction import PartialTxOutput, PartialTransaction
|
||||||
from electrum.submarine_swaps import SWAP_MAX_VALUE_SAT
|
|
||||||
|
|
||||||
from .util import (WindowModalDialog, Buttons, OkButton, CancelButton,
|
from .util import (WindowModalDialog, Buttons, OkButton, CancelButton,
|
||||||
EnterButton, ColorScheme, WWLabel, read_QIcon)
|
EnterButton, ColorScheme, WWLabel, read_QIcon)
|
||||||
@@ -114,16 +113,17 @@ class SwapDialog(WindowModalDialog):
|
|||||||
self.update_tx('!')
|
self.update_tx('!')
|
||||||
if self.tx:
|
if self.tx:
|
||||||
amount = self.tx.output_value_for_address(ln_dummy_address())
|
amount = self.tx.output_value_for_address(ln_dummy_address())
|
||||||
if amount > SWAP_MAX_VALUE_SAT:
|
max_amt = self.swap_manager.get_max_amount()
|
||||||
amount = SWAP_MAX_VALUE_SAT
|
if amount > max_amt:
|
||||||
|
amount = max_amt
|
||||||
self.update_tx(amount)
|
self.update_tx(amount)
|
||||||
if self.tx:
|
if self.tx:
|
||||||
amount = self.tx.output_value_for_address(ln_dummy_address())
|
amount = self.tx.output_value_for_address(ln_dummy_address())
|
||||||
assert amount <= SWAP_MAX_VALUE_SAT
|
assert amount <= max_amt
|
||||||
self.send_amount_e.setAmount(amount)
|
self.send_amount_e.setAmount(amount)
|
||||||
|
|
||||||
def _spend_max_reverse_swap(self):
|
def _spend_max_reverse_swap(self):
|
||||||
amount = min(self.lnworker.num_sats_can_send(), SWAP_MAX_VALUE_SAT)
|
amount = min(self.lnworker.num_sats_can_send(), self.swap_manager.get_max_amount())
|
||||||
self.send_amount_e.setAmount(amount)
|
self.send_amount_e.setAmount(amount)
|
||||||
|
|
||||||
def on_send_edited(self):
|
def on_send_edited(self):
|
||||||
|
|||||||
@@ -25,9 +25,6 @@ if TYPE_CHECKING:
|
|||||||
API_URL = 'https://lightning.electrum.org/api'
|
API_URL = 'https://lightning.electrum.org/api'
|
||||||
|
|
||||||
|
|
||||||
SWAP_MAX_VALUE_SAT = LN_MAX_HTLC_VALUE_MSAT // 1000
|
|
||||||
|
|
||||||
|
|
||||||
WITNESS_TEMPLATE_SWAP = [
|
WITNESS_TEMPLATE_SWAP = [
|
||||||
opcodes.OP_HASH160,
|
opcodes.OP_HASH160,
|
||||||
OPPushDataGeneric(lambda x: x == 20),
|
OPPushDataGeneric(lambda x: x == 20),
|
||||||
@@ -118,7 +115,7 @@ class SwapManager(Logger):
|
|||||||
self.lockup_fee = 0
|
self.lockup_fee = 0
|
||||||
self.percentage = 0
|
self.percentage = 0
|
||||||
self.min_amount = 0
|
self.min_amount = 0
|
||||||
self.max_amount = 0
|
self._max_amount = 0
|
||||||
self.network = network
|
self.network = network
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
self.lnworker = wallet.lnworker
|
self.lnworker = wallet.lnworker
|
||||||
@@ -365,12 +362,15 @@ class SwapManager(Logger):
|
|||||||
self.lockup_fee = fees['minerFees']['baseAsset']['reverse']['lockup']
|
self.lockup_fee = fees['minerFees']['baseAsset']['reverse']['lockup']
|
||||||
limits = pairs['pairs']['BTC/BTC']['limits']
|
limits = pairs['pairs']['BTC/BTC']['limits']
|
||||||
self.min_amount = limits['minimal']
|
self.min_amount = limits['minimal']
|
||||||
self.max_amount = limits['maximal']
|
self._max_amount = limits['maximal']
|
||||||
|
|
||||||
|
def get_max_amount(self):
|
||||||
|
return min(self._max_amount, LN_MAX_HTLC_VALUE_MSAT // 1000)
|
||||||
|
|
||||||
def get_recv_amount(self, send_amount: Optional[int], is_reverse: bool) -> Optional[int]:
|
def get_recv_amount(self, send_amount: Optional[int], is_reverse: bool) -> Optional[int]:
|
||||||
if send_amount is None:
|
if send_amount is None:
|
||||||
return
|
return
|
||||||
if send_amount < self.min_amount or send_amount > self.max_amount:
|
if send_amount < self.min_amount or send_amount > self._max_amount:
|
||||||
return
|
return
|
||||||
x = send_amount
|
x = send_amount
|
||||||
if is_reverse:
|
if is_reverse:
|
||||||
|
|||||||
Reference in New Issue
Block a user