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

Commit

Permalink
feat: new style map markers
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-calavera committed Oct 29, 2019
1 parent b39d72f commit f8efa61
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useStyles from './styles';

const NodesMap = () => {
const classes = useStyles();
const {mapMarkers} = NodesStore;
const {validators} = NodesStore;
const {isLoading} = Socket;
if (isLoading) {
return <Loader width="533" height="290" />;
Expand All @@ -21,7 +21,7 @@ const NodesMap = () => {
<Typography className={classes.mapTitle}>
Active Validators Map
</Typography>
<ValidatorsMap markers={mapMarkers} />
<ValidatorsMap markers={validators} />
</div>
);
};
Expand Down
8 changes: 3 additions & 5 deletions src/v2/components/Validators/Detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import useMediaQuery from '@material-ui/core/useMediaQuery/useMediaQuery';
import React, {useEffect} from 'react';
import {map, find} from 'lodash/fp';
import {Match} from 'react-router-dom';
import getUptime from 'v2/utils/getUptime';
import SectionHeader from 'v2/components/UI/SectionHeader';
import NodesStore from 'v2/stores/nodes';
import HelpLink from 'v2/components/HelpLink';
Expand Down Expand Up @@ -33,8 +32,6 @@ const ValidatorsDetail = ({match}: {match: Match}) => {
find({nodePubkey: params.id})(validators) ||
find({nodePubkey: params.id})(inactiveValidators);

const uptime = getUptime(node);

if (!node) {
return <div>Loading...</div>;
}
Expand All @@ -47,6 +44,7 @@ const ValidatorsDetail = ({match}: {match: Match}) => {
coordinates,
stakedSol,
stakedSolPercent,
calcUptime,
} = node;

const markers = [{gossip, coordinates, name: nodePubkey}];
Expand All @@ -66,7 +64,7 @@ const ValidatorsDetail = ({match}: {match: Match}) => {
{
label: 'Staked SOL',
hint: '',
value: `${stakedSol} (${stakedSolPercent}%)`,
value: stakedSol ? `${stakedSol} (${stakedSolPercent}%)` : 'N/A',
},
{
label: 'Website',
Expand All @@ -84,7 +82,7 @@ const ValidatorsDetail = ({match}: {match: Match}) => {
{
label: 'Uptime',
hint: '',
value: `${uptime}%`,
value: `${calcUptime}%`,
},
{
label: 'keybase',
Expand Down
33 changes: 10 additions & 23 deletions src/v2/components/Validators/Table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {observer} from 'mobx-react-lite';
import {Link} from 'react-router-dom';
import {eq, map, concat} from 'lodash/fp';
import NodesStore from 'v2/stores/nodes';
import getUptime from 'v2/utils/getUptime';
import Table from 'v2/components/UI/Table';
import Socket from 'v2/stores/socket';
import Loader from 'v2/components/UI/Loader';
Expand Down Expand Up @@ -71,13 +70,13 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
}

const renderRow = ({data: row}) => {
const uptime = row.uptime && getUptime(row);
const {
identity = {},
nodePubkey,
stakedSol,
stakedSolPercent,
commission,
calcCommission,
calcUptime,
} = row;
return (
<TableRow hover key={nodePubkey}>
Expand All @@ -89,27 +88,21 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
/>
</TableCell>
<TableCell>
<div>
{stakedSol || 'N/A'} ({stakedSolPercent}%)
</div>
<div>{stakedSol ? `${stakedSol} (${stakedSolPercent}%)` : 'N/A'}</div>
</TableCell>
<TableCell>
{commission || 'N/A'}
{Boolean(commission) &&
` (${(100 * (commission / 0xff)).toFixed(3)}%)`}
</TableCell>
<TableCell>{(uptime && uptime + '%') || 'Unavailable'}</TableCell>
<TableCell>{calcCommission ? `${calcCommission}%` : 'N/A'}</TableCell>
<TableCell>{calcUptime ? `${calcUptime}%` : 'Unavailable'}</TableCell>
</TableRow>
);
};
const renderCard = card => {
const uptime = card.uptime && getUptime(card);
const {
identity = {},
nodePubkey,
stakedSol,
stakedSolPercent,
commission,
calcCommission,
calcUptime,
} = card;
const data = [
{
Expand All @@ -124,21 +117,15 @@ const ValidatorsTable = ({separate}: {separate: boolean}) => {
},
{
label: 'Stake',
value: `${stakedSol || 'N/A'} (${stakedSolPercent}%)`,
value: stakedSol ? `${stakedSol} (${stakedSolPercent}%)` : 'N/A',
},
{
label: 'Commission',
value: (
<div>
{commission || 'N/A'}
{Boolean(commission) &&
` (${(100 * (commission / 0xff)).toFixed(3)}%)`}
</div>
),
value: <div>{calcCommission ? `${calcCommission}%` : 'N/A'}</div>,
},
{
label: 'Uptime',
value: (uptime && uptime + '%') || 'Unavailable',
value: calcUptime ? `${calcUptime}%` : 'Unavailable',
},
];
return <TableCard vertical={separate} key={nodePubkey} data={data} />;
Expand Down
10 changes: 2 additions & 8 deletions src/v2/components/Validators/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ import {LAMPORT_SOL_RATIO} from '../../constants';

const Validators = () => {
const classes = useStyles();
const {
supply,
validators,
fetchClusterInfo,
totalStaked,
mapMarkers,
} = NodesStore;
const {supply, validators, fetchClusterInfo, totalStaked} = NodesStore;
const {isLoading} = Socket;
useEffect(() => {
fetchClusterInfo();
Expand Down Expand Up @@ -120,7 +114,7 @@ const Validators = () => {
Active Validators Map
<HelpLink text="" term="" />
</Typography>
<ValidatorsMap markers={mapMarkers} />
<ValidatorsMap markers={validators} />
</div>
)}
</Grid>
Expand Down
31 changes: 27 additions & 4 deletions src/v2/components/ValidatorsMap/Marker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,42 @@ import React from 'react';
import MapTooltip from 'v2/components/UI/MapTooltip';
import Avatar from 'v2/components/UI/Avatar';

import ValidatorName from 'v2/components//UI/ValidatorName';
import useStyles from './styles';

const Marker = ({scale, marker}: {scale: number, marker: any}) => {
const classes = useStyles();
const transformScale = scale < 4 ? scale / 4 : 1;
const {
nodePubkey,
identity,
calcCommission,
calcUptime,
stakedSol,
stakedSolPercent,
} = marker;

return (
<MapTooltip
classes={{tooltip: classes.tooltip}}
title={() => (
<>
<div className={classes.tooltipTitle}>NODE: {marker.name}</div>
<div className={classes.tooltipDesc}>Gossip: {marker.gossip}</div>
</>
<div className={classes.inner}>
<ValidatorName
pubkey={nodePubkey}
name={identity.name}
avatar={identity.avatarUrl}
/>
<div className={classes.info}>
<div>
Total Sol:{' '}
{stakedSol ? `${stakedSol} (${stakedSolPercent}%)` : 'N/A'}
</div>
<div>
Commission: {calcCommission ? `${calcCommission}%` : 'N/A'}
</div>
<div>Uptime: {calcUptime ? `${calcUptime}%` : 'Unavailable'}</div>
</div>
</div>
)}
>
<div
Expand Down
2 changes: 1 addition & 1 deletion src/v2/components/ValidatorsMap/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const renderMarkers = zoom =>
map(marker => {
return (
<Marker
key={get('name')(marker)}
key={get('nodePubkey')(marker)}
lng={get('coordinates[0]')(marker)}
lat={get('coordinates[1]')(marker)}
scale={zoom}
Expand Down
20 changes: 19 additions & 1 deletion src/v2/components/ValidatorsMap/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ export default makeStyles(theme => ({
tooltip: {
background: '#fff',
color: getColor('dark')(theme),
padding: 10,
padding: `10px 18px`,
borderRadius: 0,
maxWidth: 300,
zIndex: 1000,
},
tooltipTitle: {
fontSize: 15,
Expand All @@ -25,4 +27,20 @@ export default makeStyles(theme => ({
transform: 'scale(2)',
},
},
inner: {
'& a': {
color: getColor('greenDark')(theme),
fontSize: 21,
},
},
info: {
marginTop: 10,
fontSize: 17,
lineHeight: '30px',
'& > div': {
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
},
},
}));
32 changes: 4 additions & 28 deletions src/v2/stores/nodes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import {filter, reject, map, getOr} from 'lodash/fp';
import {filter, reject, map} from 'lodash/fp';
import {action, computed, decorate, observable, flow} from 'mobx';
import * as API from 'v2/api/stats';
import getUptime from 'v2/utils/getUptime';

import {LAMPORT_SOL_RATIO} from '../constants';

const addNetworkSolInfo = totalStaked => node => ({
...node,
stakedSol: (node.activatedStake * LAMPORT_SOL_RATIO).toFixed(8),
stakedSolPercent: (100 * (node.activatedStake / totalStaked)).toFixed(3),
calcCommission: (100 * (node.commission / 0xff)).toFixed(3),
calcUptime: getUptime(node.uptime),
});

class Store {
Expand Down Expand Up @@ -36,32 +39,6 @@ class Store {
}
});

get mapMarkers() {
if (!this.network.length) {
return [];
}

try {
return map(
({nodePubkey: pubkey = '', tpu: gossip, coordinates, identity}) => ({
pubkey,
gossip,
coordinates:
-180 < coordinates[0] &&
coordinates[0] < 180 &&
(-90 < coordinates[1] && coordinates[1] < 90)
? coordinates
: [0, 0],
name: getOr(pubkey, 'name')(identity),
avatarUrl: getOr('', 'avatarUrl')(identity),
}),
)(this.validators);
} catch (e) {
console.error('mapMarkers()', e);
return [];
}
}

get validators() {
return filter({what: 'Validator'})(this.network);
}
Expand All @@ -80,7 +57,6 @@ decorate(Store, {
supply: observable,
stakedTokens: observable,
updateClusterInfo: action.bound,
mapMarkers: computed,
validators: computed,
activeValidators: computed,
inactiveValidators: computed,
Expand Down

0 comments on commit f8efa61

Please sign in to comment.