aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2017-01-04 11:30:45 +1100
committerIan Coleman <coleman.ian@gmail.com>2017-01-04 11:31:45 +1100
commit40892aba5013cd75927f63e66492f46b2d206ec9 (patch)
tree35f45854960e6fd6c30a11016ac89dc000977053
parent6ea15134a4ff5a443d96de5882bcddbe7300fc6f (diff)
downloadBIP39-40892aba5013cd75927f63e66492f46b2d206ec9.tar.gz
BIP39-40892aba5013cd75927f63e66492f46b2d206ec9.tar.zst
BIP39-40892aba5013cd75927f63e66492f46b2d206ec9.zip
Generation process stopped when table rows cleared
Closes #44
-rw-r--r--bip39-standalone.html35
-rw-r--r--src/js/index.js35
-rw-r--r--tests.js44
3 files changed, 106 insertions, 8 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html
index 5158b10..afef084 100644
--- a/bip39-standalone.html
+++ b/bip39-standalone.html
@@ -18664,6 +18664,8 @@ window.Entropy = new (function() {
18664 var phraseChangeTimeoutEvent = null; 18664 var phraseChangeTimeoutEvent = null;
18665 var rootKeyChangedTimeoutEvent = null; 18665 var rootKeyChangedTimeoutEvent = null;
18666 18666
18667 var generationProcesses = [];
18668
18667 var DOM = {}; 18669 var DOM = {};
18668 DOM.network = $(".network"); 18670 DOM.network = $(".network");
18669 DOM.phraseNetwork = $("#network-phrase"); 18671 DOM.phraseNetwork = $("#network-phrase");
@@ -19157,14 +19159,28 @@ window.Entropy = new (function() {
19157 } 19159 }
19158 19160
19159 function displayAddresses(start, total) { 19161 function displayAddresses(start, total) {
19160 for (var i=0; i<total; i++) { 19162 generationProcesses.push(new (function() {
19161 var index = i + start; 19163
19162 new TableRow(index); 19164 var rows = [];
19163 } 19165
19166 this.stop = function() {
19167 for (var i=0; i<rows.length; i++) {
19168 rows[i].shouldGenerate = false;
19169 }
19170 }
19171
19172 for (var i=0; i<total; i++) {
19173 var index = i + start;
19174 rows.push(new TableRow(index));
19175 }
19176
19177 })());
19164 } 19178 }
19165 19179
19166 function TableRow(index) { 19180 function TableRow(index) {
19167 19181
19182 var self = this;
19183 this.shouldGenerate = true;
19168 var useHardenedAddresses = DOM.hardenedAddresses.prop("checked"); 19184 var useHardenedAddresses = DOM.hardenedAddresses.prop("checked");
19169 19185
19170 function init() { 19186 function init() {
@@ -19173,6 +19189,9 @@ window.Entropy = new (function() {
19173 19189
19174 function calculateValues() { 19190 function calculateValues() {
19175 setTimeout(function() { 19191 setTimeout(function() {
19192 if (!self.shouldGenerate) {
19193 return;
19194 }
19176 var key = ""; 19195 var key = "";
19177 if (useHardenedAddresses) { 19196 if (useHardenedAddresses) {
19178 key = bip32ExtendedKey.deriveHardened(index); 19197 key = bip32ExtendedKey.deriveHardened(index);
@@ -19223,6 +19242,14 @@ window.Entropy = new (function() {
19223 19242
19224 function clearAddressesList() { 19243 function clearAddressesList() {
19225 DOM.addresses.empty(); 19244 DOM.addresses.empty();
19245 stopGenerating();
19246 }
19247
19248 function stopGenerating() {
19249 while (generationProcesses.length > 0) {
19250 var generation = generationProcesses.shift();
19251 generation.stop();
19252 }
19226 } 19253 }
19227 19254
19228 function clearKey() { 19255 function clearKey() {
diff --git a/src/js/index.js b/src/js/index.js
index c198977..5318800 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -19,6 +19,8 @@
19 var phraseChangeTimeoutEvent = null; 19 var phraseChangeTimeoutEvent = null;
20 var rootKeyChangedTimeoutEvent = null; 20 var rootKeyChangedTimeoutEvent = null;
21 21
22 var generationProcesses = [];
23
22 var DOM = {}; 24 var DOM = {};
23 DOM.network = $(".network"); 25 DOM.network = $(".network");
24 DOM.phraseNetwork = $("#network-phrase"); 26 DOM.phraseNetwork = $("#network-phrase");
@@ -512,14 +514,28 @@
512 } 514 }
513 515
514 function displayAddresses(start, total) { 516 function displayAddresses(start, total) {
515 for (var i=0; i<total; i++) { 517 generationProcesses.push(new (function() {
516 var index = i + start; 518
517 new TableRow(index); 519 var rows = [];
518 } 520
521 this.stop = function() {
522 for (var i=0; i<rows.length; i++) {
523 rows[i].shouldGenerate = false;
524 }
525 }
526
527 for (var i=0; i<total; i++) {
528 var index = i + start;
529 rows.push(new TableRow(index));
530 }
531
532 })());
519 } 533 }
520 534
521 function TableRow(index) { 535 function TableRow(index) {
522 536
537 var self = this;
538 this.shouldGenerate = true;
523 var useHardenedAddresses = DOM.hardenedAddresses.prop("checked"); 539 var useHardenedAddresses = DOM.hardenedAddresses.prop("checked");
524 540
525 function init() { 541 function init() {
@@ -528,6 +544,9 @@
528 544
529 function calculateValues() { 545 function calculateValues() {
530 setTimeout(function() { 546 setTimeout(function() {
547 if (!self.shouldGenerate) {
548 return;
549 }
531 var key = ""; 550 var key = "";
532 if (useHardenedAddresses) { 551 if (useHardenedAddresses) {
533 key = bip32ExtendedKey.deriveHardened(index); 552 key = bip32ExtendedKey.deriveHardened(index);
@@ -578,6 +597,14 @@
578 597
579 function clearAddressesList() { 598 function clearAddressesList() {
580 DOM.addresses.empty(); 599 DOM.addresses.empty();
600 stopGenerating();
601 }
602
603 function stopGenerating() {
604 while (generationProcesses.length > 0) {
605 var generation = generationProcesses.shift();
606 generation.stop();
607 }
581 } 608 }
582 609
583 function clearKey() { 610 function clearKey() {
diff --git a/tests.js b/tests.js
index 48e863b..16f1963 100644
--- a/tests.js
+++ b/tests.js
@@ -3291,6 +3291,50 @@ page.open(url, function(status) {
3291}); 3291});
3292}, 3292},
3293 3293
3294// Github issue 44
3295// display error switching tabs while addresses are generating
3296function() {
3297page.open(url, function(status) {
3298 // set the phrase
3299 page.evaluate(function() {
3300 $(".phrase").val("abandon abandon ability").trigger("input");
3301 });
3302 waitForGenerate(function() {
3303 // set to generate 500 more addresses
3304 // generate more addresses
3305 // change tabs which should cancel the previous generating
3306 page.evaluate(function() {
3307 $(".rows-to-add").val("100");
3308 $(".more").click();
3309 $("#bip32-tab a").click();
3310 });
3311 // check the derivation paths are in order and of the right quantity
3312 waitForGenerate(function() {
3313 var paths = page.evaluate(function() {
3314 return $(".index").map(function(i, e) {
3315 return $(e).text();
3316 });
3317 });
3318 for (var i=0; i<paths.length; i++) {
3319 var expected = "m/0/" + i;
3320 var actual = paths[i];
3321 if (actual != expected) {
3322 console.log("Path " + i + " is not in correct order");
3323 console.log("Expected: " + expected);
3324 console.log("Actual: " + actual);
3325 fail();
3326 }
3327 }
3328 if (paths.length != 20) {
3329 console.log("Generation was not cancelled by new action");
3330 fail();
3331 }
3332 next();
3333 });
3334 });
3335});
3336},
3337
3294// If you wish to add more tests, do so here... 3338// If you wish to add more tests, do so here...
3295 3339
3296// Here is a blank test template 3340// Here is a blank test template