mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-13 22:19:50 +00:00
qt swap_dialog: "max" button now respects max htlc value
This commit is contained in:
parent
a74552f3dd
commit
7570c8c1c6
2 changed files with 28 additions and 12 deletions
|
@ -1,10 +1,11 @@
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QLabel, QVBoxLayout, QGridLayout, QPushButton
|
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
|
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)
|
||||||
|
@ -24,6 +25,8 @@ Do you want to continue?
|
||||||
|
|
||||||
class SwapDialog(WindowModalDialog):
|
class SwapDialog(WindowModalDialog):
|
||||||
|
|
||||||
|
tx: Optional[PartialTransaction]
|
||||||
|
|
||||||
def __init__(self, window: 'ElectrumWindow'):
|
def __init__(self, window: 'ElectrumWindow'):
|
||||||
WindowModalDialog.__init__(self, window, _('Submarine Swap'))
|
WindowModalDialog.__init__(self, window, _('Submarine Swap'))
|
||||||
self.window = window
|
self.window = window
|
||||||
|
@ -31,6 +34,7 @@ class SwapDialog(WindowModalDialog):
|
||||||
self.lnworker = self.window.wallet.lnworker
|
self.lnworker = self.window.wallet.lnworker
|
||||||
self.swap_manager = self.lnworker.swap_manager
|
self.swap_manager = self.lnworker.swap_manager
|
||||||
self.network = window.network
|
self.network = window.network
|
||||||
|
self.tx = None
|
||||||
vbox = QVBoxLayout(self)
|
vbox = QVBoxLayout(self)
|
||||||
vbox.addWidget(WWLabel('Swap lightning funds for on-chain funds if you need to increase your receiving capacity. This service is powered by the Boltz backend.'))
|
vbox.addWidget(WWLabel('Swap lightning funds for on-chain funds if you need to increase your receiving capacity. This service is powered by the Boltz backend.'))
|
||||||
self.send_amount_e = BTCAmountEdit(self.window.get_decimal_point)
|
self.send_amount_e = BTCAmountEdit(self.window.get_decimal_point)
|
||||||
|
@ -99,15 +103,24 @@ class SwapDialog(WindowModalDialog):
|
||||||
if self.is_reverse:
|
if self.is_reverse:
|
||||||
return
|
return
|
||||||
if self.max_button.isChecked():
|
if self.max_button.isChecked():
|
||||||
self.update_tx('!')
|
self._spend_max_forward_swap()
|
||||||
if self.tx:
|
|
||||||
txo = self.tx.outputs()[0]
|
|
||||||
self.send_amount_e.setAmount(txo.value)
|
|
||||||
else:
|
else:
|
||||||
self.tx = None
|
self.tx = None
|
||||||
self.send_amount_e.setAmount(None)
|
self.send_amount_e.setAmount(None)
|
||||||
self.update_fee()
|
self.update_fee()
|
||||||
|
|
||||||
|
def _spend_max_forward_swap(self):
|
||||||
|
self.update_tx('!')
|
||||||
|
if self.tx:
|
||||||
|
amount = self.tx.output_value_for_address(ln_dummy_address())
|
||||||
|
if amount > SWAP_MAX_VALUE_SAT:
|
||||||
|
amount = SWAP_MAX_VALUE_SAT
|
||||||
|
self.update_tx(amount)
|
||||||
|
if self.tx:
|
||||||
|
amount = self.tx.output_value_for_address(ln_dummy_address())
|
||||||
|
assert amount <= SWAP_MAX_VALUE_SAT
|
||||||
|
self.send_amount_e.setAmount(amount)
|
||||||
|
|
||||||
def on_send_edited(self):
|
def on_send_edited(self):
|
||||||
if self.send_amount_e.follows:
|
if self.send_amount_e.follows:
|
||||||
return
|
return
|
||||||
|
@ -154,12 +167,12 @@ class SwapDialog(WindowModalDialog):
|
||||||
fee = sm.get_claim_fee()
|
fee = sm.get_claim_fee()
|
||||||
else:
|
else:
|
||||||
is_max = self.max_button.isChecked()
|
is_max = self.max_button.isChecked()
|
||||||
onchain_amount = '!' if is_max else self.send_amount_e.get_amount()
|
if is_max:
|
||||||
|
self._spend_max_forward_swap()
|
||||||
|
else:
|
||||||
|
onchain_amount = self.send_amount_e.get_amount()
|
||||||
self.update_tx(onchain_amount)
|
self.update_tx(onchain_amount)
|
||||||
fee = self.tx.get_fee() if self.tx else None
|
fee = self.tx.get_fee() if self.tx else None
|
||||||
if is_max and self.tx:
|
|
||||||
txo = self.tx.outputs()[0]
|
|
||||||
self.send_amount_e.setAmount(txo.value)
|
|
||||||
fee_text = self.window.format_amount(fee) + ' ' + self.window.base_unit() if fee else ''
|
fee_text = self.window.format_amount(fee) + ' ' + self.window.base_unit() if fee else ''
|
||||||
self.fee_label.setText(fee_text)
|
self.fee_label.setText(fee_text)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ from .bitcoin import address_to_script, script_to_p2wsh, redeem_script_to_addres
|
||||||
from .transaction import TxOutpoint, PartialTxInput, PartialTxOutput, PartialTransaction, construct_witness
|
from .transaction import TxOutpoint, PartialTxInput, PartialTxOutput, PartialTransaction, construct_witness
|
||||||
from .transaction import script_GetOp, match_script_against_template, OPPushDataGeneric, OPPushDataPubkey
|
from .transaction import script_GetOp, match_script_against_template, OPPushDataGeneric, OPPushDataPubkey
|
||||||
from .util import log_exceptions
|
from .util import log_exceptions
|
||||||
from .lnutil import REDEEM_AFTER_DOUBLE_SPENT_DELAY, ln_dummy_address
|
from .lnutil import REDEEM_AFTER_DOUBLE_SPENT_DELAY, ln_dummy_address, LN_MAX_HTLC_VALUE_MSAT
|
||||||
from .bitcoin import dust_threshold
|
from .bitcoin import dust_threshold
|
||||||
from .logging import Logger
|
from .logging import Logger
|
||||||
from .lnutil import hex_to_bytes
|
from .lnutil import hex_to_bytes
|
||||||
|
@ -25,6 +25,9 @@ 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),
|
||||||
|
|
Loading…
Add table
Reference in a new issue