Skip to content

Commit

Permalink
[+] added node rating
Browse files Browse the repository at this point in the history
  • Loading branch information
radumojic committed Nov 24, 2023
1 parent 53f8d78 commit 5fbf20a
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 11 deletions.
75 changes: 75 additions & 0 deletions src/components/NodeRating/NodeRating.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import BigNumber from 'bignumber.js';
import classNames from 'classnames';

import { Overlay } from 'components';
import { faDownRight, faUpRight } from 'icons/regular';
import { NodeType, WithClassnameType } from 'types';

export interface NodeRatingType extends WithClassnameType {
node: NodeType;
}

const getNodeRatingDisplay = (ratingDifference: BigNumber) => {
const shouldDisplayDifference = ratingDifference
.absoluteValue()
.isGreaterThanOrEqualTo(0.1);

if (ratingDifference.isZero() || !shouldDisplayDifference) {
return {
icon: undefined,
iconColor: ''
};
}
if (ratingDifference.isPositive()) {
return {
icon: faUpRight,
iconColor: 'text-success'
};
}
if (ratingDifference.isNegative()) {
return {
icon: faDownRight,
iconColor: 'text-danger'
};
}
return {
icon: undefined,
iconColor: ''
};
};

export const NodeRating = ({ node, className }: NodeRatingType) => {
const { rating, tempRating } = node;

if (isNaN(tempRating)) {
return <span className='text-neutral-400'>N/A</span>;
}

const bNtempRating = new BigNumber(tempRating || 0);
const bNRating = new BigNumber(rating || 0);

const ratingDifference = bNtempRating.minus(bNRating);
const { icon, iconColor } = getNodeRatingDisplay(ratingDifference);

return (
<div className={classNames('d-flex align-items-center gap-2', className)}>
{bNtempRating.toFormat(0)}
{icon && iconColor && (
<Overlay
title={`${
ratingDifference.isPositive()
? `+${ratingDifference.toFormat()}`
: ratingDifference.toFormat()
} compared to Epoch Start Rating`}
>
<FontAwesomeIcon
icon={icon}
className={classNames('cursor-context', iconColor)}
/>
</Overlay>
)}
</div>
);
};
1 change: 1 addition & 0 deletions src/components/NodeRating/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './NodeRating';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
NodeRating,
NodeStatus,
ShardSpan,
NetworkLink,
Expand Down Expand Up @@ -101,11 +102,7 @@ export const StandardRow = ({
<NodeStatus node={nodeData} className='align-items-end' />
</td>
<td className='text-end'>
{!isNaN(nodeData.tempRating) ? (
Math.floor(nodeData.tempRating)
) : (
<span className='text-neutral-400'>N/A</span>
)}
<NodeRating node={nodeData} className='justify-content-end' />
</td>
<td className='text-end'>
{nodeData.nonce ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkLink, Trim } from 'components';
import { NetworkLink, NodeRating, Trim } from 'components';
import { urlBuilder } from 'helpers';
import { NodeType } from 'types';
import { RowIcon } from '../../RowIcon';
Expand Down Expand Up @@ -62,11 +62,7 @@ export const StatisticsRow = ({ nodeData }: { nodeData: NodeType }) => {
)}
</td>
<td className='text-end'>
{nodeData.tempRating ? (
nodeData.tempRating.toLocaleString('en')
) : (
<span className='text-neutral-400'>N/A</span>
)}
<NodeRating node={nodeData} className='justify-content-end' />
</td>
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export * from './NftBadge';
export * from './NftBlock';
export * from './NftPreview';
export * from './NodesFilters';
export * from './NodeRating';
export * from './NodeStatus';
export * from './NotificationsBar';
export * from './Overlay';
Expand Down
4 changes: 4 additions & 0 deletions src/icons/regular/fontawesomeFree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
faCircleCheck as faShieldCheck,
faCircleCheck,
faCircleDot as faCircleBolt,
faCircleDown as faDownRight,
faCircleDown,
faCircleUp as faUpRight,
faCircleUp,
faClock,
faClone,
Expand Down Expand Up @@ -136,6 +138,7 @@ export {
faCube,
faDiamond,
faDollarSign,
faDownRight,
faEllipsis,
faEnvelope,
faExchange,
Expand Down Expand Up @@ -187,6 +190,7 @@ export {
faTerminal,
faTimes,
faTrophy,
faUpRight,
faUser,
faUserCheck,
faUserFriends,
Expand Down
4 changes: 4 additions & 0 deletions src/icons/regular/fontawesomePro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
faCube,
faDiamond,
faDollarSign,
faDownRight,
faEllipsis,
faEnvelope,
faExchange,
Expand Down Expand Up @@ -89,6 +90,7 @@ import {
faTerminal,
faTimes,
faTrophy,
faUpRight,
faUser,
faUserCheck,
faUserFriends,
Expand Down Expand Up @@ -138,6 +140,7 @@ export {
faCube,
faDiamond,
faDollarSign,
faDownRight,
faEllipsis,
faEnvelope,
faExchange,
Expand Down Expand Up @@ -189,6 +192,7 @@ export {
faTerminal,
faTimes,
faTrophy,
faUpRight,
faUser,
faUserCheck,
faUserFriends,
Expand Down
4 changes: 4 additions & 0 deletions src/icons/solid/fontawesomeFree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import {
faCircleCheck as faShieldCheck,
faCircleCheck,
faCircleDot as faCircleBolt,
faCircleDown as faDownRight,
faCircleDown,
faCircleMinus,
faCircleNotch as faSpinnerThird,
faCircleNotch,
faCirclePlus,
faCircleUp as faUpRight,
faCircleUp,
faCity,
faClock,
Expand Down Expand Up @@ -134,6 +136,7 @@ export {
faCube,
faDiamond,
faDollarSign,
faDownRight,
faEllipsis,
faEnvelope,
faExchange,
Expand Down Expand Up @@ -185,6 +188,7 @@ export {
faTerminal,
faTimes,
faTrophy,
faUpRight,
faUser,
faUserCheck,
faUserFriends,
Expand Down
4 changes: 4 additions & 0 deletions src/icons/solid/fontawesomePro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
faCube,
faDiamond,
faDollarSign,
faDownRight,
faEllipsis,
faEnvelope,
faExchange,
Expand Down Expand Up @@ -89,6 +90,7 @@ import {
faTerminal,
faTimes,
faTrophy,
faUpRight,
faUser,
faUserCheck,
faUserFriends,
Expand Down Expand Up @@ -138,6 +140,7 @@ export {
faCube,
faDiamond,
faDollarSign,
faDownRight,
faEllipsis,
faEnvelope,
faExchange,
Expand Down Expand Up @@ -189,6 +192,7 @@ export {
faTerminal,
faTimes,
faTrophy,
faUpRight,
faUser,
faUserCheck,
faUserFriends,
Expand Down

0 comments on commit 5fbf20a

Please sign in to comment.