tkivy: updates - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 9b2885e697008445ba4a929d18bdf1d476a9cfc4 DIR parent 84b18e0949055e6e668f27e95d307bba137f4544 HTML Author: ThomasV <thomasv@electrum.org> Date: Sat, 5 Dec 2015 18:14:17 +0100 kivy: updates Diffstat: M gui/kivy/main_window.py | 18 ++++++++++-------- M gui/kivy/uix/ui_screens/amount.kv | 6 ++++-- M plugins/exchange_rate/exchange_rat… | 1 + M plugins/exchange_rate/kivy.py | 4 ++++ 4 files changed, 19 insertions(+), 10 deletions(-) --- DIR diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py t@@ -95,18 +95,20 @@ class ElectrumWindow(App): def btc_to_fiat(self, amount_str): if not amount_str: return '' - satoshis = self.get_amount(amount_str + ' ' + self.base_unit) - fiat_text = run_hook('format_amount_and_units', satoshis) - return fiat_text if fiat_text else '' + rate = run_hook('exchange_rate') + if not rate: + return '' + fiat_amount = self.get_amount(amount_str + ' ' + self.base_unit) * rate / pow(10, 8) + return "{:.2f}".format(fiat_amount).rstrip('0').rstrip('.') + ' ' + self.fiat_unit def fiat_to_btc(self, fiat_amount): if not fiat_amount: return '' - satoshis = pow(10, 8) - x = run_hook('format_amount_and_units', satoshis) - rate, unit = x.split() - amount = satoshis * Decimal(fiat_amount) / Decimal(rate) - return format_satoshis_plain(amount, self.decimal_point()) + ' ' + self.base_unit + rate = run_hook('exchange_rate') + if not rate: + return '' + satoshis = int(pow(10,8) * Decimal(fiat_amount) / Decimal(rate)) + return format_satoshis_plain(satoshis, self.decimal_point()) + ' ' + self.base_unit def get_amount(self, amount_str): a, u = amount_str.split() DIR diff --git a/gui/kivy/uix/ui_screens/amount.kv b/gui/kivy/uix/ui_screens/amount.kv t@@ -72,12 +72,14 @@ Popup: size_hint: 1, None height: '48dp' text: 'Max' - on_release: a.amount = app.get_max_amount() + on_release: + a.is_fiat = False + a.amount = app.get_max_amount() Button: id: button_fiat size_hint: 1, None height: '48dp' - text: '/' + text: app.fiat_unit if a.is_fiat else app.base_unit on_release: app.toggle_fiat(a) Button: DIR diff --git a/plugins/exchange_rate/exchange_rate.py b/plugins/exchange_rate/exchange_rate.py t@@ -309,6 +309,7 @@ class FxPlugin(BasePlugin, ThreadJob): def on_history(self): pass + @hook def exchange_rate(self): '''Returns None, or the exchange rate as a Decimal''' rate = self.exchange.quotes.get(self.ccy) DIR diff --git a/plugins/exchange_rate/kivy.py b/plugins/exchange_rate/kivy.py t@@ -9,3 +9,7 @@ class Plugin(FxPlugin): def on_quotes(self): self.print_error("on quotes", self.ccy) self.window.fiat_unit = self.ccy + + def on_history(self): + self.print_error("on history") + self.window.history_screen.update()