electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 9d83dea0dcace1eded930308c050d143cf9df4ce
parent 5f6f7da2a1be473a34a125509413d95475011e6a
Author: ThomasV <thomasv@electrum.org>
Date:   Mon,  9 Dec 2019 10:57:14 +0100

Merge pull request #5822 from SomberNight/201912_qt_receive_tab_address

qt receive tab: show plain bitcoin address
Diffstat:
Melectrum/gui/qt/address_list.py | 2+-
Melectrum/gui/qt/main_window.py | 77++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Melectrum/gui/qt/request_list.py | 9++++++---
Melectrum/plugins/hw_wallet/qt.py | 7-------
4 files changed, 57 insertions(+), 38 deletions(-)

diff --git a/electrum/gui/qt/address_list.py b/electrum/gui/qt/address_list.py @@ -227,7 +227,7 @@ class AddressList(MyTreeView): menu.addAction(_('Details'), lambda: self.parent.show_address(addr)) persistent = QPersistentModelIndex(addr_idx) menu.addAction(_("Edit {}").format(addr_column_title), lambda p=persistent: self.edit(QModelIndex(p))) - menu.addAction(_("Request payment"), lambda: self.parent.receive_at(addr)) + #menu.addAction(_("Request payment"), lambda: self.parent.receive_at(addr)) if self.wallet.can_export(): menu.addAction(_("Private key"), lambda: self.parent.show_private_key(addr)) if not is_multisig and not self.wallet.is_watching_only(): diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -38,7 +38,7 @@ import queue import asyncio from typing import Optional, TYPE_CHECKING, Sequence, List, Union -from PyQt5.QtGui import QPixmap, QKeySequence, QIcon, QCursor +from PyQt5.QtGui import QPixmap, QKeySequence, QIcon, QCursor, QFont from PyQt5.QtCore import Qt, QRect, QStringListModel, QSize, pyqtSignal from PyQt5.QtWidgets import (QMessageBox, QComboBox, QSystemTrayIcon, QTabWidget, QMenuBar, QFileDialog, QCheckBox, QLabel, @@ -89,7 +89,7 @@ from .util import (read_QIcon, ColorScheme, text_dialog, icon_path, WaitingDialo CloseButton, HelpButton, MessageBoxMixin, EnterButton, import_meta_gui, export_meta_gui, filename_field, address_field, char_width_in_lineedit, webopen, - TRANSACTION_FILE_EXTENSION_FILTER) + TRANSACTION_FILE_EXTENSION_FILTER, MONOSPACE_FONT) from .util import ButtonsTextEdit from .installwizard import WIF_HELP_TEXT from .history_list import HistoryList, HistoryModel @@ -1003,18 +1003,36 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): buttons.addWidget(self.create_lightning_invoice_button) grid.addLayout(buttons, 4, 3, 1, 2) - self.receive_address_e = ButtonsTextEdit() - self.receive_address_e.addCopyButton(self.app) - self.receive_address_e.setReadOnly(True) - self.receive_address_e.textChanged.connect(self.update_receive_qr) - self.receive_address_e.textChanged.connect(self.update_receive_address_styling) - self.receive_address_e.setFocusPolicy(Qt.ClickFocus) + self.receive_payreq_e = ButtonsTextEdit() + self.receive_payreq_e.addCopyButton(self.app) + self.receive_payreq_e.setReadOnly(True) + self.receive_payreq_e.textChanged.connect(self.update_receive_qr) + self.receive_payreq_e.setFocusPolicy(Qt.ClickFocus) - self.receive_qr = QRCodeWidget(fixedSize=230) + self.receive_qr = QRCodeWidget(fixedSize=220) self.receive_qr.mouseReleaseEvent = lambda x: self.toggle_qr_window() self.receive_qr.enterEvent = lambda x: self.app.setOverrideCursor(QCursor(Qt.PointingHandCursor)) self.receive_qr.leaveEvent = lambda x: self.app.setOverrideCursor(QCursor(Qt.ArrowCursor)) + def on_receive_address_changed(): + addr = str(self.receive_address_e.text()) + self.receive_address_widgets.setVisible(bool(addr)) + + msg = _('Bitcoin address where the payment should be received. Note that each payment request uses a different Bitcoin address.') + receive_address_label = HelpLabel(_('Receiving address'), msg) + + self.receive_address_e = ButtonsTextEdit() + self.receive_address_e.setFont(QFont(MONOSPACE_FONT)) + self.receive_address_e.addCopyButton(self.app) + self.receive_address_e.setReadOnly(True) + self.receive_address_e.textChanged.connect(on_receive_address_changed) + self.receive_address_e.textChanged.connect(self.update_receive_address_styling) + self.receive_address_e.setMinimumHeight(6 * char_width_in_lineedit()) + self.receive_address_e.setMaximumHeight(10 * char_width_in_lineedit()) + qr_show = lambda: self.show_qrcode(str(self.receive_address_e.text()), _('Receiving address'), parent=self) + qr_icon = "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png" + self.receive_address_e.addButton(qr_icon, qr_show, _("Show as QR code")) + self.receive_requests_label = QLabel(_('Incoming payments')) from .request_list import RequestList @@ -1025,14 +1043,29 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): vbox_g.addLayout(grid) vbox_g.addStretch() - self.receive_widgets = QTabWidget() - self.receive_widgets.addTab(self.receive_qr, 'QR Code') - self.receive_widgets.addTab(self.receive_address_e, 'Text') + receive_tabbed_widgets = QTabWidget() + receive_tabbed_widgets.addTab(self.receive_qr, 'QR Code') + receive_tabbed_widgets.addTab(self.receive_payreq_e, 'Text') + + vbox_receive_address = QVBoxLayout() + vbox_receive_address.setContentsMargins(0, 0, 0, 0) + vbox_receive_address.setSpacing(0) + vbox_receive_address.addWidget(receive_address_label) + vbox_receive_address.addWidget(self.receive_address_e) + self.receive_address_widgets = QWidget() + self.receive_address_widgets.setLayout(vbox_receive_address) + size_policy = self.receive_address_widgets.sizePolicy() + size_policy.setRetainSizeWhenHidden(True) + self.receive_address_widgets.setSizePolicy(size_policy) + + vbox_receive = QVBoxLayout() + vbox_receive.addWidget(receive_tabbed_widgets) + vbox_receive.addWidget(self.receive_address_widgets) hbox = QHBoxLayout() hbox.addLayout(vbox_g) hbox.addStretch() - hbox.addWidget(self.receive_widgets) + hbox.addLayout(vbox_receive) w = QWidget() w.searchable_list = self.request_list @@ -1044,6 +1077,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): vbox.addWidget(self.request_list) vbox.setStretchFactor(self.request_list, 1000) + on_receive_address_changed() + return w def delete_request(self, key): @@ -1137,6 +1172,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.saved = True def clear_receive_tab(self): + self.receive_payreq_e.setText('') self.receive_address_e.setText('') self.receive_message_e.setText('') self.receive_amount_e.setAmount(None) @@ -1164,14 +1200,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): def show_receive_tab(self): self.tabs.setCurrentIndex(self.tabs.indexOf(self.receive_tab)) - def receive_at(self, addr): - if not bitcoin.is_address(addr): - return - self.show_receive_tab() - self.receive_address_e.setText(addr) - def update_receive_qr(self): - uri = str(self.receive_address_e.text()) + uri = str(self.receive_payreq_e.text()) if maybe_extract_bolt11_invoice(uri): # encode lightning invoices as uppercase so QR encoding can use # alphanumeric mode; resulting in smaller QR codes @@ -1182,13 +1212,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): def update_receive_address_styling(self): addr = str(self.receive_address_e.text()) - # note: 'addr' could be ln invoice or BIP21 URI - try: - uri = util.parse_URI(addr) - except InvalidBitcoinURI: - pass - else: - addr = uri.get('address') if is_address(addr) and self.wallet.is_used(addr): self.receive_address_e.setStyleSheet(ColorScheme.RED.as_stylesheet(True)) self.receive_address_e.setToolTip(_("This address has already been used. " diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py @@ -83,9 +83,12 @@ class RequestList(MyTreeView): if req is None: self.update() return - is_lightning = request_type == PR_TYPE_LN - text = req.get('invoice') if is_lightning else req.get('URI') - self.parent.receive_address_e.setText(text) + if request_type == PR_TYPE_LN: + self.parent.receive_payreq_e.setText(req.get('invoice')) + self.parent.receive_address_e.setText('') + else: + self.parent.receive_payreq_e.setText(req.get('URI')) + self.parent.receive_address_e.setText(req['address']) def refresh_status(self): m = self.model() diff --git a/electrum/plugins/hw_wallet/qt.py b/electrum/plugins/hw_wallet/qt.py @@ -263,13 +263,6 @@ class QtPluginBase(object): def show_address(): addr = str(receive_address_e.text()) - # note: 'addr' could be ln invoice or BIP21 URI - try: - uri = parse_URI(addr) - except InvalidBitcoinURI: - pass - else: - addr = uri.get('address') keystore.thread.add(partial(plugin.show_address, wallet, addr, keystore)) dev_name = f"{plugin.device} ({keystore.label})" receive_address_e.addButton("eye1.png", show_address, _("Show on {}").format(dev_name))