Skip to content

Commit

Permalink
Remove backup_leveldb.json
Browse files Browse the repository at this point in the history
  • Loading branch information
OKendigelyan committed Dec 19, 2024
1 parent a6a22ae commit 9b9a783
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
30 changes: 12 additions & 18 deletions apps/desktop/public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,24 @@ 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)) {
log.info("LevelDB database not found at path. Code:EM01", dbPath);
return;
}

const db = new Level(dbPath);
await db.open();

try {
const storage = {};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 () {
Expand Down
9 changes: 9 additions & 0 deletions packages/state/src/beacon/WalletClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

1 comment on commit 9b9a783

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.81% (1786/2131) 79.58% (850/1068) 78.27% (454/580)
apps/web Coverage: 83%
83.81% (1786/2131) 79.58% (850/1068) 78.27% (454/580)
packages/components Coverage: 97%
97.51% (196/201) 95.91% (94/98) 88.13% (52/59)
packages/core Coverage: 81%
82.47% (207/251) 72.72% (88/121) 81.35% (48/59)
packages/crypto Coverage: 100%
100% (43/43) 90.9% (10/11) 100% (7/7)
packages/data-polling Coverage: 97%
95.27% (141/148) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (36/36)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 82%
82.28% (822/999) 76.42% (188/246) 77.77% (301/387)
packages/tezos Coverage: 89%
88.72% (118/133) 94.59% (35/37) 86.84% (33/38)
packages/tzkt Coverage: 89%
87.32% (62/71) 87.5% (14/16) 80.48% (33/41)

Please sign in to comment.