mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 17:55:20 +00:00
currency conversions (bkkcoins)
This commit is contained in:
parent
e7e169888d
commit
c7edba0990
3 changed files with 41 additions and 6 deletions
|
@ -47,8 +47,11 @@ class Exchanger(threading.Thread):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_currencies(self):
|
||||||
|
return [] if self.quote_currencies == None else sorted(self.quote_currencies.keys())
|
||||||
|
|
||||||
def _lookup_rate(self, response, quote_id):
|
def _lookup_rate(self, response, quote_id):
|
||||||
return decimal.Decimal(response[str(quote_id)]["15m"])
|
return decimal.Decimal(str(response[str(quote_id)]["15m"]))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
exch = Exchanger(("BRL", "CNY", "EUR", "GBP", "RUB", "USD"))
|
exch = Exchanger(("BRL", "CNY", "EUR", "GBP", "RUB", "USD"))
|
||||||
|
|
|
@ -38,6 +38,7 @@ except:
|
||||||
|
|
||||||
from wallet import format_satoshis
|
from wallet import format_satoshis
|
||||||
import bmp, mnemonic, pyqrnative, qrscanner
|
import bmp, mnemonic, pyqrnative, qrscanner
|
||||||
|
import exchange_rate
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
@ -335,6 +336,9 @@ class ElectrumWindow(QMainWindow):
|
||||||
#self.connect(self, SIGNAL('editamount'), self.edit_amount)
|
#self.connect(self, SIGNAL('editamount'), self.edit_amount)
|
||||||
self.history_list.setFocus(True)
|
self.history_list.setFocus(True)
|
||||||
|
|
||||||
|
self.exchanger = exchange_rate.Exchanger(self)
|
||||||
|
self.connect(self, SIGNAL("refresh_balance()"), self.update_wallet)
|
||||||
|
|
||||||
# dark magic fix by flatfly; https://bitcointalk.org/index.php?topic=73651.msg959913#msg959913
|
# dark magic fix by flatfly; https://bitcointalk.org/index.php?topic=73651.msg959913#msg959913
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
n = 3 if self.wallet.seed else 2
|
n = 3 if self.wallet.seed else 2
|
||||||
|
@ -383,6 +387,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
c, u = self.wallet.get_balance()
|
c, u = self.wallet.get_balance()
|
||||||
text = _( "Balance" ) + ": %s "%( format_satoshis(c,False,self.wallet.num_zeros) )
|
text = _( "Balance" ) + ": %s "%( format_satoshis(c,False,self.wallet.num_zeros) )
|
||||||
if u: text += "[%s unconfirmed]"%( format_satoshis(u,True,self.wallet.num_zeros).strip() )
|
if u: text += "[%s unconfirmed]"%( format_satoshis(u,True,self.wallet.num_zeros).strip() )
|
||||||
|
text += self.create_quote_text(Decimal(c+u)/100000000)
|
||||||
icon = QIcon(":icons/status_connected.png")
|
icon = QIcon(":icons/status_connected.png")
|
||||||
else:
|
else:
|
||||||
text = _( "Not connected" )
|
text = _( "Not connected" )
|
||||||
|
@ -401,6 +406,14 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.update_contacts_tab()
|
self.update_contacts_tab()
|
||||||
self.update_completions()
|
self.update_completions()
|
||||||
|
|
||||||
|
def create_quote_text(self, btc_balance):
|
||||||
|
quote_currency = self.config.get("currency", "None")
|
||||||
|
quote_balance = self.exchanger.exchange(btc_balance, quote_currency)
|
||||||
|
if quote_balance is None:
|
||||||
|
quote_text = ""
|
||||||
|
else:
|
||||||
|
quote_text = " (%.2f %s)" % (quote_balance, quote_currency)
|
||||||
|
return quote_text
|
||||||
|
|
||||||
def create_history_tab(self):
|
def create_history_tab(self):
|
||||||
self.history_list = l = MyTreeWidget(self)
|
self.history_list = l = MyTreeWidget(self)
|
||||||
|
@ -1586,19 +1599,33 @@ class ElectrumWindow(QMainWindow):
|
||||||
if not self.config.is_modifiable('language'):
|
if not self.config.is_modifiable('language'):
|
||||||
for w in [lang_combo, lang_label]: w.setEnabled(False)
|
for w in [lang_combo, lang_label]: w.setEnabled(False)
|
||||||
|
|
||||||
|
currencies = self.exchanger.get_currencies()
|
||||||
|
currencies.insert(0, "None")
|
||||||
|
|
||||||
|
cur_label=QLabel(_('Currency') + ':')
|
||||||
|
grid_ui.addWidget(cur_label , 9, 0)
|
||||||
|
cur_combo = QComboBox()
|
||||||
|
cur_combo.addItems(currencies)
|
||||||
|
try:
|
||||||
|
index = currencies.index(self.config.get('currency', "None"))
|
||||||
|
except:
|
||||||
|
index = 0
|
||||||
|
cur_combo.setCurrentIndex(index)
|
||||||
|
grid_ui.addWidget(cur_combo, 9, 1)
|
||||||
|
grid_ui.addWidget(HelpButton(_('Select which currency is used for quotes. ')), 9, 2)
|
||||||
|
|
||||||
view_label=QLabel(_('Receive Tab') + ':')
|
view_label=QLabel(_('Receive Tab') + ':')
|
||||||
grid_ui.addWidget(view_label , 9, 0)
|
grid_ui.addWidget(view_label , 10, 0)
|
||||||
view_combo = QComboBox()
|
view_combo = QComboBox()
|
||||||
view_combo.addItems([_('Simple'), _('Advanced'), _('Point of Sale')])
|
view_combo.addItems([_('Simple'), _('Advanced'), _('Point of Sale')])
|
||||||
view_combo.setCurrentIndex(self.receive_tab_mode)
|
view_combo.setCurrentIndex(self.receive_tab_mode)
|
||||||
grid_ui.addWidget(view_combo, 9, 1)
|
grid_ui.addWidget(view_combo, 10, 1)
|
||||||
hh = _('This selects the interaction mode of the "Receive" tab. ') + '\n\n' \
|
hh = _('This selects the interaction mode of the "Receive" tab. ') + '\n\n' \
|
||||||
+ _('Simple') + ': ' + _('Show only addresses and labels.') + '\n\n' \
|
+ _('Simple') + ': ' + _('Show only addresses and labels.') + '\n\n' \
|
||||||
+ _('Advanced') + ': ' + _('Show address balances and add extra menu items to freeze/prioritize addresses.') + '\n\n' \
|
+ _('Advanced') + ': ' + _('Show address balances and add extra menu items to freeze/prioritize addresses.') + '\n\n' \
|
||||||
+ _('Point of Sale') + ': ' + _('Show QR code window and amounts requested for each address. Add menu item to request amount.') + '\n\n'
|
+ _('Point of Sale') + ': ' + _('Show QR code window and amounts requested for each address. Add menu item to request amount.') + '\n\n'
|
||||||
|
|
||||||
grid_ui.addWidget(HelpButton(hh), 9, 2)
|
grid_ui.addWidget(HelpButton(hh), 10, 2)
|
||||||
|
|
||||||
vbox.addLayout(ok_cancel_buttons(d))
|
vbox.addLayout(ok_cancel_buttons(d))
|
||||||
d.setLayout(vbox)
|
d.setLayout(vbox)
|
||||||
|
@ -1662,6 +1689,11 @@ class ElectrumWindow(QMainWindow):
|
||||||
self.config.set_key("language", lang_request, True)
|
self.config.set_key("language", lang_request, True)
|
||||||
need_restart = True
|
need_restart = True
|
||||||
|
|
||||||
|
cur_request = str(currencies[cur_combo.currentIndex()])
|
||||||
|
if cur_request != self.config.get('currency', "None"):
|
||||||
|
self.config.set_key('currency', cur_request, True)
|
||||||
|
self.update_wallet()
|
||||||
|
|
||||||
if need_restart:
|
if need_restart:
|
||||||
QMessageBox.warning(self, _('Success'), _('Please restart Electrum to activate the new GUI settings'), _('OK'))
|
QMessageBox.warning(self, _('Success'), _('Please restart Electrum to activate the new GUI settings'), _('OK'))
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ a SimpleConfig instance then reads the wallet file.
|
||||||
try:
|
try:
|
||||||
out = ast.literal_eval(out)
|
out = ast.literal_eval(out)
|
||||||
except:
|
except:
|
||||||
print "type error, using default value"
|
print "type error for '%s': using default value"%key
|
||||||
out = default
|
out = default
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
Loading…
Add table
Reference in a new issue