mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
Other wallets, such as Mycelium, do not allow the user to simply copy and paste the seed. This is very useful to assure users follow directions on the next screen, because previously it was easily possible to just copy the seed and paste it on the next screen. The user's wallet would work well for a while like this, but without having the seed written down it's more of a ticking time bomb than a wallet. I recommend pulling this patch as I have read many cases where users do not write the seed down, and I believe that the main cause is lack of friction forcing them to do so. This patch was inspired by reading this Reddit conversation: https://www.reddit.com/r/Bitcoin/comments/3p4bq1/electrum_v25/cw380kg But I'm not a participant in that convo.
72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
from electrum.i18n import _
|
|
from electrum.plugins import run_hook
|
|
from PyQt4.QtGui import *
|
|
from PyQt4.QtCore import *
|
|
|
|
from util import ButtonsTextEdit
|
|
|
|
|
|
class ShowQRTextEdit(ButtonsTextEdit):
|
|
|
|
def __init__(self, text=None, paranoid=False):
|
|
ButtonsTextEdit.__init__(self, text)
|
|
self.setReadOnly(1)
|
|
self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code"))
|
|
|
|
if paranoid:
|
|
# Paranoid flag forces the user to write down what's in the box,
|
|
# like Mycelium does. This is useful since many users just copy
|
|
# and paste their code, then when disaster strikes they don't have
|
|
# it written down anywhere.
|
|
self.setAcceptDrops(False) # No dragging and dropping
|
|
# Use custom context menu to remove copy/paste from menu
|
|
self.setContextMenuPolicy(Qt.ActionsContextMenu)
|
|
self.qaction = QAction(_("Show as QR code"), self)
|
|
self.qaction.triggered.connect(self.qr_show)
|
|
self.addAction(self.qaction)
|
|
# No text selection allowed.
|
|
self.setTextInteractionFlags(Qt.NoTextInteraction)
|
|
|
|
run_hook('show_text_edit', self)
|
|
|
|
def qr_show(self):
|
|
from qrcodewidget import QRDialog
|
|
try:
|
|
s = str(self.toPlainText())
|
|
except:
|
|
s = unicode(self.toPlainText())
|
|
QRDialog(s).exec_()
|
|
|
|
class ScanQRTextEdit(ButtonsTextEdit):
|
|
|
|
def __init__(self, text=""):
|
|
ButtonsTextEdit.__init__(self, text)
|
|
self.setReadOnly(0)
|
|
self.addButton(":icons/file.png", self.file_input, _("Read file"))
|
|
self.addButton(":icons/qrcode.png", self.qr_input, _("Read QR code"))
|
|
run_hook('scan_text_edit', self)
|
|
|
|
def file_input(self):
|
|
fileName = unicode(QFileDialog.getOpenFileName(self, 'select file'))
|
|
if not fileName:
|
|
return
|
|
with open(fileName, "r") as f:
|
|
data = f.read()
|
|
self.setText(data)
|
|
|
|
def qr_input(self):
|
|
from electrum import qrscanner, get_config
|
|
try:
|
|
data = qrscanner.scan_qr(get_config())
|
|
except BaseException, e:
|
|
QMessageBox.warning(self, _('Error'), _(e), _('OK'))
|
|
return ""
|
|
if type(data) != str:
|
|
return
|
|
self.setText(data)
|
|
return data
|
|
|
|
def contextMenuEvent(self, e):
|
|
m = self.createStandardContextMenu()
|
|
m.addAction(_("Read QR code"), self.qr_input)
|
|
m.exec_(e.globalPos())
|