mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-27 21:00:41 +00:00
Words not in list show error with suggestion
This commit is contained in:
+24
-1
@@ -195,8 +195,16 @@
|
||||
proper.push(part.toLowerCase());
|
||||
}
|
||||
}
|
||||
// TODO some levenstein on the words
|
||||
var properPhrase = proper.join(' ');
|
||||
// Check each word
|
||||
for (var i=0; i<proper.length; i++) {
|
||||
var word = proper[i];
|
||||
if (WORDLISTS["english"].indexOf(word) == -1) {
|
||||
console.log("Finding closest match to " + word);
|
||||
var nearestWord = findNearestWord(word);
|
||||
return word + " not in wordlist, did you mean " + nearestWord + "?";
|
||||
}
|
||||
}
|
||||
// Check the words are valid
|
||||
var isValid = mnemonic.check(properPhrase);
|
||||
if (!isValid) {
|
||||
@@ -389,6 +397,21 @@
|
||||
.show();
|
||||
}
|
||||
|
||||
function findNearestWord(word) {
|
||||
var words = WORDLISTS["english"];
|
||||
var minDistance = 99;
|
||||
var closestWord = words[0];
|
||||
for (var i=0; i<words.length; i++) {
|
||||
var comparedTo = words[i];
|
||||
var distance = Levenshtein.get(word, comparedTo);
|
||||
if (distance < minDistance) {
|
||||
closestWord = comparedTo;
|
||||
minDistance = distance;
|
||||
}
|
||||
}
|
||||
return closestWord;
|
||||
}
|
||||
|
||||
function hidePending() {
|
||||
DOM.feedback
|
||||
.text("")
|
||||
|
||||
Reference in New Issue
Block a user