From 0aa73d39309539f940457dc44d59ffbf7278c124 Mon Sep 17 00:00:00 2001 From: Taegus Date: Sat, 5 Jan 2019 19:33:26 +0100 Subject: [PATCH] * import from private key improved --- modules/accounts.js | 13 ++++++++++++- renderer/blockchain.js | 6 ++++-- renderer/wallets.js | 20 +++++++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/modules/accounts.js b/modules/accounts.js index e3db170..68a5398 100644 --- a/modules/accounts.js +++ b/modules/accounts.js @@ -58,10 +58,16 @@ class Accounts { 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) => { - EthoAccounts.exportAccounts(); + EthoAccounts.exportAccounts(); }); ipcMain.on('importAccounts', (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(); \ No newline at end of file diff --git a/renderer/blockchain.js b/renderer/blockchain.js index 4643080..5b9db45 100644 --- a/renderer/blockchain.js +++ b/renderer/blockchain.js @@ -215,8 +215,10 @@ class Blockchain { }); } - importFromPrivateKey(privateKey) { - return web3Local.eth.accounts.privateKeyToAccount(privateKey); + importFromPrivateKey(privateKey, password) { + web3Local.eth.accounts.wallet.clear(); + web3Local.eth.accounts.wallet.add(privateKey); + return web3Local.eth.accounts.wallet.encrypt('123456789'); } subsribePendingTransactions(clbError, clbSuccess, clbData) { diff --git a/renderer/wallets.js b/renderer/wallets.js index e6d4315..3de7876 100644 --- a/renderer/wallets.js +++ b/renderer/wallets.js @@ -200,9 +200,23 @@ $(document).on("render_wallets", function() { $('#dlgImportFromPrivateKey').iziModal('open'); function doImportFromPrivateKeys() { - EthoBlockchain.importFromPrivateKey($("#inputPrivateKey").val()); - $('#dlgChangeWalletName').iziModal('close'); - EthoWallets.renderWalletsState(); + var account = EthoBlockchain.importFromPrivateKey($("#inputPrivateKey").val()); + $('#dlgImportFromPrivateKey').iziModal('close'); + + 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() {