Skip to content

Commit

Permalink
perf: Call update cake apr once instead of per farm when initial load
Browse files Browse the repository at this point in the history
  • Loading branch information
memoyil committed Oct 3, 2024
1 parent 7684d26 commit 9adfdaf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
1 change: 0 additions & 1 deletion apps/web/src/state/farmsV4/state/poolApr/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ const getV3PoolsCakeAprByChainId = async (pools: V3PoolInfo[], chainId: number,
const [totalAllocPoint, latestPeriodCakePerSecond] = await Promise.all([
masterChefV3Cache ? masterChefV3Cache.totalAllocPoint : masterChefV3.read.totalAllocPoint(),
masterChefV3Cache ? masterChefV3Cache.latestPeriodCakePerSecond : masterChefV3.read.latestPeriodCakePerSecond(),
getCakePriceFromOracle(),
])

const poolInfoCalls = validPools.map(
Expand Down
7 changes: 3 additions & 4 deletions apps/web/src/state/farmsV4/state/poolApr/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ export const usePoolAprUpdater = () => {
const fetchCakeApr = useCallback(
async (newPools: PoolInfo[]) => {
if (newPools && newPools.length) {
newPools.forEach((pool) => {
getCakeApr(pool).then((apr) => {
updateCakeApr(apr)
})
const aprPromises = newPools.map((pool) => getCakeApr(pool))
Promise.all(aprPromises).then((aprList) => {
updateCakeApr(aprList.reduce((acc, apr) => Object.assign(acc, apr), {} as CakeApr))
})
}
},
Expand Down

0 comments on commit 9adfdaf

Please sign in to comment.