Skip to content

Commit

Permalink
add bonded precision
Browse files Browse the repository at this point in the history
  • Loading branch information
16601314215 authored and 16601314215 committed Aug 20, 2024
1 parent 77ec74b commit 9050e2c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
NEXT_PUBLIC_GRAPHQL_URL=https://explorer.turablockchain.com/v1/graphql
NEXT_PUBLIC_GRAPHQL_WS=wss://explorer.turablockchain.com/v1/graphql
NODE_ENV=production
#NODE_ENV=development
PORT=5000
NEXT_PUBLIC_CHAIN_TYPE=mainnet
NEXT_PUBLIC_NETWORK_NAME=mainnet-tura
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ const initialState: OnlineVotingPowerState = {
};

const formatOnlineVotingPower = (data: OnlineVotingPowerQuery) => {
const votingPower = data?.validatorVotingPowerAggregate?.aggregate?.sum?.votingPower ?? 0;
// const votingPower = data?.validatorVotingPowerAggregate?.aggregate?.sum?.votingPower ?? 0;
const votingPower =
numeral(
formatToken(
data?.validatorVotingPowerAggregate?.aggregate?.sum?.votingPower ?? 0,
votingPowerTokenUnit
).value
).value() ?? 0;
const bonded = data?.stakingPool?.[0]?.bonded ?? 0;
const activeValidators = data?.activeTotal?.aggregate?.count ?? 0;

return {
activeValidators,
votingPower,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ const OnlineVotingPower: FC<ComponentDefault> = () => {
chainName === 'wormhole'
? numeral((state.activeValidators / state.votingPower) * 100)
: state.totalVotingPower === 0
? numeral(0)
: numeral((state.votingPower / state.totalVotingPower) * 100);

? numeral(0)
: numeral((state.votingPower / state.totalVotingPower) * 100);
const { classes } = useStyles({ percentage: votingPowerPercent.format('0') });

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const ValidatorOverview: FC<ValidatorOverviewProps> = ({ status, overview, class
),
value: (
<Typography variant="body1" className="value">
{`${numeral(status.commission * 100).format('0.00')}%`}
{`${numeral((status.commission / 100000000) * 100).format('0.00')}%`}
</Typography>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { VotingPowerType } from '@/screens/validator_details/types';
import useStyles from '@/screens/validator_details/components/voting_power/styles';
import Box from '@/components/box';
import { useOnlineVotingPower } from '@/screens/home/components/hero/components/online_voting_power/hooks';
import { formatToken } from '@/utils';

type VotingPowerProps = {
className?: string;
Expand All @@ -22,14 +23,13 @@ const VotingPower: FC<VotingPowerProps> = ({ className, data, status }) => {

const { chainName } = chainConfig();

const votingPower = status === 3 ? numeral(data.self).format('0,0') : '0';

const votingPower = status === 3 ? numeral(data.self / 100000000).format('0,0') : '0';
const votingPowerPercent =
// eslint-disable-next-line no-nested-ternary
status === 3
? chainName === 'wormhole'
? numeral((Number(votingPower) / state.activeValidators) * 100)
: numeral((data.self / (numeral(data.overall.value).value() ?? 0)) * 100)
: numeral((data.self / 100000000 / (numeral(data.overall.value).value() ?? 0)) * 100)
: numeral(0);

const { classes, cx } = useStyles({
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/screens/validator_details/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const formatStatus = (data: ValidatorDetailsQuery) => {
status: data.validator[0]?.validatorStatuses?.[0]?.status ?? 3,
jailed: data.validator[0]?.validatorStatuses?.[0]?.jailed ?? false,
tombstoned: data.validator[0]?.validatorSigningInfos?.[0]?.tombstoned ?? false,
commission: data.validator[0]?.validatorCommissions?.[0]?.commission ?? 0,
commission: (data.validator[0]?.validatorCommissions?.[0]?.commission ?? 0) / 10000000000,
condition,
missedBlockCounter,
signedBlockWindow,
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/screens/validator_details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const ValidatorDetails = () => {
const { classes } = useStyles();
const { state, loading } = useValidatorDetails();
const { desmosProfile, exists, overview, status, votingPower } = state;

return (
<>
<NextSeo
Expand Down

0 comments on commit 9050e2c

Please sign in to comment.