From 05027c512ea6a0cf7ff497533547a8d65f5ddf4a Mon Sep 17 00:00:00 2001 From: Michael Wozniak Date: Wed, 5 Mar 2014 16:03:56 -0500 Subject: [PATCH] exchange rate bug fix --- plugins/exchange_rate.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index 4e57d17b..3c6d01b2 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -273,6 +273,7 @@ class Plugin(BasePlugin): def init(self): self.win = self.gui.main_window self.win.connect(self.win, SIGNAL("refresh_currencies()"), self.win.update_status) + self.btc_rate = Decimal(0.0) # Do price discovery self.exchanger = Exchanger(self) self.exchanger.start() @@ -290,10 +291,12 @@ class Plugin(BasePlugin): def create_quote_text(self, btc_balance): quote_currency = self.config.get("currency", "EUR") self.exchanger.use_exchange = self.config.get("use_exchange", "Blockchain") - quote_balance = self.exchanger.exchange(btc_balance, quote_currency) - if quote_balance is None: + cur_rate = self.exchanger.exchange(Decimal(1.0), quote_currency) + if cur_rate is None: quote_text = "" else: + quote_balance = btc_balance * Decimal(cur_rate) + self.btc_rate = cur_rate quote_text = "%.2f %s" % (quote_balance, quote_currency) return quote_text @@ -348,7 +351,10 @@ class Plugin(BasePlugin): pass tx_time = int(tx_info['timestamp']) tx_time_str = datetime.datetime.fromtimestamp(tx_time).strftime('%Y-%m-%d') - tx_USD_val = "%.2f %s" % (Decimal(tx_info['value']) / 100000000 * Decimal(resp_hist['bpi'][tx_time_str]), "USD") + try: + tx_USD_val = "%.2f %s" % (Decimal(tx_info['value']) / 100000000 * Decimal(resp_hist['bpi'][tx_time_str]), "USD") + except KeyError: + tx_USD_val = "%.2f %s" % (self.btc_rate * Decimal(tx_info['value'])/100000000 , "USD") item.setText(5, tx_USD_val) if Decimal(tx_info['value']) < 0: