Skip to content

Commit

Permalink
chore: add inactive graph & status label
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbulat committed Jan 8, 2025
1 parent 9e1b37f commit a5508c4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2024 @polkadot-cloud/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { EraPoints } from 'library/Graphs/EraPoints'

export const InactiveGraph = () => <EraPoints items={[]} height={250} />
51 changes: 32 additions & 19 deletions packages/app/src/overlay/modals/ValidatorMetrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BigNumber from 'bignumber.js'
import { useApi } from 'contexts/Api'
import { useHelp } from 'contexts/Help'
import { useNetwork } from 'contexts/Network'
import { usePlugins } from 'contexts/Plugins'
import { useStaking } from 'contexts/Staking'
import { useUi } from 'contexts/UI'
import { CardHeaderWrapper, CardWrapper } from 'library/Card/Wrappers'
Expand All @@ -23,21 +24,23 @@ import { AddressHeader, Padding } from 'ui-core/modal'
import { useOverlay } from 'ui-overlay'
import { planckToUnitBn } from 'utils'
import { ActiveGraph } from './ActiveGraph'
import { InactiveGraph } from './InactiveGraph'

export const ValidatorMetrics = () => {
const { t } = useTranslation('modals')
const { t } = useTranslation()
const {
network,
networkData: { units, unit },
} = useNetwork()
const { activeEra } = useApi()
const { containerRefs } = useUi()
const { options } = useOverlay().modal.config
const { address, identity } = options
const {
eraStakers: { stakers },
} = useStaking()
const { activeEra } = useApi()
const { openHelp } = useHelp()
const { containerRefs } = useUi()
const { pluginEnabled } = usePlugins()
const { options } = useOverlay().modal.config
const { address, identity } = options

// is the validator in the active era
const validatorInEra = stakers.find((s) => s.address === address) || null
Expand All @@ -63,19 +66,19 @@ export const ValidatorMetrics = () => {

const stats = [
{
label: t('selfStake'),
label: t('selfStake', { ns: 'modals' }),
value: `${planckToUnitBn(validatorOwnStake, units).toFormat()} ${unit}`,
help: 'Self Stake',
},
{
label: t('nominatorStake'),
label: t('nominatorStake', { ns: 'modals' }),
value: `${planckToUnitBn(otherStake, units).toFormat()} ${unit}`,
help: 'Nominator Stake',
},
]
return (
<>
<Title title={t('validatorMetrics')} />
<Title title={t('validatorMetrics', { ns: 'modals' })} />
<AddressHeader>
<Polkicon address={address} fontSize="2.75rem" />
<h2>
Expand Down Expand Up @@ -111,27 +114,37 @@ export const ValidatorMetrics = () => {
>
<CardHeaderWrapper $withMargin>
<h4>
{t('recentEraPoints')}{' '}
{t('recentEraPoints', { ns: 'modals' })}{' '}
<ButtonHelp marginLeft onClick={() => openHelp('Era Points')} />
</h4>
</CardHeaderWrapper>
<div ref={ref} style={{ minHeight }}>
<StatusLabel
status="active_service"
statusFor="subscan"
title={t('subscanDisabled')}
/>
<GraphWrapper
style={{
height: `${height}px`,
width: `${width}px`,
}}
>
<ActiveGraph
network={network}
validator={address}
fromEra={BigNumber.max(activeEra.index.minus(1), 0).toNumber()}
/>
{pluginEnabled('staking_api') ? (
<ActiveGraph
network={network}
validator={address}
fromEra={BigNumber.max(
activeEra.index.minus(1),
0
).toNumber()}
/>
) : (
<>
<StatusLabel
status="active_service"
statusFor="staking_api"
title={t('common.stakingApiDisabled', { ns: 'pages' })}
topOffset="37%"
/>
<InactiveGraph />
</>
)}
</GraphWrapper>
</div>
</CardWrapper>
Expand Down

0 comments on commit a5508c4

Please sign in to comment.