Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
feat: validators uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-calavera authored and sunnygleason committed Jul 22, 2019
1 parent d81c464 commit f6202ce
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
19 changes: 10 additions & 9 deletions src/v2/components/TourDeSol/Table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ import {observer} from 'mobx-react-lite';
import {Link} from 'react-router-dom';
import {map} from 'lodash/fp';
import NodesStore from 'v2/stores/nodes';
import HelpLink from '../../HelpLink';
import getUptime from 'v2/utils/getUptime';

import HelpLink from '../../HelpLink';
import useStyles from './styles';

const ValidatorsTable = ({separate}: {separate: boolean}) => {
const classes = useStyles();
const theme = useTheme();
const showTable = useMediaQuery(theme.breakpoints.up('md'));
const {
cluster: {voting = []},
} = NodesStore;
const {validators} = NodesStore;

const renderRow = row => {
const uptime = getUptime(row);
return (
<TableRow hover key={row.nodePubkey}>
<TableCell>1</TableCell>
Expand All @@ -43,11 +43,12 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
</Link>
</TableCell>
<TableCell>{row.stake}</TableCell>
<TableCell>TODO</TableCell>
<TableCell>{uptime}%</TableCell>
</TableRow>
);
};
const renderCard = card => {
const uptime = getUptime(card);
return (
<div
className={cn(classes.card, separate && classes.cardVertical)}
Expand All @@ -64,7 +65,7 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
</Grid>
<Grid item xs={4} zeroMinWidth>
<div className={classes.cardTitle}>Uptime</div>
<div>TODO</div>
<div>{uptime}%</div>
</Grid>
</Grid>
</div>
Expand All @@ -77,7 +78,7 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
Active Validators
<HelpLink text="" term="" />
</Typography>
<Typography variant="h5">{voting.length}</Typography>
<Typography variant="h5">{validators.length}</Typography>
{!separate && (
<Link to="/rc/validators/all" className={classes.link}>
See all &gt;
Expand All @@ -99,12 +100,12 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
root: classes.body,
}}
>
{map(renderRow)(voting)}
{map(renderRow)(validators)}
</TableBody>
</Table>
) : (
<div className={cn(classes.list, separate && classes.vertical)}>
{map(renderCard)(voting)}
{map(renderCard)(validators)}
</div>
)}
</div>
Expand Down
21 changes: 14 additions & 7 deletions src/v2/components/Validators/Table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import {observer} from 'mobx-react-lite';
import {Link} from 'react-router-dom';
import {map} from 'lodash/fp';
import NodesStore from 'v2/stores/nodes';
import getUptime from 'v2/utils/getUptime';

import useStyles from './styles';

const ValidatorsTable = ({separate}: {separate: boolean}) => {
const classes = useStyles();
const theme = useTheme();
const showTable = useMediaQuery(theme.breakpoints.up('md'));
const {
cluster: {voting = []},
} = NodesStore;
const {validators} = NodesStore;
const renderRow = row => {
const uptime = getUptime(row);
return (
<TableRow hover key={row.nodePubkey}>
<TableCell align="center">
Expand All @@ -41,10 +41,12 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
</TableCell>
<TableCell>{row.stake} Lamports</TableCell>
<TableCell>{row.commission}</TableCell>
<TableCell>{uptime}%</TableCell>
</TableRow>
);
};
const renderCard = card => {
const uptime = getUptime(card);
return (
<div
className={cn(classes.card, separate && classes.cardVertical)}
Expand All @@ -54,7 +56,7 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
<span />
<div>{card.nodePubkey}</div>
</Link>
<Grid container>
<Grid container spacing={1}>
<Grid item xs={4} zeroMinWidth>
<div className={classes.cardTitle}>Stake</div>
<div>{card.stake} Lamports</div>
Expand All @@ -63,6 +65,10 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
<div className={classes.cardTitle}>Commission</div>
<div>{card.commission}</div>
</Grid>
<Grid item xs={4} zeroMinWidth>
<div className={classes.cardTitle}>Uptime</div>
<div>{uptime}%</div>
</Grid>
</Grid>
</div>
);
Expand All @@ -71,7 +77,7 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
<div className={classes.root}>
<div className={classes.header}>
<Typography>Validators</Typography>
<Typography variant="h5">{voting.length}</Typography>
<Typography variant="h5">{validators.length}</Typography>
{!separate && (
<Link to="/rc/validators/all" className={classes.link}>
See all &gt;
Expand All @@ -85,19 +91,20 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
<TableCell align="center">Name/Moniker</TableCell>
<TableCell>Stake</TableCell>
<TableCell>Commission</TableCell>
<TableCell>Uptime</TableCell>
</TableRow>
</TableHead>
<TableBody
classes={{
root: classes.body,
}}
>
{map(renderRow)(voting)}
{map(renderRow)(validators)}
</TableBody>
</Table>
) : (
<div className={cn(classes.list, separate && classes.vertical)}>
{map(renderCard)(voting)}
{map(renderCard)(validators)}
</div>
)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/v2/components/Validators/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import useStyles from './styles';

const Validators = () => {
const classes = useStyles();
const {cluster, fetchClusterInfo, totalBondedTokens} = NodesStore;
const {cluster, validators, fetchClusterInfo, totalBondedTokens} = NodesStore;
useEffect(() => {
fetchClusterInfo();
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -34,7 +34,7 @@ const Validators = () => {
},
{
title: '# Active Validators',
value: cluster.nodes.length,
value: validators.length,
changes: '',
period: 'since yesterday',
},
Expand Down
9 changes: 9 additions & 0 deletions src/v2/stores/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
mapValues,
pick,
merge,
find,
} from 'lodash/fp';
import {action, computed, decorate, observable, observe, flow} from 'mobx';
import {parseClusterInfo} from 'v2/utils/parseMessage';
Expand All @@ -17,6 +18,7 @@ import calcChanges from 'v2/utils/calcChanges';
class Store {
cluster = {
nodes: [],
voting: [],
};
clusterChanges = {};

Expand Down Expand Up @@ -54,6 +56,13 @@ class Store {
}))(this.cluster.nodes);
}

get validators() {
return map(vote => ({
...vote,
uptime: find({votePubkey: vote.votePubkey})(this.cluster.uptime),
}))(this.cluster.voting);
}

get totalBondedTokens() {
return compose(
sumBy('stake'),
Expand Down
7 changes: 7 additions & 0 deletions src/v2/utils/getUptime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {compose, getOr, multiply} from 'lodash/fp';

export default compose(
time => time.toFixed(time ? 4 : 2),
multiply(100),
getOr(0, 'uptime.uptime.[0].percentage'),
);

0 comments on commit f6202ce

Please sign in to comment.