Streamlined code - modified two procs (get_fiat_status_text and fiat_dialog) to call exchange API only once instead of twice (as recommended by wozz).
This commit is contained in:
parent
9fb7fd5803
commit
5619859386
@ -316,19 +316,17 @@ class Plugin(BasePlugin):
|
|||||||
|
|
||||||
def get_fiat_status_text(self, btc_balance, r2):
|
def get_fiat_status_text(self, btc_balance, r2):
|
||||||
# return status as: (1.23 USD) 1 BTC~123.45 USD
|
# return status as: (1.23 USD) 1 BTC~123.45 USD
|
||||||
# balance in fiat
|
|
||||||
text = ""
|
text = ""
|
||||||
r = {}
|
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)
|
self.get_fiat_price_text(r)
|
||||||
quote = r.get(0)
|
quote = r.get(0)
|
||||||
if quote:
|
if quote:
|
||||||
text += " 1 BTC~%s "%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
|
r2[0] = text
|
||||||
|
|
||||||
def create_fiat_balance_text(self, btc_balance):
|
def create_fiat_balance_text(self, btc_balance):
|
||||||
@ -577,6 +575,9 @@ class Plugin(BasePlugin):
|
|||||||
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))
|
||||||
@ -589,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.get_fiat_price_text(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…
Reference in New Issue
Block a user