2022-11-29 20:01:55 -08:00
|
|
|
import { StarIcon } from '@heroicons/react/24/outline'
|
|
|
|
import { StarIcon as FilledStarIcon } from '@heroicons/react/20/solid'
|
|
|
|
import { PerpMarket, Serum3Market } from '@blockworks-foundation/mango-v4'
|
|
|
|
import useLocalStorageState from 'hooks/useLocalStorageState'
|
2023-08-17 12:33:15 -07:00
|
|
|
import { DEFAULT_FAVORITE_MKTS, FAVORITE_MARKETS_KEY } from 'utils/constants'
|
2022-11-29 20:01:55 -08:00
|
|
|
|
|
|
|
const FavoriteMarketButton = ({
|
|
|
|
market,
|
|
|
|
}: {
|
|
|
|
market: PerpMarket | Serum3Market
|
|
|
|
}) => {
|
2023-02-25 16:22:39 -08:00
|
|
|
const [favoriteMarkets, setFavoriteMarkets] = useLocalStorageState<string[]>(
|
2022-11-29 20:01:55 -08:00
|
|
|
FAVORITE_MARKETS_KEY,
|
2023-08-17 12:33:15 -07:00
|
|
|
DEFAULT_FAVORITE_MKTS,
|
2022-11-29 20:01:55 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
const addToFavorites = (marketName: string) => {
|
2023-02-25 16:22:39 -08:00
|
|
|
const newFavorites = [...favoriteMarkets, marketName]
|
2022-11-29 20:01:55 -08:00
|
|
|
setFavoriteMarkets(newFavorites)
|
|
|
|
}
|
|
|
|
|
|
|
|
const removeFromFavorites = (marketName: string) => {
|
|
|
|
setFavoriteMarkets(favoriteMarkets.filter((m: string) => m !== marketName))
|
|
|
|
}
|
|
|
|
|
|
|
|
return favoriteMarkets.find(
|
2023-07-21 11:47:53 -07:00
|
|
|
(marketName: string) => marketName === market.name,
|
2022-11-29 20:01:55 -08:00
|
|
|
) ? (
|
|
|
|
<button
|
2023-04-19 18:12:45 -07:00
|
|
|
className="flex items-center justify-center text-th-active focus-visible:text-th-fgd-4 md:hover:text-th-fgd-3"
|
2022-11-29 20:01:55 -08:00
|
|
|
onClick={() => removeFromFavorites(market.name)}
|
|
|
|
>
|
2023-06-18 22:39:18 -07:00
|
|
|
<FilledStarIcon className="h-4 w-4" />
|
2022-11-29 20:01:55 -08:00
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
2023-04-19 18:12:45 -07:00
|
|
|
className="flex items-center justify-center text-th-fgd-4 focus-visible:text-th-active md:hover:text-th-active"
|
2022-11-29 20:01:55 -08:00
|
|
|
onClick={() => addToFavorites(market.name)}
|
|
|
|
>
|
2023-06-18 22:39:18 -07:00
|
|
|
<StarIcon className="h-4 w-4" />
|
2022-11-29 20:01:55 -08:00
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FavoriteMarketButton
|