! fixed import from zip file

+ import from private key
This commit is contained in:
Taegus
2019-01-05 18:09:08 +01:00
parent 7fb212f7fc
commit b9d5fdadc2
5 changed files with 85 additions and 44 deletions

View File

@@ -136,7 +136,8 @@ body.pg-loaded > .inner {
#dlgAddAddressToBook .modalBody, #dlgAddAddressToBook .modalBody,
#dlgChangeWalletName .modalBody, #dlgChangeWalletName .modalBody,
#dlgChangeAddressName .modalBody { #dlgChangeAddressName .modalBody,
#dlgImportFromPrivateKey .modalBody {
height: 150px; height: 150px;
} }

View File

@@ -2,6 +2,7 @@
<button type="button" class="btn btn-etho" id="btnNewAddress"><i class="fas fa-plus"></i></button> <button type="button" class="btn btn-etho" id="btnNewAddress"><i class="fas fa-plus"></i></button>
<button type="button" class="btn btn-etho" id="btnExportAccounts"><i class="fas fa-file-export"></i></button> <button type="button" class="btn btn-etho" id="btnExportAccounts"><i class="fas fa-file-export"></i></button>
<button type="button" class="btn btn-etho" id="btnImportAccounts"><i class="fas fa-file-import"></i></button> <button type="button" class="btn btn-etho" id="btnImportAccounts"><i class="fas fa-file-import"></i></button>
<button type="button" class="btn btn-etho" id="btnImportFromPrivateKey"><i class="fas fa-key"></i></button>
<div id="sumBalance"> <div id="sumBalance">
<span class="sumBalance" id="labelSumBalance">{{sumBalance}}</span> <span class="sumBalance" id="labelSumBalance">{{sumBalance}}</span>
<span class="sumCurrency" id="labelSumCurrency">ETHO</span> <span class="sumCurrency" id="labelSumCurrency">ETHO</span>
@@ -44,7 +45,7 @@
<input type="password" class="form-control" id="walletPasswordFirst"> <input type="password" class="form-control" id="walletPasswordFirst">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="pwd">Confirm Password:</label> <label for="walletPasswordSecond">Confirm Password:</label>
<input type="password" class="form-control" id="walletPasswordSecond"> <input type="password" class="form-control" id="walletPasswordSecond">
</div> </div>
<button type="button" class="btn btn-etho btn-dialog-confirm" id="btnCreateWalletConfirm">Confirm</button> <button type="button" class="btn btn-etho btn-dialog-confirm" id="btnCreateWalletConfirm">Confirm</button>
@@ -56,9 +57,20 @@
<div id="dlgChangeWalletName" class="modalDialog" data-iziModal-title="Wallet Name" data-iziModal-subtitle="Enter the name for this address" data-iziModal-icon="icon-home"> <div id="dlgChangeWalletName" class="modalDialog" data-iziModal-title="Wallet Name" data-iziModal-subtitle="Enter the name for this address" data-iziModal-icon="icon-home">
<div class="modalBody"> <div class="modalBody">
<div class="form-group"> <div class="form-group">
<label for="usr">Type Name:</label> <label for="inputWalletName">Type Name:</label>
<input type="text" class="form-control" id="inputWalletName"> <input type="text" class="form-control" id="inputWalletName">
</div> </div>
<button type="button" class="btn btn-etho btn-dialog-confirm" id="btnChangeWalletNameConfirm">Confirm</button> <button type="button" class="btn btn-etho btn-dialog-confirm" id="btnChangeWalletNameConfirm">Confirm</button>
</div> </div>
</div> </div>
<!-- The modal to import from private key -->
<div id="dlgImportFromPrivateKey" class="modalDialog" data-iziModal-title="Import private ley" data-iziModal-subtitle="Import account from private key" data-iziModal-icon="icon-home">
<div class="modalBody">
<div class="form-group">
<label for="inputPrivateKey">Private Key:</label>
<input type="password" class="form-control" id="inputPrivateKey">
</div>
<button type="button" class="btn btn-etho btn-dialog-confirm" id="btnImportFromPrivateKeyConfirm">Import</button>
</div>
</div>

View File

@@ -9,7 +9,7 @@ class Accounts {
this.getKeyStoreLocation = function() { this.getKeyStoreLocation = function() {
switch(os.type()) { switch(os.type()) {
case "Darwin": 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; break;
default: default:
return path.join(process.env.APPDATA, 'Ether1', 'keystore'); 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(); 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({ var openPath = dialog.showOpenDialog({
defaultPath: app.getPath('documents'), defaultPath: app.getPath('documents'),
"filters": "filters":
@@ -57,45 +81,10 @@ class Accounts {
}); });
if (openPath) { if (openPath) {
var extName = path.extname(openPath[0]).toUpperCase(); event.returnValue = EthoAccounts.importAccounts(openPath[0]);
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 { } else {
iziToast.success({ event.returnValue = false;
title: 'Imported',
message: 'Account was successfully imported.',
position: 'topRight',
timeout: 2000
});
} }
});
} else {
EthoMainGUI.showGeneralError("This is not a valid account file or arhive!");
}
}
}
}
ipcMain.on('exportAccounts', (event, arg) => {
EthoAccounts.exportAccounts();
});
ipcMain.on('importAccounts', (event, arg) => {
EthoAccounts.importAccounts();
event.returnValue = true;
}); });
EthoAccounts = new Accounts(); EthoAccounts = new Accounts();

View File

@@ -215,6 +215,10 @@ class Blockchain {
}); });
} }
importFromPrivateKey(privateKey) {
return web3Local.eth.accounts.privateKeyToAccount(privateKey);
}
subsribePendingTransactions(clbError, clbSuccess, clbData) { subsribePendingTransactions(clbError, clbSuccess, clbData) {
this.txSubscribe = web3Local.eth.subscribe('pendingTransactions', function(error, result){ this.txSubscribe = web3Local.eth.subscribe('pendingTransactions', function(error, result){
if (error) { if (error) {

View File

@@ -44,6 +44,7 @@ class Wallets {
EthoUtils.createToolTip("#btnNewAddress", "Create New Address"); EthoUtils.createToolTip("#btnNewAddress", "Create New Address");
EthoUtils.createToolTip("#btnExportAccounts", "Export Accounts"); EthoUtils.createToolTip("#btnExportAccounts", "Export Accounts");
EthoUtils.createToolTip("#btnImportAccounts", "Import Accounts"); EthoUtils.createToolTip("#btnImportAccounts", "Import Accounts");
EthoUtils.createToolTip("#btnImportFromPrivateKey", "Import From Private Key");
} }
validateNewAccountForm() { validateNewAccountForm() {
@@ -178,7 +179,41 @@ $(document).on("render_wallets", function() {
}); });
$("#btnImportAccounts").off('click').on('click', 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() { $(".textAddress").off('click').on('click', function() {