Permalink
Browse files

feat(account): notification when seed has trailing whitespace characters

Added notification to draw user's attention to importance of every symbol on address generation.
  • Loading branch information...
1 parent 3d2f4d2 commit 37b5548ca76136995e8f188c37495a8bda90fd29 @beregovoy68 beregovoy68 committed Jul 27, 2016
Showing with 154 additions and 97 deletions.
  1. +21 −0 index.html
  2. +133 −97 js/waves.ui.lockscreen.js
View
@@ -118,6 +118,27 @@ <h2 id="ImportAccHeader" class="noDisp">IMPORT ACCOUNT</h2>
</div>
</div>
+ <div id="seed-whitespace-popup" class="wavesPop">
+ <img class="wPop-header" src="img/modal-header-round.svg" />
+ <div class="wPop-content">
+ <h2>SEED NOTICE</h2>
+ <p>Your wallet seed contains trailing whitespace character(s).
+ <br/><br/>
+ A seed with a whitespace at the end and a seed without it are <br/>
+ different seeds and lead to different generated addresses.
+ <br/><br/>
+ It is strongly recommended to avoid trailing whitespaces in the seed. <br/>
+ If you understand all the implications of having a seed with trailing whitespace(s)<br/> press I UNDERSTAND.
+ Press Cancel or close the dialog to edit the seed.<br/>
+ </p>
+ <br/>
+ <div class="wPop-content-buttons">
+ <a id="close-seed-whitespace-modal" href="#" class="wButton paymentForm-but fade">I UNDERSTAND</a>
+ <a href="#" rel="modal:close" class="wButton paymentForm-but fade">CLOSE</a>
+ </div>
+ </div>
+ </div>
+
<div id="step2_reg" class="wPop-content">
<label for="walletSeed">WALLET SEED</label>
<br/>
@@ -41,6 +41,112 @@ var Waves = (function(Waves, $, undefined) {
if (Waves.UI === undefined)
Waves.UI = {};
+ Waves.UI.accountForm = {
+ publicKeySelector: "#publicKeyLockscreen",
+ privateKeySelector: "#privateKeyLockscreen",
+ addressSelector: "#addresLockscreen",
+ seedSelector: "#walletSeed",
+ seedWhitespacePopupSelector: '#seed-whitespace-popup',
+ accountListSelector: '#wavesAccounts',
+
+ generateAccount: function (seed) {
+ var publicKey = Waves.getPublicKey(seed);
+ var privateKey = Waves.getPrivateKey(seed);
+
+ $(this.publicKeySelector).html(publicKey);
+ $(this.privateKeySelector).html(privateKey);
+ $(this.addressSelector).html(Waves.buildAddress(publicKey).getDisplayAddress());
+ },
+ clearAccount: function () {
+ $(this.publicKeySelector).html('');
+ $(this.privateKeySelector).html('');
+ $(this.addressSelector).html('');
+ },
+ setWalletSeed: function (value) {
+ $(this.seedSelector).val(value);
+ },
+ getWalletSeed: function() {
+ return $(this.seedSelector).val();
+ },
+ endsWithWhitespace: function (value) {
+ return /\s+$/g.test(value);
+ },
+ appendAccount: function (name, address) {
+ $(this.accountListSelector).append('<br><b>' + name + '</b> ' + address.getDisplayAddress());
+ },
+ registerSeed: function (passphrase) {
+ var publicKey = Waves.getPublicKey(passphrase);
+ var name = $("#walletName").val();
+ var password = $("#walletPassword").val();
+
+ var address = Waves.buildAddress(publicKey);
+ var cipher = Waves.encryptWalletSeed(passphrase, password).toString();
+ var checksum = converters.byteArrayToHexString(Waves.simpleHash(converters.stringToByteArray(passphrase)));
+
+ var accountData = {
+ name: name,
+ cipher: cipher,
+ checksum: checksum,
+ publicKey: publicKey,
+ address: address.getRawAddress()
+ };
+
+ if (Waves.hasLocalStorage) {
+
+ var currentAccounts = localStorage.getItem('Waves' + Waves.network);
+ currentAccounts = JSON.parse(currentAccounts);
+
+ if(currentAccounts !== undefined && currentAccounts !== null) {
+ currentAccounts.accounts.push(accountData);
+ localStorage.setItem('Waves'+Waves.network, JSON.stringify(currentAccounts));
+ this.appendAccount(accountData.name, address);
+ } else {
+ var accountArray = { accounts: [accountData] };
+ localStorage.setItem('Waves'+Waves.network, JSON.stringify(accountArray));
+ this.appendAccount(accountData.name, address);
+ }
+
+ } else {
+
+ Waves.getAccounts(function(currentAccounts) {
+
+ var saveData = {
+ name: name,
+ cipher: cipher,
+ checksum: checksum,
+ publicKey: publicKey,
+ address: address.getRawAddress()
+ };
+
+ if(currentAccounts !== '') {
+ currentAccounts = currentAccounts['WavesAccounts'];
+
+ currentAccounts.accounts.push(saveData);
+ chrome.storage.sync.set({'WavesAccounts': currentAccounts}, function() {
+ // Notify that we saved.
+ $.growl.notice({ message: "Added Account!" });
+ this.appendAccount(saveData.name, address);
+ });
+
+ } else {
+ var accountArray = { accounts: [saveData] };
+ chrome.storage.sync.set({'WavesAccounts': accountArray}, function() {
+ // Notify that we saved.
+ $.growl.notice({ message: "Added Account!" });
+ this.appendAccount(saveData.name, address);
+ });
+ }
+ });
+ }
+
+ accountData.firstTime = true;
+ accountData.password = password;
+ accountData.passphrase = passphrase;
+
+ Waves.login(accountData);
+ }
+ };
+
Waves.UI.registerForm = {
id: 'register-form',
validator: undefined,
@@ -93,10 +199,9 @@ var Waves = (function(Waves, $, undefined) {
$("#wavesAccounts").addClass('noDisp');
$("#step2_reg").show();
- $("#walletSeed").val('');
- $("#publicKeyLockscreen").html('');
- $("#privateKeyLockscreen").html('');
- $("#addresLockscreen").html('');
+
+ Waves.UI.accountForm.setWalletSeed('');
+ Waves.UI.accountForm.clearAccount();
});
//Create new Waves Acount
@@ -118,21 +223,17 @@ var Waves = (function(Waves, $, undefined) {
clickClose: false,
showClose: false
});
- $("#walletSeed").prop('disabled', true);
+ $("#walletSeed").prop('readonly', true);
NProgress.start();
});
$('#login-wPop-new').on($.modal.CLOSE, function(event, modal) {
var passphrase = PassPhraseGenerator.generatePassPhrase();
- $("#walletSeed").val(passphrase);
- var publicKey = Waves.getPublicKey(passphrase);
- var privateKey = Waves.getPrivateKey(passphrase);
+ Waves.UI.accountForm.setWalletSeed(passphrase);
+ Waves.UI.accountForm.generateAccount(passphrase);
- $("#publicKeyLockscreen").html(publicKey);
- $("#privateKeyLockscreen").html(privateKey);
- $("#addresLockscreen").html(Waves.buildAddress(publicKey).getDisplayAddress());
NProgress.done();
});
@@ -146,33 +247,31 @@ var Waves = (function(Waves, $, undefined) {
$("#generateKeys").on("click", function(e) {
e.preventDefault();
- var walletSeed = $("#walletSeed").val();
+ var walletSeed = Waves.UI.accountForm.getWalletSeed();
if (walletSeed === undefined || walletSeed.length < 1) {
$.growl.error({ message: "Wallet seed cannot be empty" });
return;
}
- var publicKey = Waves.getPublicKey(walletSeed);
- var privateKey = Waves.getPrivateKey(walletSeed);
-
- $("#publicKeyLockscreen").html(publicKey);
- $("#privateKeyLockscreen").html(privateKey);
- $("#addresLockscreen").html(Waves.buildAddress(publicKey).getDisplayAddress());
+ if (Waves.UI.accountForm.endsWithWhitespace(walletSeed)) {
+ $('#close-seed-whitespace-modal').one("click", function(e) {
+ Waves.UI.accountForm.generateAccount(walletSeed);
+ $.modal.close();
+ });
+ $(Waves.UI.accountForm.seedWhitespacePopupSelector).modal();
+ }
+ else {
+ Waves.UI.accountForm.generateAccount(walletSeed);
+ }
});
$("#generateRandomSeed").on("click", function(e) {
e.preventDefault();
var passphrase = PassPhraseGenerator.generatePassPhrase();
- $("#walletSeed").val(passphrase);
-
- var publicKey = Waves.getPublicKey(passphrase);
- var privateKey = Waves.getPrivateKey(passphrase);
-
- $("#publicKeyLockscreen").html(publicKey);
- $("#privateKeyLockscreen").html(privateKey);
- $("#addresLockscreen").html(Waves.buildAddress(publicKey).getDisplayAddress());
+ Waves.UI.accountForm.setWalletSeed(passphrase);
+ Waves.UI.accountForm.generateAccount(passphrase);
});
$(".goBack").on("click", function(e) {
@@ -191,79 +290,16 @@ var Waves = (function(Waves, $, undefined) {
return;
var passphrase = $("#walletSeed").val();
- var publicKey = Waves.getPublicKey(passphrase);
- var name = $("#walletName").val();
- var password = $("#walletPassword").val();
-
- var address = Waves.buildAddress(publicKey);
- var cipher = Waves.encryptWalletSeed(passphrase, password).toString();
- var checksum = converters.byteArrayToHexString(Waves.simpleHash(converters.stringToByteArray(passphrase)));
-
- var accountData = {
- name: name,
- cipher: cipher,
- checksum: checksum,
- publicKey: publicKey,
- address: address.getRawAddress()
- };
-
- if(Waves.hasLocalStorage) {
-
- var currentAccounts = localStorage.getItem('Waves'+Waves.network);
- currentAccounts = JSON.parse(currentAccounts);
-
- if(currentAccounts !== undefined && currentAccounts !== null) {
-
- currentAccounts.accounts.push(accountData);
- localStorage.setItem('Waves'+Waves.network, JSON.stringify(currentAccounts));
- $("#wavesAccounts").append('<br><b>'+accountData.name+'</b> ' + address.getDisplayAddress());
-
- } else {
- var accountArray = { accounts: [accountData] };
- localStorage.setItem('Waves'+Waves.network, JSON.stringify(accountArray));
- $("#wavesAccounts").append('<br><b>'+accountData.name+'</b>' + address.getDisplayAddress());
- }
-
- } else {
-
- Waves.getAccounts(function(currentAccounts) {
-
- var saveData = {
- name: name,
- cipher: cipher,
- checksum: checksum,
- publicKey: publicKey,
- address: address.getRawAddress()
- };
-
- if(currentAccounts !== '') {
-
- currentAccounts = currentAccounts['WavesAccounts'];
-
- currentAccounts.accounts.push(saveData);
- chrome.storage.sync.set({'WavesAccounts': currentAccounts}, function() {
- // Notify that we saved.
- $.growl.notice({ message: "Added Account!" });
- $("#wavesAccounts").append('<br><b>'+saveData.name+'</b> ' + address.getDisplayAddress());
- });
-
- } else {
-
- var accountArray = { accounts: [saveData] };
- chrome.storage.sync.set({'WavesAccounts': accountArray}, function() {
- // Notify that we saved.
- $.growl.notice({ message: "Added Account!" });
- $("#wavesAccounts").append('<br><b>'+saveData.name+'</b> ' + address.getDisplayAddress());
- });
- }
+ if (Waves.UI.accountForm.endsWithWhitespace(passphrase)) {
+ $('#close-seed-whitespace-modal').one("click", function(e) {
+ $.modal.close();
+ Waves.UI.accountForm.registerSeed(passphrase);
});
+ $(Waves.UI.accountForm.seedWhitespacePopupSelector).modal();
+ }
+ else {
+ Waves.UI.accountForm.registerSeed(passphrase);
}
-
- accountData.firstTime = true;
- accountData.password = password;
- accountData.passphrase = passphrase;
-
- Waves.login(accountData);
});
Waves.UI.registerForm.setupValidation();

0 comments on commit 37b5548

Please sign in to comment.