Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix footer market stats #1976

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/components/Footer/MarketStats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Markdown from '@shared/Markdown'
import content from '../../../../content/footer.json'
import { getTotalAllocatedAndLocked } from '@utils/veAllocation'
import PriceUnit from '@shared/Price/PriceUnit'
import Loader from '@components/@shared/atoms/Loader'

const initialTotal: StatsTotal = {
nfts: 0,
Expand All @@ -25,6 +26,14 @@ const initialTotal: StatsTotal = {
veLocked: 0
}

function LoaderArea() {
return (
<div className={styles.loaderWrap}>
<Loader />
</div>
)
}

export default function MarketStats(): ReactElement {
const { appConfig } = useMarketMetadata()
const { networksList } = useNetworkMetadata()
Expand All @@ -33,6 +42,7 @@ export default function MarketStats(): ReactElement {
[chainId: number]: FooterStatsValuesGlobalStatistics
}>()
const [total, setTotal] = useState(initialTotal)
const [loading, setLoading] = useState<boolean>(false)

//
// Set the main chain ids we want to display stats for
Expand Down Expand Up @@ -72,15 +82,16 @@ export default function MarketStats(): ReactElement {
LoggerInstance.error('Error fetching global stats: ', error.message)
}
}
setData(newData)
}, [mainChainIds])

async function addVeTotals(partialTotals: StatsTotal) {
const total: StatsTotal = { ...partialTotals }
const veTotals = await getTotalAllocatedAndLocked()
total.veAllocated = veTotals.totalAllocated
total.veLocked = veTotals.totalLocked
setTotal(total)

setData(newData)
}, [mainChainIds])

return total
}
//
// 1. Fetch Data
//
Expand All @@ -93,6 +104,7 @@ export default function MarketStats(): ReactElement {
//
useEffect(() => {
if (!data || !mainChainIds?.length) return
setLoading(true)
const newTotal: StatsTotal = total

for (const chainId of mainChainIds) {
Expand All @@ -108,11 +120,16 @@ export default function MarketStats(): ReactElement {
LoggerInstance.error('Error data manipulation: ', error.message)
}
}

setTotal(newTotal)
async function setTotalAllocatedAndLocked() {
setTotal(await addVeTotals(newTotal))
setLoading(false)
}
setTotalAllocatedAndLocked()
}, [data, mainChainIds])

return (
return loading ? (
<LoaderArea />
) : (
<div className={styles.stats}>
<div>
<MarketStatsTotal total={total} />{' '}
Expand Down
Loading