diff --git a/assets/styles/style.css b/assets/styles/style.css index dcfca4d..672a474 100644 --- a/assets/styles/style.css +++ b/assets/styles/style.css @@ -136,7 +136,8 @@ body.pg-loaded > .inner { #dlgAddAddressToBook .modalBody, #dlgChangeWalletName .modalBody, -#dlgChangeAddressName .modalBody { +#dlgChangeAddressName .modalBody, +#dlgImportFromPrivateKey .modalBody { height: 150px; } diff --git a/assets/templates/wallets.html b/assets/templates/wallets.html index fde703c..5c83da2 100644 --- a/assets/templates/wallets.html +++ b/assets/templates/wallets.html @@ -2,6 +2,7 @@ +
{{sumBalance}} ETHO @@ -44,7 +45,7 @@
- +
@@ -56,9 +57,20 @@
- +
+
+ + +
+
+
+ + +
+ +
\ No newline at end of file diff --git a/modules/accounts.js b/modules/accounts.js index 3367efe..6287e4b 100644 --- a/modules/accounts.js +++ b/modules/accounts.js @@ -9,7 +9,7 @@ class Accounts { this.getKeyStoreLocation = function() { switch(os.type()) { case "Darwin": - return path.join(process.env.HOMEPATH, 'Documents/ethereum-wallet/ethereum-wallet/Classes/Business layer/Core/Services', 'keystore'); + return path.join(os.homedir(), 'Documents/ethereum-wallet/ethereum-wallet/Classes/Business layer/Core/Services', 'keystore'); break; default: return path.join(process.env.APPDATA, 'Ether1', 'keystore'); @@ -38,9 +38,33 @@ class Accounts { } } - importAccounts() { + importAccounts(accountsFile) { + var extName = path.extname(accountsFile).toUpperCase(); const accPath = this.getKeyStoreLocation(); + if (extName = '.ZIP') { + var zip = new admZip(accountsFile); + zip.extractAllTo(accPath, true); + return { success: true, text: "Accounts ware successfully imported."}; + } else if (extName = '.JSON') { + fs.copyFile(accountsFile, path.join(accPath, path.basename(accountsFile)), (err) => { + if (err) { + return { success: false, text: err}; + } else { + return { success: true, text: "Account was successfully imported."}; + } + }); + } else { + return { success: false, text: "This is not a valid account file or arhive!"}; + } + } +} + +ipcMain.on('exportAccounts', (event, arg) => { + EthoAccounts.exportAccounts(); +}); + +ipcMain.on('importAccounts', (event, arg) => { var openPath = dialog.showOpenDialog({ defaultPath: app.getPath('documents'), "filters": @@ -57,45 +81,10 @@ class Accounts { }); if (openPath) { - var extName = path.extname(openPath[0]).toUpperCase(); - - if (extName = '.ZIP') { - var zip = new admZip(openPath[0]); - zip.extractAllTo(accPath, true); - - iziToast.success({ - title: 'Imported', - message: 'Accounts ware successfully imported.', - position: 'topRight', - timeout: 2000 - }); - } else if (extName = '.JSON') { - fs.copyFile(openPath[0], path.join(accPath, path.basename(openPath[0])), (err) => { - if (err) { - EthoMainGUI.showGeneralError(err); - } else { - iziToast.success({ - title: 'Imported', - message: 'Account was successfully imported.', - position: 'topRight', - timeout: 2000 - }); - } - }); - } else { - EthoMainGUI.showGeneralError("This is not a valid account file or arhive!"); - } + event.returnValue = EthoAccounts.importAccounts(openPath[0]); + } else { + event.returnValue = false; } - } -} - -ipcMain.on('exportAccounts', (event, arg) => { - EthoAccounts.exportAccounts(); -}); - -ipcMain.on('importAccounts', (event, arg) => { - EthoAccounts.importAccounts(); - event.returnValue = true; }); EthoAccounts = new Accounts(); \ No newline at end of file diff --git a/renderer/blockchain.js b/renderer/blockchain.js index 94a1b0c..4643080 100644 --- a/renderer/blockchain.js +++ b/renderer/blockchain.js @@ -215,6 +215,10 @@ class Blockchain { }); } + importFromPrivateKey(privateKey) { + return web3Local.eth.accounts.privateKeyToAccount(privateKey); + } + subsribePendingTransactions(clbError, clbSuccess, clbData) { this.txSubscribe = web3Local.eth.subscribe('pendingTransactions', function(error, result){ if (error) { diff --git a/renderer/wallets.js b/renderer/wallets.js index c50da66..e6d4315 100644 --- a/renderer/wallets.js +++ b/renderer/wallets.js @@ -44,6 +44,7 @@ class Wallets { EthoUtils.createToolTip("#btnNewAddress", "Create New Address"); EthoUtils.createToolTip("#btnExportAccounts", "Export Accounts"); EthoUtils.createToolTip("#btnImportAccounts", "Import Accounts"); + EthoUtils.createToolTip("#btnImportFromPrivateKey", "Import From Private Key"); } validateNewAccountForm() { @@ -178,7 +179,41 @@ $(document).on("render_wallets", function() { }); $("#btnImportAccounts").off('click').on('click', function() { - ipcRenderer.sendSync('importAccounts', {}); + var ImportResult = ipcRenderer.sendSync('importAccounts', {}); + + if (ImportResult.success) { + iziToast.success({ + title: 'Imported', + message: ImportResult.text, + position: 'topRight', + timeout: 2000 + }); + } else { + EthoMainGUI.showGeneralError(ImportResult.text); + } + + }); + + $("#btnImportFromPrivateKey").off('click').on('click', function() { + $("#dlgImportFromPrivateKey").iziModal(); + $("#inputPrivateKey").val(""); + $('#dlgImportFromPrivateKey').iziModal('open'); + + function doImportFromPrivateKeys() { + EthoBlockchain.importFromPrivateKey($("#inputPrivateKey").val()); + $('#dlgChangeWalletName').iziModal('close'); + EthoWallets.renderWalletsState(); + } + + $("#btnImportFromPrivateKeyConfirm").off('click').on('click', function() { + doImportFromPrivateKeys(); + }); + + $("#dlgImportFromPrivateKey").off('keypress').on('keypress', function(e) { + if(e.which == 13) { + doImportFromPrivateKeys(); + } + }); }); $(".textAddress").off('click').on('click', function() {