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

Column header not updated on new epoch #159

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
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
99 changes: 52 additions & 47 deletions src/components/AssetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { tooltipOptions, tooltipsText } from '../metadata/tootltips'

import { usePredictoorsContext } from '@/contexts/PredictoorsContext'
import { useSocketContext } from '@/contexts/SocketContext'
import LiveTime from '@/elements/LiveTime'
import { TableRowWrapper } from '@/elements/TableRowWrapper'
import Tooltip from '@/elements/Tooltip'
Expand Down Expand Up @@ -42,7 +41,7 @@ export type TAssetTableState = {
export const AssetTable: React.FC<TAssetTableProps> = ({ contracts }) => {
const { subscribedPredictoors, currentEpoch, secondsPerEpoch } =
usePredictoorsContext()
const { epochData } = useSocketContext()
const [tableColumns, setTableColumns] = useState<any>(assetTableColumns)
const [assetsData, setAssetsData] = useState<TAssetTableState['AssetsData']>(
[]
)
Expand Down Expand Up @@ -111,68 +110,74 @@ export const AssetTable: React.FC<TAssetTableProps> = ({ contracts }) => {

useEffect(() => {
if (!currentEpoch) return
assetTableColumns[1].Header = formatTime(
let newAssetTableColumns = JSON.parse(JSON.stringify(assetTableColumns))
newAssetTableColumns[1].Header = formatTime(
new Date((currentEpoch - secondsPerEpoch) * 1000)
)
assetTableColumns[2].Header = formatTime(new Date(currentEpoch * 1000))
assetTableColumns[3].Header = <LiveTime />
assetTableColumns[4].Header = (
newAssetTableColumns[2].Header = formatTime(new Date(currentEpoch * 1000))
newAssetTableColumns[3].Header = <LiveTime />
newAssetTableColumns[4].Header = (
<div className={styles.predictionHeader}>
<span>
{formatTime(new Date((currentEpoch + secondsPerEpoch) * 1000))}
</span>
<span className={styles.predictionText}>Predictions</span>
</div>
)
assetTableColumns[5].Header = (
newAssetTableColumns[5].Header = (
<div>
Accuracy
<span className={styles.greyText}>{` 24h`}</span>
</div>
)
setTableColumns(newAssetTableColumns)
}, [currentEpoch])

return (
<table className={styles.table}>
<thead>
<TableRowWrapper
className={styles.tableRow}
cellProps={{
className: styles.tableHeaderCell
}}
cellType="th"
>
{assetTableColumns.map((item) => (
<div
className={styles.assetHeaderContainer}
id={item.accessor}
key={`assetHeader${item.accessor}`}
>
<span>{item.Header}</span>
<Tooltip
selector={item.accessor}
text={tooltipsText[item.Header as keyof typeof tooltipOptions]}
tableColumns && (
<table className={styles.table}>
<thead>
<TableRowWrapper
className={styles.tableRow}
cellProps={{
className: styles.tableHeaderCell
}}
cellType="th"
>
{tableColumns.map((item: any) => (
<div
className={styles.assetHeaderContainer}
id={item.accessor}
key={`assetHeader${item.accessor}`}
>
<span>{item.Header}</span>
<Tooltip
selector={item.accessor}
text={
tooltipsText[item.Header as keyof typeof tooltipOptions]
}
/>
</div>
))}
</TableRowWrapper>
</thead>
{assetsData.length > 0 ? (
<tbody>
{assetsData.map((item) => (
<AssetRow
key={`assetRow${item.contract.address}`}
assetData={item}
/>
</div>
))}
</TableRowWrapper>
</thead>
{assetsData.length > 0 ? (
<tbody>
{assetsData.map((item) => (
<AssetRow
key={`assetRow${item.contract.address}`}
assetData={item}
/>
))}
</tbody>
) : (
<tbody className={styles.message}>
<tr>
<td>No contracts found</td>
</tr>
</tbody>
)}
</table>
))}
</tbody>
) : (
<tbody className={styles.message}>
<tr>
<td>No contracts found</td>
</tr>
</tbody>
)}
</table>
)
)
}
Loading