Skip to content

Commit

Permalink
fix some code to make it clear
Browse files Browse the repository at this point in the history
  • Loading branch information
eshark9312 committed Jul 24, 2023
1 parent afd3e5a commit 4a11d92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 1 addition & 2 deletions packages/ui/src/validators/components/statistics/Era.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ interface EraProps {

export const Era = ({ eraStartedOn, eraDuration, now, eraRewardPoints }: EraProps) => {
const { nextReward, percentage } = useMemo(() => {
const nextReward =
eraDuration && now && eraStartedOn ? Number(eraDuration) - (now.toNumber() - Number(eraStartedOn)) : undefined
const nextReward = now && eraStartedOn && eraDuration - Number(now) - Number(eraStartedOn)
const totalDuration = Number(eraDuration)
const percentage = nextReward ? Math.floor(100 - (nextReward / totalDuration) * 100) : 0
return {
Expand Down
5 changes: 2 additions & 3 deletions packages/ui/src/validators/components/statistics/Rewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import React from 'react'
import { StatisticItem, StatisticItemSpacedContent, StatisticLabel } from '@/common/components/statistics'
import { TokenValue } from '@/common/components/typography'

interface RewardsProps{
totalRewards: BN | undefined,
interface RewardsProps {
totalRewards: BN | undefined
lastRewards: BN | undefined
}

export const Rewards = ({ totalRewards, lastRewards }: RewardsProps) => {

return (
<StatisticItem
title="Rewards"
Expand Down
14 changes: 10 additions & 4 deletions packages/ui/src/validators/hooks/useStakingStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ export const useStakingStatistics = () => {

const now = useObservable(() => api?.query.timestamp.now(), [api?.isConnected])
const totalIssuance = useObservable(() => api?.query.balances.totalIssuance(), [api?.isConnected])
const currentStaking = useObservable(() => activeEra ? api?.query.staking.erasTotalStake(activeEra.eraIndex):undefined, [activeEra, api?.isConnected])
const currentStaking = useObservable(
() => activeEra && api?.query.staking.erasTotalStake(activeEra.eraIndex),
[activeEra, api?.isConnected]
)
const activeValidators = useObservable(() => api?.query.session.validators(), [api?.isConnected])
const stakers = useObservable(() => {
if (activeValidators && api)
return activeEra ? combineLatest(activeValidators.map((address) => api.query.staking.erasStakers(activeEra.eraIndex, address))): undefined
return (
activeEra &&
combineLatest(activeValidators.map((address) => api.query.staking.erasStakers(activeEra.eraIndex, address)))
)
}, [api?.isConnected, activeValidators, activeEra])
const acitveNominators = useMemo(() => {
const nominators = stakers?.map((validator) => validator.others.map((nominator) => nominator.who.toString()))
Expand All @@ -35,7 +41,7 @@ export const useStakingStatistics = () => {
const allValidatorsCount = useObservable(() => api?.query.staking.counterForValidators(), [api?.isConnected])
const allNominatorsCount = useObservable(() => api?.query.staking.counterForNominators(), [api?.isConnected])
const lastValidatorRewards = useObservable(
() => activeEra ? api?.query.staking.erasValidatorReward(activeEra.eraIndex.subn(1)) :undefined,
() => activeEra && api?.query.staking.erasValidatorReward(activeEra.eraIndex.subn(1)),
[activeEra, api?.isConnected]
)
const totalRewards = useObservable(() => api?.derive.staking.erasRewards(), [api?.isConnected])
Expand All @@ -44,7 +50,7 @@ export const useStakingStatistics = () => {
[currentStaking, totalIssuance]
)
const eraRewardPoints = useObservable(
() => activeEra ? api?.query.staking.erasRewardPoints(activeEra.eraIndex): undefined,
() => activeEra && api?.query.staking.erasRewardPoints(activeEra.eraIndex),
[activeEra, api?.isConnected]
)
return {
Expand Down

0 comments on commit 4a11d92

Please sign in to comment.