What changed, and why it matters
This commit is a simple code cleanup: it moves a small helper function that creates a colored icon from a public key from one file to a shared utility file. There is no change in behavior, no bug fix, and no security relevance.
No action required. This is a benign refactoring with no security implications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit relocates pubkey_to_q_icon() from SwapServerDialog in electrum/gui/qt/swap_dialog.py to electrum/gui/qt/util.py. It updates the two call sites in confirm_tx_dialog.py and swap_dialog.py to import and call the function from the new location. The function logic remains identical: it maps a server public key to an RGB color via pubkey_to_rgb_color() and returns a solid-color QIcon. No functional or security changes are introduced.
Changed components
electrum/gui/qt/confirm_tx_dialog.pyelectrum/gui/qt/swap_dialog.pyelectrum/gui/qt/util.pyInspect captured patch +16 / −12
diff --git a/electrum/gui/qt/confirm_tx_dialog.py b/electrum/gui/qt/confirm_tx_dialog.py
index 2722417..3935db7 100644
--- a/electrum/gui/qt/confirm_tx_dialog.py
+++ b/electrum/gui/qt/confirm_tx_dialog.py
@@ -47,7 +47,8 @@ from electrum.submarine_swaps import NostrTransport, HttpTransport
from .seed_dialog import seed_warning_msg
from .util import (WindowModalDialog, ColorScheme, HelpLabel, Buttons, CancelButton, WWLabel,
- read_QIcon, debug_widget_layouts, qt_event_listener, QtEventListener, IconLabel)
+ read_QIcon, debug_widget_layouts, qt_event_listener, QtEventListener, IconLabel,
+ pubkey_to_q_icon)
from .transaction_dialog import TxSizeLabel, TxFiatLabel, TxInOutWidget
from .fee_slider import FeeSlider, FeeComboBox
from .amountedit import FeerateEdit, BTCAmountEdit
@@ -885,7 +886,7 @@ class TxEditor(WindowModalDialog, QtEventListener, Logger):
self.server_button.setEnabled(True)
if self.config.SWAPSERVER_NPUB:
pubkey = from_nip19(self.config.SWAPSERVER_NPUB)['object'].hex()
- self.server_button.setIcon(SwapServerDialog.pubkey_to_q_icon(pubkey))
+ self.server_button.setIcon(pubkey_to_q_icon(pubkey))
self.server_button.setText(
f' {len(self.swap_transport.get_recent_offers())} ' +
(_('providers') if len(self.swap_transport.get_recent_offers()) != 1 else _('provider'))
diff --git a/electrum/gui/qt/swap_dialog.py b/electrum/gui/qt/swap_dialog.py
index 859da78..2a612e9 100644
--- a/electrum/gui/qt/swap_dialog.py
+++ b/electrum/gui/qt/swap_dialog.py
@@ -13,12 +13,13 @@ from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates, UserCancelled
from electrum.bitcoin import DummyAddress
from electrum.transaction import PartialTxOutput, PartialTransaction
from electrum.fee_policy import FeePolicy
-from electrum.submarine_swaps import NostrTransport, pubkey_to_rgb_color
+from electrum.submarine_swaps import NostrTransport
from electrum.gui import messages
from . import util
from .util import (WindowModalDialog, Buttons, OkButton, CancelButton,
- EnterButton, ColorScheme, WWLabel, read_QIcon, IconLabel, char_width_in_lineedit)
+ EnterButton, ColorScheme, WWLabel, read_QIcon, IconLabel, char_width_in_lineedit,
+ pubkey_to_q_icon)
from .util import qt_event_listener, QtEventListener
from .amountedit import BTCAmountEdit
from .fee_slider import FeeSlider, FeeComboBox
@@ -301,7 +302,7 @@ class SwapDialog(WindowModalDialog, QtEventListener):
self.needs_tx_update = True
# update icon
pubkey = from_nip19(self.config.SWAPSERVER_NPUB)['object'].hex() if self.config.SWAPSERVER_NPUB else ''
- self.server_button.setIcon(SwapServerDialog.pubkey_to_q_icon(pubkey))
+ self.server_button.setIcon(pubkey_to_q_icon(pubkey))
def get_client_swap_limits_sat(self) -> Tuple[int, int]:
"""Returns the (min, max) client swap limits in sat."""
@@ -531,13 +532,7 @@ class SwapServerDialog(WindowModalDialog, QtEventListener):
labels[self.Columns.LAST_SEEN] = age(x.timestamp)
item = QTreeWidgetItem(labels)
item.setData(self.Columns.PUBKEY, ROLE_NPUB, x.server_npub)
- item.setIcon(self.Columns.PUBKEY, self.pubkey_to_q_icon(x.server_pubkey))
+ item.setIcon(self.Columns.PUBKEY, pubkey_to_q_icon(x.server_pubkey))
items.append(item)
self.servers_list.insertTopLevelItems(0, items)
- @staticmethod
- def pubkey_to_q_icon(server_pubkey: str) -> QIcon:
- color = QColor(*pubkey_to_rgb_color(server_pubkey))
- color_pixmap = QPixmap(100, 100)
- color_pixmap.fill(color)
- return QIcon(color_pixmap)
diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py
index aad0db5..3f11a60 100644
--- a/electrum/gui/qt/util.py
+++ b/electrum/gui/qt/util.py
@@ -26,6 +26,7 @@ from electrum.util import (FileImportFailed, FileExportFailed, resource_path, Ev
from electrum.invoices import (PR_UNPAID, PR_PAID, PR_EXPIRED, PR_INFLIGHT, PR_UNKNOWN, PR_FAILED, PR_ROUTING,
PR_UNCONFIRMED, PR_BROADCASTING, PR_BROADCAST)
from electrum.qrreader import MissingQrDetectionLib, QrCodeResult
+from electrum.submarine_swaps import pubkey_to_rgb_color
from electrum.gui.common_qt.util import TaskThread
@@ -726,6 +727,13 @@ def get_icon_camera() -> QIcon:
return read_QIcon(name)
+def pubkey_to_q_icon(server_pubkey: str) -> QIcon:
+ color = QColor(*pubkey_to_rgb_color(server_pubkey))
+ color_pixmap = QPixmap(100, 100)
+ color_pixmap.fill(color)
+ return QIcon(color_pixmap)
+
+
def add_input_actions_to_context_menu(gih: 'GenericInputHandler', m: QMenu) -> None:
if gih.on_qr_from_camera_input_btn:
m.addAction(get_icon_camera(), _("Read QR code with camera"), gih.on_qr_from_camera_input_btn)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.