diff --git a/electrum/gui/qt/__init__.py b/electrum/gui/qt/__init__.py index 329083301..fbf0a61e5 100644 --- a/electrum/gui/qt/__init__.py +++ b/electrum/gui/qt/__init__.py @@ -382,12 +382,11 @@ class ElectrumGui(BaseElectrumGui, Logger): path = os.path.join(wallet_dir, filename) self.start_new_window(path, uri=None, force_wizard=True) return - if uri: - window.handle_payment_identifier(uri) window.bring_to_top() window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive) - window.activateWindow() + if uri: + window.handle_payment_identifier(uri) return window def _start_wizard_to_select_or_create_wallet(self, path) -> Optional[Abstract_Wallet]: diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index e938b4494..cfd08d2ec 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -58,7 +58,7 @@ from electrum.i18n import _ from electrum.util import (format_time, get_asyncio_loop, UserCancelled, profiler, bh2u, bfh, InvalidPassword, - UserFacingException, + UserFacingException, FailedToParsePaymentIdentifier, get_new_wallet_name, send_exception_to_crash_reporter, AddTransactionException, BITCOIN_BIP21_URI_SCHEME, os_chmod) from electrum.invoices import PR_PAID, Invoice @@ -1316,7 +1316,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener): return clayout.selected_index() def handle_payment_identifier(self, *args, **kwargs): - self.send_tab.handle_payment_identifier(*args, **kwargs) + try: + self.send_tab.handle_payment_identifier(*args, **kwargs) + except FailedToParsePaymentIdentifier as e: + self.show_error(str(e)) def set_frozen_state_of_addresses(self, addrs, freeze: bool): self.wallet.set_frozen_state_of_addresses(addrs, freeze) diff --git a/electrum/gui/qt/paytoedit.py b/electrum/gui/qt/paytoedit.py index 84305c3d7..75d8b89ae 100644 --- a/electrum/gui/qt/paytoedit.py +++ b/electrum/gui/qt/paytoedit.py @@ -32,7 +32,7 @@ from PyQt5.QtGui import QFontMetrics, QFont from PyQt5.QtWidgets import QApplication from electrum import bitcoin -from electrum.util import bfh, parse_max_spend +from electrum.util import bfh, parse_max_spend, FailedToParsePaymentIdentifier from electrum.transaction import PartialTxOutput from electrum.bitcoin import opcodes, construct_script from electrum.logging import Logger @@ -212,7 +212,7 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, Logger): except LNURLError as e: self.logger.exception("") self.send_tab.show_error(e) - except ValueError: + except FailedToParsePaymentIdentifier: pass else: return diff --git a/electrum/gui/qt/send_tab.py b/electrum/gui/qt/send_tab.py index ceeaa4a9b..a3fe4966a 100644 --- a/electrum/gui/qt/send_tab.py +++ b/electrum/gui/qt/send_tab.py @@ -15,7 +15,7 @@ from electrum import util, paymentrequest from electrum import lnutil from electrum.plugin import run_hook from electrum.i18n import _ -from electrum.util import (get_asyncio_loop, bh2u, +from electrum.util import (get_asyncio_loop, bh2u, FailedToParsePaymentIdentifier, InvalidBitcoinURI, maybe_extract_lightning_payment_identifier, NotEnoughFunds, NoDynamicFeeEstimates, InvoiceError, parse_max_spend) from electrum.invoices import PR_PAID, Invoice @@ -477,7 +477,8 @@ class SendTab(QWidget, MessageBoxMixin, Logger): elif text.lower().startswith(util.BITCOIN_BIP21_URI_SCHEME + ':'): self.set_bip21(text, can_use_network=can_use_network) else: - raise ValueError("Could not handle payment identifier.") + truncated_text = f"{text[:100]}..." if len(text) > 100 else text + raise FailedToParsePaymentIdentifier(f"Could not handle payment identifier:\n{truncated_text}") # update fiat amount self.amount_e.textEdited.emit("") self.window.show_send_tab() diff --git a/electrum/util.py b/electrum/util.py index b0859710c..94cc06f78 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -1111,6 +1111,10 @@ def is_uri(data: str) -> bool: return False +class FailedToParsePaymentIdentifier(Exception): + pass + + # Python bug (http://bugs.python.org/issue1927) causes raw_input # to be redirected improperly between stdin/stderr on Unix systems #TODO: py3