diff --git a/main.js b/main.js index 912a6e0..351f3ab 100644 --- a/main.js +++ b/main.js @@ -66,9 +66,17 @@ locker.lock().then(function() { // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. // listen for request to get template + + // get the template content from file ipcMain.on('getTemplateContent', (event, arg) => { event.returnValue = fs.readFileSync(path.join(app.getAppPath(), "assets/templates/") + arg, 'utf8'); }); + + // quit the app on coomand + ipcMain.on('appQuit', (event, arg) => { + app.quit(); + }); + }) .catch(function(err) { app.quit(); diff --git a/modules/accounts.js b/modules/accounts.js index e2b4d13..bc1f012 100644 --- a/modules/accounts.js +++ b/modules/accounts.js @@ -6,15 +6,16 @@ const os = require('os'); class Accounts { constructor() { - this.getKeyStoreLocation = function() { - switch(os.type()) { - case "Darwin": - return path.join(os.homedir(), 'Library', 'Ether1', 'keystore'); - break; - default: - return path.join(process.env.APPDATA, 'Ether1', 'keystore'); - } - } + } + + getKeyStoreLocation() { + switch(os.type()) { + case "Darwin": + return path.join(os.homedir(), 'Library', 'Ether1', 'keystore'); + break; + default: + return path.join(process.env.APPDATA, 'Ether1', 'keystore'); + } } exportAccounts() { @@ -23,7 +24,7 @@ class Accounts { }); if (savePath) { - const accPath = this.getKeyStoreLocation(); + const accPath = EthoAccounts.getKeyStoreLocation(); fs.readdir(accPath, function(err, files) { var zip = new admZip(); @@ -40,7 +41,7 @@ class Accounts { importAccounts(accountsFile) { var extName = path.extname(accountsFile).toUpperCase(); - const accPath = this.getKeyStoreLocation(); + const accPath = EthoAccounts.getKeyStoreLocation(); if (extName == '.ZIP') { var zip = new admZip(accountsFile); @@ -57,7 +58,7 @@ class Accounts { } saveAccount(account) { - fs.writeFile(path.join(this.getKeyStoreLocation(), '0x' + account.address), JSON.stringify(account), 'utf8', function() { + fs.writeFile(path.join(tEthoAccountshis.getKeyStoreLocation(), '0x' + account.address), JSON.stringify(account), 'utf8', function() { // file was written }); } diff --git a/modules/database.js b/modules/database.js index 925b405..9493502 100644 --- a/modules/database.js +++ b/modules/database.js @@ -4,6 +4,7 @@ const datastore = require('nedb'); const moment = require('moment'); const path = require('path'); const fs = require('fs'); +const os = require('os'); const dbPath = path.join(app.getPath('userData'), 'storage.db'); const db = new datastore({ filename: dbPath }); @@ -96,5 +97,35 @@ ipcMain.on('deleteWalletData', (event, arg) => { } else { event.returnValue = { success: true, error: null }; } - }); -}); \ No newline at end of file + }); +}); + +ipcMain.on('deleteBlockchainData', (event, arg) => { + var deleteFolderRecursive = function(path) { + if( fs.existsSync(path) ) { + fs.readdirSync(path).forEach(function(file,index){ + var curPath = path + "/" + file; + if(fs.lstatSync(curPath).isDirectory()) { // recurse + deleteFolderRecursive(curPath); + } else { // delete file + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(path); + } + }; + + function getBlockchainDataLocation() { + switch(os.type()) { + case "Darwin": + return path.join(os.homedir(), 'Library', 'Ether1', 'geth'); + break; + default: + return path.join(process.env.APPDATA, 'Ether1', 'geth'); + } + } + + // delete folder in a synchronous recursive maner + deleteFolderRecursive(getBlockchainDataLocation()); + event.returnValue = true; +}); diff --git a/modules/geth.js b/modules/geth.js index fd1bfff..9006aef 100644 --- a/modules/geth.js +++ b/modules/geth.js @@ -1,5 +1,5 @@ +const {app, dialog, ipcMain} = require('electron'); const child_process = require('child_process'); -const {app, dialog} = require('electron'); const appRoot = require('app-root-path'); const path = require('path'); const fs = require('fs'); @@ -79,4 +79,8 @@ class Geth { } } +ipcMain.on('stopGeth', (event, arg) => { + EthoGeth.stopGeth(); +}); + EthoGeth = new Geth(); \ No newline at end of file diff --git a/package.json b/package.json index 3e43144..e2f92f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Ether1Wallet", - "version": "0.2.5", + "version": "0.2.6", "description": "Desktop wallet for Ether1 currency", "main": "main.js", "scripts": { diff --git a/renderer/send.js b/renderer/send.js index eb93639..556b2f9 100644 --- a/renderer/send.js +++ b/renderer/send.js @@ -63,6 +63,12 @@ $(document).on("render_send", function() { $('select').formSelect( {classes: "fromAddressSelect"}); $("#sendFromAddress").on("change", function() { + var optionText = $(this).find("option:selected").text(); + var addrName = optionText.substr(0, optionText.indexOf('-')); + var addrValue = optionText.substr(optionText.indexOf("-") + 1); + $(".fromAddressSelect input").val(addrValue.trim()); + $("#sendFromAddressName").html(addrName.trim()); + web3Local.eth.getBalance(this.value, function(error, balance) { $("#sendMaxAmmount").html(parseFloat(web3Local.utils.fromWei(balance, 'ether'))); }); @@ -85,14 +91,6 @@ $(document).on("render_send", function() { $("#sendToAddressName").html(addressName); }); - $("#sendFromAddress").off('change').on('change', function() { - var optionText = $(this).find("option:selected").text(); - var addrName = optionText.substr(0, optionText.indexOf('-')); - var addrValue = optionText.substr(optionText.indexOf("-") + 1); - $(".fromAddressSelect input").val(addrValue.trim()); - $("#sendFromAddressName").html(addrName.trim()); - }); - $("#btnLookForToAddress").off('click').on('click', function() { EthoBlockchain.getAddressListData( function(error) { diff --git a/renderer/settings.js b/renderer/settings.js index 25ba34c..39fe8ee 100644 --- a/renderer/settings.js +++ b/renderer/settings.js @@ -60,22 +60,46 @@ $(document).on("render_settings", function() { }); $("#btnSettingsCleanWallets").off('click').on('click', function() { - ipcResult = ipcRenderer.sendSync('deleteWalletData', null); + EthoMainGUI.showGeneralConfirmation("Do you really want to delete wallets data?", function(result) { + if (result) { + ipcResult = ipcRenderer.sendSync('deleteWalletData', null); - if (ipcResult.success) { - iziToast.success({ - title: 'Success', - message: 'Wallet names were succesfully cleaned', - position: 'topRight', - timeout: 5000 - }); - } else { - EthoMainGUI.showGeneralError("Error clearing wallet names: " + ipcResult.error); - } + if (ipcResult.success) { + iziToast.success({ + title: 'Success', + message: 'Wallet names were succesfully cleaned', + position: 'topRight', + timeout: 5000 + }); + } else { + EthoMainGUI.showGeneralError("Error clearing wallet names: " + ipcResult.error); + } + } + }); }); $("#btnSettingsCleanBlockchain").off('click').on('click', function() { - EthoMainGUI.showGeneralError("Not implemented yet!"); + EthoMainGUI.showGeneralConfirmation("Do you really want to delete the blockchain data? Wallet will close and you will need to restart it!", function(result) { + if (result) { + var loading_screen = pleaseWait({ + logo: "assets/images/logo.png", + backgroundColor: '#000000', + loadingHtml: "
Deleting blockchain data, wallet will automatically close, please wait...
" + }); + + setTimeout(() => { + // first stop the geth process + ipcResult = ipcRenderer.send('stopGeth', null); + + setTimeout(() => { + // delete the blockchain date async and wait for 5 seconds + ipcResult = ipcRenderer.sendSync('deleteBlockchainData', null); + // finally quit the application + ipcResult = ipcRenderer.send('appQuit', null); + }, 5000); + }, 2000); + } + }); }); });