Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1043 from balancer/refactor/bal-apr-item
Browse files Browse the repository at this point in the history
refactor: bal reward apr item
  • Loading branch information
alter-eggo authored Sep 3, 2024
2 parents f496df5 + a7b299c commit 72233d4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/modules/pool/pool.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function getTotalApr(
return
}

if (item.type === GqlPoolAprItemType.Staking) {
if (item.type === GqlPoolAprItemType.VebalEmissions) {
minTotal = bn(item.apr).plus(minTotal)
maxTotal = bn(item.apr).plus(maxTotal)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { PoolListItem } from '@/lib/modules/pool/pool.types'
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'

interface Props
extends Omit<
Expand Down Expand Up @@ -45,7 +46,8 @@ export const SparklesIcon = ({
const { corePoolId } = getProjectConfig()
const hoverColor = isLBP(pool.type) ? 'inherit' : 'font.highlight'

const hasRewardApr = pool.dynamicData.aprItems.some(item => item.title === 'BAL reward APR')
const hasRewardApr =
pool.dynamicData.aprItems.filter(item => item.type !== GqlPoolAprItemType.SwapFee).length > 0

let gradFromColor = theme.colors.sparkles.default.from
let gradToColor = theme.colors.sparkles.default.to
Expand Down
14 changes: 6 additions & 8 deletions lib/shared/hooks/useAprTooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const TOTAL_BASE_APR_TYPES = [
GqlPoolAprItemType.Staking,
GqlPoolAprItemType.Merkl,
GqlPoolAprItemType.Surplus,
GqlPoolAprItemType.VebalEmissions,
]

// Types that must be added to the total APR
Expand Down Expand Up @@ -82,7 +83,7 @@ export function useAprTooltip({
})

const yieldBearingTokensDisplayed = yieldBearingTokens.map(item => ({
title: item.title.replace(' APR', ''),
title: item.rewardTokenSymbol || '',
apr: numberFormatter(item.apr.toString()),
}))

Expand All @@ -93,11 +94,11 @@ export function useAprTooltip({

// Staking incentives
const stakingIncentives = aprItems.filter(item => {
return item.type === GqlPoolAprItemType.Staking && item.title.indexOf('BAL reward') === -1
return item.type === GqlPoolAprItemType.Staking
})

const stakingIncentivesDisplayed = stakingIncentives.map(item => ({
title: item.title.replace(' reward APR', ''),
title: item.rewardTokenSymbol || '',
apr: numberFormatter(item.apr.toString()),
tooltipText: stakingTokenTooltipText,
}))
Expand All @@ -119,10 +120,7 @@ export function useAprTooltip({
const surplusIncentivesAprDisplayed = calculateSingleIncentivesAprDisplayed(surplusIncentives)

// Bal Reward
const balReward = aprItems.find(
// TO-DO refactor this so not to rely on the title
item => item.type === GqlPoolAprItemType.Staking && item.title === 'BAL reward APR'
)
const balReward = aprItems.find(item => item.type === GqlPoolAprItemType.VebalEmissions)

const maxVeBal = hasVeBalBoost ? absMaxApr(aprItems, vebalBoost) : bn(0)
const maxVeBalDisplayed = numberFormatter(maxVeBal.toString())
Expand All @@ -139,7 +137,7 @@ export function useAprTooltip({

if (balReward) {
stakingIncentivesDisplayed.push({
title: 'BAL',
title: balReward.rewardTokenSymbol || '',
apr: numberFormatter(balReward.apr.toString()),
tooltipText: stakingBalTooltipText,
})
Expand Down
2 changes: 2 additions & 0 deletions lib/shared/services/api/pool.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ query GetPool($id: String!, $chain: GqlChain!, $userAddress: String) {
title
apr
type
rewardTokenSymbol
rewardTokenAddress
}
}
allTokens {
Expand Down
4 changes: 4 additions & 0 deletions lib/shared/services/api/pools.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ query GetPools(
title
apr
type
rewardTokenSymbol
rewardTokenAddress
}
}
staking {
Expand Down Expand Up @@ -136,6 +138,8 @@ query GetFeaturedPools($chains: [GqlChain!]!) {
title
apr
type
rewardTokenSymbol
rewardTokenAddress
}
}
displayTokens {
Expand Down

0 comments on commit 72233d4

Please sign in to comment.