Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
OKendigelyan committed Dec 31, 2024
1 parent 0f8b3d3 commit e584dc4
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 99 deletions.
2 changes: 1 addition & 1 deletion apps/desktop-e2e/cucumber.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config = {
failFast: true,
paths: ["src/features/*"],
require: ["src/**/*.ts"],
requireModule: ["ts-node/register/transpile-only", "tsconfig-paths/register"],
requireModule: ["ts-node/register"],
format: ["html:test-results/cucumber-report.html", "json:test-results/cucumber-report.json"],
},
};
Expand Down
3 changes: 1 addition & 2 deletions apps/desktop-e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"eslint": "^8.57.0",
"madge": "^8.0.0",
"prettier": "^3.4.2",
"rimraf": "^6.0.1",
"tsconfig-paths": "^4.2.0"
"rimraf": "^6.0.1"
},
"dependencies": {
"@cucumber/cucumber": "^11.1.1",
Expand Down
9 changes: 0 additions & 9 deletions apps/desktop-e2e/src/global.d.ts

This file was deleted.

10 changes: 3 additions & 7 deletions apps/desktop-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "@umami/typescript-config/tsconfig.json",
"compilerOptions": {
"target": "esnext",
"allowJs": true,
Expand All @@ -15,13 +14,10 @@
"noEmit": true,
"jsx": "react-jsx",
"customConditions": ["@umami/source"],
"preserveSymlinks": true,
"types": ["node", "jest"]
"preserveSymlinks": true
},
"ts-node": {
"esm": true,
"transpileOnly": true,
"files": true
"esm": true
},
"include": ["src", ".eslintrc.cjs", "cucumber.cjs", "src/global.d.ts"]
"include": ["src", ".eslintrc.cjs", "cucumber.cjs"]
}
20 changes: 5 additions & 15 deletions apps/desktop/public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const fs = require("fs");
const APP_PROTOCOL = "app";
const APP_HOST = "assets";

// backupData is used to store the backup data from the previous version of the app
let backupData;

