Skip to content

Commit

Permalink
Merge pull request #440 from dynamic-amm/ui_changes
Browse files Browse the repository at this point in the history
fix hero apr
  • Loading branch information
tien7668 committed Sep 16, 2021
2 parents d4dc148 + 2b0fcbd commit 40496fa
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/utils/dmm.ts
Expand Up @@ -29,7 +29,7 @@ import { useActiveWeb3React } from 'hooks'
import { Farm, Reward, RewardPerBlock } from 'state/farms/types'
import { useAllTokens } from 'hooks/Tokens'
import { useRewardTokens } from 'state/farms/hooks'
import { useETHPrice, useKNCPrice } from 'state/application/hooks'
import { useETHPrice, useKNCPrice, useTokensPrice } from 'state/application/hooks'
import { getFullDisplayBalance } from './formatBalance'

export function priceRangeCalc(price?: Price | Fraction, amp?: Fraction): [Fraction | undefined, Fraction | undefined] {
Expand Down Expand Up @@ -273,6 +273,16 @@ export function useFarmApr(
const { chainId } = useActiveWeb3React()
const ethPrice = useETHPrice()
const kncPrice = useKNCPrice()
const temp = [...rewardPerBlocks]
const tokenPrices = useTokensPrice(
temp
.map(item => item.token)
.filter(
token =>
token.address.toLowerCase() !== WETH[chainId as ChainId].address.toLowerCase() &&
token.address.toLowerCase() === KNC[chainId as ChainId].address.toLowerCase()
)
)

if (parseFloat(poolLiquidityUsd) === 0 || !isLiquidityMiningActive) {
return 0
Expand All @@ -297,14 +307,25 @@ export function useFarmApr(
parseFloat(rewardPerBlockAmount.toSignificant(6)) * BLOCKS_PER_YEAR[chainId as ChainId]
total += yearlyETHRewardAllocation * parseFloat(ethPrice.currentPrice)
}

if (kncPrice && rewardPerBlock.token.address.toLowerCase() === KNC[chainId as ChainId].address.toLowerCase()) {
const rewardPerBlockAmount = new TokenAmountDMM(rewardPerBlock.token, rewardPerBlock.amount.toString())
const yearlyKNCRewardAllocation =
parseFloat(rewardPerBlockAmount.toSignificant(6)) * BLOCKS_PER_YEAR[chainId as ChainId]
total += yearlyKNCRewardAllocation * parseFloat(kncPrice)
}

if (
chainId &&
rewardPerBlock.token.address.toLowerCase() !== WETH[chainId as ChainId].address.toLowerCase() &&
rewardPerBlock.token.address.toLowerCase() != KNC[chainId as ChainId].address.toLowerCase() &&
tokenPrices[0]
) {
const rewardPerBlockAmount = new TokenAmountDMM(rewardPerBlock.token, rewardPerBlock.amount.toString())
const yearlyKNCRewardAllocation =
parseFloat(rewardPerBlockAmount.toSignificant(6)) * BLOCKS_PER_YEAR[chainId as ChainId]
total += yearlyKNCRewardAllocation * tokenPrices[0]
}

return total
}, 0)

Expand Down

0 comments on commit 40496fa

Please sign in to comment.