Files
purple-electrumwallet/plugins/ledger/qt.py
T

56 lines
1.8 KiB
Python
Raw Normal View History

2016-01-11 15:08:12 +09:00
import threading
2016-01-11 14:38:45 +09:00
from PyQt4.Qt import (QDialog, QInputDialog, QLineEdit,
QVBoxLayout, QLabel, SIGNAL)
2015-11-23 19:38:48 +01:00
import PyQt4.QtCore as QtCore
2015-12-01 10:00:39 +01:00
2016-01-11 15:08:12 +09:00
from electrum.i18n import _
from electrum.plugins import hook
2016-08-18 11:34:37 +02:00
from .ledger import LedgerPlugin, Ledger_KeyStore
2016-01-30 13:48:52 +01:00
from ..hw_wallet.qt import QtHandlerBase
2015-11-23 19:38:48 +01:00
class Plugin(LedgerPlugin):
@hook
def load_wallet(self, wallet, window):
2016-08-18 11:34:37 +02:00
keystore = wallet.get_keystore()
if type(keystore) != self.keystore_class:
2015-12-30 17:03:26 +09:00
return
2016-08-18 11:34:37 +02:00
keystore.handler = BTChipQTHandler(window)
if self.btchip_is_connected(keystore):
if not keystore.check_proper_device():
2015-12-23 20:42:30 +09:00
window.show_error(_("This wallet does not match your Ledger device"))
2015-12-30 17:03:26 +09:00
wallet.force_watching_only = True
2015-11-23 19:38:48 +01:00
else:
2015-12-23 20:42:30 +09:00
window.show_error(_("Ledger device not detected.\nContinuing in watching-only mode."))
2015-12-30 17:03:26 +09:00
wallet.force_watching_only = True
2015-11-23 19:38:48 +01:00
2016-08-21 22:44:42 +02:00
def create_keystore(self, hw_type, derivation, wizard):
from electrum.keystore import hardware_keystore
# create keystore
handler = BTChipQTHandler(wizard)
client = self.get_client()
xpub = self.get_public_key(derivation)
d = {
'xpub': self.xpub,
'type': 'hardware',
'hw_type': hw_type,
'derivation': derivation
}
k = hardware_keystore(hw_type, d)
return k
2015-11-23 19:38:48 +01:00
2016-01-30 07:46:19 +01:00
class BTChipQTHandler(QtHandlerBase):
2015-11-23 19:38:48 +01:00
def __init__(self, win):
2016-01-30 07:46:19 +01:00
super(BTChipQTHandler, self).__init__(win, 'Ledger')
2015-11-23 19:38:48 +01:00
2016-01-30 08:11:41 +01:00
def word_dialog(self, msg):
response = QInputDialog.getText(self.top_level_window(), "Ledger Wallet Authentication", msg, QLineEdit.Password)
if not response[1]:
self.word = None
else:
self.word = str(response[0])
2016-08-18 11:34:37 +02:00
self.done.set()