From cc953d4f62402895970140d243a3832a374aaa46 Mon Sep 17 00:00:00 2001 From: Luiz Gomes <8636507+LuizAsFight@users.noreply.github.com> Date: Thu, 2 Jan 2025 04:04:50 -0300 Subject: [PATCH] fix: clean opfs backup when logout (#1748) - Closes #1750 - Closes FE-1247 --- .changeset/friendly-cows-explode.md | 5 +++++ packages/app/src/systems/Core/services/core.ts | 17 +++++++++++++---- packages/app/src/systems/Core/utils/opfs.ts | 7 +++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 .changeset/friendly-cows-explode.md diff --git a/.changeset/friendly-cows-explode.md b/.changeset/friendly-cows-explode.md new file mode 100644 index 000000000..b5677f9f0 --- /dev/null +++ b/.changeset/friendly-cows-explode.md @@ -0,0 +1,5 @@ +--- +"fuels-wallet": patch +--- + +fix: clean opfs when logging out diff --git a/packages/app/src/systems/Core/services/core.ts b/packages/app/src/systems/Core/services/core.ts index 7043bacb4..ef018d20a 100644 --- a/packages/app/src/systems/Core/services/core.ts +++ b/packages/app/src/systems/Core/services/core.ts @@ -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: 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) { @@ -21,6 +29,7 @@ export class CoreService { } setTimeout(() => reloadAfterCleanCompleted(), 50); }; + reloadAfterCleanCompleted(); } } diff --git a/packages/app/src/systems/Core/utils/opfs.ts b/packages/app/src/systems/Core/utils/opfs.ts index 8c73864fd..583f5481d 100644 --- a/packages/app/src/systems/Core/utils/opfs.ts +++ b/packages/app/src/systems/Core/utils/opfs.ts @@ -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'); +}