Merge pull request #2621 from KoffeinFlummi/fiat-balance-addresses
Add optional Fiat balance column to addresses view
This commit is contained in:
commit
b7e8147ca8
|
@ -42,9 +42,18 @@ class AddressList(MyTreeWidget):
|
||||||
filter_columns = [0, 1, 2] # Address, Label, Balance
|
filter_columns = [0, 1, 2] # Address, Label, Balance
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
MyTreeWidget.__init__(self, parent, self.create_menu, [ _('Address'), _('Label'), _('Balance'), _('Tx')], 1)
|
MyTreeWidget.__init__(self, parent, self.create_menu, [], 1)
|
||||||
|
self.refresh_headers()
|
||||||
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
|
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
|
||||||
|
|
||||||
|
def refresh_headers(self):
|
||||||
|
headers = [ _('Address'), _('Label'), _('Balance')]
|
||||||
|
fx = self.parent.fx
|
||||||
|
if fx and fx.get_fiat_address_config():
|
||||||
|
headers.extend([_(fx.get_currency()+' Balance')])
|
||||||
|
headers.extend([_('Tx')])
|
||||||
|
self.update_headers(headers)
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
self.wallet = self.parent.wallet
|
self.wallet = self.parent.wallet
|
||||||
item = self.currentItem()
|
item = self.currentItem()
|
||||||
|
@ -73,7 +82,15 @@ class AddressList(MyTreeWidget):
|
||||||
label = self.wallet.labels.get(address,'')
|
label = self.wallet.labels.get(address,'')
|
||||||
c, u, x = self.wallet.get_addr_balance(address)
|
c, u, x = self.wallet.get_addr_balance(address)
|
||||||
balance = self.parent.format_amount(c + u + x)
|
balance = self.parent.format_amount(c + u + x)
|
||||||
address_item = QTreeWidgetItem([address, label, balance, "%d"%num])
|
fx = self.parent.fx
|
||||||
|
if fx and fx.get_fiat_address_config():
|
||||||
|
rate = fx.exchange_rate()
|
||||||
|
fiat_balance = fx.value_str(c + u + x, rate)
|
||||||
|
address_item = QTreeWidgetItem([address, label, balance, fiat_balance, "%d"%num])
|
||||||
|
address_item.setTextAlignment(3, Qt.AlignRight)
|
||||||
|
else:
|
||||||
|
address_item = QTreeWidgetItem([address, label, balance, "%d"%num])
|
||||||
|
address_item.setTextAlignment(2, Qt.AlignRight)
|
||||||
address_item.setFont(0, QFont(MONOSPACE_FONT))
|
address_item.setFont(0, QFont(MONOSPACE_FONT))
|
||||||
address_item.setData(0, Qt.UserRole, address)
|
address_item.setData(0, Qt.UserRole, address)
|
||||||
address_item.setData(0, Qt.UserRole+1, True) # label can be edited
|
address_item.setData(0, Qt.UserRole+1, True) # label can be edited
|
||||||
|
|
|
@ -200,6 +200,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
def on_fx_history(self):
|
def on_fx_history(self):
|
||||||
self.history_list.refresh_headers()
|
self.history_list.refresh_headers()
|
||||||
self.history_list.update()
|
self.history_list.update()
|
||||||
|
self.address_list.update()
|
||||||
|
|
||||||
def on_quotes(self, b):
|
def on_quotes(self, b):
|
||||||
self.emit(SIGNAL('new_fx_quotes'))
|
self.emit(SIGNAL('new_fx_quotes'))
|
||||||
|
@ -2350,6 +2351,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
self.fiat_receive_e.setVisible(b)
|
self.fiat_receive_e.setVisible(b)
|
||||||
self.history_list.refresh_headers()
|
self.history_list.refresh_headers()
|
||||||
self.history_list.update()
|
self.history_list.update()
|
||||||
|
self.address_list.update()
|
||||||
self.update_status()
|
self.update_status()
|
||||||
|
|
||||||
def settings_dialog(self):
|
def settings_dialog(self):
|
||||||
|
@ -2615,6 +2617,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
|
|
||||||
# Fiat Currency
|
# Fiat Currency
|
||||||
hist_checkbox = QCheckBox()
|
hist_checkbox = QCheckBox()
|
||||||
|
fiat_address_checkbox = QCheckBox()
|
||||||
ccy_combo = QComboBox()
|
ccy_combo = QComboBox()
|
||||||
ex_combo = QComboBox()
|
ex_combo = QComboBox()
|
||||||
|
|
||||||
|
@ -2631,6 +2634,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
hist_checkbox.setChecked(self.fx.get_history_config())
|
hist_checkbox.setChecked(self.fx.get_history_config())
|
||||||
hist_checkbox.setEnabled(self.fx.is_enabled())
|
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_exchanges():
|
def update_exchanges():
|
||||||
if not self.fx: return
|
if not self.fx: return
|
||||||
b = self.fx.is_enabled()
|
b = self.fx.is_enabled()
|
||||||
|
@ -2670,16 +2677,25 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
# reset timeout to get historical rates
|
# reset timeout to get historical rates
|
||||||
self.fx.timeout = 0
|
self.fx.timeout = 0
|
||||||
|
|
||||||
|
def on_fiat_address(checked):
|
||||||
|
if not self.fx: return
|
||||||
|
self.fx.set_fiat_address_config(checked)
|
||||||
|
self.address_list.refresh_headers()
|
||||||
|
self.address_list.update()
|
||||||
|
|
||||||
update_currencies()
|
update_currencies()
|
||||||
update_history_cb()
|
update_history_cb()
|
||||||
|
update_fiat_address_cb()
|
||||||
update_exchanges()
|
update_exchanges()
|
||||||
ccy_combo.currentIndexChanged.connect(on_currency)
|
ccy_combo.currentIndexChanged.connect(on_currency)
|
||||||
hist_checkbox.stateChanged.connect(on_history)
|
hist_checkbox.stateChanged.connect(on_history)
|
||||||
|
fiat_address_checkbox.stateChanged.connect(on_fiat_address)
|
||||||
ex_combo.currentIndexChanged.connect(on_exchange)
|
ex_combo.currentIndexChanged.connect(on_exchange)
|
||||||
|
|
||||||
fiat_widgets = []
|
fiat_widgets = []
|
||||||
fiat_widgets.append((QLabel(_('Fiat currency')), ccy_combo))
|
fiat_widgets.append((QLabel(_('Fiat currency')), ccy_combo))
|
||||||
fiat_widgets.append((QLabel(_('Show history rates')), hist_checkbox))
|
fiat_widgets.append((QLabel(_('Show history rates')), hist_checkbox))
|
||||||
|
fiat_widgets.append((QLabel(_('Show Fiat balance for addresses')), fiat_address_checkbox))
|
||||||
fiat_widgets.append((QLabel(_('Source')), ex_combo))
|
fiat_widgets.append((QLabel(_('Source')), ex_combo))
|
||||||
|
|
||||||
tabs_info = [
|
tabs_info = [
|
||||||
|
|
|
@ -419,6 +419,12 @@ class FxThread(ThreadJob):
|
||||||
def set_history_config(self, b):
|
def set_history_config(self, b):
|
||||||
self.config.set_key('history_rates', bool(b))
|
self.config.set_key('history_rates', 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 get_currency(self):
|
def get_currency(self):
|
||||||
'''Use when dynamic fetching is needed'''
|
'''Use when dynamic fetching is needed'''
|
||||||
return self.config.get("currency", "EUR")
|
return self.config.get("currency", "EUR")
|
||||||
|
|
Loading…
Reference in New Issue