Skip to content

Commit

Permalink
Merge pull request #1558 from oasisprotocol/mz/syncSignedBlocks
Browse files Browse the repository at this point in the history
Sync signed blocks with incoming API changes
  • Loading branch information
buberdds authored Oct 25, 2024
2 parents 32d134e + 9e13075 commit 6a11ce0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
1 change: 1 addition & 0 deletions .changelog/1558.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sync signed blocks with incoming API changes
62 changes: 40 additions & 22 deletions src/app/pages/ValidatorDetailsPage/SignedBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import { useTranslation } from 'react-i18next'
import Card from '@mui/material/Card'
import CardHeader from '@mui/material/CardHeader'
import CardContent from '@mui/material/CardContent'
import Skeleton from '@mui/material/Skeleton'
import Typography from '@mui/material/Typography'
import { COLORS } from 'styles/theme/colors'
import { BlockStats } from '../../components/BlockStats'
import { ValidatorSignedBlock } from '../../../oasis-nexus/api'

export const SignedBlocks: FC = () => {
type SignedBlocksProps = {
isLoading: boolean
isFetched: boolean
signedBlocks: ValidatorSignedBlock[] | undefined
}

export const SignedBlocks: FC<SignedBlocksProps> = ({ isLoading, isFetched, signedBlocks }) => {
const { t } = useTranslation()
// TODO: provide data from the API and sync dataKey value
const data: any[] = []
const dataKey = ''

return (
<Card sx={{ flex: 1 }}>
Expand All @@ -22,26 +27,39 @@ export const SignedBlocks: FC = () => {
sx={{ paddingBottom: 0 }}
/>
<CardContent>
{data && data.length > 0 && (
<>
<Typography
sx={{
fontSize: '18px',
color: COLORS.grayMedium,
paddingBottom: 4,
}}
>
{t('validator.signedBlocksDescription')}
</Typography>
<BlockStats
data={data}
dataKey={dataKey}
legendLabels={{ success: t('validator.signed'), fail: t('validator.missed') }}
tooltipFormatter={value => t('validator.blockWithHeight', { height: value })}
/>
</>
{isLoading && <Skeleton variant="rectangular" sx={{ height: 240 }} />}
{isFetched && signedBlocks && signedBlocks.length > 0 && (
<SignedBlocksContent signedBlocks={signedBlocks} />
)}
</CardContent>
</Card>
)
}

type SignedBlocksContentProps = {
signedBlocks: ValidatorSignedBlock[]
}

export const SignedBlocksContent: FC<SignedBlocksContentProps> = ({ signedBlocks }) => {
const { t } = useTranslation()

return (
<>
<Typography
sx={{
fontSize: '18px',
color: COLORS.grayMedium,
paddingBottom: 4,
}}
>
{t('validator.signedBlocksDescription')}
</Typography>
<BlockStats
data={signedBlocks}
dataKey="height"
legendLabels={{ success: t('validator.signed'), fail: t('validator.missed') }}
tooltipFormatter={value => t('validator.blockWithHeight', { height: value })}
/>
</>
)
}
4 changes: 2 additions & 2 deletions src/app/pages/ValidatorDetailsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const ValidatorDetailsPage: FC = () => {
const scope = useRequiredScopeParam()
const { address } = useLoaderData() as AddressLoaderData
const validatorQuery = useGetConsensusValidatorsAddress(scope.network, address)
const { isLoading, data } = validatorQuery
const { isLoading, isFetched, data } = validatorQuery
const validator = data?.data.validators[0]
const stats = data?.data.stats
const transactionsLink = useHref('')
Expand All @@ -62,7 +62,7 @@ export const ValidatorDetailsPage: FC = () => {
<StakingTrend address={address} scope={scope} />
</StyledGrid>
<StyledGrid item xs={12} md={6}>
<SignedBlocks />
<SignedBlocks isLoading={isLoading} isFetched={isFetched} signedBlocks={validator?.signed_blocks} />
</StyledGrid>
</Grid>
<ProposedBlocks scope={scope} validator={validator} />
Expand Down
13 changes: 13 additions & 0 deletions src/oasis-nexus/generated/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a11ce0

Please sign in to comment.