1
0

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).
This commit is contained in:
f321x
2025-07-20 14:31:34 +02:00
parent ba07ca3ab9
commit 225ff4aba6

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()