Cleaned up Exchange Rate plugin: more efficient code and more intuitive names for...
authorDarrin Daigle <darrin@daiglefamily.org>
Thu, 27 Mar 2014 20:30:24 +0000 (15:30 -0500)
committerDarrin Daigle <darrin@daiglefamily.org>
Thu, 27 Mar 2014 20:30:24 +0000 (15:30 -0500)
gui/qt/lite_window.py
gui/qt/main_window.py
plugins/exchange_rate.py

index 29010f1..58bbbd2 100644 (file)
@@ -437,7 +437,7 @@ class MiniWindow(QDialog):
         user has in bitcoins."""
         from electrum.plugins import run_hook
         r = {}
-        run_hook('set_quote_text', btc_balance, r)
+        run_hook('get_fiat_balance_text', btc_balance, r)
         return r.get(0,'')
 
     def send(self):
index 640ee27..9cc957a 100644 (file)
@@ -490,11 +490,12 @@ class ElectrumWindow(QMainWindow):
                 text =  _( "Balance" ) + ": %s "%( self.format_amount(c) ) + self.base_unit()
                 if u: text +=  " [%s unconfirmed]"%( self.format_amount(u,True).strip() )
 
+                # append fiat balance and price from exchange rate plugin
                 r = {}
-                run_hook('set_quote_text', c+u, r)
+                run_hook('get_fiat_status_text', c+u, r)
                 quote = r.get(0)
                 if quote:
-                    text += "  (%s)"%quote
+                    text += "%s"%quote
 
                 self.tray.setToolTip(text)
                 icon = QIcon(":icons/status_connected.png")
index d07c694..4757cbc 100644 (file)
@@ -303,11 +303,35 @@ class Plugin(BasePlugin):
         self.win.emit(SIGNAL("refresh_currencies()"))
         self.win.emit(SIGNAL("refresh_currencies_combo()"))
 
+    def get_fiat_balance_text(self, btc_balance, r):
+        # return balance as: 1.23 USD
+        r[0] = self.create_fiat_balance_text(Decimal(btc_balance) / 100000000)
+
+    def get_fiat_price_text(self, r):
+        # return BTC price as: 123.45 USD
+        r[0] = self.create_fiat_balance_text(1)
+        quote = r[0]
+        if quote:
+            r[0] = "%s"%quote
 
-    def set_quote_text(self, btc_balance, r):
-        r[0] = self.create_quote_text(Decimal(btc_balance) / 100000000)
+    def get_fiat_status_text(self, btc_balance, r2):
+        # return status as:   (1.23 USD)    1 BTC~123.45 USD
+        # balance in fiat
+        text = ""
+        r = {}
+        self.get_fiat_balance_text(btc_balance, r)
+        quote = r.get(0)
+        if quote:
+            text += "  (%s)"%quote
+        # BTC price in fiat
+        r = {}
+        self.get_fiat_price_text(r)
+        quote = r.get(0)
+        if quote:
+            text += "      1 BTC~%s "%quote
+        r2[0] = text
 
-    def create_quote_text(self, btc_balance):
+    def create_fiat_balance_text(self, btc_balance):
         quote_currency = self.config.get("currency", "EUR")
         self.exchanger.use_exchange = self.config.get("use_exchange", "Blockchain")
         cur_rate = self.exchanger.exchange(Decimal("1.0"), quote_currency)
@@ -522,16 +546,9 @@ class Plugin(BasePlugin):
         else:
             return False
 
-
-        
     def fiat_unit(self):
-        r = {}
-        self.set_quote_text(100000000, r)
-        quote = r.get(0)
-        if quote:
-          return quote[-3:]
-        else:
-          return "???"
+        quote_currency = self.config.get("currency", "???")
+        return quote_currency
 
     def fiat_dialog(self):
         if not self.config.get('use_exchange_rate'):
@@ -542,7 +559,7 @@ class Plugin(BasePlugin):
           self.gui.main_window.show_message(_("To use this feature, you must have a network connection."))
           return
 
-        quote_currency = self.config.get("currency", "EUR")
+        quote_currency = self.fiat_unit()
 
         d = QDialog(self.gui.main_window)
         d.setWindowTitle("Fiat")
@@ -555,10 +572,10 @@ class Plugin(BasePlugin):
         grid.addWidget(fiat_e, 1, 0)
 
         r = {}
-        self.set_quote_text(100000000, r)
+        self.get_fiat_price_text(r)
         quote = r.get(0)
         if quote:
-          text = "  1 BTC=%s"%quote
+          text = "1 BTC~%s"%quote
           grid.addWidget(QLabel(_(text)), 4, 0, 3, 0)
 
         vbox.addLayout(grid)
@@ -573,7 +590,7 @@ class Plugin(BasePlugin):
             fiat = "0"
 
         r = {}
-        self.set_quote_text(100000000, r)
+        self.get_fiat_price_text(r)
         quote = r.get(0)
         if not quote:
             self.gui.main_window.show_message(_("Exchange rate not available.  Please check your network connection."))