From e3ec395b35b8fcff9a6423bb118f14c9649ddcd8 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 2 Jun 2023 14:11:57 -0300 Subject: [PATCH] memory key should be string --- .../src/hooks/useOfficer.ts | 4 ++-- .../web-util/src/hooks/useMemoryStorage.ts | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/exchange-backoffice-ui/src/hooks/useOfficer.ts b/packages/exchange-backoffice-ui/src/hooks/useOfficer.ts index 2ed375846..4ec43569b 100644 --- a/packages/exchange-backoffice-ui/src/hooks/useOfficer.ts +++ b/packages/exchange-backoffice-ui/src/hooks/useOfficer.ts @@ -49,10 +49,10 @@ interface OfficerReady { } const OFFICER_KEY = buildStorageKey("officer", codecForOfficer()); -const ACCOUNT_KEY = buildStorageKey("account"); +const ACCOUNT_KEY = "account"; export function useOfficer(): OfficerState { - const accountStorage = useMemoryStorage(ACCOUNT_KEY); + const accountStorage = useMemoryStorage(ACCOUNT_KEY); const officerStorage = useLocalStorage(OFFICER_KEY); const officer = officerStorage.value; diff --git a/packages/web-util/src/hooks/useMemoryStorage.ts b/packages/web-util/src/hooks/useMemoryStorage.ts index d8be24c1e..1dd263797 100644 --- a/packages/web-util/src/hooks/useMemoryStorage.ts +++ b/packages/web-util/src/hooks/useMemoryStorage.ts @@ -27,37 +27,37 @@ const storage: ObservableMap = memoryMap(); //with initial value export function useMemoryStorage( - key: StorageKey, + key: string, defaultValue: Type, ): Required>; //with initial value export function useMemoryStorage( - key: StorageKey, + key: string, ): StorageState; // impl export function useMemoryStorage( - key: StorageKey, + key: string, defaultValue?: Type, ): StorageState { const [storedValue, setStoredValue] = useState( (): Type | undefined => { - const prev = storage.get(key.id); - return prev; + const prev = storage.get(key); + return prev === undefined ? defaultValue : prev; }, ); useEffect(() => { - return storage.onUpdate(key.id, () => { - const newValue = storage.get(key.id); - setStoredValue(newValue); + return storage.onUpdate(key, () => { + const newValue = storage.get(key); + setStoredValue(newValue === undefined ? defaultValue : newValue); }); }, []); const setValue = (value?: Type): void => { if (value === undefined) { - storage.delete(key.id); + storage.delete(key); } else { - storage.set(key.id, value); + storage.set(key, value); } };