From 225ff4aba611a928c13bc198ea187f27c127e69a Mon Sep 17 00:00:00 2001 From: f321x Date: Sun, 20 Jul 2025 14:31:34 +0200 Subject: [PATCH] qt: NewChannelDialog: do some pre-validation for Ok button Do some validation if the user input in `NewChannelDialog` before allowing to click the `Ok` button. This is done to make the UI a bit more intuitive and prevent issues like #10053 in which the user was able to click `Ok` with a empty trampoline node list which raised an `IndexError` (probably on testnet4). --- electrum/gui/qt/new_channel_dialog.py | 28 ++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/electrum/gui/qt/new_channel_dialog.py b/electrum/gui/qt/new_channel_dialog.py index 44bce8a54..85f575d8d 100644 --- a/electrum/gui/qt/new_channel_dialog.py +++ b/electrum/gui/qt/new_channel_dialog.py @@ -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()