@@ -6,41 +6,43 @@ import { useBookmarks } from '~/hooks/useBookmarks'
66
77interface IBookmarkProps {
88 readableName : string
9+ configID ?: string
910 isChain ?: boolean
1011 [ key : string ] : any
1112}
1213
13- export function Bookmark ( { readableName, isChain, ...props } : IBookmarkProps ) {
14+ export function Bookmark ( { readableName, configID , isChain, ...props } : IBookmarkProps ) {
1415 const router = useRouter ( )
1516
16- const watchlistType = isChain ? 'chains' : router . pathname . includes ( '/yields' ) ? 'yields' : 'defi'
17+ const isYieldsPage = router . pathname . includes ( '/yields' )
18+ const urlPath = isYieldsPage ? '/yields/watchlist' : '/watchlist'
19+
20+ const watchlistType = isChain ? 'chains' : isYieldsPage ? 'yields' : 'defi'
21+ const watchlistNameKey = isYieldsPage ? configID : readableName
1722
1823 const { savedProtocols, addProtocol, removeProtocol } = useBookmarks ( watchlistType )
1924
20- const isSaved : boolean = savedProtocols . has ( readableName )
25+ const isSaved : boolean = savedProtocols . has ( watchlistNameKey )
26+
27+ const showToast = ( action : 'Added' | 'Removed' ) => {
28+ toast . success (
29+ < span >
30+ { action } { readableName } { action === 'Added' ? 'to' : 'from' } { ' ' }
31+ < Link href = { urlPath } className = "font-medium underline" >
32+ watchlist
33+ </ Link >
34+ </ span >
35+ )
36+ }
2137
2238 const onClick = isSaved
2339 ? ( ) => {
24- removeProtocol ( readableName )
25- toast . success (
26- < span >
27- Removed { readableName } from{ ' ' }
28- < Link href = "/watchlist" className = "font-medium underline" >
29- watchlist
30- </ Link >
31- </ span >
32- )
40+ removeProtocol ( watchlistNameKey )
41+ showToast ( 'Removed' )
3342 }
3443 : ( ) => {
35- addProtocol ( readableName )
36- toast . success (
37- < span >
38- Added { readableName } to{ ' ' }
39- < Link href = "/watchlist" className = "font-medium underline" >
40- watchlist
41- </ Link >
42- </ span >
43- )
44+ addProtocol ( watchlistNameKey )
45+ showToast ( 'Added' )
4446 }
4547
4648 return (
0 commit comments