commit fb79f50366aeaa3db27a028a74a96b6dd3bf0fe6
parent 2f8574f7d78e3495c71253770d9a0241cbddaa0a
Author: ThomasV <thomasv@electrum.org>
Date: Fri, 4 Sep 2015 15:26:31 +0200
Merge branch 'master' of git://github.com/spesmilo/electrum
Diffstat:
2 files changed, 17 insertions(+), 26 deletions(-)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -1172,7 +1172,7 @@ class ElectrumWindow(QMainWindow):
def do_send(self):
- if run_hook('before_send', window):
+ if run_hook('before_send', self):
return
r = self.read_send_tab()
if not r:
@@ -1470,10 +1470,6 @@ class ElectrumWindow(QMainWindow):
self.update_account_selector()
def create_receive_menu(self, position):
- # fixme: this function apparently has a side effect.
- # if it is not called the menu pops up several times
- #self.address_list.selectedIndexes()
-
selected = self.address_list.selectedItems()
multi_select = len(selected) > 1
addrs = [unicode(item.text(0)) for item in selected]
@@ -1494,7 +1490,7 @@ class ElectrumWindow(QMainWindow):
if not multi_select:
menu.addAction(_("Copy to clipboard"), lambda: self.app.clipboard().setText(addr))
menu.addAction(_("Request payment"), lambda: self.receive_at(addr))
- menu.addAction(_("Edit label"), lambda: self.address_list.edit_label(item))
+ menu.addAction(_("Edit label"), lambda: self.address_list.editItem(item, self.address_list.editable_columns[0]))
menu.addAction(_('History'), lambda: self.show_address(addr))
menu.addAction(_('Public Keys'), lambda: self.show_public_keys(addr))
if self.wallet.can_export():
diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py
@@ -39,21 +39,13 @@ class Exchanger(ThreadJob):
def __init__(self, parent):
self.parent = parent
- self.quote_currencies = None
+ self.quotes = {}
self.timeout = 0
def get_json(self, site, get_string):
resp = requests.request('GET', 'https://' + site + get_string, headers={"User-Agent":"Electrum"})
return resp.json()
- def exchange(self, btc_amount, quote_currency):
- if self.quote_currencies is None:
- return None
- quote_currencies = self.quote_currencies.copy()
- if quote_currency not in quote_currencies:
- return None
- return btc_amount * Decimal(str(quote_currencies[quote_currency]))
-
def update_rate(self):
update_rates = {
"BitcoinAverage": self.update_ba,
@@ -76,7 +68,7 @@ class Exchanger(ThreadJob):
except Exception as e:
self.parent.print_error(e)
rates = {}
- self.quote_currencies = rates
+ self.quotes = rates
self.parent.set_currencies(rates)
self.parent.refresh_fields()
@@ -205,6 +197,12 @@ class Plugin(BasePlugin):
window.emit(SIGNAL("refresh_currencies()"))
window.emit(SIGNAL("refresh_currencies_combo()"))
+ def exchange_rate(self):
+ '''Returns None, or the exchange rate as a Decimal'''
+ rate = self.exchanger.quotes.get(self.fiat_unit())
+ if rate:
+ return Decimal(str(rate))
+
@hook
def get_fiat_balance_text(self, btc_balance, r):
# return balance as: 1.23 USD
@@ -234,14 +232,13 @@ class Plugin(BasePlugin):
r2[0] = text
def create_fiat_balance_text(self, btc_balance):
- quote_currency = self.fiat_unit()
- cur_rate = self.exchanger.exchange(Decimal("1.0"), quote_currency)
+ cur_rate = self.exchange_rate()
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)
+ quote_text = "%.2f %s" % (quote_balance, self.fiat_unit())
return quote_text
@hook
@@ -529,7 +526,7 @@ class Plugin(BasePlugin):
btc_e.setText("")
if fee_e: fee_e.setText("")
return
- exchange_rate = self.exchanger.exchange(Decimal("1.0"), self.fiat_unit())
+ exchange_rate = self.exchange_rate()
if exchange_rate is not None:
btc_amount = fiat_amount/exchange_rate
btc_e.setAmount(int(btc_amount*Decimal(COIN)))
@@ -539,14 +536,12 @@ class Plugin(BasePlugin):
def btc_changed():
btc_e.setStyleSheet(BLACK_FG)
window.fx_fields[(fiat_e, btc_e)] = btc_e
- if self.exchanger is None:
- return
btc_amount = btc_e.get_amount()
- if btc_amount is None:
+ rate = self.exchange_rate()
+ if rate is None or btc_amount is None:
fiat_e.setText("")
- return
- fiat_amount = self.exchanger.exchange(Decimal(btc_amount)/Decimal(COIN), self.fiat_unit())
- if fiat_amount is not None:
+ else:
+ fiat_amount = rate * Decimal(btc_amount) / Decimal(COIN)
pos = fiat_e.cursorPosition()
fiat_e.setText("%.2f"%fiat_amount)
fiat_e.setCursorPosition(pos)