Merge pull request #65 from newCodeRunner/master

Add Button to Delete addresses locally
This commit is contained in:
Ethan van Ballegooyen
2020-12-08 15:58:28 +02:00
committed by GitHub
3 changed files with 54 additions and 1 deletions

View File

@@ -47,6 +47,9 @@
<button type="button" class="btn btn-etho btnShowQRCode" data-address="{{address}}"> <button type="button" class="btn btn-etho btnShowQRCode" data-address="{{address}}">
<i class="fas fa-qrcode"></i> <i class="fas fa-qrcode"></i>
</button> </button>
<button type="button" class="btn btn-etho btnDeleteAddress" data-wallet="{{address}}">
<i class="fas fa-times"></i>
</button>
</td> </td>
<td>{{balance}}</td> <td>{{balance}}</td>
</tr> </tr>

View File

@@ -61,6 +61,32 @@ class Accounts {
// file was written // 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) => { ipcMain.on("exportAccounts", (event, arg) => {
@@ -96,4 +122,14 @@ ipcMain.on("saveAccount", (event, arg) => {
event.returnValue = true; event.returnValue = true;
}); });
ipcMain.on("deteteAccount", (event, arg) => {
EthoAccounts.deteteAccount(arg)
.then((res) => {
event.returnValue = res;
})
.catch((err) => {
event.returnValue = err;
});
});
EthoAccounts = new Accounts(); EthoAccounts = new Accounts();

View File

@@ -179,6 +179,20 @@ $(document).on("render_wallets", function () {
}); });
}); });
$(".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 () { $(".btnChangWalletName").off("click").on("click", function () {
var walletAddress = $(this).attr("data-wallet"); var walletAddress = $(this).attr("data-wallet");
var walletName = $(this).attr("data-name"); var walletName = $(this).attr("data-name");