aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Coleman <ian@iancoleman.io>2017-11-21 12:06:56 +1100
committerIan Coleman <ian@iancoleman.io>2017-11-21 12:06:56 +1100
commit9183f9f658222dc3a24c8b4794887b6ecd80ba1e (patch)
tree6c3fdc47c20562bed4bdc297f4e96d610ba9f3d0
parentf487fea9b8b37642a3940be63129d9835eb77229 (diff)
downloadBIP39-9183f9f658222dc3a24c8b4794887b6ecd80ba1e.tar.gz
BIP39-9183f9f658222dc3a24c8b4794887b6ecd80ba1e.tar.zst
BIP39-9183f9f658222dc3a24c8b4794887b6ecd80ba1e.zip
Allow more rows to be generated at a custom index
-rw-r--r--src/index.html7
-rw-r--r--src/js/index.js18
-rw-r--r--tests/spec/tests.js44
3 files changed, 66 insertions, 3 deletions
diff --git a/src/index.html b/src/index.html
index cdd2ab2..63533a9 100644
--- a/src/index.html
+++ b/src/index.html
@@ -622,9 +622,12 @@
622 </table> 622 </table>
623 </div> 623 </div>
624 </div> 624 </div>
625 <span>Show more rows</span>: 625 <span>Show</span>
626 <input type="number" class="rows-to-add" value="20"> 626 <input type="number" class="rows-to-add" value="20">
627 <button class="more">Show</button> 627 <button class="more">more rows</button>
628 <span>starting from index</span>
629 <input type="number" class="more-rows-start-index">
630 <span>(leave blank to generate from next index)</span>
628 631
629 <hr> 632 <hr>
630 633
diff --git a/src/js/index.js b/src/js/index.js
index 739dc01..38a7efd 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -80,6 +80,7 @@
80 DOM.addresses = $(".addresses"); 80 DOM.addresses = $(".addresses");
81 DOM.rowsToAdd = $(".rows-to-add"); 81 DOM.rowsToAdd = $(".rows-to-add");
82 DOM.more = $(".more"); 82 DOM.more = $(".more");
83 DOM.moreRowsStartIndex = $(".more-rows-start-index");
83 DOM.feedback = $(".feedback"); 84 DOM.feedback = $(".feedback");
84 DOM.tab = $(".derivation-type a"); 85 DOM.tab = $(".derivation-type a");
85 DOM.indexToggle = $(".index-toggle"); 86 DOM.indexToggle = $(".index-toggle");
@@ -750,12 +751,19 @@
750 } 751 }
751 752
752 function showMore() { 753 function showMore() {
753 var start = DOM.addresses.children().length;
754 var rowsToAdd = parseInt(DOM.rowsToAdd.val()); 754 var rowsToAdd = parseInt(DOM.rowsToAdd.val());
755 if (isNaN(rowsToAdd)) { 755 if (isNaN(rowsToAdd)) {
756 rowsToAdd = 20; 756 rowsToAdd = 20;
757 DOM.rowsToAdd.val("20"); 757 DOM.rowsToAdd.val("20");
758 } 758 }
759 var start = parseInt(DOM.moreRowsStartIndex.val())
760 if (isNaN(start)) {
761 start = lastIndexInTable() + 1;
762 }
763 else {
764 var newStart = start + rowsToAdd;
765 DOM.moreRowsStartIndex.val(newStart);
766 }
759 if (rowsToAdd > 200) { 767 if (rowsToAdd > 200) {
760 var msg = "Generating " + rowsToAdd + " rows could take a while. "; 768 var msg = "Generating " + rowsToAdd + " rows could take a while. ";
761 msg += "Do you want to continue?"; 769 msg += "Do you want to continue?";
@@ -1291,6 +1299,14 @@
1291 } 1299 }
1292 } 1300 }
1293 1301
1302 function lastIndexInTable() {
1303 var pathText = DOM.addresses.find(".index").last().text();
1304 var pathBits = pathText.split("/");
1305 var lastBit = pathBits[pathBits.length-1];
1306 var lastBitClean = lastBit.replace("'", "");
1307 return parseInt(lastBitClean);
1308 }
1309
1294 var networks = [ 1310 var networks = [
1295 { 1311 {
1296 name: "BCH - Bitcoin Cash", 1312 name: "BCH - Bitcoin Cash",
diff --git a/tests/spec/tests.js b/tests/spec/tests.js
index 998809a..f10f7a4 100644
--- a/tests/spec/tests.js
+++ b/tests/spec/tests.js
@@ -2577,4 +2577,48 @@ it('Can use bitpay format for bitcoin cash addresses', function(done) {
2577 }); 2577 });
2578}); 2578});
2579 2579
2580// End of tests ported from old suit, so no more comments above each test now
2581
2582it('Can generate more addresses from a custom index', function(done) {
2583 var expectedIndexes = [
2584 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
2585 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59
2586 ];
2587 driver.findElement(By.css('.phrase'))
2588 .sendKeys("abandon abandon ability");
2589 driver.sleep(generateDelay).then(function() {
2590 // Set start of next lot of rows to be from index 40
2591 // which means indexes 20-39 will not be in the table.
2592 driver.findElement(By.css('.more-rows-start-index'))
2593 .sendKeys("40");
2594 driver.findElement(By.css('.more'))
2595 .click();
2596 driver.sleep(generateDelay).then(function() {
2597 // Check actual indexes in the table match the expected pattern
2598 driver.findElements(By.css(".index"))
2599 .then(function(els) {
2600 expect(els.length).toBe(expectedIndexes.length);
2601 var testRowAtIndex = function(i) {
2602 if (i >= expectedIndexes.length) {
2603 done();
2604 }
2605 else {
2606 els[i].getText()
2607 .then(function(actualPath) {
2608 var noHardened = actualPath.replace(/'/g, "");
2609 var pathBits = noHardened.split("/")
2610 var lastBit = pathBits[pathBits.length-1];
2611 var actualIndex = parseInt(lastBit);
2612 var expectedIndex = expectedIndexes[i];
2613 expect(actualIndex).toBe(expectedIndex);
2614 testRowAtIndex(i+1);
2615 });
2616 }
2617 }
2618 testRowAtIndex(0);
2619 });
2620 });
2621 });
2622});
2623
2580}); 2624});