electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit b7e8147ca8bf09f6d952aacf33bbb6ac0c88f2ac
parent 61a7f7defb53f46a405570e1e20d24c46b17be50
Author: ThomasV <thomasv@electrum.org>
Date:   Fri,  1 Sep 2017 06:30:13 +0200

Merge pull request #2621 from KoffeinFlummi/fiat-balance-addresses

Add optional Fiat balance column to addresses view
Diffstat:
Mgui/qt/address_list.py | 21+++++++++++++++++++--
Mgui/qt/main_window.py | 16++++++++++++++++
Mlib/exchange_rate.py | 6++++++
3 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/gui/qt/address_list.py b/gui/qt/address_list.py @@ -42,9 +42,18 @@ class AddressList(MyTreeWidget): filter_columns = [0, 1, 2] # Address, Label, Balance 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) + 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): self.wallet = self.parent.wallet item = self.currentItem() @@ -73,7 +82,15 @@ class AddressList(MyTreeWidget): label = self.wallet.labels.get(address,'') c, u, x = self.wallet.get_addr_balance(address) 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.setData(0, Qt.UserRole, address) address_item.setData(0, Qt.UserRole+1, True) # label can be edited diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -200,6 +200,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): def on_fx_history(self): self.history_list.refresh_headers() self.history_list.update() + self.address_list.update() def on_quotes(self, b): self.emit(SIGNAL('new_fx_quotes')) @@ -2350,6 +2351,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.fiat_receive_e.setVisible(b) self.history_list.refresh_headers() self.history_list.update() + self.address_list.update() self.update_status() def settings_dialog(self): @@ -2615,6 +2617,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): # Fiat Currency hist_checkbox = QCheckBox() + fiat_address_checkbox = QCheckBox() ccy_combo = QComboBox() ex_combo = QComboBox() @@ -2631,6 +2634,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): 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_exchanges(): if not self.fx: return b = self.fx.is_enabled() @@ -2670,16 +2677,25 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): # reset timeout to get historical rates 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_history_cb() + update_fiat_address_cb() update_exchanges() ccy_combo.currentIndexChanged.connect(on_currency) hist_checkbox.stateChanged.connect(on_history) + fiat_address_checkbox.stateChanged.connect(on_fiat_address) ex_combo.currentIndexChanged.connect(on_exchange) fiat_widgets = [] fiat_widgets.append((QLabel(_('Fiat currency')), ccy_combo)) 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)) tabs_info = [ diff --git a/lib/exchange_rate.py b/lib/exchange_rate.py @@ -419,6 +419,12 @@ class FxThread(ThreadJob): def set_history_config(self, 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): '''Use when dynamic fetching is needed''' return self.config.get("currency", "EUR")