Skip to content

Commit

Permalink
fix some issue in Era widget
Browse files Browse the repository at this point in the history
  • Loading branch information
eshark9312 committed Jul 24, 2023
1 parent 4a11d92 commit 43c3824
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ export default {
],
},
},

query: {
balances: {
totalIssuance: joy(1000000),
},

timestamp: { now: Date.now() },

session: {
validators: [
'j4RLnWh3DWgc9u4CMprqxfBhq3kthXhvZDmnpjEtETFVm446D',
Expand All @@ -56,7 +53,6 @@ export default {
'j4S998Thq5kQHyurofh8QfHrcFN2c1T19gTdMGUVVx5EHKgky',
],
},

staking: {
activeEra: {
index: 700,
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/validators/components/statistics/Era.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ interface EraProps {

export const Era = ({ eraStartedOn, eraDuration, now, eraRewardPoints }: EraProps) => {
const { nextReward, percentage } = useMemo(() => {
const nextReward = now && eraStartedOn && eraDuration - Number(now) - Number(eraStartedOn)
const nextReward = now && eraStartedOn && eraDuration - (Number(now) - Number(eraStartedOn))
const totalDuration = Number(eraDuration)
const percentage = nextReward ? Math.floor(100 - (nextReward / totalDuration) * 100) : 0
const percentage = nextReward ? Math.ceil(100 - (nextReward / totalDuration) * 100) : 0
return {
nextReward: formatDurationDate(nextReward ?? 0),
totalDuration: formatDurationDate(totalDuration ?? 0),
Expand Down
21 changes: 11 additions & 10 deletions packages/ui/src/validators/hooks/useStakingStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ 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),
() => activeEra && api && 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)))
)
}, [api?.isConnected, activeValidators, activeEra])
const stakers = useObservable(
() =>
activeValidators &&
api &&
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()))
const uniqueNominators = [...new Set(nominators?.flat())]
Expand All @@ -41,7 +42,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)),
() => activeEra && api && api.query.staking.erasValidatorReward(activeEra.eraIndex.subn(1)),
[activeEra, api?.isConnected]
)
const totalRewards = useObservable(() => api?.derive.staking.erasRewards(), [api?.isConnected])
Expand All @@ -50,7 +51,7 @@ export const useStakingStatistics = () => {
[currentStaking, totalIssuance]
)
const eraRewardPoints = useObservable(
() => activeEra && api?.query.staking.erasRewardPoints(activeEra.eraIndex),
() => activeEra && api && api.query.staking.erasRewardPoints(activeEra.eraIndex),
[activeEra, api?.isConnected]
)
return {
Expand Down

0 comments on commit 43c3824

Please sign in to comment.