Generation process stopped when table rows cleared

Closes #44
This commit is contained in:
Ian Coleman
2017-01-04 11:30:45 +11:00
parent 6ea15134a4
commit 40892aba50
3 changed files with 106 additions and 8 deletions

View File

@@ -18664,6 +18664,8 @@ window.Entropy = new (function() {
var phraseChangeTimeoutEvent = null;
var rootKeyChangedTimeoutEvent = null;
var generationProcesses = [];
var DOM = {};
DOM.network = $(".network");
DOM.phraseNetwork = $("#network-phrase");
@@ -19157,14 +19159,28 @@ window.Entropy = new (function() {
}
function displayAddresses(start, total) {
for (var i=0; i<total; i++) {
var index = i + start;
new TableRow(index);
}
generationProcesses.push(new (function() {
var rows = [];
this.stop = function() {
for (var i=0; i<rows.length; i++) {
rows[i].shouldGenerate = false;
}
}
for (var i=0; i<total; i++) {
var index = i + start;
rows.push(new TableRow(index));
}
})());
}
function TableRow(index) {
var self = this;
this.shouldGenerate = true;
var useHardenedAddresses = DOM.hardenedAddresses.prop("checked");
function init() {
@@ -19173,6 +19189,9 @@ window.Entropy = new (function() {
function calculateValues() {
setTimeout(function() {
if (!self.shouldGenerate) {
return;
}
var key = "";
if (useHardenedAddresses) {
key = bip32ExtendedKey.deriveHardened(index);
@@ -19223,6 +19242,14 @@ window.Entropy = new (function() {
function clearAddressesList() {
DOM.addresses.empty();
stopGenerating();
}
function stopGenerating() {
while (generationProcesses.length > 0) {
var generation = generationProcesses.shift();
generation.stop();
}
}
function clearKey() {

View File

@@ -19,6 +19,8 @@
var phraseChangeTimeoutEvent = null;
var rootKeyChangedTimeoutEvent = null;
var generationProcesses = [];
var DOM = {};
DOM.network = $(".network");
DOM.phraseNetwork = $("#network-phrase");
@@ -512,14 +514,28 @@
}
function displayAddresses(start, total) {
for (var i=0; i<total; i++) {
var index = i + start;
new TableRow(index);
}
generationProcesses.push(new (function() {
var rows = [];
this.stop = function() {
for (var i=0; i<rows.length; i++) {
rows[i].shouldGenerate = false;
}
}
for (var i=0; i<total; i++) {
var index = i + start;
rows.push(new TableRow(index));
}
})());
}
function TableRow(index) {
var self = this;
this.shouldGenerate = true;
var useHardenedAddresses = DOM.hardenedAddresses.prop("checked");
function init() {
@@ -528,6 +544,9 @@
function calculateValues() {
setTimeout(function() {
if (!self.shouldGenerate) {
return;
}
var key = "";
if (useHardenedAddresses) {
key = bip32ExtendedKey.deriveHardened(index);
@@ -578,6 +597,14 @@
function clearAddressesList() {
DOM.addresses.empty();
stopGenerating();
}
function stopGenerating() {
while (generationProcesses.length > 0) {
var generation = generationProcesses.shift();
generation.stop();
}
}
function clearKey() {

View File

@@ -3291,6 +3291,50 @@ page.open(url, function(status) {
});
},
// Github issue 44
// display error switching tabs while addresses are generating
function() {
page.open(url, function(status) {
// set the phrase
page.evaluate(function() {
$(".phrase").val("abandon abandon ability").trigger("input");
});
waitForGenerate(function() {
// set to generate 500 more addresses
// generate more addresses
// change tabs which should cancel the previous generating
page.evaluate(function() {
$(".rows-to-add").val("100");
$(".more").click();
$("#bip32-tab a").click();
});
// check the derivation paths are in order and of the right quantity
waitForGenerate(function() {
var paths = page.evaluate(function() {
return $(".index").map(function(i, e) {
return $(e).text();
});
});
for (var i=0; i<paths.length; i++) {
var expected = "m/0/" + i;
var actual = paths[i];
if (actual != expected) {
console.log("Path " + i + " is not in correct order");
console.log("Expected: " + expected);
console.log("Actual: " + actual);
fail();
}
}
if (paths.length != 20) {
console.log("Generation was not cancelled by new action");
fail();
}
next();
});
});
});
},
// If you wish to add more tests, do so here...
// Here is a blank test template