1
0

rebase to master and add resources, numerous other small fixes

This commit is contained in:
qua-non
2014-03-04 23:32:03 +05:30
committed by ThomasV
parent a1681eeeba
commit 1bbb211671
13 changed files with 240 additions and 28 deletions

View File

@@ -501,7 +501,7 @@ class RestoreSeedDialog(CreateAccountDialog):
app.navigation_higherarchy.append(_back)
def on_key_down(self, keyboard, keycode, key, modifiers):
if keycode[1] == 'enter':
if keycode[0] in (13, 271):
self.on_enter()
return True
#super

View File

@@ -68,18 +68,19 @@ class InstallWizard(Widget):
if not button:
return self.dispatch('on_wizard_complete', None)
wallet = Wallet(self.storage)
gap = self.config.get('gap_limit', 5)
if gap !=5:
wallet.gap_limit = gap_limit
wallet.storage.put('gap_limit', gap, True)
#gap = self.config.get('gap_limit', 5)
#if gap !=5:
# wallet.gap_limit = gap_limit
# wallet.storage.put('gap_limit', gap, True)
dialog.close()
if button == dialog.ids.create:
# create
wallet = Wallet(self.storage)
self.change_password_dialog(wallet=wallet)
elif button == dialog.ids.restore:
# restore
wallet = None
self.restore_seed_dialog(wallet)
#if button == dialog.ids.watching:
#TODO: not available in the new design
@@ -102,20 +103,18 @@ class InstallWizard(Widget):
seed = unicode(_dlg.ids.text_input_seed.text)
if not seed:
app.show_error(_("No seed!"))
app.show_error(_("No seed!"), duration=.5)
return
try:
wallet.init_seed(seed)
except Exception:
import traceback
traceback.print_exc(file=sys.stdout)
app.show_error(_('No account tied to this seedphrase'))#, exit=True)
return
wallet = Wallet.from_seed(seed, self.storage)
except Exception as err:
_dlg.close()
return app.show_error(str(err) + '\n App will now exit',
exit=True, modal=True, duration=.5)
_dlg.close()
self.change_password_dialog(wallet=wallet, mode='restore')
return
return self.change_password_dialog(wallet=wallet, mode='restore')
def init_seed_dialog(self, wallet=None, instance=None, password=None,
wallet_name=None, mode='create'):

View File

