Skip to content

Commit

Permalink
Minor changes and clean on wallet management
Browse files Browse the repository at this point in the history
  • Loading branch information
vncoelho committed Dec 21, 2023
1 parent 9620c9d commit a5c5e41
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
7 changes: 4 additions & 3 deletions assets/eco-scripts/rawRpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,16 @@ function signAndRelay() {

function signTx(tx) {
if (isMultiSig(CONNECTED_WALLET_ID)) {
var publicKeys = Neon.wallet.getPublicKeysFromVerificationScript(Neon.u.base642hex(ECO_WALLET[CONNECTED_WALLET_ID].account.contract.script))
var threshold = Neon.wallet.getSigningThresholdFromVerificationScript(Neon.u.base642hex(ECO_WALLET[CONNECTED_WALLET_ID].account.contract.script))
var base64VerificationScript = ECO_WALLET[CONNECTED_WALLET_ID].account.contract.script;
var hexVerificationScript = Neon.u.base642hex(base64VerificationScript);
var publicKeys = Neon.wallet.getPublicKeysFromVerificationScript(hexVerificationScript);
var threshold = Neon.wallet.getSigningThresholdFromVerificationScript(hexVerificationScript);
var signingAccountsIDs = getMultiSigSignersID(publicKeys, threshold);
if (signingAccountsIDs.length < threshold) {
var sText = "Current Wallet is connected to a multisig!" + "Your wallet has " + signingAccountsIDs.length + " accounts to sign. But required is " + threshold;
swal2Simple("Wallet while signing", sText, 5500, "error");
}


for (sa = 0; sa < signingAccountsIDs.length; sa++)
tx.sign(ECO_WALLET[signingAccountsIDs[sa]].account, NETWORK_MAGIC)

Expand Down
7 changes: 4 additions & 3 deletions assets/eco-scripts/wallet_addNewAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function addAccountAndDraw(accountToAdd, labelToAdd) {
function addSafeAccount(accountToAdd, labelToAdd) {
//Asks for password if privatekey or wif or encrypted
if (MASTER_KEY_WALLET != "") {
swal2Simple("You already have a master key", "Check on config tab", 5500, "success");
swal2Simple("You have a master key", "This account will be linked to your password", 5500, "success");
addAccountAndDraw(accountToAdd, labelToAdd);
} else {
setMasterKey(() => {
Expand Down Expand Up @@ -110,6 +110,7 @@ function setMasterKey(callback, labelToAdd) {
var pass2 = document.getElementById("input-newaccount-password-2").value;
if (pass1 !== "" && pass1 == pass2) {
MASTER_KEY_WALLET = pass1;
swal2Simple("Your Master Key has been set", "Remember your password", 5500, "success");
return true;
}
else {
Expand All @@ -121,7 +122,7 @@ function setMasterKey(callback, labelToAdd) {
if (result.isConfirmed) {
callback();
}else{
swal2Simple("Be careful!", "A password is needed for this action.", 0, "error");
swal2Simple("Be carefull!", "A password is needed for this action.", 0, "error");
callback();
}
});
Expand Down Expand Up @@ -232,5 +233,5 @@ function addExtraAccountAndUpdateWallet(accToAdd, labelToAdd, print) {
};
ECO_EXTRA_ACCOUNTS.push(newAcc);
ECO_WALLET.push(newAcc);
btnWalletSave();
extraWalletSave();
}
2 changes: 1 addition & 1 deletion assets/eco-scripts/wallet_center.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function deleteAccount(idToRemove) {
if (idToRemove >= DEFAULT_WALLET.length) {
var defaultLength = DEFAULT_WALLET.length;
ECO_EXTRA_ACCOUNTS.splice(idToRemove - defaultLength, 1);
btnWalletSave();
extraWalletSave();
}
ECO_WALLET.splice(idToRemove, 1);

Expand Down
37 changes: 25 additions & 12 deletions assets/eco-scripts/wallet_localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ function getIDFromExtraAccountStillEncrypted(baseEncrypted, encryptedToSearch) {


async function getExtraWalletAccountFromLocalStorage() {
var mySafeExtraAccountsWallet = getLocalStorage("mySafeEncryptedExtraAccounts");
if (mySafeExtraAccountsWallet) {
mySafeExtraAccountsWallet = JSON.parse(mySafeExtraAccountsWallet);
var serializedAccountKeys = getLocalStorage("mySafeEncryptedExtraAccounts");

if (serializedAccountKeys) {
var serializedAccountKeysJson = JSON.parse(serializedAccountKeys);
var myRecreatedExtraAccounts = [];

await Promise.all(mySafeExtraAccountsWallet.map(async (accountData) => {
// Direct add or try to decrypt
await Promise.all(serializedAccountKeysJson.map(async (accountData) => {
var storedKey = accountData.key;
var label = accountData.label;
var print = accountData.print;
Expand All @@ -51,27 +53,28 @@ async function getExtraWalletAccountFromLocalStorage() {
}
}));

console.log(myRecreatedExtraAccounts)
//console.log(myRecreatedExtraAccounts)
if (myRecreatedExtraAccounts.length != 0) {
$("#btnWalletSaveID")[0].disabled = false;
$("#btnNewWallet")[0].disabled = false;
$("#btnLoadSavedAccount")[0].disabled = true;
}

return myRecreatedExtraAccounts;
}
return [];
}

function restoreWalletExtraAccountsLocalStorage() {
var mySafeExtraAccountsWallet = getLocalStorage("mySafeEncryptedExtraAccounts");
var mySafeExtraAccountsWalletJson = JSON.parse(mySafeExtraAccountsWallet);
var nAccounts = mySafeExtraAccountsWalletJson.length;
var nEncryptedAccounts = getNumberOfSafeEncryptedAccountsFromVector(mySafeExtraAccountsWalletJson);
console.log("You have " + nEncryptedAccounts + " encrypted accounts to be decrypted.");
// Serialized Storage
var serializedKeys = getLocalStorage("mySafeEncryptedExtraAccounts");
var serializedKeysJson = JSON.parse(serializedKeys);

var nAccounts = serializedKeysJson.length;
var nEncryptedAccounts = getNumberOfSafeEncryptedAccountsFromVector(serializedKeysJson);
//console.log("You have " + nAccounts + " account and " + nEncryptedAccounts + " encrypted accounts to be decrypted.");

if (mySafeExtraAccountsWallet && MASTER_KEY_WALLET == "") {
if (serializedKeys && MASTER_KEY_WALLET == "") {
setMasterKey(() => {
updateExtraAndEcoWallet();
}, "Restoring: " + nAccounts + " accounts (" + nEncryptedAccounts + " encrypted)");
Expand Down Expand Up @@ -101,6 +104,16 @@ function getNumberOfSafeEncryptedAccountsFromVector(mySafeExtraAccountsWallet) {
}

function btnWalletSave() {
if (MASTER_KEY_WALLET == "") {
setMasterKey(() => {
extraWalletSave();
}, "You need to set your password.");
} else {
extraWalletSave();
}
}

function extraWalletSave() {
if (ECO_EXTRA_ACCOUNTS.length > 0) {
if (MASTER_KEY_WALLET == "") {
swal2Simple("MASTER KEY IS EMPTY", "A password is required for saving new addresses", 5500, "error");
Expand Down

0 comments on commit a5c5e41

Please sign in to comment.