X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=9ea5bb56fcc613d2c63f0bf62410896c29cb11b2;hb=7f15cb6eb98d29aeb64ec4a4ad37b81a66eb6103;hp=c610d29d436cb38e98293357c573a674901c19ed;hpb=64ed10ff75b1be2d2dc47e0aea44b42e7e304af2;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index c610d29..9ea5bb5 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -15,8 +15,6 @@ var DOM = {}; DOM.network = $(".network"); DOM.phraseNetwork = $("#network-phrase"); - DOM.bip44Network = $("#network-bip44"); - DOM.addressNetwork = $("#network-address-type"); DOM.phrase = $(".phrase"); DOM.passphrase = $(".passphrase"); DOM.generate = $(".generate"); @@ -42,8 +40,9 @@ DOM.indexToggle = $(".index-toggle"); DOM.addressToggle = $(".address-toggle"); DOM.privateKeyToggle = $(".private-key-toggle"); + DOM.myceliumPath = $("#mycelium-path"); - var derivationPath = DOM.bip44path.val(); + var derivationPath = $(".tab-pane.active .path").val(); function init() { // Events @@ -64,39 +63,15 @@ disableForms(); hidePending(); hideValidationError(); + populateNetworkSelect(); } // Event handlers function networkChanged(e) { - var n = e.target.value; - if (n == "bitcoin") { - network = Bitcoin.networks.bitcoin; - DOM.bip44coin.val(0); - setBip44DerivationPath(); - enableBip44Tab(); - } - else if (n == "bitcoin-testnet") { - network = Bitcoin.networks.testnet; - DOM.bip44coin.val(1); - setBip44DerivationPath(); - enableBip44Tab(); - } - else if (n == "litecoin") { - network = Bitcoin.networks.litecoin; - DOM.bip44coin.val(2); - setBip44DerivationPath(); - enableBip44Tab(); - } - else if (n == "dogecoin") { - network = Bitcoin.networks.dogecoin; - //disableBip44Tab(); - } - DOM.phraseNetwork.val(n); - DOM.bip44Network.val(n); - if(e.target != DOM.addressNetwork.dom){ - DOM.addressNetwork.val(n); - } + var network = e.target.value; + networks[network].onSelect(); + setBip44DerivationPath(); delayedPhraseChanged(); } @@ -410,28 +385,49 @@ .hide(); } - function enableBip44Tab() { - // show bip44 tab (but don't select it) - DOM.bip44tab.removeClass("hidden"); - DOM.bip44panel.removeClass("hidden"); - } - - function disableBip44Tab() { - // hide bip44 tab - DOM.bip44tab.addClass("hidden"); - DOM.bip44tab.removeClass("active"); - // hide bip44 panel - DOM.bip44panel.addClass("hidden"); - DOM.bip44panel.removeClass("active"); - // show bip32 tab - DOM.bip32tab.addClass("active"); - // show bip32 panel - DOM.bip32panel.addClass("active"); - // set the derivation path - var activePath = $("#bip32 .path"); - derivationPath = activePath.val(); + function populateNetworkSelect() { + for (var i=0; i"); + option.attr("value", i); + option.text(network.name); + DOM.phraseNetwork.append(option); + } } + var networks = [ + { + name: "Bitcoin", + onSelect: function() { + network = Bitcoin.networks.bitcoin; + DOM.bip44coin.val(0); + DOM.myceliumPath.val("m/44'/0'/0'/0"); + }, + }, + { + name: "Bitcoin Testnet", + onSelect: function() { + network = Bitcoin.networks.testnet; + DOM.bip44coin.val(1); + DOM.myceliumPath.val("m/44'/1'/0'/0"); + }, + }, + { + name: "Litecoin", + onSelect: function() { + network = Bitcoin.networks.litecoin; + DOM.bip44coin.val(2); + }, + }, + { + name: "Dogecoin", + onSelect: function() { + network = Bitcoin.networks.dogecoin; + DOM.bip44coin.val(3); + }, + }, + ] + init(); })();