Ask user to confirm making new wallet

Warns users before they generate a new single wallet, which will erase
the old one. Also stores the addresses and keys in sessionStorage in
case it needs to be recovered.
This commit is contained in:
OKNoah 2015-09-08 14:28:31 -07:00
parent 3cd0ae0e8b
commit 295afd2fee
2 changed files with 74 additions and 38 deletions

View file

@ -9591,12 +9591,22 @@ ninja.wallets.singlewallet = {
// generate bitcoin address and private key and update information in the HTML
generateNewAddressAndKey: function () {
this.generate = function () {
if ( document.getElementById("qrcode_private").innerHTML.length && window.sessionStorage ) {
window.sessionStorage.previous_address = document.getElementById("btcaddress").innerHTML
window.sessionStorage.previous_private_key = document.getElementById("btcprivwif").innerHTML
}
try {
var key = new Bitcoin.ECKey(false);
var bitcoinAddress = key.getBitcoinAddress();
var privateKeyWif = key.getBitcoinWalletImportFormat();
document.getElementById("btcaddress").innerHTML = bitcoinAddress;
document.getElementById("btcprivwif").innerHTML = privateKeyWif;
window.sessionStorage.newest_address = bitcoinAddress
window.sessionStorage.newest_private_key = privateKeyWif
var keyValuePair = {
"qrcode_public": bitcoinAddress,
"qrcode_private": privateKeyWif
@ -9611,6 +9621,14 @@ ninja.wallets.singlewallet = {
document.getElementById("qrcode_public").innerHTML = "";
document.getElementById("qrcode_private").innerHTML = "";
}
}
if ( document.getElementById("qrcode_private").innerHTML.length ) {
if ( confirm( "WARNING: This will permanently erase the current private key that is on the screen. If you have not saved this private key, press cancel now!" ) ) {
return this.generate()
} else return
} else return this.generate()
}
};
</script>

View file

@ -16,12 +16,22 @@ ninja.wallets.singlewallet = {
// generate bitcoin address and private key and update information in the HTML
generateNewAddressAndKey: function () {
this.generate = function () {
if ( document.getElementById("qrcode_private").innerHTML.length && window.sessionStorage ) {
window.sessionStorage.previous_address = document.getElementById("btcaddress").innerHTML
window.sessionStorage.previous_private_key = document.getElementById("btcprivwif").innerHTML
}
try {
var key = new Bitcoin.ECKey(false);
var bitcoinAddress = key.getBitcoinAddress();
var privateKeyWif = key.getBitcoinWalletImportFormat();
document.getElementById("btcaddress").innerHTML = bitcoinAddress;
document.getElementById("btcprivwif").innerHTML = privateKeyWif;
window.sessionStorage.newest_address = bitcoinAddress
window.sessionStorage.newest_private_key = privateKeyWif
var keyValuePair = {
"qrcode_public": bitcoinAddress,
"qrcode_private": privateKeyWif
@ -36,5 +46,13 @@ ninja.wallets.singlewallet = {
document.getElementById("qrcode_public").innerHTML = "";
document.getElementById("qrcode_private").innerHTML = "";
}
}
if ( document.getElementById("qrcode_private").innerHTML.length ) {
if ( confirm( "WARNING: This will permanently erase the current private key that is on the screen. If you have not saved this private key, press cancel now!" ) ) {
return this.generate()
} else return
} else return this.generate()
}
};