Browse Source

move fiat columns show/hide settings from settings_dialog to tab toolbars

master
ThomasV 3 years ago
parent
commit
503776c0de
  1. 27
      electrum/exchange_rate.py
  2. 4
      electrum/gui/qml/qefx.py
  3. 7
      electrum/gui/qml/qetransactionlistmodel.py
  4. 14
      electrum/gui/qt/address_list.py
  5. 38
      electrum/gui/qt/history_list.py
  6. 1
      electrum/gui/qt/main_window.py
  7. 55
      electrum/gui/qt/settings_dialog.py
  8. 6
      electrum/wallet.py

27
electrum/exchange_rate.py

@ -583,7 +583,7 @@ class FxThread(ThreadJob, EventListener):
await self._trigger.wait()
self._trigger.clear()
# we were manually triggered, so get historical rates
if self.is_enabled() and self.show_history():
if self.is_enabled() and self.has_history():
self.exchange.get_historical_rates(self.ccy, self.cache_dir)
except TaskTimeout:
pass
@ -597,26 +597,8 @@ class FxThread(ThreadJob, EventListener):
self.config.set_key('use_exchange_rate', bool(b))
self.trigger_update()
def get_history_config(self, *, allow_none=False):
val = self.config.get('history_rates', None)
if val is None and allow_none:
return None
return bool(val)
def set_history_config(self, b):
self.config.set_key('history_rates', bool(b))
def get_history_capital_gains_config(self):
return bool(self.config.get('history_rates_capital_gains', False))
def set_history_capital_gains_config(self, b):
self.config.set_key('history_rates_capital_gains', bool(b))
def get_fiat_address_config(self):
return bool(self.config.get('fiat_address'))
def set_fiat_address_config(self, b):
self.config.set_key('fiat_address', bool(b))
def has_history(self):
return self.is_enabled() and self.ccy in self.exchange.history_ccys()
def get_currency(self) -> str:
'''Use when dynamic fetching is needed'''
@ -625,9 +607,6 @@ class FxThread(ThreadJob, EventListener):
def config_exchange(self):
return self.config.get('use_exchange', DEFAULT_EXCHANGE)
def show_history(self):
return self.is_enabled() and self.get_history_config() and self.ccy in self.exchange.history_ccys()
def set_currency(self, ccy: str):
self.ccy = ccy
self.config.set_key('currency', ccy, True)

4
electrum/gui/qml/qefx.py

@ -63,12 +63,12 @@ class QEFX(QObject, QtEventListener):
historicRatesChanged = pyqtSignal()
@pyqtProperty(bool, notify=historicRatesChanged)
def historicRates(self):
return self.fx.get_history_config()
return self.fx.config.get('history_rates', True)
@historicRates.setter
def historicRates(self, checked):
if checked != self.historicRates:
self.fx.set_history_config(checked)
self.fx.config.set_key('history_rates', bool(checked))
self.historicRatesChanged.emit()
self.rateSourcesChanged.emit()

7
electrum/gui/qml/qetransactionlistmodel.py

@ -157,8 +157,11 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
return
self._logger.debug('retrieving history')
history = self.wallet.get_full_history(onchain_domain=self.onchain_domain,
include_lightning=self.include_lightning)
history = self.wallet.get_full_history(
onchain_domain=self.onchain_domain,
include_lightning=self.include_lightning,
include_fiat=False,
)
txs = []
for key, tx in history.items():
txs.append(self.tx_to_model(tx))

14
electrum/gui/qt/address_list.py

