Skip to content

Commit

Permalink
test: moved logic to Router.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
OKendigelyan committed Dec 20, 2024
1 parent 52465f6 commit cc03870
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
4 changes: 3 additions & 1 deletion apps/desktop/public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ function createWindow() {
mainWindow.once("ready-to-show", () => {
mainWindow.show();

mainWindow.webContents.send("backupData", backupData);
if (backupData) {
mainWindow.webContents.send("backupData", backupData);
}

if (deeplinkURL) {
mainWindow.webContents.send("deeplinkURL", deeplinkURL);
Expand Down
64 changes: 57 additions & 7 deletions apps/desktop/src/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* istanbul ignore file */
import { Flex, Spinner } from "@chakra-ui/react";
import { DynamicModalContext, useDynamicModal } from "@umami/components";
import { useDataPolling } from "@umami/data-polling";
import {
Expand All @@ -8,12 +9,13 @@ import {
useResetBeaconConnections,
} from "@umami/state";
import { noop } from "lodash";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { HashRouter, Navigate, Route, Routes } from "react-router-dom";

import { AnnouncementBanner } from "./components/AnnouncementBanner";
import { SocialLoginWarningModal } from "./components/SocialLoginWarningModal/SocialLoginWarningModal";
import { BeaconProvider } from "./utils/beacon/BeaconProvider";
import { persistor } from "./utils/persistor";
import { useDeeplinkHandler } from "./utils/useDeeplinkHandler";
import { AddressBookView } from "./views/addressBook/AddressBookView";
import { BatchPage } from "./views/batch/BatchPage";
Expand Down Expand Up @@ -83,12 +85,60 @@ const LoggedOutRouter = () => {
WalletClient.destroy().then(resetBeaconConnections).catch(noop);
}, [resetBeaconConnections]);

const [isDataLoading] = 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;
}

persistor.pause();

if (window.electronAPI) {
window.electronAPI.onBackupData((_, data) => {
console.log("1. Received backup data:", data);

if (data) {
setTimeout(() => {
localStorage.clear();

localStorage.setItem("migration_2_3_3_to_2_3_4_completed", "true");
localStorage.setItem("persist:accounts", JSON.stringify(data["persist:accounts"]));
localStorage.setItem("persist:root", JSON.stringify(data["persist:root"]));

window.location.reload();
}, 3000);
}
});
}
}, []);

return (
<HashRouter>
<Routes>
<Route element={<Navigate to="/welcome" />} path="/*" />
<Route element={<WelcomeScreen />} path="/welcome" />
</Routes>
</HashRouter>
<>
{isDataLoading && (
<Flex
position="absolute"
zIndex="9999"
top="0"
left="0"
alignItems="center"
justifyContent="center"
width="full"
height="100vh"
backdropFilter="blur(10px)"
backgroundColor="rgba(0, 0, 0, 0.2)"
>
<Spinner />
</Flex>
)}
<HashRouter>
<Routes>
<Route element={<Navigate to="/welcome" />} path="/*" />
<Route element={<WelcomeScreen />} path="/welcome" />
</Routes>
</HashRouter>
</>
);
};
6 changes: 6 additions & 0 deletions packages/state/src/beacon/WalletClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export const logout = (persistor: Persistor) =>
.catch(() => {})
.finally(() => {
persistor.pause();
const migrationCompleted = localStorage.getItem("migration_2_3_3_to_2_3_4_completed");

localStorage.clear(); // TODO: fix for react-native

if (migrationCompleted) {
localStorage.setItem("migration_2_3_3_to_2_3_4_completed", "true");
}

window.location.replace("/"); // TODO: fix for react-native
});
7 changes: 7 additions & 0 deletions packages/state/src/hooks/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,15 @@ export const restoreV2BackupFile = async (
}

persistor.pause();

const migrationCompleted = localStorage.getItem("migration_2_3_3_to_2_3_4_completed");

localStorage.clear();

if (migrationCompleted) {
localStorage.setItem("migration_2_3_3_to_2_3_4_completed", "true");
}

localStorage.setItem("persist:accounts", accountsInString);
localStorage.setItem("persist:root", backup["persist:root"]);

Expand Down
2 changes: 0 additions & 2 deletions packages/state/src/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,13 @@ export const makeReducer = (storage_: Storage | undefined) => {
version: VERSION,
storage,
blacklist: ["accounts"],
getStoredState: customGetStoredState,
migrate: createAsyncMigrate(mainStoreMigrations, { debug: false }),
};

const accountsPersistConfig = {
key: "accounts",
version: VERSION,
storage,
getStoredState: customGetStoredState,
migrate: createAsyncMigrate(accountsMigrations, { debug: false }),
blacklist: ["password"],
};
Expand Down

0 comments on commit cc03870

Please sign in to comment.