diff --git a/assets/templates/wallets.html b/assets/templates/wallets.html index a183dc0..a748b8b 100755 --- a/assets/templates/wallets.html +++ b/assets/templates/wallets.html @@ -47,6 +47,9 @@ + {{balance}} diff --git a/modules/accounts.js b/modules/accounts.js index c5fe1b0..ad5f208 100755 --- a/modules/accounts.js +++ b/modules/accounts.js @@ -61,6 +61,32 @@ class Accounts { // file was written }); } + + deteteAccount(address) { + return new Promise((resolve, reject) => { + const accPath = EthoAccounts.getKeyStoreLocation(); + + fs.readdir(accPath, function (err, files) { + let deleteFilePath = null; + if (err) reject(err); + else { + const searchStr = String(address).substring(2, String(address).length).toLowerCase(); + for (let filePath of files) { + if (String(filePath).toLowerCase().indexOf(searchStr) > -1) { + deleteFilePath = filePath; + break; + } + } + if (deleteFilePath) { + fs.unlink(path.join(accPath, deleteFilePath), function(error) { + if (error) reject(error); + else resolve(true); + }); + } else resolve(true) + } + }); + }); + } } ipcMain.on("exportAccounts", (event, arg) => { @@ -96,4 +122,14 @@ ipcMain.on("saveAccount", (event, arg) => { event.returnValue = true; }); +ipcMain.on("deteteAccount", (event, arg) => { + EthoAccounts.deteteAccount(arg) + .then((res) => { + event.returnValue = res; + }) + .catch((err) => { + event.returnValue = err; + }); +}); + EthoAccounts = new Accounts(); diff --git a/renderer/wallets.js b/renderer/wallets.js index 0199f33..ba71b84 100755 --- a/renderer/wallets.js +++ b/renderer/wallets.js @@ -178,6 +178,20 @@ $(document).on("render_wallets", function () { $("#dlgShowAddressQRCode").iziModal("close"); }); }); + + $(".btnDeleteAddress").off("click").on("click", function () { + const address = $(this).attr("data-wallet"); + EthoMainGUI.showGeneralConfirmation( + `Do you really want to delete Wallet with Address: ${address}? This action can not be reversed.`, + function (result) { + if (result) { + const deleteResult = ipcRenderer.sendSync('deteteAccount', address); + if (deleteResult !== true) EthoMainGUI.showGeneralError(deleteResult); + setTimeout(EthoWallets.renderWalletsState, 1000); + } + }, + ); + }); $(".btnChangWalletName").off("click").on("click", function () { var walletAddress = $(this).attr("data-wallet"); @@ -279,4 +293,4 @@ $(document).on("onNewAccountTransaction", function () { } }); -EthoWallets = new Wallets(); \ No newline at end of file +EthoWallets = new Wallets();