-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from multiversx/development
Development
- Loading branch information
Showing
19 changed files
with
223 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './NodeRating'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import BigNumber from 'bignumber.js'; | ||
import classNames from 'classnames'; | ||
import { Led, PercentageBar } from 'components'; | ||
import { NodeType, WithClassnameType } from 'types'; | ||
|
||
export interface NodeStatusType extends WithClassnameType { | ||
node: NodeType; | ||
} | ||
|
||
const getNodeStatus = (node: NodeType) => { | ||
const { online, syncProgress } = node; | ||
|
||
switch (true) { | ||
case online && !syncProgress: | ||
return { | ||
textColor: 'text-success', | ||
ledColor: 'bg-success', | ||
status: 'online' | ||
}; | ||
case !online && !syncProgress: | ||
return { | ||
textColor: 'text-danger', | ||
ledColor: 'bg-danger', | ||
status: 'offline' | ||
}; | ||
case syncProgress && Number(syncProgress) > 0: | ||
return { | ||
textColor: '', | ||
ledColor: 'bg-primary', | ||
status: 'syncing' | ||
}; | ||
default: | ||
return { | ||
textColor: '', | ||
ledColor: '', | ||
status: '' | ||
}; | ||
} | ||
}; | ||
|
||
export const NodeStatus = ({ node, className }: NodeStatusType) => { | ||
const { syncProgress } = node; | ||
const { ledColor, textColor, status } = getNodeStatus(node); | ||
const fillPercent = new BigNumber(syncProgress || 0).times(100); | ||
|
||
return ( | ||
<div className={classNames('d-flex flex-column', className)}> | ||
<div className='d-flex align-items-center gap-2'> | ||
<Led color={ledColor} /> | ||
<span className={textColor}>{status}</span> | ||
{node?.syncProgress && ( | ||
<span className='text-neutral-400'> | ||
({`${fillPercent.toFormat(2)}%`}) | ||
</span> | ||
)} | ||
</div> | ||
{node?.syncProgress && ( | ||
<PercentageBar | ||
overallPercent={0} | ||
fillPercent={fillPercent.toNumber()} | ||
fillPercentLabel={`${fillPercent.toFormat()}%`} | ||
type='small' | ||
className='mt-2' | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './NodeStatus'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.nodes-table { | ||
.percentage-bar { | ||
width: 8.125rem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.