]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blobdiff - src/js/index.js
Update only happens when phrase is changed
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / src / js / index.js
index cee8ffbac5d36a557208e6058dd5445420f20d99..5bdb7ab5b7c7ea3036ac5210d851b32fb94cace6 100644 (file)
@@ -32,6 +32,8 @@
     DOM.privateKeyToggle = $(".private-key-toggle");
 
     var derivationPath = DOM.bip44path.val();
+    var currentPhrase = DOM.phrase.val();
+    var currentPassphrase = DOM.passphrase.val();
 
     function init() {
         // Events
@@ -56,6 +58,9 @@
     // Event handlers
 
     function delayedPhraseChanged() {
+        if (!hasChanged()) {
+            return;
+        }
         hideValidationError();
         showPending();
         if (phraseChangeTimeoutEvent != null) {
@@ -85,6 +90,9 @@
         calcBip32Seed(phrase, passphrase, derivationPath);
         displayBip32Info();
         hidePending();
+        // Set current state so we only update as needed
+        currentPhrase = phrase;
+        currentPassphrase = passphrase;
     }
 
     function generateClicked() {
     }
 
     function derivationChanged() {
-        delayedPhraseChanged();
+        hideValidationError();
+        showPending();
+        setTimeout(phraseChanged, 50);
     }
 
     function bip32Changed() {
             .hide();
     }
 
+    function hasChanged() {
+        var phraseChanged = DOM.phrase.val() != currentPhrase;
+        var passphraseChanged = DOM.passphrase.val() != currentPassphrase;
+        return phraseChanged || passphraseChanged;
+    }
+
     init();
 
 })();