Merge branch 'master' of git://github.com/spesmilo/electrum
This commit is contained in:
commit
fb79f50366
|
@ -1172,7 +1172,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
|
|
||||||
|
|
||||||
def do_send(self):
|
def do_send(self):
|
||||||
if run_hook('before_send', window):
|
if run_hook('before_send', self):
|
||||||
return
|
return
|
||||||
r = self.read_send_tab()
|
r = self.read_send_tab()
|
||||||
if not r:
|
if not r:
|
||||||
|
@ -1470,10 +1470,6 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.update_account_selector()
|
self.update_account_selector()
|
||||||
|
|
||||||
def create_receive_menu(self, position):
|
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()
|
selected = self.address_list.selectedItems()
|
||||||
multi_select = len(selected) > 1
|
multi_select = len(selected) > 1
|
||||||
addrs = [unicode(item.text(0)) for item in selected]
|
addrs = [unicode(item.text(0)) for item in selected]
|
||||||
|
@ -1494,7 +1490,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
if not multi_select:
|
if not multi_select:
|
||||||
menu.addAction(_("Copy to clipboard"), lambda: self.app.clipboard().setText(addr))
|
menu.addAction(_("Copy to clipboard"), lambda: self.app.clipboard().setText(addr))
|
||||||
menu.addAction(_("Request payment"), lambda: self.receive_at(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(_('History'), lambda: self.show_address(addr))
|
||||||
menu.addAction(_('Public Keys'), lambda: self.show_public_keys(addr))
|
menu.addAction(_('Public Keys'), lambda: self.show_public_keys(addr))
|
||||||
if self.wallet.can_export():
|
if self.wallet.can_export():
|
||||||
|
|
|
@ -39,21 +39,13 @@ class Exchanger(ThreadJob):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.quote_currencies = None
|
self.quotes = {}
|
||||||
self.timeout = 0
|
self.timeout = 0
|
||||||
|
|
||||||
def get_json(self, site, get_string):
|
def get_json(self, site, get_string):
|
||||||
resp = requests.request('GET', 'https://' + site + get_string, headers={"User-Agent":"Electrum"})
|
resp = requests.request('GET', 'https://' + site + get_string, headers={"User-Agent":"Electrum"})
|
||||||
return resp.json()
|
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):
|
def update_rate(self):
|
||||||
update_rates = {
|
update_rates = {
|
||||||
"BitcoinAverage": self.update_ba,
|
"BitcoinAverage": self.update_ba,
|
||||||
|
@ -76,7 +68,7 @@ class Exchanger(ThreadJob):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.parent.print_error(e)
|
self.parent.print_error(e)
|
||||||
rates = {}
|
rates = {}
|
||||||
self.quote_currencies = rates
|
self.quotes = rates
|
||||||
self.parent.set_currencies(rates)
|
self.parent.set_currencies(rates)
|
||||||
self.parent.refresh_fields()
|
self.parent.refresh_fields()
|
||||||
|
|
||||||
|
@ -205,6 +197,12 @@ class Plugin(BasePlugin):
|
||||||
window.emit(SIGNAL("refresh_currencies()"))
|
window.emit(SIGNAL("refresh_currencies()"))
|
||||||
window.emit(SIGNAL("refresh_currencies_combo()"))
|
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
|
@hook
|
||||||
def get_fiat_balance_text(self, btc_balance, r):
|
def get_fiat_balance_text(self, btc_balance, r):
|
||||||
# return balance as: 1.23 USD
|
# return balance as: 1.23 USD
|
||||||
|
@ -234,14 +232,13 @@ class Plugin(BasePlugin):
|
||||||
r2[0] = text
|
r2[0] = text
|
||||||
|
|
||||||
def create_fiat_balance_text(self, btc_balance):
|
def create_fiat_balance_text(self, btc_balance):
|
||||||
quote_currency = self.fiat_unit()
|
cur_rate = self.exchange_rate()
|
||||||
cur_rate = self.exchanger.exchange(Decimal("1.0"), quote_currency)
|
|
||||||
if cur_rate is None:
|
if cur_rate is None:
|
||||||
quote_text = ""
|
quote_text = ""
|
||||||
else:
|
else:
|
||||||
quote_balance = btc_balance * Decimal(cur_rate)
|
quote_balance = btc_balance * Decimal(cur_rate)
|
||||||
self.btc_rate = 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
|
return quote_text
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
|
@ -529,7 +526,7 @@ class Plugin(BasePlugin):
|
||||||
btc_e.setText("")
|
btc_e.setText("")
|
||||||
if fee_e: fee_e.setText("")
|
if fee_e: fee_e.setText("")
|
||||||
return
|
return
|
||||||
exchange_rate = self.exchanger.exchange(Decimal("1.0"), self.fiat_unit())
|
exchange_rate = self.exchange_rate()
|
||||||
if exchange_rate is not None:
|
if exchange_rate is not None:
|
||||||
btc_amount = fiat_amount/exchange_rate
|
btc_amount = fiat_amount/exchange_rate
|
||||||
btc_e.setAmount(int(btc_amount*Decimal(COIN)))
|
btc_e.setAmount(int(btc_amount*Decimal(COIN)))
|
||||||
|
@ -539,14 +536,12 @@ class Plugin(BasePlugin):
|
||||||
def btc_changed():
|
def btc_changed():
|
||||||
btc_e.setStyleSheet(BLACK_FG)
|
btc_e.setStyleSheet(BLACK_FG)
|
||||||
window.fx_fields[(fiat_e, btc_e)] = btc_e
|
window.fx_fields[(fiat_e, btc_e)] = btc_e
|
||||||
if self.exchanger is None:
|
|
||||||
return
|
|
||||||
btc_amount = btc_e.get_amount()
|
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("")
|
fiat_e.setText("")
|
||||||
return
|
else:
|
||||||
fiat_amount = self.exchanger.exchange(Decimal(btc_amount)/Decimal(COIN), self.fiat_unit())
|
fiat_amount = rate * Decimal(btc_amount) / Decimal(COIN)
|
||||||
if fiat_amount is not None:
|
|
||||||
pos = fiat_e.cursorPosition()
|
pos = fiat_e.cursorPosition()
|
||||||
fiat_e.setText("%.2f"%fiat_amount)
|
fiat_e.setText("%.2f"%fiat_amount)
|
||||||
fiat_e.setCursorPosition(pos)
|
fiat_e.setCursorPosition(pos)
|
||||||
|
|
Loading…
Reference in New Issue