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

Commit

Permalink
feat: compute in api, format in display, plus robustify access
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnygleason committed Oct 22, 2019
1 parent 4ff10aa commit 3a63c8f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
36 changes: 22 additions & 14 deletions api/views/tourdesol/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ export class TourDeSolIndexView {

const {isDemo, activeStage, clusterInfo, lastSlot} = rawData;

const activeValidatorsRaw = filter(
node => node.what === 'Validator' && node.activatedStake,
)(clusterInfo.network);
const inactiveValidatorsRaw = filter(
node => node.what === 'Validator' && !node.activatedStake,
)(clusterInfo.network);
const activeValidatorsRaw =
clusterInfo &&
filter(node => node.what === 'Validator' && node.activatedStake)(
clusterInfo.network,
);
const inactiveValidatorsRaw =
clusterInfo &&
filter(node => node.what === 'Validator' && !node.activatedStake)(
clusterInfo.network,
);

const currentStage = activeStage ? stages[activeStage] : null;
const slotsLeftInStage =
Expand All @@ -69,11 +73,11 @@ export class TourDeSolIndexView {
slotsLeftInStage,
daysLeftInStage,
stageDurationBlocks: currentStage && currentStage.duration,
networkInflationRate: clusterInfo.networkInflationRate,
totalSupply: clusterInfo.supply * LAMPORT_SOL_RATIO,
totalStaked: clusterInfo.totalStaked * LAMPORT_SOL_RATIO,
activeValidators: activeValidatorsRaw.length,
inactiveValidators: inactiveValidatorsRaw.length,
networkInflationRate: clusterInfo && clusterInfo.networkInflationRate,
totalSupply: clusterInfo && clusterInfo.supply * LAMPORT_SOL_RATIO,
totalStaked: clusterInfo && clusterInfo.totalStaked * LAMPORT_SOL_RATIO,
activeValidators: activeValidatorsRaw && activeValidatorsRaw.length,
inactiveValidators: inactiveValidatorsRaw && inactiveValidatorsRaw.length,
};

const scoreParams = this.computeScoreParams(
Expand All @@ -86,20 +90,25 @@ export class TourDeSolIndexView {
const activeValidatorsPre = reduce((a, x) => {
const pubkey = x.nodePubkey;
const slot = x.currentSlot;
const {name, avatarUrl} = x.identity;
const name = x.identity && x.identity.name;
const avatarUrl = x.identity && x.identity.avatarUrl;
const activatedStake = x.activatedStake * LAMPORT_SOL_RATIO;
const activatedStakePercent =
clusterInfo && 100.0 * (x.activatedStake / clusterInfo.totalStaked);

const uptimePercent =
x.uptime &&
x.uptime.uptime &&
x.uptime.uptime.length &&
100.0 * parseFloat(x.uptime.uptime[0].percentage);
Math.min(100.0, 100.0 * parseFloat(x.uptime.uptime[0].percentage));
const score = this.computeNodeScore(x, scoreParams);

const validator = {
name,
pubkey,
avatarUrl,
activatedStake,
activatedStakePercent,
slot,
uptimePercent,
score,
Expand Down Expand Up @@ -127,7 +136,6 @@ export class TourDeSolIndexView {
if (version === 'TourDeSolIndexView@latest' || version === __VERSION__) {
return {
__VERSION__,
rawData,
clusterStats,
activeValidators: result.accum,
stages,
Expand Down
46 changes: 29 additions & 17 deletions src/v2/components/TourDeSol/Table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,25 @@ const fields = [
const ValidatorsTable = ({
activeValidators,
separate,
totalStaked,
}: {
activeValidators: Array,
separate: boolean,
totalStaked: number,
}) => {
const classes = useStyles();
const theme = useTheme();
const showTable = useMediaQuery(theme.breakpoints.up('md'));

const renderRow = ({data: row}) => {
const {name, pubkey, avatarUrl, activatedStake, uptimePercent, rank} = row;
const uptime =
uptimePercent > 100
? 100
: parseFloat(uptimePercent.toFixed(uptimePercent ? 4 : 2));
const {
name,
pubkey,
avatarUrl,
activatedStake,
activatedStakePercent,
uptimePercent,
rank,
} = row;

return (
<TableRow hover key={pubkey}>
<TableCell width={100}>{rank}</TableCell>
Expand All @@ -68,20 +71,25 @@ const ValidatorsTable = ({
</TableCell>
<TableCell width={200}>
{activatedStake.toFixed(8) || 'N/A'} (
{(100 * (activatedStake / totalStaked)).toFixed(3)}%)
{activatedStakePercent.toFixed(3)}%)
</TableCell>
<TableCell width={150}>
{(uptime && `${uptime}%`) || 'Unavailable'}
{(uptimePercent &&
`${uptimePercent.toFixed(uptimePercent ? 4 : 2)}%`) ||
'Unavailable'}
</TableCell>
</TableRow>
);
};
const renderCard = card => {
const {name, pubkey, avatarUrl, activatedStake, uptimePercent} = card;
const uptime =
uptimePercent > 100
? 100
: parseFloat(uptimePercent.toFixed(uptimePercent ? 4 : 2));
const {
name,
pubkey,
avatarUrl,
activatedStake,
activatedStakePercent,
uptimePercent,
} = card;
return (
<div
className={cn(classes.card, separate && classes.cardVertical)}
Expand All @@ -92,13 +100,17 @@ const ValidatorsTable = ({
<Grid item xs={6} zeroMinWidth>
<div className={classes.cardTitle}>Stake</div>
<div>
{activatedStake.toFixed(4) || 'N/A'}(
{(100 * (activatedStake / totalStaked)).toFixed(3)}%)
{activatedStake.toFixed(4) || 'N/A'} (
{activatedStakePercent.toFixed(3)}%)
</div>
</Grid>
<Grid item xs={6} zeroMinWidth>
<div className={classes.cardTitle}>Uptime</div>
<div>{(uptime && `${uptime}%`) || 'Unavailable'}</div>
<div>
{(uptimePercent &&
`${uptimePercent.toFixed(uptimePercent ? 4 : 2)}%`) ||
'Unavailable'}
</div>
</Grid>
</Grid>
</div>
Expand Down

0 comments on commit 3a63c8f

Please sign in to comment.