diff --git a/assets/templates/wallets.html b/assets/templates/wallets.html
index d52608e..805418f 100644
--- a/assets/templates/wallets.html
+++ b/assets/templates/wallets.html
@@ -89,6 +89,14 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/renderer/blockchain.js b/renderer/blockchain.js
index 8b1efbf..0777b11 100644
--- a/renderer/blockchain.js
+++ b/renderer/blockchain.js
@@ -213,10 +213,14 @@ class Blockchain {
});
}
- importFromPrivateKey(privateKey, password) {
- web3Local.eth.accounts.wallet.clear();
- web3Local.eth.accounts.wallet.add(privateKey);
- return web3Local.eth.accounts.wallet.encrypt("123456789");
+ importFromPrivateKey(privateKey, keyPassword, clbError, clbSuccess) {
+ web3Local.eth.personal.importRawKey(privateKey, keyPassword, function (error, account) {
+ if (error) {
+ clbError(error);
+ } else {
+ clbSuccess(account);
+ }
+ });
}
subsribePendingTransactions(clbError, clbSuccess, clbData) {
diff --git a/renderer/wallets.js b/renderer/wallets.js
index 21411e2..aee2d9e 100644
--- a/renderer/wallets.js
+++ b/renderer/wallets.js
@@ -70,6 +70,34 @@ class Wallets {
}
}
+ validateImportFromKeyForm() {
+ if (EthoMainGUI.getAppState() == "account") {
+ if (!$("#inputPrivateKey").val()) {
+ EthoMainGUI.showGeneralError("Private key cannot be empty!");
+ return false;
+ }
+
+ if (!$("#keyPasswordFirst").val()) {
+ EthoMainGUI.showGeneralError("Password cannot be empty!");
+ return false;
+ }
+
+ if (!$("#keyPasswordSecond").val()) {
+ EthoMainGUI.showGeneralError("Password cannot be empty!");
+ return false;
+ }
+
+ if ($("#keyPasswordFirst").val() !== $("#keyPasswordSecond").val()) {
+ EthoMainGUI.showGeneralError("Passwords do not match!");
+ return false;
+ }
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
renderWalletsState() {
// clear the list of addresses
EthoWallets.clearAddressList();
@@ -193,16 +221,19 @@ $(document).on("render_wallets", function () {
$("#dlgImportFromPrivateKey").iziModal("open");
function doImportFromPrivateKeys() {
- 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!");
+ if (EthoWallets.validateImportFromKeyForm()) {
+ var account = EthoBlockchain.importFromPrivateKey($("#inputPrivateKey").val(), $("#keyPasswordFirst").val(), function (error) {
+ EthoMainGUI.showGeneralError(error);
+ }, function (account) {
+ if (account) {
+ EthoWallets.renderWalletsState();
+ iziToast.success({title: "Imported", message: "Account was succesfully imported", position: "topRight", timeout: 2000});
+ } else {
+ EthoMainGUI.showGeneralError("Error importing account from private key!");
+ }
+ });
}
}