1
0

support TrustedCoin plugin in the kivy GUI

This commit is contained in:
ThomasV
2018-05-18 18:07:52 +02:00
parent 5a75ce74d7
commit 8d5e666d30
10 changed files with 291 additions and 92 deletions

View File

@@ -38,7 +38,7 @@ from electrum_gui.qt.amountedit import AmountEdit
from electrum_gui.qt.main_window import StatusBarButton
from electrum.i18n import _
from electrum.plugins import hook
from electrum.util import PrintError
from electrum.util import PrintError, is_valid_email
from .trustedcoin import TrustedCoinPlugin, server
@@ -48,36 +48,28 @@ class TOS(QTextEdit):
class HandlerTwoFactor(QObject, PrintError):
otp_start_signal = pyqtSignal(object, object)
def __init__(self, plugin, window):
super().__init__()
self.plugin = plugin
self.window = window
self.otp_start_signal.connect(self._prompt_user_for_otp)
self.otp_done = threading.Event()
def prompt_user_for_otp(self, wallet, tx):
self.otp_done.clear()
self.otp_start_signal.emit(wallet, tx)
self.otp_done.wait()
def _prompt_user_for_otp(self, wallet, tx):
def prompt_user_for_otp(self, wallet, tx, on_success, on_failure):
if not isinstance(wallet, self.plugin.wallet_class):
return
if wallet.can_sign_without_server():
return
if not wallet.keystores['x3/'].get_tx_derivations(tx):
self.print_error("twofactor: xpub3 not needed")
return
window = self.window.top_level_window()
auth_code = self.plugin.auth_dialog(window)
try:
window = self.window.top_level_window()
if not isinstance(wallet, self.plugin.wallet_class):
return
if not wallet.can_sign_without_server():
self.print_error("twofactor:sign_tx")
auth_code = None
if wallet.keystores['x3/'].get_tx_derivations(tx):
auth_code = self.plugin.auth_dialog(window)
else:
self.print_error("twofactor: xpub3 not needed")
wallet.auth_code = auth_code
finally:
self.otp_done.set()
wallet.on_otp(tx, auth_code)
except:
on_failure(sys.exc_info())
return
on_success(tx)
class Plugin(TrustedCoinPlugin):
@@ -123,8 +115,8 @@ class Plugin(TrustedCoinPlugin):
return
return pw.get_amount()
def prompt_user_for_otp(self, wallet, tx):
wallet.handler_2fa.prompt_user_for_otp(wallet, tx)
def prompt_user_for_otp(self, wallet, tx, on_success, on_failure):
wallet.handler_2fa.prompt_user_for_otp(wallet, tx, on_success, on_failure)
def waiting_dialog(self, window, on_finished=None):
task = partial(self.request_billing_info, window.wallet)
@@ -145,7 +137,6 @@ class Plugin(TrustedCoinPlugin):
return True
return False
def settings_dialog(self, window):
self.waiting_dialog(window, partial(self.show_settings_dialog, window))
@@ -216,6 +207,20 @@ class Plugin(TrustedCoinPlugin):
window.message_e.setFrozen(True)
window.amount_e.setFrozen(True)
def go_online_dialog(self, wizard):
msg = [
_("Your wallet file is: {}.").format(os.path.abspath(wizard.storage.path)),
_("You need to be online in order to complete the creation of "
"your wallet. If you generated your seed on an offline "
'computer, click on "{}" to close this window, move your '
"wallet file to an online computer, and reopen it with "
"Electrum.").format(_('Cancel')),
_('If you are online, click on "{}" to continue.').format(_('Next'))
]
msg = '\n\n'.join(msg)
wizard.stack = []
wizard.confirm_dialog(title='', message=msg, run_next = lambda x: wizard.run('accept_terms_of_use'))
def accept_terms_of_use(self, window):
vbox = QVBoxLayout()
vbox.addWidget(QLabel(_("Terms of Service")))
@@ -256,24 +261,21 @@ class Plugin(TrustedCoinPlugin):
window.terminate()
def set_enabled():
valid_email = re.match(regexp, email_e.text()) is not None
next_button.setEnabled(tos_received and valid_email)
next_button.setEnabled(tos_received and is_valid_email(email_e.text()))
tos_e.tos_signal.connect(on_result)
tos_e.error_signal.connect(on_error)
t = Thread(target=request_TOS)
t.setDaemon(True)
t.start()
regexp = r"[^@]+@[^@]+\.[^@]+"
email_e.textChanged.connect(set_enabled)
email_e.setFocus(True)
window.exec_layout(vbox, next_enabled=False)
next_button.setText(prior_button_text)
return str(email_e.text())
email = str(email_e.text())
self.create_remote_key(email, window)
def request_otp_dialog(self, window, _id, otp_secret):
def request_otp_dialog(self, window, short_id, otp_secret, xpub3):
vbox = QVBoxLayout()
if otp_secret is not None:
uri = "otpauth://totp/%s?secret=%s"%('trustedcoin.com', otp_secret)
@@ -291,7 +293,6 @@ class Plugin(TrustedCoinPlugin):
label.setWordWrap(1)
vbox.addWidget(label)
msg = _('Google Authenticator code:')
hbox = QHBoxLayout()
hbox.addWidget(WWLabel(msg))
pw = AmountEdit(None, is_int = True)
@@ -299,21 +300,14 @@ class Plugin(TrustedCoinPlugin):
pw.setMaximumWidth(50)
hbox.addWidget(pw)
vbox.addLayout(hbox)
cb_lost = QCheckBox(_("I have lost my Google Authenticator account"))
cb_lost.setToolTip(_("Check this box to request a new secret. You will need to retype your seed."))
vbox.addWidget(cb_lost)
cb_lost.setVisible(otp_secret is None)
def set_enabled():
b = True if cb_lost.isChecked() else len(pw.text()) == 6
window.next_button.setEnabled(b)
pw.textChanged.connect(set_enabled)
cb_lost.toggled.connect(set_enabled)
window.exec_layout(vbox, next_enabled=False,
raise_on_cancel=False)
return pw.get_amount(), cb_lost.isChecked()
window.exec_layout(vbox, next_enabled=False, raise_on_cancel=False)
self.check_otp(window, short_id, otp_secret, xpub3, pw.get_amount(), cb_lost.isChecked())