* import from private key improved

This commit is contained in:
Taegus
2019-01-05 19:33:26 +01:00
parent df603f7607
commit 0aa73d3930
3 changed files with 33 additions and 6 deletions

View File

@@ -58,6 +58,12 @@ class Accounts {
return { success: false, text: "This is not a valid account file or arhive!"}; return { success: false, text: "This is not a valid account file or arhive!"};
} }
} }
saveAccount(account) {
fs.writeFile(path.join(this.getKeyStoreLocation(), '0x' + account.address), JSON.stringify(account), 'utf8', function() {
// file was written
});
}
} }
ipcMain.on('exportAccounts', (event, arg) => { ipcMain.on('exportAccounts', (event, arg) => {
@@ -87,4 +93,9 @@ ipcMain.on('importAccounts', (event, arg) => {
} }
}); });
ipcMain.on('saveAccount', (event, arg) => {
EthoAccounts.saveAccount(arg);
event.returnValue = true;
});
EthoAccounts = new Accounts(); EthoAccounts = new Accounts();

View File

@@ -215,8 +215,10 @@ class Blockchain {
}); });
} }
importFromPrivateKey(privateKey) { importFromPrivateKey(privateKey, password) {
return web3Local.eth.accounts.privateKeyToAccount(privateKey); web3Local.eth.accounts.wallet.clear();
web3Local.eth.accounts.wallet.add(privateKey);
return web3Local.eth.accounts.wallet.encrypt('123456789');
} }
subsribePendingTransactions(clbError, clbSuccess, clbData) { subsribePendingTransactions(clbError, clbSuccess, clbData) {

View File

@@ -200,9 +200,23 @@ $(document).on("render_wallets", function() {
$('#dlgImportFromPrivateKey').iziModal('open'); $('#dlgImportFromPrivateKey').iziModal('open');
function doImportFromPrivateKeys() { function doImportFromPrivateKeys() {
EthoBlockchain.importFromPrivateKey($("#inputPrivateKey").val()); var account = EthoBlockchain.importFromPrivateKey($("#inputPrivateKey").val());
$('#dlgChangeWalletName').iziModal('close'); $('#dlgImportFromPrivateKey').iziModal('close');
EthoWallets.renderWalletsState();
if (account) {
ipcRenderer.sendSync('saveAccount', account[0]);
EthoWallets.renderWalletsState();
iziToast.success({
title: 'Imported',
message: "Account was succesfully imported",
position: 'topRight',
timeout: 2000
});
} else {
EthoMainGUI.showGeneralError("Error importing account from private key!");
}
} }
$("#btnImportFromPrivateKeyConfirm").off('click').on('click', function() { $("#btnImportFromPrivateKeyConfirm").off('click').on('click', function() {