diff --git a/electron/preload.js b/electron/preload.js index 82d88e44..8431dbe3 100644 --- a/electron/preload.js +++ b/electron/preload.js @@ -15,6 +15,7 @@ contextBridge.exposeInMainWorld('electronAPI', { get: (key) => ipcRenderer.invoke('store-get', key), set: (key, value) => ipcRenderer.invoke('store-set', key, value), delete: (key) => ipcRenderer.invoke('store-delete', key), + clear: () => ipcRenderer.invoke('store-clear'), }, setAppHeight: (height) => ipcRenderer.send('set-height', height), showNotification: (title, description) => diff --git a/electron/store.js b/electron/store.js index a9a5867c..91cde5be 100644 --- a/electron/store.js +++ b/electron/store.js @@ -32,6 +32,7 @@ const setupStoreIpc = async (ipcChannel, mainWindow) => { ipcChannel.handle('store-get', (_, key) => store.get(key)); ipcChannel.handle('store-set', (_, key, value) => store.set(key, value)); ipcChannel.handle('store-delete', (_, key) => store.delete(key)); + ipcChannel.handle('store-clear', (_) => store.clear()); }; module.exports = { setupStoreIpc }; diff --git a/frontend/components/Setup/SetupWelcome.tsx b/frontend/components/Setup/SetupWelcome.tsx index 92c4b5dd..cf78db14 100644 --- a/frontend/components/Setup/SetupWelcome.tsx +++ b/frontend/components/Setup/SetupWelcome.tsx @@ -14,6 +14,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; import { AccountIsSetup } from '@/client'; import { PageState, SetupScreen } from '@/enums'; import { usePageState, useSetup } from '@/hooks'; +import { useElectronApi } from '@/hooks/useElectronApi'; import { useWallet } from '@/hooks/useWallet'; import { AccountService } from '@/service/Account'; @@ -22,6 +23,7 @@ import { FormFlex } from '../styled/FormFlex'; const { Title } = Typography; export const SetupWelcome = () => { + const electronApi = useElectronApi(); const [isSetup, setIsSetup] = useState( AccountIsSetup.Loading, ); @@ -32,8 +34,12 @@ export const SetupWelcome = () => { switch (res.is_setup) { case true: setIsSetup(AccountIsSetup.True); + break; case false: + // Reset persistent state + // if creating new account + electronApi.store?.clear?.(); setIsSetup(AccountIsSetup.False); break; default: diff --git a/frontend/context/ElectronApiProvider.tsx b/frontend/context/ElectronApiProvider.tsx index 6710b843..81b12ff7 100644 --- a/frontend/context/ElectronApiProvider.tsx +++ b/frontend/context/ElectronApiProvider.tsx @@ -20,6 +20,7 @@ type ElectronApiContextProps = { get?: (key: string) => Promise; set?: (key: string, value: unknown) => Promise; delete?: (key: string) => Promise; + clear?: () => Promise; }; setAppHeight?: (height: unknown) => void; notifyAgentRunning?: () => void; @@ -40,6 +41,7 @@ export const ElectronApiContext = createContext({ get: async () => {}, set: async () => {}, delete: async () => {}, + clear: async () => {}, }, setAppHeight: () => {}, }); @@ -74,6 +76,7 @@ export const ElectronApiProvider = ({ children }: PropsWithChildren) => { get: getElectronApiFunction('store.get'), set: getElectronApiFunction('store.set'), delete: getElectronApiFunction('store.delete'), + clear: getElectronApiFunction('store.clear'), }, setAppHeight: getElectronApiFunction('setAppHeight'), showNotification: getElectronApiFunction('showNotification'),