mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Fix footer market stats (#1976)
* fix footer market stats * add loader component
This commit is contained in:
parent
031f6eb8f1
commit
1514e785f2
@ -16,6 +16,7 @@ import Markdown from '@shared/Markdown'
|
|||||||
import content from '../../../../content/footer.json'
|
import content from '../../../../content/footer.json'
|
||||||
import { getTotalAllocatedAndLocked } from '@utils/veAllocation'
|
import { getTotalAllocatedAndLocked } from '@utils/veAllocation'
|
||||||
import PriceUnit from '@shared/Price/PriceUnit'
|
import PriceUnit from '@shared/Price/PriceUnit'
|
||||||
|
import Loader from '@components/@shared/atoms/Loader'
|
||||||
|
|
||||||
const initialTotal: StatsTotal = {
|
const initialTotal: StatsTotal = {
|
||||||
nfts: 0,
|
nfts: 0,
|
||||||
@ -25,6 +26,14 @@ const initialTotal: StatsTotal = {
|
|||||||
veLocked: 0
|
veLocked: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function LoaderArea() {
|
||||||
|
return (
|
||||||
|
<div className={styles.loaderWrap}>
|
||||||
|
<Loader />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default function MarketStats(): ReactElement {
|
export default function MarketStats(): ReactElement {
|
||||||
const { appConfig } = useMarketMetadata()
|
const { appConfig } = useMarketMetadata()
|
||||||
const { networksList } = useNetworkMetadata()
|
const { networksList } = useNetworkMetadata()
|
||||||
@ -33,6 +42,7 @@ export default function MarketStats(): ReactElement {
|
|||||||
[chainId: number]: FooterStatsValuesGlobalStatistics
|
[chainId: number]: FooterStatsValuesGlobalStatistics
|
||||||
}>()
|
}>()
|
||||||
const [total, setTotal] = useState(initialTotal)
|
const [total, setTotal] = useState(initialTotal)
|
||||||
|
const [loading, setLoading] = useState<boolean>(false)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set the main chain ids we want to display stats for
|
// Set the main chain ids we want to display stats for
|
||||||
@ -72,15 +82,16 @@ export default function MarketStats(): ReactElement {
|
|||||||
LoggerInstance.error('Error fetching global stats: ', error.message)
|
LoggerInstance.error('Error fetching global stats: ', error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const veTotals = await getTotalAllocatedAndLocked()
|
|
||||||
total.veAllocated = veTotals.totalAllocated
|
|
||||||
total.veLocked = veTotals.totalLocked
|
|
||||||
setTotal(total)
|
|
||||||
|
|
||||||
setData(newData)
|
setData(newData)
|
||||||
}, [mainChainIds])
|
}, [mainChainIds])
|
||||||
|
|
||||||
|
async function addVeTotals(partialTotals: StatsTotal) {
|
||||||
|
const total: StatsTotal = { ...partialTotals }
|
||||||
|
const veTotals = await getTotalAllocatedAndLocked()
|
||||||
|
total.veAllocated = veTotals.totalAllocated
|
||||||
|
total.veLocked = veTotals.totalLocked
|
||||||
|
return total
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// 1. Fetch Data
|
// 1. Fetch Data
|
||||||
//
|
//
|
||||||
@ -93,6 +104,7 @@ export default function MarketStats(): ReactElement {
|
|||||||
//
|
//
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!data || !mainChainIds?.length) return
|
if (!data || !mainChainIds?.length) return
|
||||||
|
setLoading(true)
|
||||||
const newTotal: StatsTotal = total
|
const newTotal: StatsTotal = total
|
||||||
|
|
||||||
for (const chainId of mainChainIds) {
|
for (const chainId of mainChainIds) {
|
||||||
@ -108,11 +120,16 @@ export default function MarketStats(): ReactElement {
|
|||||||
LoggerInstance.error('Error data manipulation: ', error.message)
|
LoggerInstance.error('Error data manipulation: ', error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async function setTotalAllocatedAndLocked() {
|
||||||
setTotal(newTotal)
|
setTotal(await addVeTotals(newTotal))
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
setTotalAllocatedAndLocked()
|
||||||
}, [data, mainChainIds])
|
}, [data, mainChainIds])
|
||||||
|
|
||||||
return (
|
return loading ? (
|
||||||
|
<LoaderArea />
|
||||||
|
) : (
|
||||||
<div className={styles.stats}>
|
<div className={styles.stats}>
|
||||||
<div>
|
<div>
|
||||||
<MarketStatsTotal total={total} />{' '}
|
<MarketStatsTotal total={total} />{' '}
|
||||||
|
Loading…
Reference in New Issue
Block a user