]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Allow more rows to be generated at a custom index
authorIan Coleman <ian@iancoleman.io>
Tue, 21 Nov 2017 01:06:56 +0000 (12:06 +1100)
committerIan Coleman <ian@iancoleman.io>
Tue, 21 Nov 2017 01:06:56 +0000 (12:06 +1100)
src/index.html
src/js/index.js
tests/spec/tests.js

index cdd2ab24daacf6b2f00d13b7f0b2a4c1294b814f..63533a9c4b8762b73f048ce4f03f71757d364f06 100644 (file)
                     </table>
                 </div>
             </div>
-            <span>Show more rows</span>:
+            <span>Show</span>
             <input type="number" class="rows-to-add" value="20">
-            <button class="more">Show</button>
+            <button class="more">more rows</button>
+            <span>starting from index</span>
+            <input type="number" class="more-rows-start-index">
+            <span>(leave blank to generate from next index)</span>
 
             <hr>
 
index 739dc01e8835736654aacde4ff8875d058faea04..38a7efdd41642d1f892aa4750b0c318ea146b482 100644 (file)
@@ -80,6 +80,7 @@
     DOM.addresses = $(".addresses");
     DOM.rowsToAdd = $(".rows-to-add");
     DOM.more = $(".more");
+    DOM.moreRowsStartIndex = $(".more-rows-start-index");
     DOM.feedback = $(".feedback");
     DOM.tab = $(".derivation-type a");
     DOM.indexToggle = $(".index-toggle");
     }
 
     function showMore() {
-        var start = DOM.addresses.children().length;
         var rowsToAdd = parseInt(DOM.rowsToAdd.val());
         if (isNaN(rowsToAdd)) {
             rowsToAdd = 20;
             DOM.rowsToAdd.val("20");
         }
+        var start = parseInt(DOM.moreRowsStartIndex.val())
+        if (isNaN(start)) {
+            start = lastIndexInTable() + 1;
+        }
+        else {
+            var newStart = start + rowsToAdd;
+            DOM.moreRowsStartIndex.val(newStart);
+        }
         if (rowsToAdd > 200) {
             var msg = "Generating " + rowsToAdd + " rows could take a while. ";
             msg += "Do you want to continue?";
         }
     }
 
+    function lastIndexInTable() {
+        var pathText = DOM.addresses.find(".index").last().text();
+        var pathBits = pathText.split("/");
+        var lastBit = pathBits[pathBits.length-1];
+        var lastBitClean = lastBit.replace("'", "");
+        return parseInt(lastBitClean);
+    }
+
     var networks = [
         {
             name: "BCH - Bitcoin Cash",
index 998809a8c0ccc4b96f8b76334e9588b97fb1259c..f10f7a402a85e050fbffa74b47474aa9f527fd4b 100644 (file)
@@ -2577,4 +2577,48 @@ it('Can use bitpay format for bitcoin cash addresses', function(done) {
     });
 });
 
+// End of tests ported from old suit, so no more comments above each test now
+
+it('Can generate more addresses from a custom index', function(done) {
+    var expectedIndexes = [
+        0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
+        40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59
+    ];
+    driver.findElement(By.css('.phrase'))
+        .sendKeys("abandon abandon ability");
+    driver.sleep(generateDelay).then(function() {
+        // Set start of next lot of rows to be from index 40
+        // which means indexes 20-39 will not be in the table.
+        driver.findElement(By.css('.more-rows-start-index'))
+            .sendKeys("40");
+        driver.findElement(By.css('.more'))
+            .click();
+        driver.sleep(generateDelay).then(function() {
+            // Check actual indexes in the table match the expected pattern
+            driver.findElements(By.css(".index"))
+                .then(function(els) {
+                    expect(els.length).toBe(expectedIndexes.length);
+                    var testRowAtIndex = function(i) {
+                        if (i >= expectedIndexes.length) {
+                            done();
+                        }
+                        else {
+                            els[i].getText()
+                                .then(function(actualPath) {
+                                    var noHardened = actualPath.replace(/'/g, "");
+                                    var pathBits = noHardened.split("/")
+                                    var lastBit = pathBits[pathBits.length-1];
+                                    var actualIndex = parseInt(lastBit);
+                                    var expectedIndex = expectedIndexes[i];
+                                    expect(actualIndex).toBe(expectedIndex);
+                                    testRowAtIndex(i+1);
+                                });
+                        }
+                    }
+                    testRowAtIndex(0);
+                });
+        });
+    });
+});
+
 });