1
0

qt: ServerWidget/wizard: validate server_e

The `ServerWidget` didn't validate the input of server_e, which allowed
the user to enter an invalid server connection string and exit the
dialog without knowing they entered an invalid string.
In the wizard this behavior is very misleading as the user explicitly
wanted to use a custom server, can click next after entering an invalid
server, and we will just silently fall back to automatic server selection.

This change will disable the "Next" button in the wizard if an invalid
address has been entered and show a red background in the server_e while
the input is not valid, so the user clearly sees that this input is not
going to be used.
This commit is contained in:
f321x
2026-01-26 12:07:04 +01:00
parent cfe2a57f2c
commit c3d1b2046a
2 changed files with 17 additions and 1 deletions

View File

@@ -361,6 +361,8 @@ class ServerWidget(QWidget, QtEventListener):
ConnectMode.ONESERVER: messages.MSG_CONNECTMODE_ONESERVER,
}
server_e_valid = pyqtSignal(bool)
def __init__(self, network: Network, parent=None):
super().__init__(parent)
self.network = network
@@ -390,6 +392,7 @@ class ServerWidget(QWidget, QtEventListener):
grid.addWidget(self.connect_combo, 0, 1, 1, 3)
self.server_e = QLineEdit()
self.server_e.textChanged.connect(self.validate_server_e)
self.server_e.editingFinished.connect(self.on_server_settings_changed)
grid.addWidget(QLabel(_('Server') + ':'), 1, 0)
grid.addWidget(self.server_e, 1, 1, 1, 3)
@@ -502,6 +505,7 @@ class ServerWidget(QWidget, QtEventListener):
self.status_label_header, self.status_label, self.status_label_helpbutton,
self.height_label_header, self.height_label, self.height_label_helpbutton]:
item.setVisible(self.network._was_started)
self.validate_server_e()
msg = _('Fork detection disabled') if self.is_one_server() else ''
if self.network._was_started:
# Network was started, so we don't run in initial setup wizard.
@@ -522,6 +526,15 @@ class ServerWidget(QWidget, QtEventListener):
msg += _('Your server is on branch {0} ({1} blocks)').format(name, chain.get_branch_size())
self.split_label.setText(msg)
def validate_server_e(self):
if not self.server_e.isEnabled():
self.server_e.setStyleSheet("")
self.server_e_valid.emit(True)
return
server = ServerAddr.from_str_with_inference(self.server_e.text())
self.server_e.setStyleSheet("background-color: rgba(255, 0, 0, 0.2);" if not server else "")
self.server_e_valid.emit(server is not None)
def update_from_config(self):
auto_connect = self.config.NETWORK_AUTO_CONNECT
one_server = self.config.NETWORK_ONESERVER

View File

@@ -91,7 +91,10 @@ class WCServerConfig(WizardComponent):
WizardComponent.__init__(self, parent, wizard, title=_('Server'))
self.sw = ServerWidget(wizard._daemon.network, self)
self.layout().addWidget(self.sw)
self._valid = True
self.sw.server_e_valid.connect(self.on_server_e_valid)
def on_server_e_valid(self, valid):
self.valid = valid
def apply(self):
self.wizard_data['autoconnect'] = self.sw.server_e.text().strip() == ''