Skip to content

Commit

Permalink
Merge pull request #142 from valory-xyz/tanya/clear-persistent-store
Browse files Browse the repository at this point in the history
Clear store state when new account is created
  • Loading branch information
Tanya-atatakai authored May 27, 2024
2 parents 7c150c0 + bb54aad commit 549d4c8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
1 change: 1 addition & 0 deletions electron/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
6 changes: 6 additions & 0 deletions frontend/components/Setup/SetupWelcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -22,6 +23,7 @@ import { FormFlex } from '../styled/FormFlex';
const { Title } = Typography;

export const SetupWelcome = () => {
const electronApi = useElectronApi();
const [isSetup, setIsSetup] = useState<AccountIsSetup>(
AccountIsSetup.Loading,
);
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions frontend/context/ElectronApiProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ElectronApiContextProps = {
get?: (key: string) => Promise<unknown>;
set?: (key: string, value: unknown) => Promise<void>;
delete?: (key: string) => Promise<void>;
clear?: () => Promise<void>;
};
setAppHeight?: (height: unknown) => void;
notifyAgentRunning?: () => void;
Expand All @@ -40,6 +41,7 @@ export const ElectronApiContext = createContext<ElectronApiContextProps>({
get: async () => {},
set: async () => {},
delete: async () => {},
clear: async () => {},
},
setAppHeight: () => {},
});
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 549d4c8

Please sign in to comment.