Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sparkles star system to differentiate between different yield types #1110

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions lib/shared/components/icons/StarIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useTheme } from '@chakra-ui/react'
import { SVGProps } from 'react'

interface Props extends SVGProps<SVGSVGElement> {
gradFrom?: string
gradTo?: string
variant?: 'gradient' | 'solid'
id?: string
}

function StarIcon({
gradFrom = 'yellow',
gradTo = 'pink',
variant = 'gradient',
id,
...rest
}: Props) {
const theme = useTheme()
const gradientId = `stars-gradient-${gradFrom}-${gradTo}-${id}`

const startColor = theme.colors[gradTo] ? theme.colors[gradTo]['500'] : gradTo
const stopColor = theme.colors[gradFrom] ? theme.colors[gradFrom]['500'] : gradFrom
return (
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" {...rest}>
<defs>
<linearGradient
id={gradientId}
x1="24"
y1="-11.5"
x2="2.7273"
y2="16.3182"
gradientUnits="userSpaceOnUse"
>
<stop stopColor={startColor} />
<stop offset="1" stopColor={stopColor} />
</linearGradient>
</defs>
<path
fillRule="evenodd"
clipRule="evenodd"
// eslint-disable-next-line max-len
d="M11.888 8.974a4.726 4.726 0 0 0-2.913 2.914l-.885 2.548a.094.094 0 0 1-.18 0l-.885-2.548a4.726 4.726 0 0 0-2.913-2.914L1.563 8.09a.095.095 0 0 1 0-.178l2.549-.885a4.726 4.726 0 0 0 2.913-2.914l.885-2.548a.095.095 0 0 1 .18 0l.885 2.548a4.726 4.726 0 0 0 2.913 2.914l2.549.885a.095.095 0 0 1 0 .178l-2.549.885Z"
fill={variant === 'gradient' ? `url(#${gradientId})` : 'currentColor'}
/>
</svg>
)
}

export default StarIcon
59 changes: 50 additions & 9 deletions lib/shared/components/tooltips/apr-tooltip/MainAprTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PopoverContent,
Text,
TextProps,
useTheme,
useColorModeValue,
} from '@chakra-ui/react'
import BaseAprTooltip, { BaseAprTooltipProps } from './BaseAprTooltip'
import { Info } from 'react-feather'
Expand All @@ -18,6 +18,7 @@ import { FeaturedPool, Pool } from '@/lib/modules/pool/PoolProvider'
import { isLBP } from '@/lib/modules/pool/pool.helpers'
import { getProjectConfig } from '@/lib/config/getProjectConfig'
import { GqlPoolAprItemType } from '@/lib/shared/services/api/generated/graphql'
import StarIcon from '../../icons/StarIcon'

interface Props
extends Omit<
Expand All @@ -42,31 +43,71 @@ export const SparklesIcon = ({
pool: Pool | PoolListItem | FeaturedPool
id?: string
}) => {
const theme = useTheme()
const { corePoolId } = getProjectConfig()
const hoverColor = isLBP(pool.type) ? 'inherit' : 'font.highlight'

const hasRewardApr =
pool.dynamicData.aprItems.filter(item => item.type !== GqlPoolAprItemType.SwapFee).length > 0
pool.dynamicData.aprItems.filter(item =>
[GqlPoolAprItemType.Staking, GqlPoolAprItemType.VebalEmissions].includes(item.type)
).length > 0

let gradFromColor = theme.colors.sparkles.default.from
let gradToColor = theme.colors.sparkles.default.to
const hasOnlySwapApr =
pool.dynamicData.aprItems.filter(item => item.type === GqlPoolAprItemType.SwapFee).length ===
pool.dynamicData.aprItems.length

const defaultGradFrom = useColorModeValue(
'#91A1B6', // light from
'#A0AEC0' // dark from
)
const defaultGradTo = useColorModeValue(
'#BCCCE1', // light to
'#E9EEF5' // dark to
)

const corePoolGradFrom = useColorModeValue(
'#BFA672', // light from
'#AE8C56' // dark from
)
const corePoolGradTo = useColorModeValue(
'#D9C47F', // light to
'#F4EAD2' // dark to
)

const rewardsGradFrom = useColorModeValue(
'#F49A55', // light from
'#F49175' // dark from
)
const rewardsGradTo = useColorModeValue(
'#FCD45B', // light to
'#FFCC33' // dark to
)

let gradFromColor = defaultGradFrom
let gradToColor = defaultGradTo

if (pool.id === corePoolId) {
gradFromColor = theme.colors.sparkles.corePool.from
gradToColor = theme.colors.sparkles.corePool.to
gradFromColor = corePoolGradFrom
gradToColor = corePoolGradTo
}

if (hasRewardApr) {
gradFromColor = theme.colors.sparkles.rewards.from
gradToColor = theme.colors.sparkles.rewards.to
gradFromColor = rewardsGradFrom
gradToColor = rewardsGradTo
}

return (
<Box w="16px" h="auto" minW="16px">
<Center w="16px">
{isLBP(pool.type) ? (
<Icon as={Info} boxSize={4} color={isOpen ? hoverColor : 'gray.400'} />
) : hasOnlySwapApr ? (
<Icon
as={StarIcon}
boxSize={4}
gradFrom={isOpen ? 'green' : defaultGradFrom}
gradTo={isOpen ? 'green' : defaultGradTo}
id={id || ''}
/>
) : (
<Icon
as={StarsIcon}
Expand Down
Loading