refactor active account and clean up

This commit is contained in:
Ren Amamiya
2023-03-31 16:06:40 +07:00
parent c7e2b9430a
commit 5b88b335a1
15 changed files with 101 additions and 490 deletions

View File

@@ -1,9 +1,12 @@
import { isSSR } from '@utils/ssr';
import { getActiveAccount } from '@utils/storage';
import { atomWithStorage, createJSONStorage } from 'jotai/utils';
import { atomWithCache } from 'jotai-cache';
const createMyJsonStorage = () => {
const storage = createJSONStorage(() => localStorage);
const getItem = (key) => {
const value = storage.getItem(key);
return value;
};
return { ...storage, getItem };
};
export const activeAccountAtom = atomWithCache(async () => {
const response = isSSR ? {} : await getActiveAccount();
return response;
});
export const activeAccountAtom = atomWithStorage('activeAccount', {}, createMyJsonStorage());