const appURL = app.isPackaged
? url.format({
pathname: `${APP_HOST}/index.html`,
Expand Down Expand Up @@ -64,20 +61,19 @@ async function createBackupFromPrevDB() {
return;
}

// Copy the database to not lose original data
fs.cpSync(dbPath, dbBackupPath, { recursive: true });


if (fs.existsSync(backupPath)) {
log.info("Backup file already exists. Skipping migration.");
return;
}

// Copy the database to not lose original data
fs.cpSync(dbPath, dbBackupPath, { recursive: true });

const db = new Level(dbBackupPath);

// Retry logic for opening the database
const maxRetries = 3;
const retryDelay = 1000; // 1 second
const retryDelay = 1000;

const tryOpenDb = async retriesLeft => {
try {
Expand All @@ -88,7 +84,6 @@ async function createBackupFromPrevDB() {
} catch (error) {
if (retriesLeft <= 0) {
log.error("Failed to open DB after all retries", error);
await db.close();
throw error;
}

Expand All @@ -100,7 +95,6 @@ async function createBackupFromPrevDB() {

try {
await tryOpenDb(maxRetries);
log.info("DB is opened");

const storage = {};

Expand Down Expand Up @@ -169,9 +163,7 @@ async function createBackupFromPrevDB() {
"persist:root": extractKeys(storage["persist:root"]),
};

backupData = preparedStorage;

// Write storage object to JSON file
// Write preparedStorage to JSON file
try {
fs.writeFileSync(backupPath, JSON.stringify(preparedStorage, null, 2), "utf-8");
log.info("Backup successfully created at:", backupPath);
Expand Down Expand Up @@ -294,8 +286,6 @@ function createWindow() {
mainWindow.once("ready-to-show", () => {
mainWindow.show();

mainWindow.webContents.send("backupData", backupData);

if (deeplinkURL) {
mainWindow.webContents.send("deeplinkURL", deeplinkURL);
deeplinkURL = null;
Expand Down
6 changes: 2 additions & 4 deletions apps/desktop/public/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ contextBridge.exposeInMainWorld("electronAPI", {
// Notify UI if app update is available to be installed.
onAppUpdateDownloaded: callback => ipcRenderer.on("app-update-downloaded", callback),

// handle the backupData send in electron.js
onBackupData: callback => ipcRenderer.on("backupData", callback),
getBackupData: () => ipcRenderer.invoke("getBackupData"),

// Notify Electron that app update should be installed.
installAppUpdateAndQuit: () => ipcRenderer.send("install-app-update"),

clipboardWriteText: text => ipcRenderer.send("clipboard-write", text),
clipboardClear: () => ipcRenderer.send("clipboard-clear"),

getBackupData: () => ipcRenderer.invoke("getBackupData"),
});
28 changes: 9 additions & 19 deletions apps/desktop/src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import {
useResetBeaconConnections,
} from "@umami/state";
import { noop } from "lodash";
import { useEffect, useState } from "react";
import { useEffect } from "react";
import { HashRouter, Navigate, Route, Routes } from "react-router-dom";

import { AnnouncementBanner } from "./components/AnnouncementBanner";
import { Loader } from "./components/Loader/Loader";
import { SocialLoginWarningModal } from "./components/SocialLoginWarningModal/SocialLoginWarningModal";
import { BeaconProvider } from "./utils/beacon/BeaconProvider";
import { persistor } from "./utils/persistor";
Expand Down Expand Up @@ -87,27 +86,21 @@ const LoggedOutRouter = () => {
WalletClient.destroy().then(resetBeaconConnections).catch(noop);
}, [resetBeaconConnections]);

const [isDataLoading, setIsDataLoading] = useState(
() => !localStorage.getItem("migration_2_3_3_to_2_3_4_completed")
);

useEffect(() => {
if (localStorage.getItem("migration_2_3_3_to_2_3_4_completed")) {
return;
}

const getBackupData = async () => {
persistor.pause();

const backupData = await window.electronAPI.getBackupData();

if (!backupData) {
setIsDataLoading(false);
localStorage.setItem("migration_2_3_3_to_2_3_4_completed", "true");
persistor.persist();
return;
}

persistor.pause();

await persistor.flush();
localStorage.clear();

Expand All @@ -124,14 +117,11 @@ const LoggedOutRouter = () => {
}, []);

return (
<>
{isDataLoading && <Loader />}
<HashRouter>
<Routes>
<Route element={<Navigate to="/welcome" />} path="/*" />
<Route element={<WelcomeScreen />} path="/welcome" />
</Routes>
</HashRouter>
</>
<HashRouter>
<Routes>
<Route element={<Navigate to="/welcome" />} path="/*" />
<Route element={<WelcomeScreen />} path="/welcome" />
</Routes>
</HashRouter>
);
};
1 change: 0 additions & 1 deletion apps/desktop/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ declare global {
onDeeplink: (callback: (url: string) => void) => void;
onAppUpdateDownloaded: (callback: () => void) => void;
installAppUpdateAndQuit: () => void;
onBackupData: (fn: (event: any, data?: Record<string, string>) => void) => void;
getBackupData: () => Promise<Record<string, string> | undefined>;
};
}
Expand Down
9 changes: 0 additions & 9 deletions apps/web/src/global.d.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/components/src/global.d.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/data-polling/src/global.d.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/state/src/global.d.ts

This file was deleted.

12 changes: 12 additions & 0 deletions packages/state/src/slices/accounts/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ describe("accountsSlice", () => {
seedPhrases: {},
secretKeys: {},
password: "",
alerts: {
isSocialLoginWarningShown: false,
isExtensionsWarningShown: false,
},
});
});

Expand Down Expand Up @@ -57,6 +61,10 @@ describe("accountsSlice", () => {
seedPhrases: { mockPrint1: {}, mockPrint2: {} },
secretKeys: {},
password: "",
alerts: {
isSocialLoginWarningShown: false,
isExtensionsWarningShown: false,
},
});

store.dispatch(accountsActions.removeMnemonicAndAccounts({ fingerPrint: "mockPrint1" }));
Expand All @@ -66,6 +74,10 @@ describe("accountsSlice", () => {
seedPhrases: { mockPrint2: {} },
secretKeys: {},
password: "",
alerts: {
isSocialLoginWarningShown: false,
isExtensionsWarningShown: false,
},
});
});
});
Expand Down
5 changes: 0 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 comments on commit e584dc4

@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% (1787/2132) 79.58% (850/1068) 78.27% (454/580)
apps/web Coverage: 83%
83.81% (1787/2132) 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: 85%
84.39% (822/974) 81.03% (188/232) 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)

@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% (1787/2132) 79.58% (850/1068) 78.27% (454/580)
apps/web Coverage: 83%
83.81% (1787/2132) 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: 85%
84.39% (822/974) 81.03% (188/232) 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.