Add a button to remove the "change" in the derivation path for ethereum master
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 24 Apr 2020 23:37:24 +0000 (01:37 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 25 Apr 2020 00:08:03 +0000 (02:08 +0200)
src/index.html
src/js/index.js

index 1184a0c69aca0ae82aea0bcd08b053f5de7b72f7..5035b2c5c017b56d342b006c929c21e89ef25305 100644 (file)
                                         <a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#change" target="_blank">External / Internal</a>
                                     </label>
                                     <div class="col-sm-10">
-                                      <input id="change-bip44" type="text" class="change form-control" value="0">
+                                        <div class="input-group">
+                                          <input id="change-bip44" type="text" class="change form-control" value="0">
+                                          <a class="default-bip44-change-value btn btn-primary input-group-addon" role="button">Default</a>
+                                        </div>
                                     </div>
                                 </div>
                                 <div class="form-group">
index c2d34a711ac3c2be0ca06cb79984f35419b6fc23..614bcc50923ae77cc224c6468743b5b3af8a933b 100644 (file)
@@ -15,6 +15,7 @@
     var showPrivKey = true;
     var showQr = false;
     var litecoinUseLtub = true;
+    var isDefaultBip44ChangeValue = true;
 
     var entropyTypeAutoDetect = true;
     var entropyChangeTimeoutEvent = null;
@@ -74,6 +75,7 @@
     DOM.bip44accountXprv = $("#bip44 .account-xprv");
     DOM.bip44accountXpub = $("#bip44 .account-xpub");
     DOM.bip44change = $("#bip44 .change");
+    DOM.defaultBip44ChangeValue = $("#bip44 .default-bip44-change-value");
     DOM.bip49unavailable = $("#bip49 .unavailable");
     DOM.bip49available = $("#bip49 .available");
     DOM.bip49path = $("#bip49-path");
         DOM.litecoinUseLtub.on("change", litecoinUseLtubChanged);
         DOM.bip32path.on("input", calcForDerivationPath);
         DOM.bip44account.on("input", calcForDerivationPath);
+        DOM.bip44change.on("input", modifiedDefaultBip44ChangeValue);
         DOM.bip44change.on("input", calcForDerivationPath);
+        DOM.defaultBip44ChangeValue.on("click", resetDefaultBip44ChangeValue);
         DOM.bip49account.on("input", calcForDerivationPath);
         DOM.bip49change.on("input", calcForDerivationPath);
         DOM.bip84account.on("input", calcForDerivationPath);
             var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
             var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
             var account = parseIntNoNaN(DOM.bip44account.val(), 0);
-            var change = parseIntNoNaN(DOM.bip44change.val(), 0);
-            var path = "m/";
-            path += purpose + "'/";
-            path += coin + "'/";
-            path += account + "'/";
-            path += change;
+            var change = parseIntNoNaN(DOM.bip44change.val(), "");
+            var path = "m";
+            path += "/" + purpose + "'";
+            path += "/" + coin + "'";
+            path += "/" + account + "'";
+            if (change !== "") {
+              path += "/" + change;
+            }
             DOM.bip44path.val(path);
             var derivationPath = DOM.bip44path.val();
             console.log("Using derivation path from BIP44 tab: " + derivationPath);
         return DOM.bip141tab.hasClass("active");
     }
 
+    function setBip44ChangeValue() {
+        if (isDefaultBip44ChangeValue) {
+            if (networkIsEthereum()) {
+                DOM.bip44change.val("");
+            } else {
+                DOM.bip44change.val(0);
+            }
+        }
+    }
+
+    function modifiedDefaultBip44ChangeValue() {
+        isDefaultBip44ChangeValue = false;
+    }
+
+    function resetDefaultBip44ChangeValue() {
+        isDefaultBip44ChangeValue = true;
+        setBip44ChangeValue();
+    }
+
     function setHdCoin(coinValue) {
         DOM.bip44coin.val(coinValue);
         DOM.bip49coin.val(coinValue);
         DOM.bip84coin.val(coinValue);
+        setBip44ChangeValue();
     }
 
     function showSegwitAvailable() {