simplify get_label
This commit is contained in:
parent
2990b1e865
commit
9d3162b1a1
|
@ -332,7 +332,7 @@ def get_history_values(n):
|
||||||
except Exception:
|
except Exception:
|
||||||
time_str = 'pending'
|
time_str = 'pending'
|
||||||
conf_str = 'v' if conf else 'o'
|
conf_str = 'v' if conf else 'o'
|
||||||
label, is_default_label = wallet.get_label(tx_hash)
|
label = wallet.get_label(tx_hash)
|
||||||
label = label.replace('<','').replace('>','')
|
label = label.replace('<','').replace('>','')
|
||||||
values.append((conf_str, ' ' + time_str, ' ' + format_satoshis(value, True), ' ' + label))
|
values.append((conf_str, ' ' + time_str, ' ' + format_satoshis(value, True), ' ' + label))
|
||||||
|
|
||||||
|
|
|
@ -1185,7 +1185,7 @@ class ElectrumWindow:
|
||||||
time_str = 'pending'
|
time_str = 'pending'
|
||||||
conf_icon = Gtk.STOCK_EXECUTE
|
conf_icon = Gtk.STOCK_EXECUTE
|
||||||
|
|
||||||
label, is_default_label = self.wallet.get_label(tx_hash)
|
label = self.wallet.get_label(tx_hash)
|
||||||
tooltip = tx_hash + "\n%d confirmations"%conf if tx_hash else ''
|
tooltip = tx_hash + "\n%d confirmations"%conf if tx_hash else ''
|
||||||
details = self.get_tx_details(tx_hash)
|
details = self.get_tx_details(tx_hash)
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ class HistoryScreen(CScreen):
|
||||||
def label_dialog(self, obj):
|
def label_dialog(self, obj):
|
||||||
from dialogs.label_dialog import LabelDialog
|
from dialogs.label_dialog import LabelDialog
|
||||||
key = obj.tx_hash
|
key = obj.tx_hash
|
||||||
text = self.app.wallet.get_label(key)[0]
|
text = self.app.wallet.get_label(key)
|
||||||
def callback(text):
|
def callback(text):
|
||||||
self.app.wallet.set_label(key, text)
|
self.app.wallet.set_label(key, text)
|
||||||
self.update()
|
self.update()
|
||||||
|
@ -127,12 +127,7 @@ class HistoryScreen(CScreen):
|
||||||
else:
|
else:
|
||||||
icon = "atlas://gui/kivy/theming/light/confirmed"
|
icon = "atlas://gui/kivy/theming/light/confirmed"
|
||||||
|
|
||||||
if tx_hash:
|
label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs')
|
||||||
label, is_default_label = self.app.wallet.get_label(tx_hash)
|
|
||||||
else:
|
|
||||||
label = _('Pruned transaction outputs')
|
|
||||||
is_default_label = False
|
|
||||||
|
|
||||||
date = timestamp_to_datetime(timestamp)
|
date = timestamp_to_datetime(timestamp)
|
||||||
rate = run_hook('history_rate', date)
|
rate = run_hook('history_rate', date)
|
||||||
if self.app.fiat_unit:
|
if self.app.fiat_unit:
|
||||||
|
@ -430,9 +425,7 @@ class RequestsScreen(CScreen):
|
||||||
signature = req.get('sig')
|
signature = req.get('sig')
|
||||||
ci = Factory.RequestItem()
|
ci = Factory.RequestItem()
|
||||||
ci.address = req['address']
|
ci.address = req['address']
|
||||||
label, is_default = self.app.wallet.get_label(address)
|
ci.memo = self.app.wallet.get_label(address)
|
||||||
if label:
|
|
||||||
ci.memo = label
|
|
||||||
status = req.get('status')
|
status = req.get('status')
|
||||||
if status == PR_PAID:
|
if status == PR_PAID:
|
||||||
ci.icon = "atlas://gui/kivy/theming/light/confirmed"
|
ci.icon = "atlas://gui/kivy/theming/light/confirmed"
|
||||||
|
|
|
@ -74,7 +74,7 @@ class HistoryWidget(MyTreeWidget):
|
||||||
icon, time_str = self.get_icon(conf, timestamp)
|
icon, time_str = self.get_icon(conf, timestamp)
|
||||||
v_str = self.parent.format_amount(value, True, whitespaces=True)
|
v_str = self.parent.format_amount(value, True, whitespaces=True)
|
||||||
balance_str = self.parent.format_amount(balance, whitespaces=True)
|
balance_str = self.parent.format_amount(balance, whitespaces=True)
|
||||||
label, is_default_label = self.wallet.get_label(tx_hash)
|
label = self.wallet.get_label(tx_hash)
|
||||||
entry = ['', tx_hash, time_str, label, v_str, balance_str]
|
entry = ['', tx_hash, time_str, label, v_str, balance_str]
|
||||||
run_hook('history_tab_update', tx, entry)
|
run_hook('history_tab_update', tx, entry)
|
||||||
item = QTreeWidgetItem(entry)
|
item = QTreeWidgetItem(entry)
|
||||||
|
@ -88,8 +88,6 @@ class HistoryWidget(MyTreeWidget):
|
||||||
item.setForeground(4, QBrush(QColor("#BC1E1E")))
|
item.setForeground(4, QBrush(QColor("#BC1E1E")))
|
||||||
if tx_hash:
|
if tx_hash:
|
||||||
item.setData(0, Qt.UserRole, tx_hash)
|
item.setData(0, Qt.UserRole, tx_hash)
|
||||||
if is_default_label:
|
|
||||||
item.setForeground(3, QBrush(QColor('grey')))
|
|
||||||
self.insertTopLevelItem(0, item)
|
self.insertTopLevelItem(0, item)
|
||||||
if current_tx == tx_hash:
|
if current_tx == tx_hash:
|
||||||
self.setCurrentItem(item)
|
self.setCurrentItem(item)
|
||||||
|
|
|
@ -2435,7 +2435,7 @@ class ElectrumWindow(QMainWindow, PrintError):
|
||||||
value_string = '--'
|
value_string = '--'
|
||||||
|
|
||||||
if tx_hash:
|
if tx_hash:
|
||||||
label, is_default_label = wallet.get_label(tx_hash)
|
label = wallet.get_label(tx_hash)
|
||||||
label = label.encode('utf-8')
|
label = label.encode('utf-8')
|
||||||
else:
|
else:
|
||||||
label = ""
|
label = ""
|
||||||
|
|
|
@ -173,7 +173,7 @@ class TxDialog(QDialog):
|
||||||
status = _("Signed")
|
status = _("Signed")
|
||||||
|
|
||||||
if tx_hash in self.wallet.transactions.keys():
|
if tx_hash in self.wallet.transactions.keys():
|
||||||
desc, is_default = self.wallet.get_label(tx_hash)
|
desc = self.wallet.get_label(tx_hash)
|
||||||
conf, timestamp = self.wallet.get_confirmations(tx_hash)
|
conf, timestamp = self.wallet.get_confirmations(tx_hash)
|
||||||
if timestamp:
|
if timestamp:
|
||||||
time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
|
time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
|
||||||
|
|
|
@ -383,12 +383,6 @@ class MyTreeWidget(QTreeWidget):
|
||||||
key = str(item.data(0, Qt.UserRole).toString())
|
key = str(item.data(0, Qt.UserRole).toString())
|
||||||
text = unicode(item.text(column))
|
text = unicode(item.text(column))
|
||||||
self.parent.wallet.set_label(key, text)
|
self.parent.wallet.set_label(key, text)
|
||||||
if text:
|
|
||||||
item.setForeground(column, QBrush(QColor('black')))
|
|
||||||
else:
|
|
||||||
text = self.parent.wallet.get_default_label(key)
|
|
||||||
item.setText(column, text)
|
|
||||||
item.setForeground(column, QBrush(QColor('gray')))
|
|
||||||
self.parent.history_list.update()
|
self.parent.history_list.update()
|
||||||
self.parent.update_completions()
|
self.parent.update_completions()
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ class ElectrumGui:
|
||||||
else:
|
else:
|
||||||
time_str = 'pending'
|
time_str = 'pending'
|
||||||
|
|
||||||
label, is_default_label = self.wallet.get_label(tx_hash)
|
label = self.wallet.get_label(tx_hash)
|
||||||
messages.append( format_str%( time_str, label, format_satoshis(value, whitespaces=True), format_satoshis(balance, whitespaces=True) ) )
|
messages.append( format_str%( time_str, label, format_satoshis(value, whitespaces=True), format_satoshis(balance, whitespaces=True) ) )
|
||||||
|
|
||||||
self.print_list(messages[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance")))
|
self.print_list(messages[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance")))
|
||||||
|
|
|
@ -116,7 +116,7 @@ class ElectrumGui:
|
||||||
else:
|
else:
|
||||||
time_str = 'pending'
|
time_str = 'pending'
|
||||||
|
|
||||||
label, is_default_label = self.wallet.get_label(tx_hash)
|
label = self.wallet.get_label(tx_hash)
|
||||||
if len(label) > 40:
|
if len(label) > 40:
|
||||||
label = label[0:37] + '...'
|
label = label[0:37] + '...'
|
||||||
self.history.append( format_str%( time_str, label, format_satoshis(value, whitespaces=True), format_satoshis(balance, whitespaces=True) ) )
|
self.history.append( format_str%( time_str, label, format_satoshis(value, whitespaces=True), format_satoshis(balance, whitespaces=True) ) )
|
||||||
|
|
|
@ -867,24 +867,9 @@ class Abstract_Wallet(PrintError):
|
||||||
|
|
||||||
return h2
|
return h2
|
||||||
|
|
||||||
|
|
||||||
def get_label(self, tx_hash):
|
def get_label(self, tx_hash):
|
||||||
label = self.labels.get(tx_hash)
|
label = self.labels.get(tx_hash, '')
|
||||||
is_default = (label == '') or (label is None)
|
return label
|
||||||
if is_default:
|
|
||||||
label = self.get_default_label(tx_hash)
|
|
||||||
return label, is_default
|
|
||||||
|
|
||||||
def get_default_label(self, tx_hash):
|
|
||||||
if self.txi.get(tx_hash) == {}:
|
|
||||||
d = self.txo.get(tx_hash, {})
|
|
||||||
labels = []
|
|
||||||
for addr in d.keys():
|
|
||||||
label = self.labels.get(addr)
|
|
||||||
if label:
|
|
||||||
labels.append(label)
|
|
||||||
return ', '.join(labels)
|
|
||||||
return ''
|
|
||||||
|
|
||||||
def fee_per_kb(self, config):
|
def fee_per_kb(self, config):
|
||||||
b = config.get('dynamic_fees')
|
b = config.get('dynamic_fees')
|
||||||
|
|
Loading…
Reference in New Issue