@ -88,6 +88,7 @@ class AddressList(MyTreeView):
super().__init__(parent, self.create_menu,
stretch_column=self.Columns.LABEL,
editable_columns=[self.Columns.LABEL])
self.main_window = parent
self.wallet = self.parent.wallet
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.setSortingEnabled(True)
@ -111,10 +112,14 @@ class AddressList(MyTreeView):
def create_toolbar(self, config):
toolbar, menu = self.create_toolbar_with_menu('')
menu.addToggle(_("Show Filter"), lambda: self.toggle_toolbar(self.config))
menu.addConfig(_('Show Fiat balances'), 'fiat_address', False, callback=self.main_window.app.update_fiat_signal.emit)
hbox = self.create_toolbar_buttons()
toolbar.insertLayout(1, hbox)
return toolbar
def should_show_fiat(self):
return self.parent.fx and self.parent.fx.is_enabled() and self.config.get('fiat_address', False)
def get_toolbar_buttons(self):
return QLabel(_("Filter:")), self.change_button, self.used_button
@ -124,9 +129,8 @@ class AddressList(MyTreeView):
self.update()
def refresh_headers(self):
fx = self.parent.fx
if fx and fx.get_fiat_address_config():
ccy = fx.get_currency()
if self.should_show_fiat():
ccy = self.parent.fx.get_currency()
else:
ccy = _('Fiat')
headers = {
@ -211,7 +215,7 @@ class AddressList(MyTreeView):
set_address = QPersistentModelIndex(address_idx)
self.set_current_idx(set_address)
# show/hide columns
if fx and fx.get_fiat_address_config():
if self.should_show_fiat():
self.showColumn(self.Columns.FIAT_BALANCE)
else:
self.hideColumn(self.Columns.FIAT_BALANCE)
@ -228,7 +232,7 @@ class AddressList(MyTreeView):
balance_text = self.parent.format_amount(balance, whitespaces=True)
# create item
fx = self.parent.fx
if fx and fx.get_fiat_address_config():
if self.should_show_fiat():
rate = fx.exchange_rate()
fiat_balance_str = fx.value_str(balance, rate)
else:

38
electrum/gui/qt/history_list.py

@ -262,6 +262,17 @@ class HistoryModel(CustomModel, Logger):
"""Overridden in address_dialog.py"""
return True
def should_show_fiat(self):
if not self.window.config.get('history_rates', False):
return False
fx = self.window.fx
if not fx or not fx.is_enabled():
return False
return fx.has_history()
def should_show_capital_gains(self):
return self.should_show_fiat() and self.window.config.get('history_rates_capital_gains', False)
@profiler
def refresh(self, reason: str):
self.logger.info(f"refreshing... reason: {reason}")
@ -280,7 +291,9 @@ class HistoryModel(CustomModel, Logger):
transactions = wallet.get_full_history(
self.window.fx,
onchain_domain=self.get_domain(),
include_lightning=self.should_include_lightning_payments())
include_lightning=self.should_include_lightning_payments(),
include_fiat=self.should_show_fiat(),
)
if transactions == self.transactions:
return
old_length = self._root.childCount()
@ -361,8 +374,8 @@ class HistoryModel(CustomModel, Logger):
set_visible(HistoryColumns.TXID, False)
set_visible(HistoryColumns.SHORT_ID, False)
# fiat
history = self.window.fx.show_history()
cap_gains = self.window.fx.get_history_capital_gains_config()
history = self.should_show_fiat()
cap_gains = self.should_show_capital_gains()
set_visible(HistoryColumns.FIAT_VALUE, history)
set_visible(HistoryColumns.FIAT_ACQ_PRICE, history and cap_gains)
set_visible(HistoryColumns.FIAT_CAP_GAINS, history and cap_gains)
@ -412,7 +425,7 @@ class HistoryModel(CustomModel, Logger):
fiat_title = 'n/a fiat value'
fiat_acq_title = 'n/a fiat acquisition price'
fiat_cg_title = 'n/a fiat capital gains'
if fx and fx.show_history():
if self.should_show_fiat():
fiat_title = '%s '%fx.ccy + _('Value')
fiat_acq_title = '%s '%fx.ccy + _('Acquisition price')
fiat_cg_title = '%s '%fx.ccy + _('Capital Gains')
@ -473,6 +486,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
super().__init__(parent, self.create_menu,
stretch_column=HistoryColumns.DESCRIPTION,
editable_columns=[HistoryColumns.DESCRIPTION, HistoryColumns.FIAT_VALUE])
self.main_window = parent
self.config = parent.config
self.hm = model
self.proxy = HistorySortModel(self)
@ -529,14 +543,23 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
def create_toolbar(self, config):
toolbar, menu = self.create_toolbar_with_menu('')
menu.addToggle(_("&Filter Period"), lambda: self.toggle_toolbar(self.config))
menu.addToggle(_("Filter by Date"), lambda: self.toggle_toolbar(self.config))
self.menu_fiat = menu.addConfig(_('Show Fiat Values'), 'history_rates', False, callback=self.main_window.app.update_fiat_signal.emit)
self.menu_capgains = menu.addConfig(_('Show Capital Gains'), 'history_rates_capital_gains', False, callback=self.main_window.app.update_fiat_signal.emit)
menu.addAction(_("&Summary"), self.show_summary)
menu.addAction(_("&Plot"), self.plot_history_dialog)
menu.addAction(_("&Export"), self.export_history_dialog)
hbox = self.create_toolbar_buttons()
toolbar.insertLayout(1, hbox)
self.update_toolbar_menu()
return toolbar
def update_toolbar_menu(self):
fx = self.main_window.fx
b = fx and fx.is_enabled() and fx.has_history()
self.menu_fiat.setEnabled(b)
self.menu_capgains.setEnabled(b)
def get_toolbar_buttons(self):
return self.period_combo, self.start_button, self.end_button
@ -574,11 +597,10 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
return datetime.datetime(date.year, date.month, date.day)
def show_summary(self):
fx = self.parent.fx
show_fiat = fx and fx.is_enabled() and fx.get_history_config()
if not show_fiat:
if not self.hm.should_show_fiat():
self.parent.show_message(_("Enable fiat exchange rate with history."))
return
fx = self.parent.fx
h = self.wallet.get_detailed_history(
from_timestamp = time.mktime(self.start_date.timetuple()) if self.start_date else None,
to_timestamp = time.mktime(self.end_date.timetuple()) if self.end_date else None,

1
electrum/gui/qt/main_window.py

@ -2463,6 +2463,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
self.send_tab.fiat_send_e.setVisible(b)
self.receive_tab.fiat_receive_e.setVisible(b)
self.history_model.refresh('update_fiat')
self.history_list.update_toolbar_menu()
self.address_list.refresh_headers()
self.address_list.update()
self.update_status()

55
electrum/gui/qt/settings_dialog.py

@ -313,41 +313,25 @@ class SettingsDialog(QDialog, QtEventListener):
block_ex_hbox_w.setLayout(block_ex_hbox)
# Fiat Currency
hist_checkbox = QCheckBox()
hist_capgains_checkbox = QCheckBox()
fiat_address_checkbox = QCheckBox()
self.require_history_checkbox = QCheckBox()
ccy_combo = QComboBox()
ex_combo = QComboBox()
def update_currencies():
if not self.fx:
return
currencies = sorted(self.fx.get_currencies(self.fx.get_history_config()))
currencies = sorted(self.fx.get_currencies(self.require_history_checkbox.isChecked()))
ccy_combo.clear()
ccy_combo.addItems([_('None')] + currencies)
if self.fx.is_enabled():
ccy_combo.setCurrentIndex(ccy_combo.findText(self.fx.get_currency()))
def update_history_cb():
if not self.fx: return
hist_checkbox.setChecked(self.fx.get_history_config())
hist_checkbox.setEnabled(self.fx.is_enabled())
def update_fiat_address_cb():
if not self.fx: return
fiat_address_checkbox.setChecked(self.fx.get_fiat_address_config())
def update_history_capgains_cb():
if not self.fx: return
hist_capgains_checkbox.setChecked(self.fx.get_history_capital_gains_config())
hist_capgains_checkbox.setEnabled(hist_checkbox.isChecked())
def update_exchanges():
if not self.fx: return
b = self.fx.is_enabled()
ex_combo.setEnabled(b)
if b:
h = self.fx.get_history_config()
h = self.require_history_checkbox.isChecked()
c = self.fx.get_currency()
exchanges = self.fx.get_exchanges_by_ccy(c, h)
else:
@ -365,7 +349,6 @@ class SettingsDialog(QDialog, QtEventListener):
self.fx.set_enabled(b)
if b and ccy != self.fx.ccy:
self.fx.set_currency(ccy)
update_history_cb()
update_exchanges()
self.app.update_fiat_signal.emit()
@ -373,35 +356,17 @@ class SettingsDialog(QDialog, QtEventListener):
exchange = str(ex_combo.currentText())
if self.fx and self.fx.is_enabled() and exchange and exchange != self.fx.exchange.name():
self.fx.set_exchange(exchange)
def on_history(checked):
if not self.fx: return
self.fx.set_history_config(checked)
update_exchanges()
if self.fx.is_enabled() and checked:
self.fx.trigger_update()
update_history_capgains_cb()
self.app.update_fiat_signal.emit()
def on_history_capgains(checked):
if not self.fx: return
self.fx.set_history_capital_gains_config(checked)
self.app.update_fiat_signal.emit()
def on_fiat_address(checked):
if not self.fx: return
self.fx.set_fiat_address_config(checked)
self.app.update_fiat_signal.emit()
def on_require_history(checked):
if not self.fx:
return
update_exchanges()
update_currencies()
update_history_cb()
update_history_capgains_cb()
update_fiat_address_cb()
update_exchanges()
ccy_combo.currentIndexChanged.connect(on_currency)
hist_checkbox.stateChanged.connect(on_history)
hist_capgains_checkbox.stateChanged.connect(on_history_capgains)
fiat_address_checkbox.stateChanged.connect(on_fiat_address)
self.require_history_checkbox.stateChanged.connect(on_require_history)
ex_combo.currentIndexChanged.connect(on_exchange)
gui_widgets = []
@ -419,9 +384,7 @@ class SettingsDialog(QDialog, QtEventListener):
fiat_widgets = []
fiat_widgets.append((QLabel(_('Fiat currency')), ccy_combo))
fiat_widgets.append((QLabel(_('Source')), ex_combo))
fiat_widgets.append((QLabel(_('Show history rates')), hist_checkbox))
fiat_widgets.append((QLabel(_('Show capital gains in history')), hist_capgains_checkbox))
fiat_widgets.append((QLabel(_('Show Fiat balance for addresses')), fiat_address_checkbox))
fiat_widgets.append((QLabel(_('Show sources with historical data')), self.require_history_checkbox))
misc_widgets = []
misc_widgets.append((updatecheck_cb, None))
misc_widgets.append((filelogging_cb, None))

6
electrum/wallet.py

@ -1189,7 +1189,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
return is_paid, conf_needed
@profiler
def get_full_history(self, fx=None, *, onchain_domain=None, include_lightning=True):
def get_full_history(self, fx=None, *, onchain_domain=None, include_lightning=True, include_fiat=False):
transactions_tmp = OrderedDictWithIndex()
# add on-chain txns
onchain_history = self.get_onchain_history(domain=onchain_domain)
@ -1245,7 +1245,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
item['value'] = Satoshis(value)
balance += value
item['balance'] = Satoshis(balance)
if fx and fx.is_enabled() and fx.get_history_config():
if include_fiat:
txid = item.get('txid')
if not item.get('lightning') and txid:
fiat_fields = self.get_tx_item_fiat(tx_hash=txid, amount_sat=value, fx=fx, tx_fee=item['fee_sat'])
@ -1272,7 +1272,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
and (from_height is not None or to_height is not None):
raise Exception('timestamp and block height based filtering cannot be used together')
show_fiat = fx and fx.is_enabled() and fx.get_history_config()
show_fiat = fx and fx.is_enabled() and fx.has_history()
out = []
income = 0
expenditures = 0

Loading…
Cancel
Save