X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=1cc77d3eff9035590ecde2dbc0b507f6c7aba240;hb=057722b034672d240eea2ff01a7a5a01a4706e00;hp=cd7f281b5489f8e1a956a19fb4784e3fa3c1cb8c;hpb=c6624d51f4e5607202e48903352574c47571baab;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index cd7f281..1cc77d3 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -109,6 +109,7 @@ DOM.entropyContainer.addClass("hidden"); DOM.generateContainer.removeClass("hidden"); DOM.phrase.prop("readonly", false); + hidePending(); } } @@ -149,8 +150,31 @@ } function entropyChanged() { + // If blank entropy, clear mnemonic, addresses, errors + if (DOM.entropy.val().trim().length == 0) { + clearDisplay(); + hideEntropyError(); + DOM.phrase.val(""); + showValidationError("Blank entropy"); + return; + } + // Get the current phrase to detect changes + var phrase = DOM.phrase.val(); + // Set the phrase from the entropy setMnemonicFromEntropy(); - phraseChanged(); + // Recalc addresses if the phrase has changed + var newPhrase = DOM.phrase.val(); + if (newPhrase != phrase) { + if (newPhrase.length == 0) { + clearDisplay(); + } + else { + phraseChanged(); + } + } + else { + hidePending(); + } } function delayedRootKeyChanged() { @@ -311,10 +335,13 @@ } function findPhraseErrors(phrase) { - // TODO make this right // Preprocess the words phrase = mnemonic.normalizeString(phrase); var words = phraseToWordArray(phrase); + // Detect blank phrase + if (words.length == 0) { + return "Blank mnemonic"; + } // Check each word for (var i=0; i