Browse Source

Merge pull request #634 from dpdtex/FiatPrice

Show Current Fiat Price in Status Panel
283
ThomasV 11 years ago
parent
commit
93ead1a90e
  1. 2
      gui/qt/lite_window.py
  2. 5
      gui/qt/main_window.py
  3. 69
      plugins/exchange_rate.py

2
gui/qt/lite_window.py

@ -437,7 +437,7 @@ class MiniWindow(QDialog):
user has in bitcoins.""" user has in bitcoins."""
from electrum.plugins import run_hook from electrum.plugins import run_hook
r = {} r = {}
run_hook('set_quote_text', btc_balance, r) run_hook('get_fiat_balance_text', btc_balance, r)
return r.get(0,'') return r.get(0,'')
def send(self): def send(self):

5
gui/qt/main_window.py

@ -490,11 +490,12 @@ class ElectrumWindow(QMainWindow):
text = _( "Balance" ) + ": %s "%( self.format_amount(c) ) + self.base_unit() text = _( "Balance" ) + ": %s "%( self.format_amount(c) ) + self.base_unit()
if u: text += " [%s unconfirmed]"%( self.format_amount(u,True).strip() ) if u: text += " [%s unconfirmed]"%( self.format_amount(u,True).strip() )
# append fiat balance and price from exchange rate plugin
r = {} r = {}
run_hook('set_quote_text', c+u, r) run_hook('get_fiat_status_text', c+u, r)
quote = r.get(0) quote = r.get(0)
if quote: if quote:
text += " (%s)"%quote text += "%s"%quote
self.tray.setToolTip(text) self.tray.setToolTip(text)
icon = QIcon(":icons/status_connected.png") icon = QIcon(":icons/status_connected.png")

69
plugins/exchange_rate.py

@ -303,11 +303,33 @@ class Plugin(BasePlugin):
self.win.emit(SIGNAL("refresh_currencies()")) self.win.emit(SIGNAL("refresh_currencies()"))
self.win.emit(SIGNAL("refresh_currencies_combo()")) 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): def get_fiat_status_text(self, btc_balance, r2):
r[0] = self.create_quote_text(Decimal(btc_balance) / 100000000) # return status as: (1.23 USD) 1 BTC~123.45 USD
text = ""
def create_quote_text(self, btc_balance): r = {}
self.get_fiat_price_text(r)
quote = r.get(0)
if quote:
price_text = "1 BTC~%s"%quote
fiat_currency = quote[-3:]
btc_price = quote[:-4]
fiat_balance = Decimal(btc_price) * (Decimal(btc_balance)/100000000)
balance_text = "(%.2f %s)" % (fiat_balance,fiat_currency)
text = " " + balance_text + " " + price_text + " "
r2[0] = text
def create_fiat_balance_text(self, btc_balance):
quote_currency = self.config.get("currency", "EUR") quote_currency = self.config.get("currency", "EUR")
self.exchanger.use_exchange = self.config.get("use_exchange", "Blockchain") self.exchanger.use_exchange = self.config.get("use_exchange", "Blockchain")
cur_rate = self.exchanger.exchange(Decimal("1.0"), quote_currency) cur_rate = self.exchanger.exchange(Decimal("1.0"), quote_currency)
@ -522,16 +544,9 @@ class Plugin(BasePlugin):
else: else:
return False return False
def fiat_unit(self): def fiat_unit(self):
r = {} quote_currency = self.config.get("currency", "???")
self.set_quote_text(100000000, r) return quote_currency
quote = r.get(0)
if quote:
return quote[-3:]
else:
return "???"
def fiat_dialog(self): def fiat_dialog(self):
if not self.config.get('use_exchange_rate'): if not self.config.get('use_exchange_rate'):
@ -542,7 +557,7 @@ class Plugin(BasePlugin):
self.gui.main_window.show_message(_("To use this feature, you must have a network connection.")) self.gui.main_window.show_message(_("To use this feature, you must have a network connection."))
return return
quote_currency = self.config.get("currency", "EUR") quote_currency = self.fiat_unit()
d = QDialog(self.gui.main_window) d = QDialog(self.gui.main_window)
d.setWindowTitle("Fiat") d.setWindowTitle("Fiat")
@ -555,11 +570,14 @@ class Plugin(BasePlugin):
grid.addWidget(fiat_e, 1, 0) grid.addWidget(fiat_e, 1, 0)
r = {} r = {}
self.set_quote_text(100000000, r) self.get_fiat_price_text(r)
quote = r.get(0) quote = r.get(0)
if quote: if quote:
text = " 1 BTC=%s"%quote text = "1 BTC~%s"%quote
grid.addWidget(QLabel(_(text)), 4, 0, 3, 0) grid.addWidget(QLabel(_(text)), 4, 0, 3, 0)
else:
self.gui.main_window.show_message(_("Exchange rate not available. Please check your network connection."))
return
vbox.addLayout(grid) vbox.addLayout(grid)
vbox.addLayout(ok_cancel_buttons(d)) vbox.addLayout(ok_cancel_buttons(d))
@ -572,19 +590,12 @@ class Plugin(BasePlugin):
if str(fiat) == "" or str(fiat) == ".": if str(fiat) == "" or str(fiat) == ".":
fiat = "0" fiat = "0"
r = {} quote = quote[:-4]
self.set_quote_text(100000000, r) btcamount = Decimal(fiat) / Decimal(quote)
quote = r.get(0) if str(self.gui.main_window.base_unit()) == "mBTC":
if not quote: btcamount = btcamount * 1000
self.gui.main_window.show_message(_("Exchange rate not available. Please check your network connection.")) quote = "%.8f"%btcamount
return self.gui.main_window.amount_e.setText( quote )
else:
quote = quote[:-4]
btcamount = Decimal(fiat) / Decimal(quote)
if str(self.gui.main_window.base_unit()) == "mBTC":
btcamount = btcamount * 1000
quote = "%.8f"%btcamount
self.gui.main_window.amount_e.setText( quote )
def exchange_rate_button(self, grid): def exchange_rate_button(self, grid):
quote_currency = self.config.get("currency", "EUR") quote_currency = self.config.get("currency", "EUR")

Loading…
Cancel
Save