From 96f7d91e3a440ceccad0abb3c385b4c580b45bc7 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 23 Oct 2024 16:09:28 +0200 Subject: [PATCH] qml: improve validation of pubkey/connectstring --- .../gui/qml/components/OpenChannelDialog.qml | 24 ++++++++++++++++--- electrum/gui/qml/qeapp.py | 3 ++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/electrum/gui/qml/components/OpenChannelDialog.qml b/electrum/gui/qml/components/OpenChannelDialog.qml index dc3a95fe0..b1a3df358 100644 --- a/electrum/gui/qml/components/OpenChannelDialog.qml +++ b/electrum/gui/qml/components/OpenChannelDialog.qml @@ -82,6 +82,11 @@ ElDialog { font.family: FixedFont wrapMode: Text.Wrap placeholderText: qsTr('Paste or scan node uri/pubkey') + inputMethodHints: Qt.ImhSensitiveData | Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase + onTextChanged: { + if (activeFocus) + channelopener.connectStr = text + } onActiveFocusChanged: { if (!activeFocus) channelopener.connectStr = text @@ -96,9 +101,17 @@ ElDialog { icon.height: constants.iconSizeMedium icon.width: constants.iconSizeMedium onClicked: { - if (channelopener.validateConnectString(AppController.clipboardToText())) { - channelopener.connectStr = AppController.clipboardToText() + var cliptext = AppController.clipboardToText() + if (!cliptext) + return + if (channelopener.validateConnectString(cliptext)) { + channelopener.connectStr = cliptext node.text = channelopener.connectStr + } else { + var dialog = app.messageDialog.createObject(app, { + text: qsTr('Invalid node-id or connect string') + }) + dialog.open() } } } @@ -109,12 +122,17 @@ ElDialog { scale: 1.2 onClicked: { var dialog = app.scanDialog.createObject(app, { - hint: qsTr('Scan a channel connect string') + hint: qsTr('Scan a node-id or a connect string') }) dialog.onFound.connect(function() { if (channelopener.validateConnectString(dialog.scanData)) { channelopener.connectStr = dialog.scanData node.text = channelopener.connectStr + } else { + var errdialog = app.messageDialog.createObject(app, { + text: qsTr('Invalid node-id or connect string') + }) + errdialog.open() } dialog.close() }) diff --git a/electrum/gui/qml/qeapp.py b/electrum/gui/qml/qeapp.py index bdbec8700..f0c1197f8 100644 --- a/electrum/gui/qml/qeapp.py +++ b/electrum/gui/qml/qeapp.py @@ -240,7 +240,8 @@ class QEAppController(BaseCrashReporter, QObject): @pyqtSlot(result='QString') def clipboardToText(self): - return QGuiApplication.clipboard().text() + clip = QGuiApplication.clipboard() + return clip.text() if clip.mimeData().hasText() else '' @pyqtSlot(str, result=QObject) def plugin(self, plugin_name):