Browse Source

qt seed completer: colour words yellow if only in old electrum list

Some people complained that due to merging the two word lists,
it is difficult to restore from a metal backup, as they planned
to rely on the "4 letter prefixes are unique in bip39 word list" property.
So we colour words that are only in old list.
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 6 years ago
parent
commit
7120c344b2
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 27
      electrum/gui/qt/seed_dialog.py

27
electrum/gui/qt/seed_dialog.py

@ -24,16 +24,16 @@
# SOFTWARE. # SOFTWARE.
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap from PyQt5.QtGui import QPixmap, QPalette
from PyQt5.QtWidgets import (QVBoxLayout, QCheckBox, QHBoxLayout, QLineEdit, from PyQt5.QtWidgets import (QVBoxLayout, QCheckBox, QHBoxLayout, QLineEdit,
QLabel, QCompleter, QDialog) QLabel, QCompleter, QDialog, QStyledItemDelegate)
from electrum.i18n import _ from electrum.i18n import _
from electrum.mnemonic import Mnemonic, seed_type from electrum.mnemonic import Mnemonic, seed_type
import electrum.old_mnemonic import electrum.old_mnemonic
from .util import (Buttons, OkButton, WWLabel, ButtonsTextEdit, icon_path, from .util import (Buttons, OkButton, WWLabel, ButtonsTextEdit, icon_path,
EnterButton, CloseButton, WindowModalDialog) EnterButton, CloseButton, WindowModalDialog, ColorScheme)
from .qrtextedit import ShowQRTextEdit, ScanQRTextEdit from .qrtextedit import ShowQRTextEdit, ScanQRTextEdit
from .completion_text_edit import CompletionTextEdit from .completion_text_edit import CompletionTextEdit
@ -149,11 +149,26 @@ class SeedLayout(QVBoxLayout):
self.addWidget(self.seed_warning) self.addWidget(self.seed_warning)
def initialize_completer(self): def initialize_completer(self):
english_list = Mnemonic('en').wordlist bip39_english_list = Mnemonic('en').wordlist
old_list = electrum.old_mnemonic.words old_list = electrum.old_mnemonic.words
self.wordlist = english_list + list(set(old_list) - set(english_list)) #concat both lists only_old_list = set(old_list) - set(bip39_english_list)
self.wordlist = bip39_english_list + list(only_old_list) # concat both lists
self.wordlist.sort() self.wordlist.sort()
class CompleterDelegate(QStyledItemDelegate):
def initStyleOption(self, option, index):
super().initStyleOption(option, index)
# Some people complained that due to merging the two word lists,
# it is difficult to restore from a metal backup, as they planned
# to rely on the "4 letter prefixes are unique in bip39 word list" property.
# So we color words that are only in old list.
if option.text in only_old_list:
# yellow bg looks ~ok on both light/dark theme, regardless if (un)selected
option.backgroundBrush = ColorScheme.YELLOW.as_color(background=True)
self.completer = QCompleter(self.wordlist) self.completer = QCompleter(self.wordlist)
delegate = CompleterDelegate(self.seed_e)
self.completer.popup().setItemDelegate(delegate)
self.seed_e.set_completer(self.completer) self.seed_e.set_completer(self.completer)
def get_seed(self): def get_seed(self):
@ -174,7 +189,7 @@ class SeedLayout(QVBoxLayout):
self.seed_type_label.setText(label) self.seed_type_label.setText(label)
self.parent.next_button.setEnabled(b) self.parent.next_button.setEnabled(b)
# to account for bip39 seeds # disable suggestions if user already typed an unknown word
for word in self.get_seed().split(" ")[:-1]: for word in self.get_seed().split(" ")[:-1]:
if word not in self.wordlist: if word not in self.wordlist:
self.seed_e.disable_suggestions() self.seed_e.disable_suggestions()

Loading…
Cancel
Save