From 5b1c78dfd847bab5c5c7389ac8b810d443c9697e Mon Sep 17 00:00:00 2001 From: Quentin Burg Date: Tue, 9 Apr 2024 09:30:23 +0200 Subject: [PATCH] :recycle: manage one entry on localstorage per user --- context/state.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/context/state.ts b/context/state.ts index 70edc26..c0616a5 100644 --- a/context/state.ts +++ b/context/state.ts @@ -151,9 +151,8 @@ type action = }; const saveState = (state: tezosState) => { - const storage = JSON.parse(localStorage.getItem("app_state")!); localStorage.setItem( - "app_state", + `app_state:${state.address}`, JSON.stringify({ contracts: state.contracts, aliases: state.aliases, @@ -296,8 +295,13 @@ function reducer(state: tezosState, action: action): tezosState { }; } case "login": { + const rawStorage = window!.localStorage.getItem( + `app_state:${action.address}` + )!; + const storage: storage = JSON.parse(rawStorage); return { ...state, + ...storage, balance: action.balance, accountInfo: action.accountInfo, address: action.address, @@ -369,14 +373,9 @@ function reducer(state: tezosState, action: action): tezosState { } } function init(): tezosState { - let rawStorage = window!.localStorage.getItem("app_state")!; - let storage: storage = JSON.parse(rawStorage); - - return { - ...emptyState(), - ...storage, - }; + return emptyState(); } + let AppStateContext: Context = createContext(null); let AppDispatchContext: Context | null> =