X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=9ea5bb56fcc613d2c63f0bf62410896c29cb11b2;hb=7f15cb6eb98d29aeb64ec4a4ad37b81a66eb6103;hp=f8b67616c530af1ae84c873a7302f6d59781ac20;hpb=a8c454871dafb83d47f65367ef46e64e4e47589f;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index f8b6761..9ea5bb5 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -6,15 +6,25 @@ var network = Bitcoin.networks.bitcoin; var addressRowTemplate = $("#address-row-template"); + var showIndex = true; + var showAddress = true; + var showPrivKey = true; + var phraseChangeTimeoutEvent = null; var DOM = {}; + DOM.network = $(".network"); + DOM.phraseNetwork = $("#network-phrase"); DOM.phrase = $(".phrase"); DOM.passphrase = $(".passphrase"); DOM.generate = $(".generate"); DOM.rootKey = $(".root-key"); DOM.extendedPrivKey = $(".extended-priv-key"); DOM.extendedPubKey = $(".extended-pub-key"); + DOM.bip32tab = $("#bip32-tab"); + DOM.bip44tab = $("#bip44-tab"); + DOM.bip32panel = $("#bip32"); + DOM.bip44panel = $("#bip44"); DOM.bip32path = $("#bip32-path"); DOM.bip44path = $("#bip44-path"); DOM.bip44purpose = $("#bip44 .purpose"); @@ -30,11 +40,13 @@ 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 + DOM.network.on("change", networkChanged); DOM.phrase.on("input", delayedPhraseChanged); DOM.passphrase.on("input", delayedPhraseChanged); DOM.generate.on("click", generateClicked); @@ -51,10 +63,18 @@ disableForms(); hidePending(); hideValidationError(); + populateNetworkSelect(); } // Event handlers + function networkChanged(e) { + var network = e.target.value; + networks[network].onSelect(); + setBip44DerivationPath(); + delayedPhraseChanged(); + } + function delayedPhraseChanged() { hideValidationError(); showPending(); @@ -121,14 +141,17 @@ } function toggleIndexes() { + showIndex = !showIndex; $("td.index span").toggleClass("invisible"); } function toggleAddresses() { + showAddress = !showAddress; $("td.address span").toggleClass("invisible"); } function togglePrivateKeys() { + showPrivKey = !showPrivKey; $("td.privkey span").toggleClass("invisible"); } @@ -298,9 +321,24 @@ function addAddressToList(index, address, privkey) { var row = $(addressRowTemplate.html()); - row.find(".index span").text(index); - row.find(".address span").text(address); - row.find(".privkey span").text(privkey); + // Elements + var indexCell = row.find(".index span"); + var addressCell = row.find(".address span"); + var privkeyCell = row.find(".privkey span"); + // Content + indexCell.text(index); + addressCell.text(address); + privkeyCell.text(privkey); + // Visibility + if (!showIndex) { + indexCell.addClass("invisible"); + } + if (!showAddress) { + addressCell.addClass("invisible"); + } + if (!showPrivKey) { + privkeCell.addClass("invisible"); + } DOM.addresses.append(row); } @@ -347,6 +385,49 @@ .hide(); } + 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(); })();