From 1521eebb9ea7e25495c47a6568b0fa19edb197d7 Mon Sep 17 00:00:00 2001 From: newCodeRunner <57590297+newCodeRunner@users.noreply.github.com> Date: Tue, 8 Dec 2020 18:45:56 +0500 Subject: [PATCH] Update accounts.js Updating accounts module to delete address locally --- modules/accounts.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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();