1
0

Merge pull request #10060 from f321x/fix_issue_10053

qt: NewChannelDialog: do some validation before enabling Ok button
This commit is contained in:
ghost43
2025-07-20 16:03:30 +00:00
committed by GitHub

View File

@@ -8,6 +8,7 @@ from electrum.lnutil import MIN_FUNDING_SAT
from electrum.lnworker import hardcoded_trampoline_nodes
from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates
from electrum.fee_policy import FeePolicy
from electrum.lntransport import extract_nodeid, ConnStringFormatError
from .util import (WindowModalDialog, Buttons, OkButton, CancelButton,
EnterButton, WWLabel, char_width_in_lineedit)
@@ -43,14 +44,18 @@ class NewChannelDialog(WindowModalDialog):
vbox.addWidget(QLabel(_('Enter Remote Node ID or connection string or invoice')))
self.remote_nodeid = QLineEdit()
self.remote_nodeid.setMinimumWidth(700)
self.remote_nodeid.textChanged.connect(self.maybe_enable_ok_button)
self.suggest_button = QPushButton(self, text=_('Suggest Peer'))
self.suggest_button.clicked.connect(self.on_suggest)
else:
self.trampoline_combo = QComboBox()
self.trampoline_combo.addItems(self.trampoline_names)
# index 1 is "Electrum trampoline" on mainnet, this defaults to -1 if 1 is not available
self.trampoline_combo.setCurrentIndex(1)
self.trampoline_combo.currentIndexChanged.connect(self.maybe_enable_ok_button)
self.amount_e = BTCAmountEdit(self.window.get_decimal_point)
self.amount_e.setAmount(amount_sat)
self.amount_e.textChanged.connect(self.maybe_enable_ok_button)
btn_width = 10 * char_width_in_lineedit()
self.min_button = EnterButton(_("Min"), self.spend_min)
@@ -83,9 +88,26 @@ class NewChannelDialog(WindowModalDialog):
vbox.addLayout(h)
vbox.addStretch()
ok_button = OkButton(self)
ok_button.setDefault(True)
vbox.addLayout(Buttons(CancelButton(self), ok_button))
self.ok_button = OkButton(self)
self.ok_button.setDefault(True)
self.maybe_enable_ok_button()
vbox.addLayout(Buttons(CancelButton(self), self.ok_button))
def maybe_enable_ok_button(self):
enable = True
if self.network.channel_db:
try:
extract_nodeid(str(self.remote_nodeid.text()).strip())
except ConnStringFormatError:
enable = False
else:
try:
self.trampoline_names[self.trampoline_combo.currentIndex()]
except IndexError:
enable = False
if not self.amount_e.get_amount():
enable = False
self.ok_button.setEnabled(enable)
def on_suggest(self):
self.network.start_gossip()