@@ -40,7 +40,7 @@ class ElectrumWindow(App):
status = StringProperty(_('Uninitialised'))
'''The status of the connection should show the balance when connected
:attr:`status` is a `StringProperty` defaults to _'uninitialised'
:attr:`status` is a `StringProperty` defaults to 'uninitialised'
'''
def _get_num_zeros(self):
@@ -144,14 +144,15 @@ class ElectrumWindow(App):
self.exchanger = None
super(ElectrumWindow, self).__init__(**kwargs)
self.network = network = kwargs.get('network')
self.electrum_config = config = kwargs.get('config')
# create triggers so as to minimize updation a max of 5 times a sec
self._trigger_update_status = Clock.create_trigger(self.update_status,
.2)
self._trigger_update_console = Clock.create_trigger(self.update_console,
.2)
self._trigger_update_status =\
Clock.create_trigger(self.update_status, .2)
self._trigger_update_console =\
Clock.create_trigger(self.update_console, .2)
self._trigger_notify_transactions = \
Clock.create_trigger(self.notify_transactions, .2)
@@ -197,7 +198,8 @@ class ElectrumWindow(App):
self.on_resume()
def on_stop(self):
self.wallet.stop_threads()
if self.wallet:
self.wallet.stop_threads()
def on_back(self):
''' Manage screen hierarchy
@@ -251,7 +253,6 @@ class ElectrumWindow(App):
Logger.debug('Electrum: No Wallet set/found. Exiting...')
app.show_error('Electrum: No Wallet set/found. Exiting...',
exit=True)
Logger.info('wizard complete')
self.init_ui()
@@ -322,7 +323,7 @@ class ElectrumWindow(App):
'''
'''
if not self.exchanger:
from plugins.exchange_rate import Exchanger
from electrum_gui.kivy.plugins.exchange_rate import Exchanger
self.exchanger = Exchanger(self)
self.exchanger.start()
quote_currency = self.electrum_config.get("currency", 'EUR')
@@ -701,7 +702,8 @@ class ElectrumWindow(App):
arrow_pos=None,
exit=False,
icon='atlas://gui/kivy/theming/light/error',
duration=0):
duration=0,
modal=False):
''' Show a error Message Bubble.
'''
self.show_info_bubble(
@@ -711,18 +713,24 @@ class ElectrumWindow(App):
pos=pos or Window.center,
arrow_pos=arrow_pos,
exit=exit,
duration=duration)
duration=duration,
modal=modal)
def show_info(self, error,
width='200dp',
pos=None,
arrow_pos=None,
exit=False,
duration=0):
duration=0,
modal=False):
''' Show a Info Message Bubble.
'''
self.show_error(error, icon='atlas://gui/kivy/theming/light/error',
duration=duration)
duration=duration,
modal=modal,
exit=exit,
pos=pos,
arrow_pos=arrow_pos)
def show_info_bubble(self,
text=_('Hello World'),

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,179 @@
# -*- encoding: utf8 -*-
'''Module exchange_rate:
This module is responsible for getting the conversion rates between different
currencies.
'''
from kivy.network.urlrequest import UrlRequest
#kivy.event import EventDispatcher
from kivy.clock import Clock
import decimal
import json
class Exchanger(object):
'''
'''
symbols = {'ALL': 'Lek', 'AED': 'د.إ', 'AFN':'؋', 'ARS': '$', 'AMD': '֏',
'AWG': 'ƒ', 'ANG': 'ƒ', 'AOA': 'Kz', 'BDT': '', 'BHD': 'BD',
'BIF': 'FBu', 'BTC': 'BTC', 'BTN': 'Nu',
'AUD': '$', 'AZN': 'ман', 'BSD': '$', 'BBD': '$', 'BYR': 'p',
'BZD': 'BZ$', 'BMD': '$', 'BOB': '$b', 'BAM': 'KM', 'BWP': 'P',
'BGN': 'лв', 'BRL': 'R$', 'BND': '$', 'KHR': '', 'CAD': '$',
'KYD': '$', 'USD': '$', 'CLP': '$', 'CNY': '¥', 'COP': '$', 'CRC': '',
'HRK': 'kn', 'CUP':'', 'CZK': '', 'DKK': 'kr', 'DOP': 'RD$',
'XCD': '$', 'EGP': '£', 'SVC': '$' , 'EEK': 'kr', 'EUR': '',
'FKP': '£', 'FJD': '$', 'GHC': '¢', 'GIP': '£', 'GTQ': 'Q', 'GBP': '£',
'GYD': '$', 'HNL': 'L', 'HKD': '$', 'HUF': 'Ft', 'ISK': 'kr',
'INR': '', 'IDR': 'Rp', 'IRR': '', 'IMP': '£', 'ILS': '',
'JMD': 'J$', 'JPY': '¥', 'JEP': '£', 'KZT': 'лв', 'KPW': '',
'KRW': '', 'KGS': 'лв', 'LAK': '', 'LVL': 'Ls'}
def __init__(self, parent):
self.parent = parent
self.quote_currencies = None
self.exchanges = ('BlockChain', 'Coinbase', 'CoinDesk')
try:
self.use_exchange = parent.electrum_config.get('use_exchange',
'BlockChain')
except AttributeError:
self.use_exchange = 'BlockChain'
self.currencies = self.symbols.keys()
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
if self.use_exchange == "CoinDesk":
try:
connection = httplib.HTTPSConnection('api.coindesk.com')
connection.request("GET", "/v1/bpi/currentprice/" + str(quote_currency) + ".json")
except Exception:
return
resp = connection.getresponse()
if resp.reason == httplib.responses[httplib.NOT_FOUND]:
return
try:
resp_rate = json.loads(resp.read())
except Exception:
return
return btc_amount * decimal.Decimal(str(resp_rate["bpi"][str(quote_currency)]["rate_float"]))
return btc_amount * decimal.Decimal(quote_currencies[quote_currency])
def check_rates(self, dt):
if self.use_exchange == 'BlockChain':
self.check_blockchain()
elif self.use_exchange == 'CoinDesk':
self.check_coindesk()
elif self.use_exchange == 'Coinbase':
self.check_coinbase()
def check_coindesk(self):
def _lookup_rate(response, quote_id):
return decimal.Decimal(str(response[str(quote_id)]["15m"]))
def on_success(request, response):
quote_currencies = {}
try:
for r in response:
quote_currencies[r] = _lookup_rate(response, r)
self.quote_currencies = quote_currencies
except KeyError:
pass
self.parent.set_currencies(quote_currencies)
def on_failure(*args):
pass
def on_error(*args):
pass
def on_redirect(*args):
pass
req = UrlRequest(
url='https://api.coindesk.com/v1/bpi/supported-currencies.json',
on_success=on_success,
on_failure=on_failure,
on_error=on_error,
on_redirect=on_redirect,
timeout=5)
def check_coinbase(self):
def _lookup_rate(response, quote_id):
return decimal.Decimal(str(response[str(quote_id)]))
def on_success(request, response):
quote_currencies = {}
try:
for r in response:
if r[:7] == "btc_to_":
quote_currencies[r[7:].upper()] =\
_lookup_rate(response, r)
self.quote_currencies = quote_currencies
except KeyError:
pass
self.parent.set_currencies(quote_currencies)
def on_failure(*args):
pass
def on_error(*args):
pass
def on_redirect(*args):
pass
req = UrlRequest(
url='https://coinbase.com/api/v1/currencies/exchange_rates',
on_success=on_success,
on_failure=on_failure,
on_error=on_error,
on_redirect=on_redirect,
timeout=5)
def check_blockchain(self):
def _lookup_rate(response, quote_id):
return decimal.Decimal(str(response[str(quote_id)]["15m"]))
def on_success(request, response):
quote_currencies = {}
try:
for r in response:
quote_currencies[r] = _lookup_rate(response, r)
self.quote_currencies = quote_currencies
except KeyError:
pass
self.parent.set_currencies(quote_currencies)
def on_failure(*args):
pass
def on_error(*args):
pass
def on_redirect(*args):
pass
req = UrlRequest(url='https://blockchain.info/ticker',
on_success=on_success,
on_failure=on_failure,
on_error=on_error,
on_redirect=on_redirect,
timeout=5)
def start(self):
# check every 5 seconds
self.check_rates(0)
Clock.schedule_interval(self.check_rates, 5)
def stop(self):
Clock.unschedule(self.check_rates)

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB