Skip to content

Commit

Permalink
Address issues on Docker PoS Mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
wirednkod committed Jun 22, 2022
1 parent d31a7ec commit c3122b2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
37 changes: 24 additions & 13 deletions packages/page-staking/src/Overview/SummaryNominators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import React from 'react';

import { Card, CardSummary, MarkWarning, SummaryBox } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';

Expand All @@ -23,6 +24,12 @@ function SummaryNominators ({ targets: { maxNominatorsCount,
nominatorMinActiveThreshold } }: Props) {
const { t } = useTranslation();

const { api } = useApi();

const maxElectingVotersDefined = !!api.consts.electionProviderMultiPhase?.maxElectingVoters;
const maxNominatorDefined = !!api.query.staking.maxNominatorsCount;
const minNominatorBondDefined = !!api.query.staking.minNominatorBond;

return (
<>
<Card withBottomMargin>
Expand All @@ -33,21 +40,23 @@ function SummaryNominators ({ targets: { maxNominatorsCount,
help={t<string>('Maximum number of nominator intentions.')}
label={t<string>('maximum')}
>
<SpinnerWrap check={maxNominatorsCount}>
{formatNumber(maxNominatorsCount?.toNumber())}
</SpinnerWrap>
{maxNominatorDefined
? <SpinnerWrap check={maxNominatorsCount}>
{formatNumber(maxNominatorsCount?.toNumber())}
</SpinnerWrap>
: '-'}
</CardSummary>
</Section>
<Section>
<CardSummary
help={t<string>('Number of electing nominators.')}
label={t<string>('electing')}
>
{nominatorMaxElectingCount === null
? <>-</>
: <SpinnerWrap check={nominatorMaxElectingCount}>
{maxElectingVotersDefined
? <SpinnerWrap check={nominatorMaxElectingCount}>
{formatNumber(nominatorMaxElectingCount)}
</SpinnerWrap>}
</SpinnerWrap>
: '-'}
</CardSummary>
</Section>
<Section>
Expand All @@ -67,12 +76,14 @@ function SummaryNominators ({ targets: { maxNominatorsCount,
help={t<string>('Threshold stake to intend nomination.')}
label={t<string>('intention thrs')}
>
<SpinnerWrap check={minNominatorBond}>
<FormatBalance
value={minNominatorBond}
withSi
/>
</SpinnerWrap>
{minNominatorBondDefined
? <SpinnerWrap check={minNominatorBond}>
<FormatBalance
value={minNominatorBond}
withSi
/>
</SpinnerWrap>
: '-'}
</CardSummary>
</Section>
<Section>
Expand Down
27 changes: 18 additions & 9 deletions packages/page-staking/src/Overview/SummaryValidators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import React from 'react';

import { Card, CardSummary, SummaryBox } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';

Expand All @@ -24,6 +25,10 @@ function SummaryValidators ({ targets:
validatorMinActiveThreshold,
waitingIds } }: Props) {
const { t } = useTranslation();
const { api } = useApi();

const maxValidatorDefined = !!api.query.staking.maxValidatorsCount;
const minValidatorBondDefined = !!api.query.staking.minValidatorBond;

return (
<Card withBottomMargin>
Expand All @@ -34,9 +39,11 @@ function SummaryValidators ({ targets:
help={t<string>('Maximum number of validator intentions.')}
label={t<string>('max intention')}
>
<SpinnerWrap check={maxValidatorsCount}>
{maxValidatorsCount?.toNumber()}
</SpinnerWrap>
{maxValidatorDefined
? <SpinnerWrap check={maxValidatorsCount}>
{maxValidatorsCount?.toNumber()}
</SpinnerWrap>
: '-'}
</CardSummary>
</Section>
<Section>
Expand Down Expand Up @@ -66,12 +73,14 @@ function SummaryValidators ({ targets:
help={t<string>('Threshold stake among intended validators.')}
label={t<string>('intention thrs')}
>
<SpinnerWrap check={minValidatorBond}>
<FormatBalance
value={minValidatorBond}
withSi
/>
</SpinnerWrap>
{minValidatorBondDefined
? <SpinnerWrap check={minValidatorBond}>
<FormatBalance
value={minValidatorBond}
withSi
/>
</SpinnerWrap>
: '-'}
</CardSummary>
</Section>
<Section>
Expand Down
5 changes: 3 additions & 2 deletions packages/page-staking/src/useSortedTargets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,14 @@ function useSortedTargetsImpl (favorites: string[], withLedger: boolean): Sorted
api.query.staking.minValidatorBond,
api.query.balances?.totalIssuance
], OPT_MULTI);

const electedInfo = useCall<DeriveStakingElected>(api.derive.staking.electedInfo, [{ ...DEFAULT_FLAGS_ELECTED, withLedger }]);
const waitingInfo = useCall<DeriveStakingWaiting>(api.derive.staking.waitingInfo, [{ ...DEFAULT_FLAGS_WAITING, withLedger }]);
const lastEraInfo = useCall<LastEra>(api.derive.session.info, undefined, OPT_ERA);
const [stakers, setStakers] = useState<[StorageKey<[u32, AccountId32]>, PalletStakingExposure][]>([]);
const [stakersTotal, setStakersTotal] = useState<BN | undefined>();
const [nominatorMinActiveThreshold, setNominatorMinActiveThreshold] = useState<string>('');
const [nominatorMaxElectingCount, setNominatorMaxElectingCount] = useState<u32 | null>();
const [nominatorMaxElectingCount, setNominatorMaxElectingCount] = useState<u32>();
const [nominatorElectingCount, setNominatorElectingCount] = useState<number | undefined>();
const [nominatorActiveCount, setNominatorActiveCount] = useState<number | undefined>();
const [validatorActiveCount, setValidatorActiveCount] = useState<number | undefined>();
Expand Down Expand Up @@ -323,7 +324,7 @@ function useSortedTargetsImpl (favorites: string[], withLedger: boolean): Sorted

nominatorStakes.sort((a, b) => a[1].cmp(b[1]));

setNominatorMaxElectingCount(api.consts.electionProviderMultiPhase?.maxElectingVoters || null);
setNominatorMaxElectingCount(api.consts.electionProviderMultiPhase?.maxElectingVoters);

setNominatorElectingCount(assignments.size);
setNominatorActiveCount(assignments.size);
Expand Down

0 comments on commit c3122b2

Please sign in to comment.