Skip to content

Commit

Permalink
fix: Use query
Browse files Browse the repository at this point in the history
  • Loading branch information
memoyil committed Oct 17, 2024
1 parent 62117f5 commit d5dbc2a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions apps/web/src/state/farmsV4/state/farmPools/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ type UnwrapPromise<T> = T extends Promise<infer U> ? U : T
type ArrayItemType<T> = T extends Array<infer U> ? U : T

export const useFarmPools = () => {
const [loaded, setLoaded] = useState(false)
const [pools, setPools] = useAtom(farmPoolsAtom)

// useEffect(() => {
// if (!loaded) {
// fetchFarmPools()
// .then(setPools)
// .finally(() => setLoaded(true))
// }
// // only fetch once when mount
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, [])
const { isLoading } = useQuery({
queryKey: ['fetchFarmPools'],
queryFn: async () => {
const data = await fetchFarmPools()
setPools(data)
},
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
})

const { data: poolsStatus, pending: isPoolStatusPending } = useMultiChainV3PoolsStatus(UNIVERSAL_FARMS)
const { data: poolsTimeFrame, pending: isPoolsTimeFramePending } = useMultiChainPoolsTimeFrame(UNIVERSAL_FARMS)
Expand All @@ -60,7 +60,7 @@ export const useFarmPools = () => {
})
}, [pools, poolsStatus, isPoolStatusPending, poolsTimeFrame, isPoolsTimeFramePending])

return { loaded, data: poolsWithStatus }
return { loaded: !isLoading, data: poolsWithStatus }
}

export const useV3PoolsLength = (chainIds: number[]) => {
Expand Down

0 comments on commit d5dbc2a

Please sign in to comment.