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'
|
|
|
|
import { FAVORITE_MARKETS_KEY } from 'utils/constants'
|
|
|
|
|
|
|
|
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,
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
|
|
|
|
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(
|
|
|
|
(marketName: string) => marketName === market.name
|
|
|
|
) ? (
|
|
|
|
<button
|
2023-04-19 17:43:33 -07:00
|
|
|
className="default-transition 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)}
|
|
|
|
>
|
|
|
|
<FilledStarIcon className="h-5 w-5" />
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
2023-04-19 17:43:33 -07:00
|
|
|
className="default-transition 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)}
|
|
|
|
>
|
|
|
|
<StarIcon className="h-5 w-5" />
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FavoriteMarketButton
|