trustedcoin: don't use assert in hooks, it crashes when using multiple windows. show message if wallet is restored from seed.

This commit is contained in:
ThomasV 2016-01-03 19:16:37 +01:00
parent 9ed987c2da
commit c2accd64cf
1 changed files with 21 additions and 11 deletions

View File

@ -50,14 +50,22 @@ class Plugin(TrustedCoinPlugin):
@hook @hook
def on_new_window(self, window): def on_new_window(self, window):
wallet = window.wallet wallet = window.wallet
if wallet.storage.get('wallet_type') == '2fa': if not isinstance(wallet, self.wallet_class):
button = StatusBarButton(QIcon(":icons/trustedcoin.png"), return
_("TrustedCoin"), if wallet.can_sign_without_server():
partial(self.settings_dialog, window)) msg = ' '.join([
window.statusBar().addPermanentWidget(button) _('This wallet is was restored from seed, and it contains two master private keys.'),
t = Thread(target=self.request_billing_info, args=(wallet,)) _('Therefore, two-factor authentication is disabled.')
t.setDaemon(True) ])
t.start() action = lambda: window.show_message(msg)
else:
action = partial(self.settings_dialog, window)
button = StatusBarButton(QIcon(":icons/trustedcoin.png"),
_("TrustedCoin"), action)
window.statusBar().addPermanentWidget(button)
t = Thread(target=self.request_billing_info, args=(wallet,))
t.setDaemon(True)
t.start()
def auth_dialog(self, window): def auth_dialog(self, window):
d = WindowModalDialog(window, _("Authorization")) d = WindowModalDialog(window, _("Authorization"))
@ -77,10 +85,11 @@ class Plugin(TrustedCoinPlugin):
@hook @hook
def sign_tx(self, window, tx): def sign_tx(self, window, tx):
self.print_error("twofactor:sign_tx")
wallet = window.wallet wallet = window.wallet
assert isinstance(wallet, self.wallet_class) if not isinstance(wallet, self.wallet_class):
return
if not wallet.can_sign_without_server(): if not wallet.can_sign_without_server():
self.print_error("twofactor:sign_tx")
auth_code = None auth_code = None
if need_server(wallet, tx): if need_server(wallet, tx):
auth_code = self.auth_dialog(window) auth_code = self.auth_dialog(window)
@ -101,7 +110,8 @@ class Plugin(TrustedCoinPlugin):
@hook @hook
def abort_send(self, window): def abort_send(self, window):
wallet = window.wallet wallet = window.wallet
assert isinstance(wallet, self.wallet_class) if not isinstance(wallet, self.wallet_class):
return
if not wallet.can_sign_without_server(): if not wallet.can_sign_without_server():
if wallet.billing_info is None: if wallet.billing_info is None:
# request billing info before forming the transaction # request billing info before forming the transaction