Skip to content

Commit

Permalink
Merge pull request #1080 from galacticcouncil/display-zero-apr
Browse files Browse the repository at this point in the history
Display zero farm apr
  • Loading branch information
vkulinich-cl authored Mar 7, 2024
2 parents 8f1c6ac + abd3617 commit 64e7a66
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 70 deletions.
12 changes: 8 additions & 4 deletions src/api/farms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ function getFarmApr(
apr = poolYieldPerPeriod.times(periodsPerYear)
}

// multiply by 100 since APR should be a percentage
apr = apr.times(100)

const minApr = loyaltyFactor ? apr.times(loyaltyFactor) : null
// max distribution of rewards
// https://www.notion.so/Screen-elements-mapping-Farms-baee6acc456542ca8d2cccd1cc1548ae?p=4a2f16a9f2454095945dbd9ce0eb1b6b&pm=s
const distributedRewards = globalFarm.pendingRewards
Expand Down Expand Up @@ -314,6 +310,13 @@ function getFarmApr(
.times(100)
.times(priceAdjustment.shiftedBy(-18))

const isDistributed = distributedRewards.gte(maxRewards)

// multiply by 100 since APR should be a percentage
apr = isDistributed ? BN_0 : apr.times(100)

const minApr = loyaltyFactor ? apr.times(loyaltyFactor) : null

return {
apr,
minApr,
Expand All @@ -327,6 +330,7 @@ function getFarmApr(
rewardCurrency,
incentivizedAsset,
yieldFarmId: yieldFarm.id.toString(),
isDistributed,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const FarmDetailsCard = ({
</Text>
</div>
<Text fs={19} lh={28} fw={400} font="FontOver">
{apr.data.minApr
{apr.data.minApr && apr.data?.apr.gt(0)
? t("value.APR.range", { from: apr.data.minApr, to: apr.data?.apr })
: t("value.APR", { apr: apr.data?.apr })}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ export const GlobalFarmRowMulti = ({

if (!farmAprs.data) return null

const { minApr, maxApr } = getMinAndMaxAPR(farmAprs)

return (
<div sx={{ flex: "row", gap: 4, align: "center" }} className={className}>
{!!farmAprs.data && (
<Text fs={fontSize} color="brightBlue200">
{t(`value.multiAPR`, getMinAndMaxAPR(farmAprs))}
</Text>
)}
<Text fs={fontSize} color="brightBlue200">
{maxApr.gt(0)
? t(`value.multiAPR`, { minApr, maxApr })
: t(`value.percentage`, { value: maxApr })}
</Text>

<MultipleIcons
size={iconSize}
icons={farmAprs.data.map((farm) => ({
Expand Down
29 changes: 9 additions & 20 deletions src/sections/pools/table/PoolsTable.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useRpcProvider } from "providers/rpcProvider"
import { MultipleIcons } from "components/MultipleIcons/MultipleIcons"
import { AssetLogo } from "components/AssetIcon/AssetIcon"
import { TPool, TXYKPool, isXYKPoolType } from "sections/pools/PoolsPage.utils"
import { Farm, useFarmAprs, useFarms } from "api/farms"
import { Farm, getMinAndMaxAPR, useFarmAprs, useFarms } from "api/farms"
import { GlobalFarmRowMulti } from "sections/pools/farms/components/globalFarm/GlobalFarmRowMulti"
import { Button, ButtonTransparent } from "components/Button/Button"
import ChevronRightIcon from "assets/icons/ChevronRight.svg?react"
Expand Down Expand Up @@ -212,27 +212,14 @@ const APYFarming = ({ farms, apy }: { farms: Farm[]; apy: number }) => {

const percentage = useMemo(() => {
if (farmAprs.data?.length) {
const aprs = farmAprs.data
? farmAprs.data.reduce((memo, { apr }) => memo.plus(apr), BN_0)
: BN_0
const minAprs = farmAprs.data
? farmAprs.data.map(({ minApr, apr }) => (minApr ? minApr : apr))
: [BN_0]

const minApr = BN.minimum(...minAprs)
const maxApr = aprs

return {
minApr,
maxApr,
}
return getMinAndMaxAPR(farmAprs)
}

return {
minApr: BN_0,
maxApr: BN_0,
}
}, [farmAprs.data])
}, [farmAprs])

const isLoading = farmAprs.isInitialLoading

Expand All @@ -241,10 +228,12 @@ const APYFarming = ({ farms, apy }: { farms: Farm[]; apy: number }) => {
return (
<NonClickableContainer>
<Text color="white" fs={14}>
{t("value.percentage.range", {
from: percentage.minApr.lt(apy) ? percentage.minApr : BN(apy),
to: percentage.maxApr.plus(apy),
})}
{percentage.maxApr.gt(0)
? t("value.percentage.range", {
from: percentage.minApr.lt(apy) ? percentage.minApr : BN(apy),
to: percentage.maxApr.plus(apy),
})
: t("value.percentage", { value: BN(apy) })}
</Text>
</NonClickableContainer>
)
Expand Down
31 changes: 11 additions & 20 deletions src/sections/stats/sections/omnipoolAsset/stats/AssetStats.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTranslation } from "react-i18next"
import { AssetStatsCard } from "./AssetStatsCard"
import BN from "bignumber.js"
import { Farm, useFarmAprs, useFarms } from "api/farms"
import { Farm, getMinAndMaxAPR, useFarmAprs, useFarms } from "api/farms"
import { useMemo } from "react"
import { BN_0 } from "utils/constants"
import { useRpcProvider } from "providers/rpcProvider"
Expand All @@ -12,35 +12,26 @@ const APYFarmStatsCard = ({ farms, apy }: { farms: Farm[]; apy: number }) => {

const percentage = useMemo(() => {
if (farmAprs.data?.length) {
const aprs = farmAprs.data
? farmAprs.data.reduce((memo, { apr }) => memo.plus(apr), BN_0)
: BN_0
const minAprs = farmAprs.data
? farmAprs.data.map(({ minApr, apr }) => (minApr ? minApr : apr))
: [BN_0]

const minApr = BN.minimum(...minAprs)
const maxApr = aprs

return {
minApr,
maxApr,
}
return getMinAndMaxAPR(farmAprs)
}

return {
minApr: BN_0,
maxApr: BN_0,
}
}, [farmAprs.data])
}, [farmAprs])

return (
<AssetStatsCard
title={t("stats.omnipool.stats.card.apyWithFarm")}
value={t("value.percentage.range", {
from: percentage.minApr.lt(apy) ? percentage.minApr : BN(apy),
to: percentage.maxApr.plus(apy),
})}
value={
percentage.maxApr.gt(0)
? t("value.percentage.range", {
from: percentage.minApr.lt(apy) ? percentage.minApr : BN(apy),
to: percentage.maxApr.plus(apy),
})
: t("value.percentage", { value: BN(apy) })
}
loading={farmAprs.isInitialLoading}
tooltip={t("stats.overview.table.assets.header.apy.desc")}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { OmnipoolAssetsTableColumn } from "sections/stats/components/OmnipoolAss
import { useMedia } from "react-use"
import { MultipleIcons } from "components/MultipleIcons/MultipleIcons"
import { CellSkeleton } from "components/Skeleton/CellSkeleton"
import { Farm, useFarmAprs, useFarms } from "api/farms"
import { Farm, getMinAndMaxAPR, useFarmAprs, useFarms } from "api/farms"
import { useMemo } from "react"
import { BN_0 } from "utils/constants"
import BigNumber from "bignumber.js"
Expand All @@ -27,38 +27,29 @@ const APYFarming = ({ farms, apy }: { farms: Farm[]; apy: number }) => {

const percentage = useMemo(() => {
if (farmAprs.data?.length) {
const aprs = farmAprs.data
? farmAprs.data.reduce((memo, { apr }) => memo.plus(apr), BN_0)
: BN_0
const minAprs = farmAprs.data
? farmAprs.data.map(({ minApr, apr }) => (minApr ? minApr : apr))
: [BN_0]

const minApr = BigNumber.minimum(...minAprs)
const maxApr = aprs

return {
minApr,
maxApr,
}
return getMinAndMaxAPR(farmAprs)
}

return {
minApr: BN_0,
maxApr: BN_0,
}
}, [farmAprs.data])
}, [farmAprs])

const isLoading = farmAprs.isInitialLoading

if (isLoading) return <CellSkeleton />

return (
<Text color="white" fs={14}>
{t("value.percentage.range", {
from: percentage.minApr.lt(apy) ? percentage.minApr : BigNumber(apy),
to: percentage.maxApr.plus(apy),
})}
{percentage.maxApr.gt(0)
? t("value.percentage.range", {
from: percentage.minApr.lt(apy)
? percentage.minApr
: BigNumber(apy),
to: percentage.maxApr.plus(apy),
})
: t("value.percentage", { value: BigNumber(apy) })}
</Text>
)
}
Expand Down

0 comments on commit 64e7a66

Please sign in to comment.