mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 17:01:34 +00:00
hide seed options in a popup dialog. simplify seed_dialog classes
This commit is contained in:
parent
f225a26952
commit
f8aaa4a50f
2 changed files with 113 additions and 147 deletions
|
@ -11,7 +11,7 @@ from electrum.util import UserCancelled
|
||||||
from electrum.base_wizard import BaseWizard
|
from electrum.base_wizard import BaseWizard
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
|
|
||||||
from seed_dialog import SeedDisplayLayout, CreateSeedLayout, SeedInputLayout, TextInputLayout
|
from seed_dialog import SeedLayout, TextInputLayout
|
||||||
from network_dialog import NetworkChoiceLayout
|
from network_dialog import NetworkChoiceLayout
|
||||||
from util import *
|
from util import *
|
||||||
from password_dialog import PasswordLayout, PW_NEW
|
from password_dialog import PasswordLayout, PW_NEW
|
||||||
|
@ -248,42 +248,10 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
|
||||||
self.set_main_layout(slayout.layout(), title, next_enabled=False)
|
self.set_main_layout(slayout.layout(), title, next_enabled=False)
|
||||||
return slayout.get_text()
|
return slayout.get_text()
|
||||||
|
|
||||||
def seed_input(self, title, message, is_seed):
|
def seed_input(self, title, message, is_seed, options):
|
||||||
slayout = SeedInputLayout(self, message, is_seed)
|
slayout = SeedLayout(title=message, is_seed=is_seed, options=options, parent=self)
|
||||||
vbox = QVBoxLayout()
|
self.set_main_layout(slayout, title, next_enabled=False)
|
||||||
vbox.addLayout(slayout.layout())
|
return slayout.get_seed(), slayout.is_bip39, slayout.is_ext
|
||||||
if self.opt_ext or self.opt_bip39:
|
|
||||||
vbox.addStretch(1)
|
|
||||||
vbox.addWidget(QLabel(_('Options') + ':'))
|
|
||||||
if self.opt_ext:
|
|
||||||
cb_pass = QCheckBox(_('Extend this seed with custom words'))
|
|
||||||
vbox.addWidget(cb_pass)
|
|
||||||
if self.opt_bip39:
|
|
||||||
def f(b):
|
|
||||||
if b:
|
|
||||||
msg = ' '.join([
|
|
||||||
'<b>' + _('Warning') + '</b>' + ': ',
|
|
||||||
_('BIP39 seeds may not be supported in the future.'),
|
|
||||||
'<br/><br/>',
|
|
||||||
_('As technology matures, Bitcoin address generation may change.'),
|
|
||||||
_('However, BIP39 seeds do not include a version number.'),
|
|
||||||
_('As a result, it is not possible to infer your wallet type from a BIP39 seed.'),
|
|
||||||
'<br/><br/>',
|
|
||||||
_('We do not guarantee that BIP39 seeds will be supported in future versions of Electrum.'),
|
|
||||||
_('We recommend to use seeds generated by Electrum or compatible wallets.'),
|
|
||||||
])
|
|
||||||
self.show_warning(msg)
|
|
||||||
slayout.seed_type_label.setVisible(not b)
|
|
||||||
slayout.is_seed = (lambda x: bool(x)) if b else is_seed
|
|
||||||
slayout.on_edit()
|
|
||||||
cb_bip39 = QCheckBox(_('BIP39 seed'))
|
|
||||||
cb_bip39.toggled.connect(f)
|
|
||||||
vbox.addWidget(cb_bip39)
|
|
||||||
self.set_main_layout(vbox, title, next_enabled=False)
|
|
||||||
seed = slayout.get_seed()
|
|
||||||
is_bip39 = cb_bip39.isChecked() if self.opt_bip39 else False
|
|
||||||
is_ext = cb_pass.isChecked() if self.opt_ext else False
|
|
||||||
return seed, is_bip39, is_ext
|
|
||||||
|
|
||||||
@wizard_dialog
|
@wizard_dialog
|
||||||
def add_xpub_dialog(self, title, message, is_valid, run_next):
|
def add_xpub_dialog(self, title, message, is_valid, run_next):
|
||||||
|
@ -302,7 +270,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
|
||||||
def restore_seed_dialog(self, run_next, test):
|
def restore_seed_dialog(self, run_next, test):
|
||||||
title = _('Enter Seed')
|
title = _('Enter Seed')
|
||||||
message = _('Please enter your seed phrase in order to restore your wallet.')
|
message = _('Please enter your seed phrase in order to restore your wallet.')
|
||||||
return self.seed_input(title, message, test)
|
return self.seed_input(title, message, test, ['ext', 'bip39'])
|
||||||
|
|
||||||
@wizard_dialog
|
@wizard_dialog
|
||||||
def confirm_seed_dialog(self, run_next, test):
|
def confirm_seed_dialog(self, run_next, test):
|
||||||
|
@ -313,22 +281,15 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
|
||||||
_('If you lose your seed, your money will be permanently lost.'),
|
_('If you lose your seed, your money will be permanently lost.'),
|
||||||
_('To make sure that you have properly saved your seed, please retype it here.')
|
_('To make sure that you have properly saved your seed, please retype it here.')
|
||||||
])
|
])
|
||||||
self.opt_ext = False
|
seed, is_bip39, is_ext = self.seed_input(title, message, test, None)
|
||||||
self.opt_bip39 = False
|
|
||||||
seed, is_bip39, is_ext = self.seed_input(title, message, test)
|
|
||||||
return seed
|
return seed
|
||||||
|
|
||||||
@wizard_dialog
|
@wizard_dialog
|
||||||
def show_seed_dialog(self, run_next, seed_text):
|
def show_seed_dialog(self, run_next, seed_text):
|
||||||
vbox = QVBoxLayout()
|
title = _("Your wallet generation seed is:")
|
||||||
slayout = CreateSeedLayout(seed_text)
|
slayout = SeedLayout(seed=seed_text, title=title, msg=True, options=['ext'])
|
||||||
vbox.addLayout(slayout.layout())
|
self.set_main_layout(slayout)
|
||||||
vbox.addStretch(1)
|
return slayout.is_ext
|
||||||
vbox.addWidget(QLabel(_('Option') + ':'))
|
|
||||||
cb_pass = QCheckBox(_('Extend this seed with custom words'))
|
|
||||||
vbox.addWidget(cb_pass)
|
|
||||||
self.set_main_layout(vbox)
|
|
||||||
return cb_pass.isChecked()
|
|
||||||
|
|
||||||
def pw_layout(self, msg, kind):
|
def pw_layout(self, msg, kind):
|
||||||
playout = PasswordLayout(None, msg, kind, self.next_button)
|
playout = PasswordLayout(None, msg, kind, self.next_button)
|
||||||
|
@ -425,7 +386,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
|
||||||
_("Please share it with your cosigners.")
|
_("Please share it with your cosigners.")
|
||||||
])
|
])
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
layout = SeedDisplayLayout(xpub, title=msg, icon=False)
|
layout = SeedLayout(xpub, title=msg, icon=False)
|
||||||
vbox.addLayout(layout.layout())
|
vbox.addLayout(layout.layout())
|
||||||
self.set_main_layout(vbox, _('Master Public Key'))
|
self.set_main_layout(vbox, _('Master Public Key'))
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -31,44 +31,6 @@ from util import *
|
||||||
from qrtextedit import ShowQRTextEdit, ScanQRTextEdit
|
from qrtextedit import ShowQRTextEdit, ScanQRTextEdit
|
||||||
|
|
||||||
|
|
||||||
class SeedLayoutBase(object):
|
|
||||||
|
|
||||||
def _seed_layout(self, seed=None, title=None, icon=True):
|
|
||||||
if seed:
|
|
||||||
self.seed_e = ShowQRTextEdit()
|
|
||||||
self.seed_e.setText(seed)
|
|
||||||
else:
|
|
||||||
self.seed_e = ScanQRTextEdit()
|
|
||||||
self.seed_e.setTabChangesFocus(True)
|
|
||||||
self.seed_e.setMaximumHeight(75)
|
|
||||||
hbox = QHBoxLayout()
|
|
||||||
if icon:
|
|
||||||
logo = QLabel()
|
|
||||||
logo.setPixmap(QPixmap(":icons/seed.png").scaledToWidth(64))
|
|
||||||
logo.setMaximumWidth(60)
|
|
||||||
hbox.addWidget(logo)
|
|
||||||
hbox.addWidget(self.seed_e)
|
|
||||||
if not title:
|
|
||||||
return hbox
|
|
||||||
vbox = QVBoxLayout()
|
|
||||||
vbox.addWidget(WWLabel(title))
|
|
||||||
vbox.addLayout(hbox)
|
|
||||||
return vbox
|
|
||||||
|
|
||||||
def layout(self):
|
|
||||||
return self.layout_
|
|
||||||
|
|
||||||
def seed_edit(self):
|
|
||||||
return self.seed_e
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SeedDisplayLayout(SeedLayoutBase):
|
|
||||||
def __init__(self, seed, title=None, icon=True):
|
|
||||||
self.layout_ = self._seed_layout(seed=seed, title=title, icon=icon)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def seed_warning_msg(seed):
|
def seed_warning_msg(seed):
|
||||||
return ''.join([
|
return ''.join([
|
||||||
"<p>",
|
"<p>",
|
||||||
|
@ -85,18 +47,106 @@ def seed_warning_msg(seed):
|
||||||
]) % len(seed.split())
|
]) % len(seed.split())
|
||||||
|
|
||||||
|
|
||||||
class CreateSeedLayout(SeedLayoutBase):
|
|
||||||
|
|
||||||
def __init__(self, seed):
|
class SeedLayout(QVBoxLayout):
|
||||||
title = _("Your wallet generation seed is:")
|
#options
|
||||||
vbox = QVBoxLayout()
|
is_bip39 = False
|
||||||
vbox.addLayout(self._seed_layout(seed=seed, title=title))
|
is_ext = False
|
||||||
msg = seed_warning_msg(seed)
|
|
||||||
vbox.addWidget(WWLabel(msg))
|
def seed_options(self):
|
||||||
self.layout_ = vbox
|
dialog = QDialog()
|
||||||
|
vbox = QVBoxLayout(dialog)
|
||||||
|
if 'ext' in self.options:
|
||||||
|
cb_ext = QCheckBox(_('Extend this seed with custom words'))
|
||||||
|
vbox.addWidget(cb_ext)
|
||||||
|
if 'bip39' in self.options:
|
||||||
|
def f(b):
|
||||||
|
if b:
|
||||||
|
msg = ' '.join([
|
||||||
|
'<b>' + _('Warning') + '</b>' + ': ',
|
||||||
|
_('BIP39 seeds may not be supported in the future.'),
|
||||||
|
'<br/><br/>',
|
||||||
|
_('As technology matures, Bitcoin address generation may change.'),
|
||||||
|
_('However, BIP39 seeds do not include a version number.'),
|
||||||
|
_('As a result, it is not possible to infer your wallet type from a BIP39 seed.'),
|
||||||
|
'<br/><br/>',
|
||||||
|
_('We do not guarantee that BIP39 seeds will be supported in future versions of Electrum.'),
|
||||||
|
_('We recommend to use seeds generated by Electrum or compatible wallets.'),
|
||||||
|
])
|
||||||
|
#self.parent.show_warning(msg)
|
||||||
|
self.seed_type_label.setVisible(not b)
|
||||||
|
self.is_seed = (lambda x: bool(x)) if b else self.saved_is_seed
|
||||||
|
self.on_edit()
|
||||||
|
cb_bip39 = QCheckBox(_('BIP39 seed'))
|
||||||
|
cb_bip39.toggled.connect(f)
|
||||||
|
vbox.addWidget(cb_bip39)
|
||||||
|
vbox.addLayout(Buttons(OkButton(dialog)))
|
||||||
|
if not dialog.exec_():
|
||||||
|
return None
|
||||||
|
self.is_ext = cb_ext.isChecked() if 'ext' in self.options else False
|
||||||
|
self.is_bip39 = cb_bip39.isChecked() if 'bip39' in self.options else False
|
||||||
|
|
||||||
|
|
||||||
class TextInputLayout(SeedLayoutBase):
|
def __init__(self, seed=None, title=None, icon=True, msg=None, options=None, is_seed=None, passphrase=None, parent=None):
|
||||||
|
QVBoxLayout.__init__(self)
|
||||||
|
self.parent = parent
|
||||||
|
self.options = options
|
||||||
|
if title:
|
||||||
|
self.addWidget(WWLabel(title))
|
||||||
|
if seed:
|
||||||
|
self.seed_e = ShowQRTextEdit()
|
||||||
|
self.seed_e.setText(seed)
|
||||||
|
else:
|
||||||
|
self.seed_e = ScanQRTextEdit()
|
||||||
|
self.seed_e.setTabChangesFocus(True)
|
||||||
|
self.is_seed = is_seed
|
||||||
|
self.saved_is_seed = self.is_seed
|
||||||
|
self.seed_e.textChanged.connect(self.on_edit)
|
||||||
|
self.seed_e.setMaximumHeight(75)
|
||||||
|
hbox = QHBoxLayout()
|
||||||
|
if icon:
|
||||||
|
logo = QLabel()
|
||||||
|
logo.setPixmap(QPixmap(":icons/seed.png").scaledToWidth(64))
|
||||||
|
logo.setMaximumWidth(60)
|
||||||
|
hbox.addWidget(logo)
|
||||||
|
hbox.addWidget(self.seed_e)
|
||||||
|
self.addLayout(hbox)
|
||||||
|
hbox = QHBoxLayout()
|
||||||
|
hbox.addStretch(1)
|
||||||
|
self.seed_type_label = QLabel('')
|
||||||
|
hbox.addWidget(self.seed_type_label)
|
||||||
|
if options:
|
||||||
|
opt_button = EnterButton(_('Options'), self.seed_options)
|
||||||
|
hbox.addWidget(opt_button)
|
||||||
|
self.addLayout(hbox)
|
||||||
|
if passphrase:
|
||||||
|
hbox = QHBoxLayout()
|
||||||
|
passphrase_e = QLineEdit()
|
||||||
|
passphrase_e.setText(passphrase)
|
||||||
|
passphrase_e.setReadOnly(True)
|
||||||
|
hbox.addWidget(QLabel(_("Your seed extension is") + ':'))
|
||||||
|
hbox.addWidget(passphrase_e)
|
||||||
|
self.addLayout(hbox)
|
||||||
|
self.addStretch(1)
|
||||||
|
if msg:
|
||||||
|
msg = seed_warning_msg(seed)
|
||||||
|
self.addWidget(WWLabel(msg))
|
||||||
|
|
||||||
|
def get_seed(self):
|
||||||
|
return clean_text(self.seed_e)
|
||||||
|
|
||||||
|
def on_edit(self):
|
||||||
|
from electrum.bitcoin import seed_type
|
||||||
|
s = self.get_seed()
|
||||||
|
b = self.is_seed(s)
|
||||||
|
t = seed_type(s)
|
||||||
|
label = _('Seed Type') + ': ' + t if t else ''
|
||||||
|
self.seed_type_label.setText(label)
|
||||||
|
self.parent.next_button.setEnabled(b)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TextInputLayout(SeedLayout):
|
||||||
|
|
||||||
def __init__(self, parent, title, is_valid):
|
def __init__(self, parent, title, is_valid):
|
||||||
self.is_valid = is_valid
|
self.is_valid = is_valid
|
||||||
|
@ -111,59 +161,14 @@ class TextInputLayout(SeedLayoutBase):
|
||||||
self.parent.next_button.setEnabled(self.is_valid(self.get_text()))
|
self.parent.next_button.setEnabled(self.is_valid(self.get_text()))
|
||||||
|
|
||||||
|
|
||||||
class SeedInputLayout(SeedLayoutBase):
|
|
||||||
|
|
||||||
def __init__(self, parent, title, is_seed):
|
|
||||||
vbox = QVBoxLayout()
|
|
||||||
vbox.addLayout(self._seed_layout(title=title))
|
|
||||||
hbox = QHBoxLayout()
|
|
||||||
hbox.addStretch(1)
|
|
||||||
hbox.addWidget(QLabel(''))
|
|
||||||
self.seed_type_label = QLabel('')
|
|
||||||
hbox.addWidget(self.seed_type_label)
|
|
||||||
vbox.addLayout(hbox)
|
|
||||||
self.layout_ = vbox
|
|
||||||
self.parent = parent
|
|
||||||
self.is_seed = is_seed
|
|
||||||
self.seed_e.textChanged.connect(self.on_edit)
|
|
||||||
|
|
||||||
def get_seed(self):
|
|
||||||
return clean_text(self.seed_edit())
|
|
||||||
|
|
||||||
def on_edit(self):
|
|
||||||
from electrum.bitcoin import seed_type
|
|
||||||
s = self.get_seed()
|
|
||||||
b = self.is_seed(s)
|
|
||||||
t = seed_type(s)
|
|
||||||
label = _('Seed Type') + ': ' + t if t else ''
|
|
||||||
self.seed_type_label.setText(label)
|
|
||||||
self.parent.next_button.setEnabled(b)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ShowSeedLayout(SeedLayoutBase):
|
|
||||||
|
|
||||||
def __init__(self, seed, passphrase):
|
|
||||||
title = _("Your wallet generation seed is:")
|
|
||||||
vbox = QVBoxLayout()
|
|
||||||
vbox.addLayout(self._seed_layout(seed=seed, title=title))
|
|
||||||
if passphrase:
|
|
||||||
hbox = QHBoxLayout()
|
|
||||||
passphrase_e = QLineEdit()
|
|
||||||
passphrase_e.setText(passphrase)
|
|
||||||
passphrase_e.setReadOnly(True)
|
|
||||||
hbox.addWidget(QLabel(_("Your seed extension is") + ':'))
|
|
||||||
hbox.addWidget(passphrase_e)
|
|
||||||
vbox.addLayout(hbox)
|
|
||||||
msg = seed_warning_msg(seed)
|
|
||||||
vbox.addWidget(WWLabel(msg))
|
|
||||||
self.layout_ = vbox
|
|
||||||
|
|
||||||
|
|
||||||
class SeedDialog(WindowModalDialog):
|
class SeedDialog(WindowModalDialog):
|
||||||
|
|
||||||
def __init__(self, parent, seed, passphrase):
|
def __init__(self, parent, seed, passphrase):
|
||||||
WindowModalDialog.__init__(self, parent, ('Electrum - ' + _('Seed')))
|
WindowModalDialog.__init__(self, parent, ('Electrum - ' + _('Seed')))
|
||||||
self.setMinimumWidth(400)
|
self.setMinimumWidth(400)
|
||||||
vbox = QVBoxLayout(self)
|
vbox = QVBoxLayout(self)
|
||||||
vbox.addLayout(ShowSeedLayout(seed, passphrase).layout())
|
title = _("Your wallet generation seed is:")
|
||||||
|
slayout = SeedLayout(title=title, seed=seed, msg=True, passphrase=passphrase)
|
||||||
|
vbox.addLayout(slayout)
|
||||||
vbox.addLayout(Buttons(CloseButton(self)))
|
vbox.addLayout(Buttons(CloseButton(self)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue