diff --git a/src/api/farms.ts b/src/api/farms.ts
index 6802540d5..c4cf2ed10 100644
--- a/src/api/farms.ts
+++ b/src/api/farms.ts
@@ -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
@@ -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,
@@ -327,6 +330,7 @@ function getFarmApr(
rewardCurrency,
incentivizedAsset,
yieldFarmId: yieldFarm.id.toString(),
+ isDistributed,
}
}
diff --git a/src/sections/pools/farms/components/detailsCard/FarmDetailsCard.tsx b/src/sections/pools/farms/components/detailsCard/FarmDetailsCard.tsx
index f5ea30f91..c67873371 100644
--- a/src/sections/pools/farms/components/detailsCard/FarmDetailsCard.tsx
+++ b/src/sections/pools/farms/components/detailsCard/FarmDetailsCard.tsx
@@ -102,7 +102,7 @@ export const FarmDetailsCard = ({
- {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 })}
diff --git a/src/sections/pools/farms/components/globalFarm/GlobalFarmRowMulti.tsx b/src/sections/pools/farms/components/globalFarm/GlobalFarmRowMulti.tsx
index 4ab6be057..545f7e0e2 100644
--- a/src/sections/pools/farms/components/globalFarm/GlobalFarmRowMulti.tsx
+++ b/src/sections/pools/farms/components/globalFarm/GlobalFarmRowMulti.tsx
@@ -29,13 +29,16 @@ export const GlobalFarmRowMulti = ({
if (!farmAprs.data) return null
+ const { minApr, maxApr } = getMinAndMaxAPR(farmAprs)
+
return (
- {!!farmAprs.data && (
-
- {t(`value.multiAPR`, getMinAndMaxAPR(farmAprs))}
-
- )}
+
+ {maxApr.gt(0)
+ ? t(`value.multiAPR`, { minApr, maxApr })
+ : t(`value.percentage`, { value: maxApr })}
+
+
({
diff --git a/src/sections/pools/table/PoolsTable.utils.tsx b/src/sections/pools/table/PoolsTable.utils.tsx
index fe9717a6f..800778c3b 100644
--- a/src/sections/pools/table/PoolsTable.utils.tsx
+++ b/src/sections/pools/table/PoolsTable.utils.tsx
@@ -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"
@@ -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
@@ -241,10 +228,12 @@ const APYFarming = ({ farms, apy }: { farms: Farm[]; apy: number }) => {
return (
- {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) })}
)
diff --git a/src/sections/stats/sections/omnipoolAsset/stats/AssetStats.tsx b/src/sections/stats/sections/omnipoolAsset/stats/AssetStats.tsx
index 61ad234cb..6cc03cbc8 100644
--- a/src/sections/stats/sections/omnipoolAsset/stats/AssetStats.tsx
+++ b/src/sections/stats/sections/omnipoolAsset/stats/AssetStats.tsx
@@ -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"
@@ -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 (
diff --git a/src/sections/stats/sections/overview/components/OmnipoolAssetsTableWrapper/OmnipoolAssetsTableWrapper.utils.tsx b/src/sections/stats/sections/overview/components/OmnipoolAssetsTableWrapper/OmnipoolAssetsTableWrapper.utils.tsx
index 87d51f2d5..22a97caff 100644
--- a/src/sections/stats/sections/overview/components/OmnipoolAssetsTableWrapper/OmnipoolAssetsTableWrapper.utils.tsx
+++ b/src/sections/stats/sections/overview/components/OmnipoolAssetsTableWrapper/OmnipoolAssetsTableWrapper.utils.tsx
@@ -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"
@@ -27,27 +27,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 = 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
@@ -55,10 +42,14 @@ const APYFarming = ({ farms, apy }: { farms: Farm[]; apy: number }) => {
return (
- {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) })}
)
}