diff options
author | Ian Coleman <coleman.ian@gmail.com> | 2014-09-25 10:32:50 +1000 |
---|---|---|
committer | Ian Coleman <coleman.ian@gmail.com> | 2014-09-25 10:32:50 +1000 |
commit | 04f789cdbdb8e50511efdf97c900f7f83662eedb (patch) | |
tree | 86e485edc43a2dfca8a4d1db2ef77b6927fa2fde | |
parent | d198865f7552237188659c778c0456988c6619df (diff) | |
download | BIP39-04f789cdbdb8e50511efdf97c900f7f83662eedb.tar.gz BIP39-04f789cdbdb8e50511efdf97c900f7f83662eedb.tar.zst BIP39-04f789cdbdb8e50511efdf97c900f7f83662eedb.zip |
Update only happens when phrase is changed
ie not on keyup where the key is ctrl or arrow-key etc.
-rw-r--r-- | bip39-standalone.html | 18 | ||||
-rw-r--r-- | src/js/index.js | 18 |
2 files changed, 34 insertions, 2 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html index 591cdce..9bc6e88 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html | |||
@@ -22733,6 +22733,8 @@ WORDLISTS = { | |||
22733 | DOM.privateKeyToggle = $(".private-key-toggle"); | 22733 | DOM.privateKeyToggle = $(".private-key-toggle"); |
22734 | 22734 | ||
22735 | var derivationPath = DOM.bip44path.val(); | 22735 | var derivationPath = DOM.bip44path.val(); |
22736 | var currentPhrase = DOM.phrase.val(); | ||
22737 | var currentPassphrase = DOM.passphrase.val(); | ||
22736 | 22738 | ||
22737 | function init() { | 22739 | function init() { |
22738 | // Events | 22740 | // Events |
@@ -22757,6 +22759,9 @@ WORDLISTS = { | |||
22757 | // Event handlers | 22759 | // Event handlers |
22758 | 22760 | ||
22759 | function delayedPhraseChanged() { | 22761 | function delayedPhraseChanged() { |
22762 | if (!hasChanged()) { | ||
22763 | return; | ||
22764 | } | ||
22760 | hideValidationError(); | 22765 | hideValidationError(); |
22761 | showPending(); | 22766 | showPending(); |
22762 | if (phraseChangeTimeoutEvent != null) { | 22767 | if (phraseChangeTimeoutEvent != null) { |
@@ -22786,6 +22791,9 @@ WORDLISTS = { | |||
22786 | calcBip32Seed(phrase, passphrase, derivationPath); | 22791 | calcBip32Seed(phrase, passphrase, derivationPath); |
22787 | displayBip32Info(); | 22792 | displayBip32Info(); |
22788 | hidePending(); | 22793 | hidePending(); |
22794 | // Set current state so we only update as needed | ||
22795 | currentPhrase = phrase; | ||
22796 | currentPassphrase = passphrase; | ||
22789 | } | 22797 | } |
22790 | 22798 | ||
22791 | function generateClicked() { | 22799 | function generateClicked() { |
@@ -22807,7 +22815,9 @@ WORDLISTS = { | |||
22807 | } | 22815 | } |
22808 | 22816 | ||
22809 | function derivationChanged() { | 22817 | function derivationChanged() { |
22810 | delayedPhraseChanged(); | 22818 | hideValidationError(); |
22819 | showPending(); | ||
22820 | setTimeout(phraseChanged, 50); | ||
22811 | } | 22821 | } |
22812 | 22822 | ||
22813 | function bip32Changed() { | 22823 | function bip32Changed() { |
@@ -23036,6 +23046,12 @@ WORDLISTS = { | |||
23036 | .hide(); | 23046 | .hide(); |
23037 | } | 23047 | } |
23038 | 23048 | ||
23049 | function hasChanged() { | ||
23050 | var phraseChanged = DOM.phrase.val() != currentPhrase; | ||
23051 | var passphraseChanged = DOM.passphrase.val() != currentPassphrase; | ||
23052 | return phraseChanged || passphraseChanged; | ||
23053 | } | ||
23054 | |||
23039 | init(); | 23055 | init(); |
23040 | 23056 | ||
23041 | })(); | 23057 | })(); |
diff --git a/src/js/index.js b/src/js/index.js index cee8ffb..5bdb7ab 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -32,6 +32,8 @@ | |||
32 | DOM.privateKeyToggle = $(".private-key-toggle"); | 32 | DOM.privateKeyToggle = $(".private-key-toggle"); |
33 | 33 | ||
34 | var derivationPath = DOM.bip44path.val(); | 34 | var derivationPath = DOM.bip44path.val(); |
35 | var currentPhrase = DOM.phrase.val(); | ||
36 | var currentPassphrase = DOM.passphrase.val(); | ||
35 | 37 | ||
36 | function init() { | 38 | function init() { |
37 | // Events | 39 | // Events |
@@ -56,6 +58,9 @@ | |||
56 | // Event handlers | 58 | // Event handlers |
57 | 59 | ||
58 | function delayedPhraseChanged() { | 60 | function delayedPhraseChanged() { |
61 | if (!hasChanged()) { | ||
62 | return; | ||
63 | } | ||
59 | hideValidationError(); | 64 | hideValidationError(); |
60 | showPending(); | 65 | showPending(); |
61 | if (phraseChangeTimeoutEvent != null) { | 66 | if (phraseChangeTimeoutEvent != null) { |
@@ -85,6 +90,9 @@ | |||
85 | calcBip32Seed(phrase, passphrase, derivationPath); | 90 | calcBip32Seed(phrase, passphrase, derivationPath); |
86 | displayBip32Info(); | 91 | displayBip32Info(); |
87 | hidePending(); | 92 | hidePending(); |
93 | // Set current state so we only update as needed | ||
94 | currentPhrase = phrase; | ||
95 | currentPassphrase = passphrase; | ||
88 | } | 96 | } |
89 | 97 | ||
90 | function generateClicked() { | 98 | function generateClicked() { |
@@ -106,7 +114,9 @@ | |||
106 | } | 114 | } |
107 | 115 | ||
108 | function derivationChanged() { | 116 | function derivationChanged() { |
109 | delayedPhraseChanged(); | 117 | hideValidationError(); |
118 | showPending(); | ||
119 | setTimeout(phraseChanged, 50); | ||
110 | } | 120 | } |
111 | 121 | ||
112 | function bip32Changed() { | 122 | function bip32Changed() { |
@@ -335,6 +345,12 @@ | |||
335 | .hide(); | 345 | .hide(); |
336 | } | 346 | } |
337 | 347 | ||
348 | function hasChanged() { | ||
349 | var phraseChanged = DOM.phrase.val() != currentPhrase; | ||
350 | var passphraseChanged = DOM.passphrase.val() != currentPassphrase; | ||
351 | return phraseChanged || passphraseChanged; | ||
352 | } | ||
353 | |||
338 | init(); | 354 | init(); |
339 | 355 | ||
340 | })(); | 356 | })(); |