From 9b9a7833e626a7ff55604c66ea1c09704e7cc372 Mon Sep 17 00:00:00 2001 From: Oleg Chendighelean Date: Thu, 19 Dec 2024 12:29:01 +0000 Subject: [PATCH] Remove backup_leveldb.json --- apps/desktop/public/electron.js | 30 +++++++++-------------- packages/state/src/beacon/WalletClient.ts | 9 +++++++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/apps/desktop/public/electron.js b/apps/desktop/public/electron.js index c0a31fe444..63d8cc5a2e 100644 --- a/apps/desktop/public/electron.js +++ b/apps/desktop/public/electron.js @@ -38,13 +38,17 @@ log.transports.file.resolvePathFn = () => path.join(app.getPath("userData"), "um async function createBackupFromPrevDB() { const dbPath = path.normalize(path.join(app.getPath("userData"), "Local Storage", "leveldb")); - const backupPath = path.normalize( - path.join(app.getPath("userData"), "Local Storage", "backup_leveldb.json") + + const db = new Level(dbPath); + await db.open(); + + const isMigrationCompleted = await db.get( + "_app://assets\x00\x01migration_2_3_3_to_2_3_4_completed" ); - if (fs.existsSync(backupPath)) { - console.log("Backup file already exists. Skipping migration."); - return; + if (isMigrationCompleted) { + log.info("Migration already completed. Skipping migration."); + return await db.close(); } if (!fs.existsSync(dbPath)) { @@ -52,9 +56,6 @@ async function createBackupFromPrevDB() { return; } - const db = new Level(dbPath); - await db.open(); - try { const storage = {}; @@ -119,14 +120,6 @@ async function createBackupFromPrevDB() { }; backupData = preparedStorage; - - // Write storage object to JSON file - try { - fs.writeFileSync(backupPath, JSON.stringify(preparedStorage, null, 2), "utf-8"); - log.info("Backup successfully created at:", backupPath); - } catch (err) { - log.error("Error during LevelDB backup creation. Code:EM2.", err); - } } catch (err) { log.error("Error during key migration. Code:EM4.", err); } finally { @@ -342,10 +335,11 @@ function start() { // Execute createBackupFromPrevDB at the beginning try { await createBackupFromPrevDB(); - createWindow(); } catch (error) { - log.error("Error has occured while initialising the app", error); + log.error("Error has occured while migrating the app", error); } + + createWindow(); }); app.on("activate", function () { diff --git a/packages/state/src/beacon/WalletClient.ts b/packages/state/src/beacon/WalletClient.ts index 6e6bd9b339..4eea2cd6eb 100644 --- a/packages/state/src/beacon/WalletClient.ts +++ b/packages/state/src/beacon/WalletClient.ts @@ -15,7 +15,16 @@ export const logout = (persistor: Persistor) => WalletClient.destroy() .catch(() => {}) .finally(() => { + // check if migration from desktop v2.3.3 to v2.3.4 is completed + // TODO: remove this once all users have upgraded to v2.3.4 + const isMigrationCompleted = localStorage.getItem("migration_2_3_3_to_2_3_4_completed"); + persistor.pause(); localStorage.clear(); // TODO: fix for react-native + + if (isMigrationCompleted) { + localStorage.setItem("migration_2_3_3_to_2_3_4_completed", "true"); + } + window.location.replace("/"); // TODO: fix for react-native });