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

Commit

Permalink
feat: fix commision (0-100) and staked sol (handle null/NaN)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnygleason committed Dec 31, 2019
1 parent 6c4e7ef commit 6c2b189
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,13 +709,13 @@ async function getClusterInfo() {
_.find(voteAccounts.current, x => x.nodePubkey === nodePubkey) ||
_.find(voteAccounts.delinquent, x => x.nodePubkey === nodePubkey);
node.activatedStake = node.voteStatus && node.voteStatus.activatedStake;
node.commission = node.voteStatus && node.voteStatus.commission;
node.commission = (node.voteStatus && node.voteStatus.commission) || 0.0;

node.stakedSol = lamportsToSol(node.activatedStake).toFixed(8);
node.stakedSolPercent = (100 * (node.activatedStake / totalStaked)).toFixed(
3,
);
node.calcCommission = (100 * (node.commission / 0xff)).toFixed(3);
node.calcCommission = node.commission.toFixed(3);
}

for (const node of Object.keys(network).sort()) {
Expand Down
3 changes: 1 addition & 2 deletions src/v1/BxDialogWorldMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ class Node extends React.Component {
<hr />
<b>Stake:</b> {node.voteAccount.stake}
<br />
<b>Commission:</b>{' '}
{(100 * (node.voteAccount.commission / 0xff)).toFixed(3)}%
<b>Commission:</b> {node.voteAccount.calcCommission}%
<br />
<b>Vote Account:</b> {node.voteAccount.votePubkey}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/v2/components/Validators/Detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ValidatorsDetail = ({match}: {match: Match}) => {

const {
nodePubkey,
commission,
calcCommission,
identity = {},
stakedSol,
stakedSolPercent,
Expand Down Expand Up @@ -116,7 +116,7 @@ const ValidatorsDetail = ({match}: {match: Match}) => {
{
label: 'commission',
hint: '',
value: `${commission} (${(100 * (commission / 0xff)).toFixed(3)}%)`,
value: `${calcCommission}%`,
},
];

Expand Down
2 changes: 1 addition & 1 deletion src/v2/components/Validators/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Validators = () => {
},
{
title: 'Staked SOL',
value: totalStakedSol.toFixed(8),
value: totalStakedSol && totalStakedSol.toFixed(8),
changes: '',
period: 'since yesterday',
helpText: 'The total number of SOL staked to validators and activated.',
Expand Down

0 comments on commit 6c2b189

Please sign in to comment.