Skip to content

Commit

Permalink
remove promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
SidharthK2 committed Sep 16, 2024
1 parent cbd6382 commit d0fbaed
Showing 1 changed file with 78 additions and 18 deletions.
96 changes: 78 additions & 18 deletions src/utils/use-stats-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,89 @@ export function useStatsData() {

useEffect(() => {
const fetchData = async () => {
const [holders, volume, iq, lp, social, ep] = await Promise.all([
getTokenHolders(),
getVolume(),
getIQ(),
getLPs(),
getSocialData(),
getEpData(),
])

const newData = { ...holders, ...volume, ...iq, ...lp, ...social, ...ep }

setData(newData)

setTotals({
holders: getMappedValue(holders.holders),
volume: getMappedValue(volume.volume),
})
const newData: Dict = {}

const fetchHolders = async () => {
try {
const holders = await getTokenHolders()
newData.holders = holders.holders
setData((prevData) => ({ ...prevData, ...newData }))
setTotals((prevTotals) => ({
...prevTotals,
holders: getMappedValue(holders.holders),
}))
} catch (error) {
console.error('Error fetching holders:', error)
}
}

const fetchVolume = async () => {
try {
const volume = await getVolume()
newData.volume = volume.volume
setData((prevData) => ({ ...prevData, ...newData }))
setTotals((prevTotals) => ({
...prevTotals,
volume: getMappedValue(volume.volume),
}))
} catch (error) {
console.error('Error fetching volume:', error)
}
}

const fetchIQ = async () => {
try {
const iq = await getIQ()
newData.Iq = iq.Iq
setData((prevData) => ({ ...prevData, ...newData }))
} catch (error) {
console.error('Error fetching IQ data:', error)
}
}

const fetchLPs = async () => {
try {
const lp = await getLPs()
newData.lp = lp.lp
setData((prevData) => ({ ...prevData, ...newData }))
} catch (error) {
console.error('Error fetching LP data:', error)
}
}

const fetchSocial = async () => {
try {
const social = await getSocialData()
newData.social = social.social
setData((prevData) => ({ ...prevData, ...newData }))
} catch (error) {
console.error('Error fetching social data:', error)
}
}

const fetchEp = async () => {
try {
const ep = await getEpData()
newData.ep = ep.ep
setData((prevData) => ({ ...prevData, ...newData }))
} catch (error) {
console.error('Error fetching EP data:', error)
}
}

fetchHolders()
fetchVolume()
fetchIQ()
fetchLPs()
fetchSocial()
fetchEp()
}

if (!isFetched.current) {
isFetched.current = true
fetchData()
}
}, [data, totals])
}, [])

return { data, totals }
}

0 comments on commit d0fbaed

Please sign in to comment.