support TrustedCoin plugin in the kivy GUI
This commit is contained in:
@@ -15,6 +15,7 @@ from kivy.clock import Clock
|
||||
from kivy.utils import platform
|
||||
|
||||
from electrum.base_wizard import BaseWizard
|
||||
from electrum.util import is_valid_email
|
||||
|
||||
|
||||
from . import EventsDialog
|
||||
@@ -24,6 +25,7 @@ from .password_dialog import PasswordDialog
|
||||
# global Variables
|
||||
is_test = (platform == "linux")
|
||||
test_seed = "time taxi field recycle tiny license olive virus report rare steel portion achieve"
|
||||
test_seed = "grape impose jazz bind spatial mind jelly tourist tank today holiday stomach"
|
||||
test_xpub = "xpub661MyMwAqRbcEbvVtRRSjqxVnaWVUMewVzMiURAKyYratih4TtBpMypzzefmv8zUNebmNVzB3PojdC5sV2P9bDgMoo9B3SARw1MXUUfU1GL"
|
||||
|
||||
Builder.load_string('''
|
||||
@@ -171,6 +173,95 @@ Builder.load_string('''
|
||||
spacing: '14dp'
|
||||
size_hint: 1, None
|
||||
|
||||
<WizardConfirmDialog>
|
||||
message : ''
|
||||
Widget:
|
||||
size_hint: 1, 1
|
||||
Label:
|
||||
color: root.text_color
|
||||
size_hint: 1, None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
text: root.message
|
||||
Widget
|
||||
size_hint: 1, 1
|
||||
|
||||
<WizardTOSDialog>
|
||||
message : ''
|
||||
ScrollView:
|
||||
size_hint: 1, 1
|
||||
Label:
|
||||
color: root.text_color
|
||||
size_hint: 1, None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
text: root.message
|
||||
|
||||
<WizardEmailDialog>
|
||||
Label:
|
||||
color: root.text_color
|
||||
size_hint: 1, None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
text: 'Please enter your email address'
|
||||
WizardTextInput:
|
||||
id: email
|
||||
on_text: Clock.schedule_once(root.on_text)
|
||||
|
||||
<WizardKnownOTPDialog>
|
||||
message : ''
|
||||
message2: ''
|
||||
Widget:
|
||||
size_hint: 1, 1
|
||||
Label:
|
||||
color: root.text_color
|
||||
size_hint: 1, None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
text: root.message
|
||||
Widget
|
||||
size_hint: 1, 1
|
||||
WizardTextInput:
|
||||
id: otp
|
||||
on_text: Clock.schedule_once(root.on_text)
|
||||
Widget
|
||||
size_hint: 1, 1
|
||||
Label:
|
||||
color: root.text_color
|
||||
size_hint: 1, None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
text: root.message2
|
||||
BoxLayout:
|
||||
orientation: 'horizontal'
|
||||
size_hint: 1, 0.2
|
||||
Widget
|
||||
CheckBox:
|
||||
id:cb
|
||||
on_state: Clock.schedule_once(root.on_cb)
|
||||
|
||||
<WizardNewOTPDialog>
|
||||
message : ''
|
||||
message2 : ''
|
||||
Label:
|
||||
color: root.text_color
|
||||
size_hint: 1, None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
text: root.message
|
||||
QRCodeWidget:
|
||||
id: qr
|
||||
size_hint: 1, 1
|
||||
Label:
|
||||
color: root.text_color
|
||||
size_hint: 1, None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
text: root.message2
|
||||
WizardTextInput:
|
||||
id: otp
|
||||
on_text: Clock.schedule_once(root.on_text)
|
||||
|
||||
<MButton@Button>:
|
||||
size_hint: 1, None
|
||||
height: '33dp'
|
||||
@@ -485,6 +576,87 @@ class WizardMultisigDialog(WizardDialog):
|
||||
n = self.ids.n.value
|
||||
return m, n
|
||||
|
||||
class WizardKnownOTPDialog(WizardDialog):
|
||||
|
||||
def __init__(self, wizard, **kwargs):
|
||||
WizardDialog.__init__(self, wizard, **kwargs)
|
||||
self.message = _("This wallet is already registered with TrustedCoin. To finalize wallet creation, please enter your Google Authenticator Code.")
|
||||
self.message2 =_("If you have lost your Google Authenticator account, check the box below to request a new secret. You will need to retype your seed.")
|
||||
|
||||
def get_otp(self):
|
||||
otp = self.ids.otp.text
|
||||
if len(otp) != 6:
|
||||
return
|
||||
try:
|
||||
return int(otp)
|
||||
except:
|
||||
return
|
||||
|
||||
def get_params(self, button):
|
||||
return (self.get_otp(), self.ids.cb.active)
|
||||
|
||||
def on_cb(self, dt):
|
||||
self.ids.otp.text = ''
|
||||
self.ids.next.disabled = not self.ids.cb.active
|
||||
|
||||
def on_text(self, dt):
|
||||
self.ids.next.disabled = self.get_otp() is None
|
||||
|
||||
class WizardNewOTPDialog(WizardDialog):
|
||||
|
||||
def __init__(self, wizard, **kwargs):
|
||||
WizardDialog.__init__(self, wizard, **kwargs)
|
||||
otp_secret = kwargs['otp_secret']
|
||||
uri = "otpauth://totp/%s?secret=%s"%('trustedcoin.com', otp_secret)
|
||||
self.message = "Please scan the following QR code in Google Authenticator. You may also use the secret key: %s"%otp_secret
|
||||
self.message2 = _('Then, enter your Google Authenticator code:')
|
||||
self.ids.qr.set_data(uri)
|
||||
|
||||
def get_otp(self):
|
||||
otp = self.ids.otp.text
|
||||
if len(otp) != 6:
|
||||
return
|
||||
try:
|
||||
return int(otp)
|
||||
except:
|
||||
return
|
||||
|
||||
def on_text(self, dt):
|
||||
self.ids.next.disabled = self.get_otp() is None
|
||||
|
||||
def get_params(self, button):
|
||||
return (self.get_otp(), False)
|
||||
|
||||
class WizardTOSDialog(WizardDialog):
|
||||
|
||||
def __init__(self, wizard, **kwargs):
|
||||
WizardDialog.__init__(self, wizard, **kwargs)
|
||||
self.ids.next.text = 'Accept'
|
||||
self.ids.next.disabled = False
|
||||
self.message = kwargs['tos']
|
||||
self.message2 = _('Enter your email address:')
|
||||
|
||||
class WizardEmailDialog(WizardDialog):
|
||||
def get_params(self, button):
|
||||
return (self.ids.email.text,)
|
||||
def on_text(self, dt):
|
||||
self.ids.next.disabled = not is_valid_email(self.ids.email.text)
|
||||
|
||||
class WizardConfirmDialog(WizardDialog):
|
||||
|
||||
def __init__(self, wizard, **kwargs):
|
||||
super(WizardConfirmDialog, self).__init__(wizard, **kwargs)
|
||||
self.message = kwargs.get('message', '')
|
||||
self.value = 'ok'
|
||||
|
||||
def on_parent(self, instance, value):
|
||||
if value:
|
||||
app = App.get_running_app()
|
||||
self._back = _back = partial(app.dispatch, 'on_back')
|
||||
|
||||
def get_params(self, button):
|
||||
return (True,)
|
||||
|
||||
class WizardChoiceDialog(WizardDialog):
|
||||
|
||||
def __init__(self, wizard, **kwargs):
|
||||
@@ -789,6 +961,21 @@ class InstallWizard(BaseWizard, Widget):
|
||||
def restore_seed_dialog(self, **kwargs):
|
||||
RestoreSeedDialog(self, **kwargs).open()
|
||||
|
||||
def confirm_dialog(self, **kwargs):
|
||||
WizardConfirmDialog(self, **kwargs).open()
|
||||
|
||||
def tos_dialog(self, **kwargs):
|
||||
WizardTOSDialog(self, **kwargs).open()
|
||||
|
||||
def email_dialog(self, **kwargs):
|
||||
WizardEmailDialog(self, **kwargs).open()
|
||||
|
||||
def otp_dialog(self, **kwargs):
|
||||
if kwargs['otp_secret']:
|
||||
WizardNewOTPDialog(self, **kwargs).open()
|
||||
else:
|
||||
WizardKnownOTPDialog(self, **kwargs).open()
|
||||
|
||||
def add_xpub_dialog(self, **kwargs):
|
||||
kwargs['message'] += ' ' + _('Use the camera button to scan a QR code.')
|
||||
AddXpubDialog(self, **kwargs).open()
|
||||
@@ -800,6 +987,8 @@ class InstallWizard(BaseWizard, Widget):
|
||||
|
||||
def show_xpub_dialog(self, **kwargs): ShowXpubDialog(self, **kwargs).open()
|
||||
|
||||
def show_message(self, msg): self.show_error(msg)
|
||||
|
||||
def show_error(self, msg):
|
||||
app = App.get_running_app()
|
||||
Clock.schedule_once(lambda dt: app.show_error(msg))
|
||||
|
||||
Reference in New Issue
Block a user