diff --git a/electron/main/index.ts b/electron/main/index.ts index 392711d34..157c10817 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -16,6 +16,7 @@ import { WalletManager } from '../walletManager' import { IPC_ACTIONS } from '../ipc/ipcActions' import { AutoUpdaterManager } from '../autoUpdaterManager' import overwriteWitnetNodeConfiguration from '../utils/overwriteWitnetNodeConfiguration' +import { SHEIKAH_PATH } from '../constants' const { SHUTDOWN, SHUTDOWN_FINISHED } = IPC_ACTIONS.Window @@ -92,7 +93,7 @@ async function createWindow() { { label: 'Clean Data & Relaunch', click: () => { - walletManager.clearWalletFiles() + walletManager.clearWalletFiles(SHEIKAH_PATH) win.webContents.send(SHUTDOWN) actions.relaunch() }, diff --git a/electron/walletManager.ts b/electron/walletManager.ts index 9b4265e13..cda0748bd 100644 --- a/electron/walletManager.ts +++ b/electron/walletManager.ts @@ -168,20 +168,23 @@ export class WalletManager { } } - public clearWalletFiles() { - if (fs.existsSync(SHEIKAH_PATH)) { - const entries = fs.readdirSync(SHEIKAH_PATH, { withFileTypes: true }) - - for (const entry of entries) { - const thisPath = path.resolve(SHEIKAH_PATH, entry.name) - - if (fs.existsSync(thisPath)) { - entry.isDirectory() && this.clearWalletFiles() - entry.isFile() && fs.unlinkSync(thisPath) + public clearWalletFiles(pathToClear: string) { + if (fs.existsSync(pathToClear)) { + const items = fs.readdirSync(pathToClear, { withFileTypes: true }) + + for (const item of items) { + const itemPath = path.resolve(pathToClear, item.name) + + if (fs.existsSync(itemPath)) { + if (item.isDirectory()) { + this.clearWalletFiles(itemPath) + } else if (item.isFile()) { + fs.unlinkSync(itemPath) + } } } - fs.rmdirSync(SHEIKAH_PATH) + fs.rmdirSync(pathToClear) } }