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 latest blocks #128

Merged
merged 1 commit into from
Sep 9, 2024
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
46 changes: 13 additions & 33 deletions src/components/Stats/LatestBlocks.tsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,30 @@
import { Button, Stack } from '@chakra-ui/react'
import { Flex } from '@chakra-ui/react'
import { keepPreviousData } from '@tanstack/react-query'
import { Trans } from 'react-i18next'
import { generatePath, Link as RouterLink } from 'react-router-dom'
import { BlockCard } from '~components/Blocks/BlockCard'
import { ContentError } from '~components/Layout/ContentError'
import { LoadingCards } from '~components/Layout/Loading'
import { RoutePath } from '~constants'
import { PaginatedAsyncList } from '~components/Layout/AsyncList'
import { useBlockList } from '~queries/blocks'
import { useChainInfo } from '~queries/stats'

export const LatestBlocks = () => {
const blockListSize = 3

const { data: stats, isLoading: isLoadingStats } = useChainInfo()
const {
data: blocks,
isLoading: isLoadingBlocks,
error,
isError,
} = useBlockList({
const { data, isLoading, error, isError } = useBlockList({
params: {
page: 0,
limit: blockListSize,
},
enabled: !!stats?.height,
placeholderData: keepPreviousData,
})

const isLoading = isLoadingStats || isLoadingBlocks

if (isLoading || !stats || !stats?.height || !blocks) {
return <LoadingCards length={blockListSize} />
}

if (isError) {
return <ContentError error={error} />
}

return (
<Stack spacing={4}>
{blocks.blocks.map((block, i) => (
<BlockCard key={i} block={block} compact />
))}
<Button as={RouterLink} to={generatePath(RoutePath.BlocksList)} bgColor='accent1' color={'white'}>
<Trans i18nKey='stats.view_all_blocks'>View all blocks</Trans>
</Button>
</Stack>
<Flex direction={'column'} gap={7}>
<PaginatedAsyncList
isLoading={isLoading}
elements={data?.blocks}
isError={isError}
error={error}
component={({ element }) => <BlockCard block={element} />}
skeletonProps={{ length: blockListSize }}
/>
</Flex>
)
}
Loading