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:
parent
3cd0ae0e8b
commit
295afd2fee
2 changed files with 74 additions and 38 deletions
|
@ -9591,26 +9591,44 @@ ninja.wallets.singlewallet = {
|
||||||
|
|
||||||
// generate bitcoin address and private key and update information in the HTML
|
// generate bitcoin address and private key and update information in the HTML
|
||||||
generateNewAddressAndKey: function () {
|
generateNewAddressAndKey: function () {
|
||||||
try {
|
this.generate = function () {
|
||||||
var key = new Bitcoin.ECKey(false);
|
if ( document.getElementById("qrcode_private").innerHTML.length && window.sessionStorage ) {
|
||||||
var bitcoinAddress = key.getBitcoinAddress();
|
window.sessionStorage.previous_address = document.getElementById("btcaddress").innerHTML
|
||||||
var privateKeyWif = key.getBitcoinWalletImportFormat();
|
window.sessionStorage.previous_private_key = document.getElementById("btcprivwif").innerHTML
|
||||||
document.getElementById("btcaddress").innerHTML = bitcoinAddress;
|
}
|
||||||
document.getElementById("btcprivwif").innerHTML = privateKeyWif;
|
|
||||||
var keyValuePair = {
|
try {
|
||||||
"qrcode_public": bitcoinAddress,
|
var key = new Bitcoin.ECKey(false);
|
||||||
"qrcode_private": privateKeyWif
|
var bitcoinAddress = key.getBitcoinAddress();
|
||||||
};
|
var privateKeyWif = key.getBitcoinWalletImportFormat();
|
||||||
ninja.qrCode.showQrCode(keyValuePair, 4);
|
document.getElementById("btcaddress").innerHTML = bitcoinAddress;
|
||||||
}
|
document.getElementById("btcprivwif").innerHTML = privateKeyWif;
|
||||||
catch (e) {
|
|
||||||
// browser does not have sufficient JavaScript support to generate a bitcoin address
|
window.sessionStorage.newest_address = bitcoinAddress
|
||||||
alert(e);
|
window.sessionStorage.newest_private_key = privateKeyWif
|
||||||
document.getElementById("btcaddress").innerHTML = "error";
|
|
||||||
document.getElementById("btcprivwif").innerHTML = "error";
|
var keyValuePair = {
|
||||||
document.getElementById("qrcode_public").innerHTML = "";
|
"qrcode_public": bitcoinAddress,
|
||||||
document.getElementById("qrcode_private").innerHTML = "";
|
"qrcode_private": privateKeyWif
|
||||||
|
};
|
||||||
|
ninja.qrCode.showQrCode(keyValuePair, 4);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// browser does not have sufficient JavaScript support to generate a bitcoin address
|
||||||
|
alert(e);
|
||||||
|
document.getElementById("btcaddress").innerHTML = "error";
|
||||||
|
document.getElementById("btcprivwif").innerHTML = "error";
|
||||||
|
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>
|
</script>
|
||||||
|
|
|
@ -16,25 +16,43 @@ ninja.wallets.singlewallet = {
|
||||||
|
|
||||||
// generate bitcoin address and private key and update information in the HTML
|
// generate bitcoin address and private key and update information in the HTML
|
||||||
generateNewAddressAndKey: function () {
|
generateNewAddressAndKey: function () {
|
||||||
try {
|
this.generate = function () {
|
||||||
var key = new Bitcoin.ECKey(false);
|
if ( document.getElementById("qrcode_private").innerHTML.length && window.sessionStorage ) {
|
||||||
var bitcoinAddress = key.getBitcoinAddress();
|
window.sessionStorage.previous_address = document.getElementById("btcaddress").innerHTML
|
||||||
var privateKeyWif = key.getBitcoinWalletImportFormat();
|
window.sessionStorage.previous_private_key = document.getElementById("btcprivwif").innerHTML
|
||||||
document.getElementById("btcaddress").innerHTML = bitcoinAddress;
|
}
|
||||||
document.getElementById("btcprivwif").innerHTML = privateKeyWif;
|
|
||||||
var keyValuePair = {
|
try {
|
||||||
"qrcode_public": bitcoinAddress,
|
var key = new Bitcoin.ECKey(false);
|
||||||
"qrcode_private": privateKeyWif
|
var bitcoinAddress = key.getBitcoinAddress();
|
||||||
};
|
var privateKeyWif = key.getBitcoinWalletImportFormat();
|
||||||
ninja.qrCode.showQrCode(keyValuePair, 4);
|
document.getElementById("btcaddress").innerHTML = bitcoinAddress;
|
||||||
}
|
document.getElementById("btcprivwif").innerHTML = privateKeyWif;
|
||||||
catch (e) {
|
|
||||||
// browser does not have sufficient JavaScript support to generate a bitcoin address
|
window.sessionStorage.newest_address = bitcoinAddress
|
||||||
alert(e);
|
window.sessionStorage.newest_private_key = privateKeyWif
|
||||||
document.getElementById("btcaddress").innerHTML = "error";
|
|
||||||
document.getElementById("btcprivwif").innerHTML = "error";
|
var keyValuePair = {
|
||||||
document.getElementById("qrcode_public").innerHTML = "";
|
"qrcode_public": bitcoinAddress,
|
||||||
document.getElementById("qrcode_private").innerHTML = "";
|
"qrcode_private": privateKeyWif
|
||||||
|
};
|
||||||
|
ninja.qrCode.showQrCode(keyValuePair, 4);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// browser does not have sufficient JavaScript support to generate a bitcoin address
|
||||||
|
alert(e);
|
||||||
|
document.getElementById("btcaddress").innerHTML = "error";
|
||||||
|
document.getElementById("btcprivwif").innerHTML = "error";
|
||||||
|
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()
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Reference in a new issue