Skip to content

Commit

Permalink
fix: clean opfs backup when logout (#1748)
Browse files Browse the repository at this point in the history
- Closes #1750 
- Closes FE-1247
  • Loading branch information
LuizAsFight authored Jan 2, 2025
1 parent 9cb81db commit cc953d4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-cows-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": patch
---

fix: clean opfs when logging out
17 changes: 13 additions & 4 deletions packages/app/src/systems/Core/services/core.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { IS_LOGGED_KEY } from '~/config';
import { clearParallelDb } from '~/systems/Core/utils/databaseNoDexie';
import { VaultService } from '~/systems/Vault';
import { db } from '../utils/database';
import { cleanOPFS } from '../utils/opfs';
import { Storage } from '../utils/storage';
import { chromeStorage } from './chromeStorage';
import { clearParallelDb } from '~/systems/Core/utils/databaseNoDexie';
import { IS_LOGGED_KEY } from '~/config';

// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
export class CoreService {
static async clear() {
await chromeStorage.clear();
await VaultService.clear();
await db.clear();
Storage.clear();
await clearParallelDb();
try {
// this ones can fail depending on environment
Storage.clear();
await chromeStorage.clear();
await cleanOPFS();
} catch (e) {
console.error(e);
}

const reloadAfterCleanCompleted = () => {
const isLogged = Storage.getItem(IS_LOGGED_KEY);
if (!isLogged) {
Expand All @@ -21,6 +29,7 @@ export class CoreService {
}
setTimeout(() => reloadAfterCleanCompleted(), 50);
};

reloadAfterCleanCompleted();
}
}
7 changes: 7 additions & 0 deletions packages/app/src/systems/Core/utils/opfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ export async function readFromOPFS() {
return {};
}
}

// create a function to clean opfs
export async function cleanOPFS() {
const root = await initOPFS();
if (!root) return;
await root.removeEntry('backup.json');
}

0 comments on commit cc953d4

Please sign in to comment.