Skip to content

Commit

Permalink
feat: allow clear wallet files from menu
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Mar 18, 2024
1 parent 439ef10 commit e000783
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -92,7 +93,7 @@ async function createWindow() {
{
label: 'Clean Data & Relaunch',
click: () => {
walletManager.clearWalletFiles()
walletManager.clearWalletFiles(SHEIKAH_PATH)
win.webContents.send(SHUTDOWN)
actions.relaunch()
},
Expand Down
25 changes: 14 additions & 11 deletions electron/walletManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit e000783

Please sign in to comment.