commit 6b4edc650abb66fcd1190452a0e2ad7e89d1e8e4
parent 72950bf3794b2a2dce67c152ebc8fadb8d31b8a1
Author: SomberNight <somber.night@protonmail.com>
Date: Mon, 31 Aug 2020 20:55:14 +0200
qt history: fixes for tx context-menu "View invoice" if more than one
fixes #6516
coalesce "View invoice" options into submenu if there are multiple;
also make sure lambda uses bound argument
Diffstat:
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py
@@ -675,7 +675,6 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
tx_URL = block_explorer_URL(self.config, 'tx', tx_hash)
tx_details = self.wallet.get_tx_info(tx)
is_unconfirmed = tx_details.tx_mined_status.height <= 0
- invoice_keys = self.wallet.get_relevant_invoice_keys_for_tx(tx)
menu = QMenu()
if tx_details.can_remove:
menu.addAction(_("Remove"), lambda: self.remove_local_tx(tx_hash))
@@ -699,10 +698,13 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
child_tx = self.wallet.cpfp(tx, 0)
if child_tx:
menu.addAction(_("Child pays for parent"), lambda: self.parent.cpfp(tx, child_tx))
- for key in invoice_keys:
- invoice = self.parent.wallet.get_invoice(key)
- if invoice:
- menu.addAction(_("View invoice"), lambda: self.parent.show_onchain_invoice(invoice))
+ invoices = self.wallet.get_relevant_invoices_for_tx(tx)
+ if len(invoices) == 1:
+ menu.addAction(_("View invoice"), lambda inv=invoices[0]: self.parent.show_onchain_invoice(inv))
+ elif len(invoices) > 1:
+ menu_invs = menu.addMenu(_("Related invoices"))
+ for inv in invoices:
+ menu_invs.addAction(_("View invoice"), lambda inv=inv: self.parent.show_onchain_invoice(inv))
if tx_URL:
menu.addAction(_("View on block explorer"), lambda: webopen(tx_URL))
menu.exec_(self.viewport().mapToGlobal(position))
diff --git a/electrum/wallet.py b/electrum/wallet.py
@@ -764,7 +764,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
def export_invoices(self, path):
write_json_file(path, list(self.invoices.values()))
- def get_relevant_invoice_keys_for_tx(self, tx: Transaction) -> Set[str]:
+ def _get_relevant_invoice_keys_for_tx(self, tx: Transaction) -> Set[str]:
relevant_invoice_keys = set()
for txout in tx.outputs():
for invoice_key in self._invoices_from_scriptpubkey_map.get(txout.scriptpubkey, set()):
@@ -773,6 +773,14 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
relevant_invoice_keys.add(invoice_key)
return relevant_invoice_keys
+ def get_relevant_invoices_for_tx(self, tx: Transaction) -> Sequence[OnchainInvoice]:
+ invoice_keys = self._get_relevant_invoice_keys_for_tx(tx)
+ invoices = [self.get_invoice(key) for key in invoice_keys]
+ invoices = [inv for inv in invoices if inv] # filter out None
+ for inv in invoices:
+ assert isinstance(inv, OnchainInvoice), f"unexpected type {type(inv)}"
+ return invoices
+
def _prepare_onchain_invoice_paid_detection(self):
# scriptpubkey -> list(invoice_keys)
self._invoices_from_scriptpubkey_map = defaultdict(set) # type: Dict[bytes, Set[str]]
@@ -811,10 +819,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
tx_hash = tx.txid()
with self.transaction_lock:
labels = []
- for invoice_key in self.get_relevant_invoice_keys_for_tx(tx):
- invoice = self.invoices.get(invoice_key)
- if invoice is None: continue
- assert isinstance(invoice, OnchainInvoice)
+ for invoice in self.get_relevant_invoices_for_tx(tx):
if invoice.message:
labels.append(invoice.message)
if labels: