diff --git a/src/components/molecules/Bookmarks.tsx b/src/components/molecules/Bookmarks.tsx index 66a0282cb..9fbeff3f3 100644 --- a/src/components/molecules/Bookmarks.tsx +++ b/src/components/molecules/Bookmarks.tsx @@ -85,15 +85,13 @@ export default function Bookmarks(): ReactElement { const [pinned, setPinned] = useState() const [isLoading, setIsLoading] = useState() - const networkName = (config as ConfigHelperConfig)?.network - useEffect(() => { - if (!appConfig.metadataCacheUri || !networkName || bookmarks === {}) return + if (!appConfig.metadataCacheUri || bookmarks === []) return const source = axios.CancelToken.source() async function init() { - if (!bookmarks[networkName]?.length) { + if (!bookmarks?.length) { setPinned([]) return } @@ -102,7 +100,7 @@ export default function Bookmarks(): ReactElement { try { const resultPinned = await getAssetsBookmarked( - bookmarks[networkName], + bookmarks, appConfig.metadataCacheUri, source.token ) @@ -118,7 +116,7 @@ export default function Bookmarks(): ReactElement { return () => { source.cancel() } - }, [bookmarks, appConfig.metadataCacheUri, networkName]) + }, [bookmarks, appConfig.metadataCacheUri]) return ( }
- {/* */} + {isInPurgatory ? (

Bookmarks

- {/* */} + {queryAndDids && ( diff --git a/src/providers/UserPreferences.tsx b/src/providers/UserPreferences.tsx index 614319cf8..b83e31ed2 100644 --- a/src/providers/UserPreferences.tsx +++ b/src/providers/UserPreferences.tsx @@ -15,9 +15,7 @@ interface UserPreferencesValue { currency: string locale: string chainIds: number[] - bookmarks: { - [network: string]: string[] - } + bookmarks: string[] setChainIds: (chainIds: number[]) => void setDebug: (value: boolean) => void setCurrency: (value: string) => void @@ -56,7 +54,7 @@ function UserPreferencesProvider({ localStorage?.currency || 'EUR' ) const [locale, setLocale] = useState() - const [bookmarks, setBookmarks] = useState(localStorage?.bookmarks || {}) + const [bookmarks, setBookmarks] = useState(localStorage?.bookmarks || []) const [chainIds, setChainIds] = useState( localStorage?.chainIds || appConfig.chainIds ) @@ -79,28 +77,25 @@ function UserPreferencesProvider({ setLocale(window.navigator.language) }, []) - // function addBookmark(didToAdd: string): void { - // const newPinned = { - // ...bookmarks, - // [networkName]: [didToAdd].concat(bookmarks[networkName]) - // } - // setBookmarks(newPinned) - // } + function addBookmark(didToAdd: string): void { + const newPinned = [...bookmarks, didToAdd] + setBookmarks(newPinned) + } - // function removeBookmark(didToAdd: string): void { - // const newPinned = { - // ...bookmarks, - // [networkName]: bookmarks[networkName].filter( - // (did: string) => did !== didToAdd - // ) - // } - // setBookmarks(newPinned) - // } + function removeBookmark(didToAdd: string): void { + const newPinned = bookmarks.filter((did: string) => did !== didToAdd) + setBookmarks(newPinned) + } // Bookmarks old data structure migration useEffect(() => { - if (!bookmarks.length) return - const newPinned = { mainnet: bookmarks as any } + if (bookmarks.length !== undefined) return + const newPinned: string[] = [] + for (const network in bookmarks) { + ;(bookmarks[network] as unknown as string[]).forEach((did: string) => { + did !== null && newPinned.push(did) + }) + } setBookmarks(newPinned) }, [bookmarks]) @@ -115,9 +110,9 @@ function UserPreferencesProvider({ bookmarks, setChainIds, setDebug, - setCurrency - // addBookmark, - // removeBookmark + setCurrency, + addBookmark, + removeBookmark } as UserPreferencesValue } >