diff --git a/apps/desktop/public/electron.js b/apps/desktop/public/electron.js index 54f0de58e..0474bf20f 100644 --- a/apps/desktop/public/electron.js +++ b/apps/desktop/public/electron.js @@ -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); diff --git a/apps/desktop/src/Router.tsx b/apps/desktop/src/Router.tsx index 72d9d64d4..9d388623e 100644 --- a/apps/desktop/src/Router.tsx +++ b/apps/desktop/src/Router.tsx @@ -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 { @@ -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"; @@ -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 ( - - - } path="/*" /> - } path="/welcome" /> - - + <> + {isDataLoading && ( + + + + )} + + + } path="/*" /> + } path="/welcome" /> + + + ); }; diff --git a/packages/state/src/beacon/WalletClient.ts b/packages/state/src/beacon/WalletClient.ts index bc9484e62..39b5a3461 100644 --- a/packages/state/src/beacon/WalletClient.ts +++ b/packages/state/src/beacon/WalletClient.ts @@ -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 }); diff --git a/packages/state/src/hooks/backup.ts b/packages/state/src/hooks/backup.ts index 4b451d668..5f99acb78 100644 --- a/packages/state/src/hooks/backup.ts +++ b/packages/state/src/hooks/backup.ts @@ -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"]); diff --git a/packages/state/src/reducer.ts b/packages/state/src/reducer.ts index 8d3ea611f..7c7bf4768 100644 --- a/packages/state/src/reducer.ts +++ b/packages/state/src/reducer.ts @@ -104,7 +104,6 @@ export const makeReducer = (storage_: Storage | undefined) => { version: VERSION, storage, blacklist: ["accounts"], - getStoredState: customGetStoredState, migrate: createAsyncMigrate(mainStoreMigrations, { debug: false }), }; @@ -112,7 +111,6 @@ export const makeReducer = (storage_: Storage | undefined) => { key: "accounts", version: VERSION, storage, - getStoredState: customGetStoredState, migrate: createAsyncMigrate(accountsMigrations, { debug: false }), blacklist: ["password"], };