2015-10-13 03:12:49 -07:00
|
|
|
import re
|
2015-09-08 07:19:02 -07:00
|
|
|
import sys
|
2015-09-30 06:39:02 -07:00
|
|
|
import time
|
2014-06-04 17:42:29 -07:00
|
|
|
import datetime
|
2015-09-09 03:09:16 -07:00
|
|
|
import traceback
|
2015-10-13 03:12:49 -07:00
|
|
|
from decimal import Decimal
|
2015-09-08 07:19:02 -07:00
|
|
|
|
2015-10-16 02:18:24 -07:00
|
|
|
import electrum
|
2014-02-17 23:12:57 -08:00
|
|
|
from electrum import WalletStorage, Wallet
|
2016-02-04 01:49:51 -08:00
|
|
|
from electrum_gui.kivy.i18n import _
|
2015-09-03 07:53:11 -07:00
|
|
|
from electrum.contacts import Contacts
|
2015-12-10 02:33:58 -08:00
|
|
|
from electrum.paymentrequest import InvoiceStore
|
2015-12-07 05:33:18 -08:00
|
|
|
from electrum.util import profiler, InvalidPassword
|
2015-10-13 03:12:49 -07:00
|
|
|
from electrum.plugins import run_hook
|
2015-12-03 13:43:43 -08:00
|
|
|
from electrum.util import format_satoshis, format_satoshis_plain
|
2015-12-12 14:23:58 -08:00
|
|
|
from electrum.paymentrequest import PR_UNPAID, PR_PAID, PR_UNKNOWN, PR_EXPIRED
|
2014-02-17 23:12:57 -08:00
|
|
|
|
|
|
|
from kivy.app import App
|
|
|
|
from kivy.core.window import Window
|
|
|
|
from kivy.logger import Logger
|
|
|
|
from kivy.utils import platform
|
|
|
|
from kivy.properties import (OptionProperty, AliasProperty, ObjectProperty,
|
2014-06-04 17:42:29 -07:00
|
|
|
StringProperty, ListProperty, BooleanProperty)
|
|
|
|
from kivy.cache import Cache
|
2014-03-01 11:11:58 -08:00
|
|
|
from kivy.clock import Clock
|
2014-06-04 17:42:29 -07:00
|
|
|
from kivy.factory import Factory
|
2015-10-06 00:59:29 -07:00
|
|
|
from kivy.metrics import inch, metrics
|
2015-10-13 03:12:49 -07:00
|
|
|
from kivy.lang import Builder
|
2014-02-17 23:12:57 -08:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
# lazy imports for factory so that widgets can be used in kv
|
|
|
|
Factory.register('InstallWizard',
|
|
|
|
module='electrum_gui.kivy.uix.dialogs.installwizard')
|
|
|
|
Factory.register('InfoBubble', module='electrum_gui.kivy.uix.dialogs')
|
2016-02-17 02:40:05 -08:00
|
|
|
Factory.register('OutputList', module='electrum_gui.kivy.uix.dialogs')
|
2016-02-17 22:47:09 -08:00
|
|
|
Factory.register('OutputItem', module='electrum_gui.kivy.uix.dialogs')
|
2014-06-21 10:09:31 -07:00
|
|
|
|
2015-12-14 03:08:11 -08:00
|
|
|
|
2016-02-17 22:26:31 -08:00
|
|
|
|
2015-12-01 07:51:14 -08:00
|
|
|
#from kivy.core.window import Window
|
|
|
|
#Window.softinput_mode = 'below_target'
|
2015-11-01 01:32:40 -07:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
|
|
|
|
# delayed imports: for startup speed on android
|
2015-12-03 13:43:43 -08:00
|
|
|
notification = app = ref = None
|
2014-06-04 17:42:29 -07:00
|
|
|
util = False
|
2015-10-06 00:59:29 -07:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
|
2014-08-01 09:09:34 -07:00
|
|
|
# register widget cache for keeping memory down timeout to forever to cache
|
2014-06-04 17:42:29 -07:00
|
|
|
# the data
|
2014-08-01 09:09:34 -07:00
|
|
|
Cache.register('electrum_widgets', timeout=0)
|
2014-03-01 11:11:58 -08:00
|
|
|
|
2015-10-06 00:59:29 -07:00
|
|
|
from kivy.uix.screenmanager import Screen
|
|
|
|
from kivy.uix.tabbedpanel import TabbedPanel
|
2015-10-13 03:12:49 -07:00
|
|
|
from kivy.uix.label import Label
|
|
|
|
from kivy.uix.checkbox import CheckBox
|
2015-12-06 01:41:32 -08:00
|
|
|
from kivy.uix.switch import Switch
|
2015-12-04 02:47:46 -08:00
|
|
|
from kivy.core.clipboard import Clipboard
|
2015-10-06 00:59:29 -07:00
|
|
|
|
|
|
|
Factory.register('TabbedCarousel', module='electrum_gui.kivy.uix.screens')
|
|
|
|
|
2016-02-15 01:40:14 -08:00
|
|
|
# Register fonts without this you won't be able to use bold/italic...
|
|
|
|
# inside markup.
|
|
|
|
from kivy.core.text import Label
|
|
|
|
Label.register('Roboto',
|
|
|
|
'gui/kivy/data/fonts/Roboto.ttf',
|
|
|
|
'gui/kivy/data/fonts/Roboto.ttf',
|
|
|
|
'gui/kivy/data/fonts/Roboto-Bold.ttf',
|
|
|
|
'gui/kivy/data/fonts/Roboto-Bold.ttf')
|
|
|
|
|
2015-10-06 00:59:29 -07:00
|
|
|
|
2015-12-16 02:53:37 -08:00
|
|
|
from electrum.util import base_units
|
2015-10-06 00:59:29 -07:00
|
|
|
|
2015-10-15 02:18:10 -07:00
|
|
|
|
2014-02-17 23:12:57 -08:00
|
|
|
class ElectrumWindow(App):
|
|
|
|
|
2015-10-15 02:35:32 -07:00
|
|
|
electrum_config = ObjectProperty(None)
|
|
|
|
|
2016-02-04 01:49:51 -08:00
|
|
|
language = StringProperty('en')
|
|
|
|
|
2016-02-15 01:40:14 -08:00
|
|
|
def set_URI(self, uri):
|
|
|
|
self.switch_to('send')
|
|
|
|
self.send_screen.set_URI(uri)
|
|
|
|
|
2016-02-10 23:34:40 -08:00
|
|
|
def on_new_intent(self, intent):
|
|
|
|
if intent.getScheme() != 'bitcoin':
|
|
|
|
return
|
|
|
|
uri = intent.getDataString()
|
2016-02-15 01:40:14 -08:00
|
|
|
self.set_URI(uri)
|
2016-02-10 23:34:40 -08:00
|
|
|
|
2016-02-04 01:49:51 -08:00
|
|
|
def on_language(self, instance, language):
|
|
|
|
Logger.info('language: {}'.format(language))
|
|
|
|
_.switch_lang(language)
|
|
|
|
|
2016-01-25 10:30:16 -08:00
|
|
|
def on_quotes(self, d):
|
2016-02-04 23:56:23 -08:00
|
|
|
#Logger.info("on_quotes")
|
2016-01-25 10:30:16 -08:00
|
|
|
pass
|
|
|
|
|
|
|
|
def on_history(self, d):
|
2016-02-04 23:56:23 -08:00
|
|
|
#Logger.info("on_history")
|
2016-01-25 10:30:16 -08:00
|
|
|
if self.history_screen:
|
|
|
|
self.history_screen.update()
|
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
def _get_bu(self):
|
2015-10-15 02:18:10 -07:00
|
|
|
return self.electrum_config.get('base_unit', 'mBTC')
|
2014-02-17 23:12:57 -08:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
def _set_bu(self, value):
|
2015-10-15 02:18:10 -07:00
|
|
|
assert value in base_units.keys()
|
|
|
|
self.electrum_config.set_key('base_unit', value, True)
|
|
|
|
self.update_status()
|
|
|
|
if self.history_screen:
|
|
|
|
self.history_screen.update()
|
2014-06-04 17:42:29 -07:00
|
|
|
|
2015-10-15 02:18:10 -07:00
|
|
|
base_unit = AliasProperty(_get_bu, _set_bu)
|
2015-12-09 00:41:24 -08:00
|
|
|
status = StringProperty('')
|
2015-12-03 13:43:43 -08:00
|
|
|
fiat_unit = StringProperty('')
|
|
|
|
|
2016-01-21 07:29:46 -08:00
|
|
|
def on_fiat_unit(self, a, b):
|
|
|
|
if self.history_screen:
|
|
|
|
self.history_screen.update()
|
|
|
|
|
2015-10-15 02:18:10 -07:00
|
|
|
def decimal_point(self):
|
|
|
|
return base_units[self.base_unit]
|
2014-02-17 23:12:57 -08:00
|
|
|
|
2015-12-03 13:43:43 -08:00
|
|
|
def btc_to_fiat(self, amount_str):
|
|
|
|
if not amount_str:
|
|
|
|
return ''
|
2015-12-05 09:14:17 -08:00
|
|
|
rate = run_hook('exchange_rate')
|
|
|
|
if not rate:
|
|
|
|
return ''
|
|
|
|
fiat_amount = self.get_amount(amount_str + ' ' + self.base_unit) * rate / pow(10, 8)
|
2015-12-07 01:40:10 -08:00
|
|
|
return "{:.2f}".format(fiat_amount).rstrip('0').rstrip('.')
|
2015-12-03 13:43:43 -08:00
|
|
|
|
|
|
|
def fiat_to_btc(self, fiat_amount):
|
|
|
|
if not fiat_amount:
|
|
|
|
return ''
|
2015-12-05 09:14:17 -08:00
|
|
|
rate = run_hook('exchange_rate')
|
|
|
|
if not rate:
|
|
|
|
return ''
|
|
|
|
satoshis = int(pow(10,8) * Decimal(fiat_amount) / Decimal(rate))
|
2015-12-07 01:40:10 -08:00
|
|
|
return format_satoshis_plain(satoshis, self.decimal_point())
|
2015-12-02 03:11:28 -08:00
|
|
|
|
2015-09-09 03:09:16 -07:00
|
|
|
def get_amount(self, amount_str):
|
2015-10-16 02:18:24 -07:00
|
|
|
a, u = amount_str.split()
|
|
|
|
assert u == self.base_unit
|
2015-09-09 03:09:16 -07:00
|
|
|
try:
|
2015-10-16 02:18:24 -07:00
|
|
|
x = Decimal(a)
|
2015-09-09 03:09:16 -07:00
|
|
|
except:
|
|
|
|
return None
|
2015-10-15 02:18:10 -07:00
|
|
|
p = pow(10, self.decimal_point())
|
2015-09-09 03:09:16 -07:00
|
|
|
return int(p * x)
|
|
|
|
|
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
_orientation = OptionProperty('landscape',
|
|
|
|
options=('landscape', 'portrait'))
|
2014-03-01 11:11:58 -08:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
def _get_orientation(self):
|
|
|
|
return self._orientation
|
2014-03-01 11:11:58 -08:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
orientation = AliasProperty(_get_orientation,
|
|
|
|
None,
|
|
|
|
bind=('_orientation',))
|
|
|
|
'''Tries to ascertain the kind of device the app is running on.
|
|
|
|
Cane be one of `tablet` or `phone`.
|
2014-02-17 23:12:57 -08:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
:data:`orientation` is a read only `AliasProperty` Defaults to 'landscape'
|
2014-02-17 23:12:57 -08:00
|
|
|
'''
|
|
|
|
|
|
|
|
_ui_mode = OptionProperty('phone', options=('tablet', 'phone'))
|
|
|
|
|
|
|
|
def _get_ui_mode(self):
|
|
|
|
return self._ui_mode
|
|
|
|
|
|
|
|
ui_mode = AliasProperty(_get_ui_mode,
|
|
|
|
None,
|
|
|
|
bind=('_ui_mode',))
|
|
|
|
'''Defines tries to ascertain the kind of device the app is running on.
|
|
|
|
Cane be one of `tablet` or `phone`.
|
|
|
|
|
|
|
|
:data:`ui_mode` is a read only `AliasProperty` Defaults to 'phone'
|
|
|
|
'''
|
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
wallet = ObjectProperty(None)
|
|
|
|
'''Holds the electrum wallet
|
2014-02-17 23:12:57 -08:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
:attr:`wallet` is a `ObjectProperty` defaults to None.
|
2014-02-17 23:12:57 -08:00
|
|
|
'''
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
# initialize variables
|
2015-12-04 02:47:46 -08:00
|
|
|
self._clipboard = Clipboard
|
2014-06-04 17:42:29 -07:00
|
|
|
self.info_bubble = None
|
|
|
|
self.qrscanner = None
|
|
|
|
self.nfcscanner = None
|
|
|
|
self.tabs = None
|
2016-02-10 03:53:03 -08:00
|
|
|
self.is_exit = False
|
2015-12-12 14:23:58 -08:00
|
|
|
|
2014-02-17 23:12:57 -08:00
|
|
|
super(ElectrumWindow, self).__init__(**kwargs)
|
2014-03-04 10:02:03 -08:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
title = _('Electrum App')
|
|
|
|
self.electrum_config = config = kwargs.get('config', None)
|
2016-02-04 01:49:51 -08:00
|
|
|
self.language = config.get('language', 'en')
|
2015-10-13 03:12:49 -07:00
|
|
|
self.network = network = kwargs.get('network', None)
|
|
|
|
self.plugins = kwargs.get('plugins', [])
|
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
self.gui_object = kwargs.get('gui_object', None)
|
|
|
|
|
2015-09-09 03:09:16 -07:00
|
|
|
#self.config = self.gui_object.config
|
|
|
|
self.contacts = Contacts(self.electrum_config)
|
2015-12-10 02:33:58 -08:00
|
|
|
self.invoices = InvoiceStore(self.electrum_config)
|
2015-09-03 07:53:11 -07:00
|
|
|
|
2014-03-10 11:48:12 -07:00
|
|
|
# create triggers so as to minimize updation a max of 2 times a sec
|
2014-06-04 17:42:29 -07:00
|
|
|
self._trigger_update_wallet =\
|
|
|
|
Clock.create_trigger(self.update_wallet, .5)
|
2014-03-04 10:02:03 -08:00
|
|
|
self._trigger_update_status =\
|
2014-03-10 11:48:12 -07:00
|
|
|
Clock.create_trigger(self.update_status, .5)
|
2014-03-01 11:11:58 -08:00
|
|
|
self._trigger_notify_transactions = \
|
2014-06-04 17:42:29 -07:00
|
|
|
Clock.create_trigger(self.notify_transactions, 5)
|
|
|
|
|
2015-12-12 14:23:58 -08:00
|
|
|
|
2015-12-11 06:21:21 -08:00
|
|
|
def on_pr(self, pr):
|
|
|
|
if pr.verify(self.contacts):
|
|
|
|
key = self.invoices.add(pr)
|
2016-02-05 09:16:48 -08:00
|
|
|
if self.invoices_screen:
|
|
|
|
self.invoices_screen.update()
|
2015-12-11 06:21:21 -08:00
|
|
|
status = self.invoices.get_status(key)
|
|
|
|
if status == PR_PAID:
|
2015-12-12 14:23:58 -08:00
|
|
|
self.show_error("invoice already paid")
|
2015-12-11 06:21:21 -08:00
|
|
|
self.send_screen.do_clear()
|
|
|
|
else:
|
2015-12-12 14:23:58 -08:00
|
|
|
if pr.has_expired():
|
|
|
|
self.show_error(_('Payment request has expired'))
|
|
|
|
else:
|
2015-12-18 02:05:10 -08:00
|
|
|
self.switch_to('send')
|
2016-02-12 13:20:20 -08:00
|
|
|
self.send_screen.set_request(pr)
|
2015-12-11 06:21:21 -08:00
|
|
|
else:
|
2015-12-12 14:23:58 -08:00
|
|
|
self.show_error("invoice error:" + pr.error)
|
2015-12-11 06:21:21 -08:00
|
|
|
self.send_screen.do_clear()
|
|
|
|
|
2016-02-12 07:09:16 -08:00
|
|
|
def on_qr(self, data):
|
|
|
|
if data.startswith('bitcoin:'):
|
2016-02-15 01:40:14 -08:00
|
|
|
self.set_URI(data)
|
2016-02-15 01:43:57 -08:00
|
|
|
return
|
|
|
|
# try to decode transaction
|
|
|
|
from electrum.bitcoin import base_decode
|
|
|
|
from electrum.transaction import Transaction
|
|
|
|
try:
|
2016-02-12 07:09:16 -08:00
|
|
|
text = base_decode(data, None, base=43).encode('hex')
|
|
|
|
tx = Transaction(text)
|
2016-02-15 01:43:57 -08:00
|
|
|
except:
|
|
|
|
tx = None
|
|
|
|
if tx:
|
2016-02-12 07:09:16 -08:00
|
|
|
self.tx_dialog(tx)
|
2016-02-15 01:43:57 -08:00
|
|
|
return
|
|
|
|
# show error
|
|
|
|
self.show_error("Unable to decode QR data")
|
2016-02-12 07:09:16 -08:00
|
|
|
|
2015-12-18 02:05:10 -08:00
|
|
|
def update_tab(self, name):
|
2015-12-12 14:23:58 -08:00
|
|
|
s = getattr(self, name + '_screen', None)
|
|
|
|
if s:
|
|
|
|
s.update()
|
|
|
|
|
2015-12-18 02:05:10 -08:00
|
|
|
@profiler
|
|
|
|
def update_tabs(self):
|
|
|
|
for tab in ['invoices', 'send', 'history', 'receive', 'requests']:
|
|
|
|
self.update_tab(tab)
|
|
|
|
|
|
|
|
def switch_to(self, name):
|
2016-02-05 09:16:48 -08:00
|
|
|
s = getattr(self, name + '_screen', None)
|
|
|
|
if self.send_screen is None:
|
|
|
|
s = self.tabs.ids[name + '_screen']
|
|
|
|
s.load_screen()
|
|
|
|
panel = self.tabs.ids.panel
|
2015-12-18 02:05:10 -08:00
|
|
|
tab = self.tabs.ids[name + '_tab']
|
2016-02-05 09:16:48 -08:00
|
|
|
panel.switch_to(tab)
|
2015-12-18 02:05:10 -08:00
|
|
|
|
2015-12-12 14:23:58 -08:00
|
|
|
def show_request(self, addr):
|
2015-12-18 02:05:10 -08:00
|
|
|
self.switch_to('receive')
|
2016-02-09 03:48:25 -08:00
|
|
|
self.receive_screen.screen.address = addr
|
2014-02-17 23:12:57 -08:00
|
|
|
|
2016-02-15 04:49:33 -08:00
|
|
|
def show_pr_details(self, req, status, is_invoice):
|
|
|
|
from electrum.util import format_time
|
|
|
|
requestor = req.get('requestor')
|
|
|
|
exp = req.get('exp')
|
|
|
|
memo = req.get('memo')
|
|
|
|
amount = req.get('amount')
|
|
|
|
popup = Builder.load_file('gui/kivy/uix/ui_screens/invoice.kv')
|
2016-02-16 01:24:13 -08:00
|
|
|
popup.is_invoice = is_invoice
|
|
|
|
popup.amount = amount
|
|
|
|
popup.requestor = requestor if is_invoice else req.get('address')
|
|
|
|
popup.exp = format_time(exp) if exp else ''
|
|
|
|
popup.description = memo if memo else ''
|
|
|
|
popup.signature = req.get('signature', '')
|
|
|
|
popup.status = status
|
2016-02-15 04:49:33 -08:00
|
|
|
txid = req.get('txid')
|
2016-02-17 09:04:34 -08:00
|
|
|
popup.tx_hash = txid or ''
|
2016-02-17 23:51:27 -08:00
|
|
|
popup.on_open = lambda: popup.ids.output_list.update(req.get('outputs', []))
|
2016-02-17 09:04:34 -08:00
|
|
|
popup.open()
|
2016-02-15 04:49:33 -08:00
|
|
|
|
2016-02-18 04:53:23 -08:00
|
|
|
def qr_dialog(self, title, data, show_text=False):
|
2016-02-12 06:21:03 -08:00
|
|
|
from uix.dialogs.qr_dialog import QRDialog
|
2016-02-18 04:53:23 -08:00
|
|
|
popup = QRDialog(title, data, show_text)
|
2016-02-12 06:21:03 -08:00
|
|
|
popup.open()
|
|
|
|
|
2015-09-08 07:19:02 -07:00
|
|
|
def scan_qr(self, on_complete):
|
2016-02-08 02:06:45 -08:00
|
|
|
if platform != 'android':
|
|
|
|
return
|
2015-09-08 07:19:02 -07:00
|
|
|
from jnius import autoclass
|
2015-09-09 03:09:16 -07:00
|
|
|
from android import activity
|
2015-09-08 07:19:02 -07:00
|
|
|
PythonActivity = autoclass('org.renpy.android.PythonActivity')
|
|
|
|
Intent = autoclass('android.content.Intent')
|
|
|
|
intent = Intent("com.google.zxing.client.android.SCAN")
|
|
|
|
intent.putExtra("SCAN_MODE", "QR_CODE_MODE")
|
|
|
|
def on_qr_result(requestCode, resultCode, intent):
|
|
|
|
if requestCode == 0:
|
|
|
|
if resultCode == -1: # RESULT_OK:
|
|
|
|
contents = intent.getStringExtra("SCAN_RESULT")
|
|
|
|
if intent.getStringExtra("SCAN_RESULT_FORMAT") == 'QR_CODE':
|
2015-12-11 06:21:21 -08:00
|
|
|
on_complete(contents)
|
2015-09-08 07:19:02 -07:00
|
|
|
activity.bind(on_activity_result=on_qr_result)
|
2016-02-09 10:45:14 -08:00
|
|
|
try:
|
|
|
|
PythonActivity.mActivity.startActivityForResult(intent, 0)
|
|
|
|
except:
|
|
|
|
self.show_error('Could not start Barcode Scanner')
|
2015-10-06 00:59:29 -07:00
|
|
|
|
2015-10-13 03:12:49 -07:00
|
|
|
def build(self):
|
2014-02-17 23:12:57 -08:00
|
|
|
return Builder.load_file('gui/kivy/main.kv')
|
|
|
|
|
|
|
|
def _pause(self):
|
|
|
|
if platform == 'android':
|
2014-03-01 11:11:58 -08:00
|
|
|
# move activity to back
|
2014-02-17 23:12:57 -08:00
|
|
|
from jnius import autoclass
|
|
|
|
python_act = autoclass('org.renpy.android.PythonActivity')
|
|
|
|
mActivity = python_act.mActivity
|
|
|
|
mActivity.moveTaskToBack(True)
|
|
|
|
|
|
|
|
def on_start(self):
|
2014-03-01 11:11:58 -08:00
|
|
|
''' This is the start point of the kivy ui
|
|
|
|
'''
|
2016-02-04 23:56:23 -08:00
|
|
|
import time
|
|
|
|
Logger.info('Time to on_start: {} <<<<<<<<'.format(time.clock()))
|
2015-10-06 00:59:29 -07:00
|
|
|
Logger.info("dpi: {} {}".format(metrics.dpi, metrics.dpi_rounded))
|
2014-06-04 17:42:29 -07:00
|
|
|
win = Window
|
2016-02-15 01:40:14 -08:00
|
|
|
win.bind(size=self.on_size, on_keyboard=self.on_keyboard)
|
2014-06-04 17:42:29 -07:00
|
|
|
win.bind(on_key_down=self.on_key_down)
|
2016-01-27 06:51:20 -08:00
|
|
|
win.softinput_mode = 'below_target'
|
2014-06-04 17:42:29 -07:00
|
|
|
self.on_size(win, win.size)
|
2015-12-18 01:53:50 -08:00
|
|
|
self.init_ui()
|
2015-12-15 23:57:47 -08:00
|
|
|
self.load_wallet_by_name(self.electrum_config.get_wallet_path())
|
2016-02-05 09:16:48 -08:00
|
|
|
# init plugins
|
2016-01-25 10:30:16 -08:00
|
|
|
run_hook('init_kivy', self)
|
2016-02-05 09:16:48 -08:00
|
|
|
# default tab
|
2016-02-15 01:25:00 -08:00
|
|
|
self.switch_to('history')
|
2016-02-10 23:34:40 -08:00
|
|
|
# bind intent for bitcoin: URI scheme
|
|
|
|
if platform == 'android':
|
|
|
|
from android import activity
|
|
|
|
activity.bind(on_new_intent=self.on_new_intent)
|
2014-02-17 23:12:57 -08:00
|
|
|
|
2016-02-15 01:40:14 -08:00
|
|
|
# URI passed in config
|
|
|
|
uri = self.electrum_config.get('url')
|
|
|
|
if uri:
|
|
|
|
self.set_URI(uri)
|
|
|
|
|
2015-12-15 23:57:47 -08:00
|
|
|
def load_wallet_by_name(self, wallet_path):
|
|
|
|
if not wallet_path:
|
|
|
|
return
|
|
|
|
config = self.electrum_config
|
|
|
|
storage = WalletStorage(wallet_path)
|
|
|
|
Logger.info('Electrum: Check for existing wallet')
|
2014-06-04 17:42:29 -07:00
|
|
|
if storage.file_exists:
|
|
|
|
wallet = Wallet(storage)
|
|
|
|
action = wallet.get_action()
|
|
|
|
else:
|
|
|
|
action = 'new'
|
|
|
|
if action is not None:
|
2014-02-17 23:12:57 -08:00
|
|
|
# start installation wizard
|
|
|
|
Logger.debug('Electrum: Wallet not found. Launching install wizard')
|
2014-06-04 17:42:29 -07:00
|
|
|
wizard = Factory.InstallWizard(config, self.network, storage)
|
2015-12-18 01:53:50 -08:00
|
|
|
wizard.bind(on_wizard_complete=lambda instance, wallet: self.load_wallet(wallet))
|
2014-06-04 17:42:29 -07:00
|
|
|
wizard.run(action)
|
2014-02-17 23:12:57 -08:00
|
|
|
else:
|
2015-12-18 01:53:50 -08:00
|
|
|
self.load_wallet(wallet)
|
2014-02-17 23:12:57 -08:00
|
|
|
self.on_resume()
|
|
|
|
|
2014-03-01 11:11:58 -08:00
|
|
|
def on_stop(self):
|
2015-12-15 23:57:47 -08:00
|
|
|
self.stop_wallet()
|
|
|
|
|
|
|
|
def stop_wallet(self):
|
2014-03-04 10:02:03 -08:00
|
|
|
if self.wallet:
|
|
|
|
self.wallet.stop_threads()
|
2014-03-01 11:11:58 -08:00
|
|
|
|
|
|
|
def on_key_down(self, instance, key, keycode, codepoint, modifiers):
|
|
|
|
if 'ctrl' in modifiers:
|
|
|
|
# q=24 w=25
|
|
|
|
if keycode in (24, 25):
|
|
|
|
self.stop()
|
|
|
|
elif keycode == 27:
|
|
|
|
# r=27
|
|
|
|
# force update wallet
|
|
|
|
self.update_wallet()
|
|
|
|
elif keycode == 112:
|
|
|
|
# pageup
|
|
|
|
#TODO move to next tab
|
|
|
|
pass
|
|
|
|
elif keycode == 117:
|
|
|
|
# pagedown
|
|
|
|
#TODO move to prev tab
|
|
|
|
pass
|
|
|
|
#TODO: alt+tab_number to activate the particular tab
|
|
|
|
|
2014-02-17 23:12:57 -08:00
|
|
|
def on_keyboard(self, instance, key, keycode, codepoint, modifiers):
|
2016-02-10 03:53:03 -08:00
|
|
|
if key == 27 and self.is_exit is False:
|
|
|
|
self.is_exit = True
|
|
|
|
self.show_info(_('Press again to exit'))
|
2014-02-17 23:12:57 -08:00
|
|
|
return True
|
2016-02-10 03:53:03 -08:00
|
|
|
self.is_exit = False
|
|
|
|
# override settings button
|
2016-02-10 05:01:02 -08:00
|
|
|
if key in (319, 282): #f1/settings button on android
|
|
|
|
#self.gui.main_gui.toggle_settings(self)
|
|
|
|
return True
|
2014-02-17 23:12:57 -08:00
|
|
|
|
2015-10-06 00:59:29 -07:00
|
|
|
def popup_dialog(self, name):
|
2015-12-16 03:40:30 -08:00
|
|
|
if name == 'settings':
|
2015-12-18 06:03:38 -08:00
|
|
|
from uix.dialogs.settings import SettingsDialog
|
|
|
|
d = SettingsDialog(self)
|
|
|
|
d.open()
|
|
|
|
elif name == 'wallets':
|
|
|
|
from uix.dialogs.wallets import WalletDialog
|
|
|
|
d = WalletDialog()
|
|
|
|
d.open()
|
2015-12-16 03:40:30 -08:00
|
|
|
else:
|
|
|
|
popup = Builder.load_file('gui/kivy/uix/ui_screens/'+name+'.kv')
|
|
|
|
popup.open()
|
2015-10-06 00:59:29 -07:00
|
|
|
|
2015-09-30 06:39:02 -07:00
|
|
|
@profiler
|
2014-03-01 11:11:58 -08:00
|
|
|
def init_ui(self):
|
|
|
|
''' Initialize The Ux part of electrum. This function performs the basic
|
|
|
|
tasks of setting up the ui.
|
|
|
|
'''
|
2015-10-13 10:09:12 -07:00
|
|
|
from weakref import ref
|
2014-03-01 11:11:58 -08:00
|
|
|
|
|
|
|
self.funds_error = False
|
|
|
|
# setup UX
|
2015-10-06 00:59:29 -07:00
|
|
|
self.screens = {}
|
2014-06-04 17:42:29 -07:00
|
|
|
|
|
|
|
#setup lazy imports for mainscreen
|
|
|
|
Factory.register('AnimatedPopup',
|
|
|
|
module='electrum_gui.kivy.uix.dialogs')
|
|
|
|
Factory.register('QRCodeWidget',
|
|
|
|
module='electrum_gui.kivy.uix.qrcodewidget')
|
2015-09-09 07:02:06 -07:00
|
|
|
|
2014-08-01 09:09:34 -07:00
|
|
|
# preload widgets. Remove this if you want to load the widgets on demand
|
2015-10-07 04:06:28 -07:00
|
|
|
#Cache.append('electrum_widgets', 'AnimatedPopup', Factory.AnimatedPopup())
|
|
|
|
#Cache.append('electrum_widgets', 'QRCodeWidget', Factory.QRCodeWidget())
|
2014-08-01 09:09:34 -07:00
|
|
|
|
|
|
|
# load and focus the ui
|
2015-10-06 00:59:29 -07:00
|
|
|
self.root.manager = self.root.ids['manager']
|
2016-02-05 09:16:48 -08:00
|
|
|
|
2015-10-06 00:59:29 -07:00
|
|
|
self.history_screen = None
|
|
|
|
self.contacts_screen = None
|
2016-02-05 09:16:48 -08:00
|
|
|
self.send_screen = None
|
|
|
|
self.invoices_screen = None
|
|
|
|
self.receive_screen = None
|
|
|
|
self.requests_screen = None
|
2014-06-04 17:42:29 -07:00
|
|
|
|
|
|
|
self.icon = "icons/electrum.png"
|
2014-03-01 11:11:58 -08:00
|
|
|
|
|
|
|
# connect callbacks
|
|
|
|
if self.network:
|
2015-12-01 04:50:47 -08:00
|
|
|
interests = ['updated', 'status', 'new_transaction']
|
2015-11-13 05:42:21 -08:00
|
|
|
self.network.register_callback(self.on_network, interests)
|
2014-03-01 11:11:58 -08:00
|
|
|
|
2015-12-15 23:57:47 -08:00
|
|
|
#self.wallet = None
|
2015-12-12 14:23:58 -08:00
|
|
|
self.tabs = self.root.ids['tabs']
|
2014-03-01 11:11:58 -08:00
|
|
|
|
2015-11-13 05:42:21 -08:00
|
|
|
def on_network(self, event, *args):
|
|
|
|
if event == 'updated':
|
|
|
|
self._trigger_update_wallet()
|
|
|
|
elif event == 'status':
|
|
|
|
self._trigger_update_status()
|
|
|
|
elif event == 'new_transaction':
|
|
|
|
self._trigger_notify_transactions(*args)
|
2014-03-01 11:11:58 -08:00
|
|
|
|
2015-09-30 06:39:02 -07:00
|
|
|
@profiler
|
2014-03-01 11:11:58 -08:00
|
|
|
def load_wallet(self, wallet):
|
2016-01-18 05:09:48 -08:00
|
|
|
self.stop_wallet()
|
2014-03-01 11:11:58 -08:00
|
|
|
self.wallet = wallet
|
2016-01-18 05:09:48 -08:00
|
|
|
self.wallet.start_threads(self.network)
|
2014-03-01 11:11:58 -08:00
|
|
|
self.current_account = self.wallet.storage.get('current_account', None)
|
|
|
|
self.update_wallet()
|
|
|
|
# Once GUI has been initialized check if we want to announce something
|
|
|
|
# since the callback has been called before the GUI was initialized
|
2015-12-18 02:05:10 -08:00
|
|
|
self.update_tabs()
|
2014-03-01 11:11:58 -08:00
|
|
|
self.notify_transactions()
|
2015-12-01 08:29:24 -08:00
|
|
|
run_hook('load_wallet', wallet, self)
|
2014-03-01 11:11:58 -08:00
|
|
|
|
|
|
|
def update_status(self, *dt):
|
|
|
|
if not self.wallet:
|
|
|
|
return
|
|
|
|
if self.network is None or not self.network.is_running():
|
2015-12-09 00:41:24 -08:00
|
|
|
self.status = _("Offline")
|
2014-03-01 11:11:58 -08:00
|
|
|
elif self.network.is_connected():
|
2015-09-04 01:23:56 -07:00
|
|
|
server_height = self.network.get_server_height()
|
|
|
|
server_lag = self.network.get_local_height() - server_height
|
|
|
|
if not self.wallet.up_to_date or server_height == 0:
|
2015-10-06 00:59:29 -07:00
|
|
|
self.status = _("Synchronizing...")
|
2015-09-04 01:23:56 -07:00
|
|
|
elif server_lag > 1:
|
2015-10-06 00:59:29 -07:00
|
|
|
self.status = _("Server lagging (%d blocks)"%server_lag)
|
2014-03-01 11:11:58 -08:00
|
|
|
else:
|
2015-09-04 01:23:56 -07:00
|
|
|
c, u, x = self.wallet.get_account_balance(self.current_account)
|
2015-12-09 00:41:24 -08:00
|
|
|
text = self.format_amount(c+x+u)
|
2016-02-04 01:49:51 -08:00
|
|
|
self.status = str(text.strip() + ' ' + self.base_unit)
|
2014-03-01 11:11:58 -08:00
|
|
|
else:
|
2015-10-06 00:59:29 -07:00
|
|
|
self.status = _("Not connected")
|
2015-10-30 07:11:54 -07:00
|
|
|
|
2015-10-30 06:10:41 -07:00
|
|
|
def get_max_amount(self):
|
|
|
|
inputs = self.wallet.get_spendable_coins(None)
|
2016-02-03 02:01:36 -08:00
|
|
|
addr = str(self.send_screen.screen.address) or self.wallet.dummy_address()
|
|
|
|
amount, fee = self.wallet.get_max_amount(self.electrum_config, inputs, addr, None)
|
2015-10-31 07:25:22 -07:00
|
|
|
return format_satoshis_plain(amount, self.decimal_point())
|
2015-10-30 06:10:41 -07:00
|
|
|
|
2014-03-01 11:11:58 -08:00
|
|
|
def format_amount(self, x, is_diff=False, whitespaces=False):
|
2015-12-03 13:43:43 -08:00
|
|
|
return format_satoshis(x, is_diff, 0, self.decimal_point(), whitespaces)
|
2014-06-04 17:42:29 -07:00
|
|
|
|
2015-12-12 21:41:22 -08:00
|
|
|
def format_amount_and_units(self, x):
|
|
|
|
return format_satoshis_plain(x, self.decimal_point()) + ' ' + self.base_unit
|
|
|
|
|
2015-09-30 06:39:02 -07:00
|
|
|
@profiler
|
2014-06-04 17:42:29 -07:00
|
|
|
def update_wallet(self, *dt):
|
|
|
|
self._trigger_update_status()
|
2015-12-20 08:37:07 -08:00
|
|
|
#if self.wallet.up_to_date or not self.network or not self.network.is_connected():
|
|
|
|
self.update_tabs()
|
2014-06-04 17:42:29 -07:00
|
|
|
|
2015-09-30 06:39:02 -07:00
|
|
|
@profiler
|
2014-03-01 11:11:58 -08:00
|
|
|
def notify_transactions(self, *dt):
|
|
|
|
if not self.network or not self.network.is_connected():
|
|
|
|
return
|
2015-09-03 06:09:45 -07:00
|
|
|
# temporarily disabled for merge
|
|
|
|
return
|
2014-06-04 17:42:29 -07:00
|
|
|
iface = self.network
|
|
|
|
ptfn = iface.pending_transactions_for_notifications
|
|
|
|
if len(ptfn) > 0:
|
2014-03-01 11:11:58 -08:00
|
|
|
# Combine the transactions if there are more then three
|
2014-06-04 17:42:29 -07:00
|
|
|
tx_amount = len(ptfn)
|
2014-03-01 11:11:58 -08:00
|
|
|
if(tx_amount >= 3):
|
|
|
|
total_amount = 0
|
2014-06-04 17:42:29 -07:00
|
|
|
for tx in ptfn:
|
2014-03-01 11:11:58 -08:00
|
|
|
is_relevant, is_mine, v, fee = self.wallet.get_tx_value(tx)
|
|
|
|
if(v > 0):
|
|
|
|
total_amount += v
|
|
|
|
self.notify(_("{txs}s new transactions received. Total amount"
|
|
|
|
"received in the new transactions {amount}s"
|
|
|
|
"{unit}s").format(txs=tx_amount,
|
|
|
|
amount=self.format_amount(total_amount),
|
|
|
|
unit=self.base_unit()))
|
|
|
|
|
|
|
|
iface.pending_transactions_for_notifications = []
|
|
|
|
else:
|
|
|
|
for tx in iface.pending_transactions_for_notifications:
|
|
|
|
if tx:
|
|
|
|
iface.pending_transactions_for_notifications.remove(tx)
|
|
|
|
is_relevant, is_mine, v, fee = self.wallet.get_tx_value(tx)
|
|
|
|
if(v > 0):
|
|
|
|
self.notify(
|
2014-06-21 10:09:31 -07:00
|
|
|
_("{txs} new transaction received. {amount} {unit}").
|
|
|
|
format(txs=tx_amount, amount=self.format_amount(v),
|
2014-06-04 17:42:29 -07:00
|
|
|
unit=self.base_unit))
|
|
|
|
|
2014-03-01 11:11:58 -08:00
|
|
|
def notify(self, message):
|
|
|
|
try:
|
|
|
|
global notification, os
|
|
|
|
if not notification:
|
|
|
|
from plyer import notification
|
|
|
|
import os
|
|
|
|
icon = (os.path.dirname(os.path.realpath(__file__))
|
|
|
|
+ '/../../' + self.icon)
|
|
|
|
notification.notify('Electrum', message,
|
|
|
|
app_icon=icon, app_name='Electrum')
|
|
|
|
except ImportError:
|
|
|
|
Logger.Error('Notification: needs plyer; `sudo pip install plyer`')
|
2014-02-17 23:12:57 -08:00
|
|
|
|
|
|
|
def on_pause(self):
|
|
|
|
# pause nfc
|
2014-06-04 17:42:29 -07:00
|
|
|
if self.qrscanner:
|
|
|
|
self.qrscanner.stop()
|
|
|
|
if self.nfcscanner:
|
|
|
|
self.nfcscanner.nfc_disable()
|
2014-02-17 23:12:57 -08:00
|
|
|
return True
|
|
|
|
|
|
|
|
def on_resume(self):
|
2014-06-04 17:42:29 -07:00
|
|
|
if self.qrscanner and qrscanner.get_parent_window():
|
|
|
|
self.qrscanner.start()
|
|
|
|
if self.nfcscanner:
|
|
|
|
self.nfcscanner.nfc_enable()
|
2014-02-17 23:12:57 -08:00
|
|
|
|
|
|
|
def on_size(self, instance, value):
|
|
|
|
width, height = value
|
|
|
|
self._orientation = 'landscape' if width > height else 'portrait'
|
|
|
|
self._ui_mode = 'tablet' if min(width, height) > inch(3.51) else 'phone'
|
2015-10-06 00:59:29 -07:00
|
|
|
|
2016-02-18 04:53:23 -08:00
|
|
|
def on_ref_label(self, label, touch):
|
|
|
|
if label.touched:
|
|
|
|
label.touched = False
|
|
|
|
self.qr_dialog(label.name, label.data, True)
|
2016-02-18 03:41:05 -08:00
|
|
|
else:
|
2016-02-18 04:53:23 -08:00
|
|
|
label.touched = True
|
|
|
|
self._clipboard.copy(label.data)
|
|
|
|
Clock.schedule_once(lambda dt: self.show_info(_('Text copied to clipboard.\nTap again to display it as QR code.')))
|
2016-02-18 03:41:05 -08:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
def set_send(self, address, amount, label, message):
|
|
|
|
self.send_payment(address, amount=amount, label=label, message=message)
|
|
|
|
|
|
|
|
def show_error(self, error, width='200dp', pos=None, arrow_pos=None,
|
|
|
|
exit=False, icon='atlas://gui/kivy/theming/light/error', duration=0,
|
|
|
|
modal=False):
|
2014-02-17 23:12:57 -08:00
|
|
|
''' Show a error Message Bubble.
|
|
|
|
'''
|
2014-06-04 17:42:29 -07:00
|
|
|
self.show_info_bubble( text=error, icon=icon, width=width,
|
|
|
|
pos=pos or Window.center, arrow_pos=arrow_pos, exit=exit,
|
|
|
|
duration=duration, modal=modal)
|
|
|
|
|
|
|
|
def show_info(self, error, width='200dp', pos=None, arrow_pos=None,
|
|
|
|
exit=False, duration=0, modal=False):
|
2014-02-20 23:50:27 -08:00
|
|
|
''' Show a Info Message Bubble.
|
|
|
|
'''
|
2016-02-17 02:40:05 -08:00
|
|
|
self.show_error(error, icon='atlas://gui/kivy/theming/light/important',
|
2014-06-04 17:42:29 -07:00
|
|
|
duration=duration, modal=modal, exit=exit, pos=pos,
|
|
|
|
arrow_pos=arrow_pos)
|
|
|
|
|
|
|
|
def show_info_bubble(self, text=_('Hello World'), pos=None, duration=0,
|
|
|
|
arrow_pos='bottom_mid', width=None, icon='', modal=False, exit=False):
|
2014-02-17 23:12:57 -08:00
|
|
|
'''Method to show a Information Bubble
|
|
|
|
|
|
|
|
.. parameters::
|
|
|
|
text: Message to be displayed
|
|
|
|
pos: position for the bubble
|
|
|
|
duration: duration the bubble remains on screen. 0 = click to hide
|
|
|
|
width: width of the Bubble
|
|
|
|
arrow_pos: arrow position for the bubble
|
|
|
|
'''
|
|
|
|
info_bubble = self.info_bubble
|
|
|
|
if not info_bubble:
|
2014-06-04 17:42:29 -07:00
|
|
|
info_bubble = self.info_bubble = Factory.InfoBubble()
|
2014-02-17 23:12:57 -08:00
|
|
|
|
2014-06-04 17:42:29 -07:00
|
|
|
win = Window
|
2014-02-17 23:12:57 -08:00
|
|
|
if info_bubble.parent:
|
2014-06-04 17:42:29 -07:00
|
|
|
win.remove_widget(info_bubble
|
2014-02-20 23:50:27 -08:00
|
|
|
if not info_bubble.modal else
|
|
|
|
info_bubble._modal_view)
|
2014-02-17 23:12:57 -08:00
|
|
|
|
|
|
|
if not arrow_pos:
|
|
|
|
info_bubble.show_arrow = False
|
|
|
|
else:
|
|
|
|
info_bubble.show_arrow = True
|
|
|
|
info_bubble.arrow_pos = arrow_pos
|
|
|
|
img = info_bubble.ids.img
|
|
|
|
if text == 'texture':
|
|
|
|
# icon holds a texture not a source image
|
|
|
|
# display the texture in full screen
|
|
|
|
text = ''
|
|
|
|
img.texture = icon
|
|
|
|
info_bubble.fs = True
|
|
|
|
info_bubble.show_arrow = False
|
|
|
|
img.allow_stretch = True
|
|
|
|
info_bubble.dim_background = True
|
|
|
|
info_bubble.background_image = 'atlas://gui/kivy/theming/light/card'
|
|
|
|
else:
|
|
|
|
info_bubble.fs = False
|
|
|
|
info_bubble.icon = icon
|
2015-09-09 07:13:40 -07:00
|
|
|
#if img.texture and img._coreimage:
|
|
|
|
# img.reload()
|
2014-02-17 23:12:57 -08:00
|
|
|
img.allow_stretch = False
|
|
|
|
info_bubble.dim_background = False
|
|
|
|
info_bubble.background_image = 'atlas://data/images/defaulttheme/bubble'
|
|
|
|
info_bubble.message = text
|
2014-06-04 17:42:29 -07:00
|
|
|
if not pos:
|
2015-12-02 03:11:28 -08:00
|
|
|
pos = (win.center[0], win.center[1] - (info_bubble.height/2))
|
2014-08-01 09:09:34 -07:00
|
|
|
info_bubble.show(pos, duration, width, modal=modal, exit=exit)
|
2015-10-13 10:09:12 -07:00
|
|
|
|
2016-02-12 07:09:16 -08:00
|
|
|
def tx_dialog(self, tx):
|
2016-02-12 23:15:06 -08:00
|
|
|
from uix.dialogs.tx_dialog import TxDialog
|
|
|
|
d = TxDialog(self, tx)
|
|
|
|
d.open()
|
2016-02-11 02:40:23 -08:00
|
|
|
|
2015-12-12 21:41:22 -08:00
|
|
|
def address_dialog(self, screen):
|
2016-02-09 14:05:39 -08:00
|
|
|
pass
|
2015-12-12 21:41:22 -08:00
|
|
|
|
2015-12-14 03:08:11 -08:00
|
|
|
def description_dialog(self, screen):
|
|
|
|
from uix.dialogs.label_dialog import LabelDialog
|
|
|
|
text = screen.message
|
|
|
|
def callback(text):
|
|
|
|
screen.message = text
|
|
|
|
d = LabelDialog(_('Enter description'), text, callback)
|
|
|
|
d.open()
|
|
|
|
|
2015-12-14 12:34:25 -08:00
|
|
|
@profiler
|
2015-12-04 02:47:46 -08:00
|
|
|
def amount_dialog(self, screen, show_max):
|
2015-12-14 05:27:39 -08:00
|
|
|
from uix.dialogs.amount_dialog import AmountDialog
|
2015-12-04 02:47:46 -08:00
|
|
|
amount = screen.amount
|
|
|
|
if amount:
|
2015-12-14 05:27:39 -08:00
|
|
|
amount, u = str(amount).split()
|
2015-10-16 02:18:24 -07:00
|
|
|
assert u == self.base_unit
|
2015-12-14 05:27:39 -08:00
|
|
|
def cb(amount):
|
|
|
|
screen.amount = amount
|
|
|
|
popup = AmountDialog(show_max, amount, cb)
|
2015-10-14 02:44:01 -07:00
|
|
|
popup.open()
|
|
|
|
|
2016-02-13 01:00:20 -08:00
|
|
|
def protected(self, msg, f, args):
|
2015-12-07 05:33:18 -08:00
|
|
|
if self.wallet.use_encryption:
|
2016-02-13 01:00:20 -08:00
|
|
|
self.password_dialog(msg, f, args)
|
2015-12-07 05:33:18 -08:00
|
|
|
else:
|
|
|
|
apply(f, args + (None,))
|
|
|
|
|
2016-02-11 03:54:04 -08:00
|
|
|
def show_seed(self, label):
|
2016-02-13 01:00:20 -08:00
|
|
|
self.protected(_("Enter your PIN code in order to decrypt your seed"), self._show_seed, (label,))
|
2016-02-11 03:54:04 -08:00
|
|
|
|
|
|
|
def _show_seed(self, label, password):
|
|
|
|
try:
|
|
|
|
seed = self.wallet.get_seed(password)
|
|
|
|
except:
|
|
|
|
self.show_error("Invalid PIN")
|
|
|
|
return
|
|
|
|
label.text = _('Seed') + ':\n' + seed
|
|
|
|
|
2015-12-07 01:40:10 -08:00
|
|
|
def change_password(self):
|
2016-02-13 01:00:20 -08:00
|
|
|
self.protected(_("Changing PIN code.") + '\n' + _("Enter your current PIN:"), self._change_password, ())
|
2015-12-07 05:33:18 -08:00
|
|
|
|
|
|
|
def _change_password(self, old_password):
|
2015-12-07 06:59:59 -08:00
|
|
|
if self.wallet.use_encryption:
|
2015-12-07 05:33:18 -08:00
|
|
|
try:
|
|
|
|
self.wallet.check_password(old_password)
|
|
|
|
except InvalidPassword:
|
|
|
|
self.show_error("Invalid PIN")
|
|
|
|
return
|
|
|
|
self.password_dialog(_('Enter new PIN'), self._change_password2, (old_password,))
|
2015-12-07 01:40:10 -08:00
|
|
|
|
2015-12-07 05:33:18 -08:00
|
|
|
def _change_password2(self, old_password, new_password):
|
|
|
|
self.password_dialog(_('Confirm new PIN'), self._change_password3, (old_password, new_password))
|
2015-12-07 01:40:10 -08:00
|
|
|
|
2015-12-07 05:33:18 -08:00
|
|
|
def _change_password3(self, old_password, new_password, confirmed_password):
|
|
|
|
if new_password == confirmed_password:
|
|
|
|
self.wallet.update_password(old_password, new_password)
|
2015-10-13 10:09:12 -07:00
|
|
|
else:
|
2015-12-07 05:33:18 -08:00
|
|
|
self.show_error("PIN numbers do not match")
|
|
|
|
|
2016-02-13 01:00:20 -08:00
|
|
|
def password_dialog(self, msg, f, args):
|
2015-12-20 08:37:07 -08:00
|
|
|
from uix.dialogs.password_dialog import PasswordDialog
|
|
|
|
def callback(pw):
|
2015-12-07 05:33:18 -08:00
|
|
|
Clock.schedule_once(lambda x: apply(f, args + (pw,)), 0.1)
|
2016-02-13 01:00:20 -08:00
|
|
|
popup = PasswordDialog(msg, callback)
|
2015-12-07 05:33:18 -08:00
|
|
|
popup.open()
|
|
|
|
|