Skip to content

Commit

Permalink
Run history_list_filter hook on updated labels (#1990)
Browse files Browse the repository at this point in the history
* Run history_list_filter hook on updated labels

This way an edited label can be filtered directly instead of during
update of the entire history_list.

This can be seen if someone has CashFusion running and the "Hide
CashFusions" option enabled and proceeds to rename a label to start with
"CashFusion ".
Without this fix the transaction is not hidden until the
wallet is restarted or the "Hide CashFusions" option is toggled off and
on.

* Create itemChanged callback for history_list

* Send None as h_item

This is to avoid a costly wallet.get_history() call.

* Use item.text() instead of item.data()
  • Loading branch information
jonas-lundqvist committed Sep 12, 2020
1 parent fa5a5a4 commit 8a4774c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions gui/qt/history_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, parent):
self.withdrawalBrush = QBrush(QColor("#BC1E1E"))
self.invoiceIcon = QIcon(":icons/seal")
self._item_cache = Weak.ValueDictionary()
self.itemChanged.connect(self.item_changed)

self.has_unknown_balances = False

Expand Down Expand Up @@ -187,8 +188,22 @@ def update_labels(self):
for i in range(child_count):
item = root.child(i)
txid = item.data(0, Qt.UserRole)
label = self.wallet.get_label(txid)
item.setText(3, label)
h_label = self.wallet.get_label(txid)
current_label = item.text(3)
item.setText(3, h_label)
if current_label != h_label:
self.item_changed(item, 3)

def item_changed(self, item, column):
# Run the label of the changed item thru the filter hook
if column != 3:
return

label = item.text(3)
# NB: 'h_item' parameter is None due to performance reasons
should_skip = run_hook("history_list_filter", self, None, label, multi=True) or []
if any(should_skip):
item.setHidden(True)

def update_item(self, tx_hash, height, conf, timestamp):
if not self.wallet: return # can happen on startup if this is called before self.on_update()
Expand Down
1 change: 1 addition & 0 deletions plugins/fusion/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ def on_status(controller):

@hook
def history_list_filter(self, history_list, h_item, label):
# NB: 'h_item' might be None due to performance reasons
if self._hide_history_txs:
return bool(label.startswith("CashFusion ")) # this string is not translated for performance reasons
return None
Expand Down
1 change: 1 addition & 0 deletions plugins/shuffle_deprecated/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ def utxo_list_context_menu_setup(self, utxo_list, menu, selected):

@hook
def history_list_filter(self, history_list, h_item, label):
# NB: 'h_item' might be None due to performance reasons
if self._hide_history_txs:
return bool(label.startswith("Shuffle ") # this string is not translated for performance reasons. _make_label also does not translate this string.
and ( any( x for x in BackgroundShufflingThread.SCALE_ARROWS
Expand Down

0 comments on commit 8a4774c

Please sign in to comment.