Add a placeholder for full balance retrieval (#8734)

* Add a placeholder for full balance retrieval

* Adjust sidebar

* Add --placeholder class

* staking overview placeholder

* Adjust preimage & council

* Account Summary

* Additional

* Additionals

* Some more around staking

* Slight opacity adjustment

* Last remaining for this round

* One final for now
This commit is contained in:
Jaco 2023-01-09 17:37:40 +02:00 committed by GitHub
parent 4db9653c2b
commit f495761c0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 439 additions and 373 deletions

View File

@ -58,4 +58,9 @@ export default React.memo(styled(Apps)`
.--hidden {
display: none;
}
.--placeholder {
background: grey;
filter: blur(2px) opacity(0.25);
}
`);

View File

@ -712,7 +712,6 @@ function Account ({ account: { address, meta }, className = '', delegation, filt
address={address}
balancesAll={balancesAll}
withBalance={BAL_OPTS_DEFAULT}
withExtended={false}
/>
</td>
<td />
@ -728,7 +727,6 @@ function Account ({ account: { address, meta }, className = '', delegation, filt
balancesAll={balancesAll}
convictionLocks={convictionLocks}
withBalance={BAL_OPTS_EXPANDED}
withExtended={false}
/>
<Columar size='tiny'>
<Columar.Column>

View File

@ -19,45 +19,48 @@ function Summary ({ balance, className }: Props) {
return (
<SummaryBox className={className}>
{balance && (
<>
{balance.total.gtn(0) &&
<CardSummary label={t<string>('total balance')}>
<FormatBalance value={balance.total} />
</CardSummary>}
{balance.transferrable.gtn(0) &&
<CardSummary
className='media--900'
label={t<string>('total transferrable')}
>
<FormatBalance value={balance.transferrable} />
</CardSummary>}
{balance.locked.gtn(0) &&
<CardSummary label={t<string>('total locked')}>
<FormatBalance value={balance.locked} />
</CardSummary>}
{balance.bonded.gtn(0) &&
<CardSummary
className='media--1100'
label={t<string>('bonded')}
>
<FormatBalance value={balance.bonded} />
</CardSummary>}
{balance.redeemable.gtn(0) &&
<CardSummary
className='media--1500'
label={t<string>('redeemable')}
>
<FormatBalance value={balance.redeemable} />
</CardSummary>}
{balance.unbonding.gtn(0) &&
<CardSummary
className='media--1300'
label={t<string>('unbonding')}
>
<FormatBalance value={balance.unbonding} />
</CardSummary>}
</>)}
<CardSummary label={t<string>('total balance')}>
<FormatBalance
className={balance ? '' : '--placeholder'}
value={balance?.total || 1}
/>
</CardSummary>
<CardSummary
className='media--900'
label={t<string>('total transferrable')}
>
<FormatBalance
className={balance ? '' : '--placeholder'}
value={balance?.transferrable || 1}
/>
</CardSummary>
<CardSummary label={t<string>('total locked')}>
<FormatBalance
className={balance ? '' : '--placeholder'}
value={balance?.locked || 1}
/>
</CardSummary>
{balance?.bonded.gtn(0) &&
<CardSummary
className='media--1100'
label={t<string>('bonded')}
>
<FormatBalance value={balance.bonded} />
</CardSummary>}
{balance?.redeemable.gtn(0) &&
<CardSummary
className='media--1500'
label={t<string>('redeemable')}
>
<FormatBalance value={balance.redeemable} />
</CardSummary>}
{balance?.unbonding.gtn(0) &&
<CardSummary
className='media--1300'
label={t<string>('unbonding')}
>
<FormatBalance value={balance.unbonding} />
</CardSummary>}
</SummaryBox>
);
}

View File

@ -26,8 +26,8 @@ function Balances ({ address, className }: Props): React.ReactElement<Props> | n
<AddressInfo
address={address}
className='balanceExpander'
key={address}
withBalance={WITH_BALANCE}
withExtended={false}
withLabel
/>
</section>

View File

@ -25,7 +25,18 @@ interface Props {
const isEditable = true;
const BALANCE_OPTS = {
const BAL_OPTS_DEFAULT = {
available: false,
bonded: false,
locked: false,
redeemable: false,
reserved: false,
total: true,
unlocking: false,
vested: false
};
const BAL_OPTS_EXPANDED = {
available: true,
bonded: true,
locked: true,
@ -37,17 +48,6 @@ const BALANCE_OPTS = {
vested: true
};
const BALANCE_OPTS_ONLY = {
available: false,
bonded: false,
locked: false,
redeemable: false,
reserved: false,
total: true,
unlocking: false,
vested: false
};
function Address ({ address, className = '', filter, isFavorite, toggleFavorite }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const api = useApi();
@ -238,8 +238,7 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite
<AddressInfo
address={address}
balancesAll={balancesAll}
withBalance={BALANCE_OPTS_ONLY}
withExtended={false}
withBalance={BAL_OPTS_DEFAULT}
/>
</td>
<td />
@ -253,8 +252,7 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite
<AddressInfo
address={address}
balancesAll={balancesAll}
withBalance={BALANCE_OPTS}
withExtended={false}
withBalance={BAL_OPTS_EXPANDED}
/>
<Columar size='tiny'>
<Columar.Column>

View File

@ -5,7 +5,7 @@ import type { Member as MemberType, Rule } from '../types';
import React from 'react';
import { CardSummary, Spinner, SummaryBox } from '@polkadot/react-components';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { useIpfsLink } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';
@ -36,13 +36,13 @@ function Summary ({ className, members, rule }: Props): React.ReactElement<Props
)
: t<string>('yes')
: t<string>('no')
: <Spinner noLabel />
: <span className='--placeholder'>{t<string>('no')}</span>
}
</CardSummary>
<CardSummary label={t<string>('members')}>
{members
? formatNumber(members.length)
: <Spinner noLabel />
: <span className='--placeholder'>99</span>
}
</CardSummary>
</SummaryBox>

View File

@ -101,7 +101,6 @@ function Contract ({ className, contract, index, links, onCall }: Props): React.
address={contract.address}
withBalance
withBalanceToggle
withExtended={false}
/>
</td>
<td className='start together'>

View File

@ -8,7 +8,7 @@ import type { ComponentProps } from './types';
import React from 'react';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { BN_ZERO, formatNumber } from '@polkadot/util';
import { BN_THREE, BN_TWO, BN_ZERO, formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
@ -22,43 +22,43 @@ interface Props extends ComponentProps {
function Summary ({ bestNumber, className = '', electionsInfo, hasElections }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
if (!electionsInfo) {
return null;
}
const { candidateCount, desiredRunnersUp, desiredSeats, members, runnersUp, termDuration, voteCount } = electionsInfo;
return (
<SummaryBox className={className}>
<section>
<CardSummary label={t<string>('seats')}>
{formatNumber(members.length)}{desiredSeats && <>&nbsp;/&nbsp;{formatNumber(desiredSeats)}</>}
{electionsInfo
? <>{formatNumber(electionsInfo.members.length)}{electionsInfo.desiredSeats && <>&nbsp;/&nbsp;{formatNumber(electionsInfo.desiredSeats)}</>}</>
: <span className='--placeholder'>99</span>}
</CardSummary>
{hasElections && (
<>
<CardSummary label={t<string>('runners up')}>
{formatNumber(runnersUp.length)}{desiredRunnersUp && <>&nbsp;/&nbsp;{formatNumber(desiredRunnersUp)}</>}
{electionsInfo
? <>{formatNumber(electionsInfo.runnersUp.length)}{electionsInfo.desiredRunnersUp && <>&nbsp;/&nbsp;{formatNumber(electionsInfo.desiredRunnersUp)}</>}</>
: <span className='--placeholder'>99</span>}
</CardSummary>
<CardSummary label={t<string>('candidates')}>
{formatNumber(candidateCount)}
{electionsInfo
? formatNumber(electionsInfo.candidateCount)
: <span className='--placeholder'>99</span>}
</CardSummary>
</>
)}
</section>
{voteCount && (
{electionsInfo && electionsInfo.voteCount && (
<section>
<CardSummary label={t<string>('voting round')}>
#{formatNumber(voteCount)}
#{formatNumber(electionsInfo.voteCount)}
</CardSummary>
</section>
)}
{bestNumber && termDuration && termDuration.gt(BN_ZERO) && (
{electionsInfo && bestNumber && electionsInfo.termDuration && electionsInfo.termDuration.gt(BN_ZERO) && (
<section>
<CardSummary
label={t<string>('term progress')}
progress={{
total: termDuration,
value: bestNumber.mod(termDuration),
total: (electionsInfo && bestNumber) ? electionsInfo.termDuration : BN_THREE,
value: (electionsInfo && bestNumber) ? bestNumber.mod(electionsInfo.termDuration) : BN_TWO,
withTime: true
}}
/>

View File

@ -26,20 +26,20 @@ function Voters ({ balance, voters }: Props): React.ReactElement<Props> {
[voters]
);
if (!balance || !voters || !voters.length) {
return <><td className='all number' /><td className='number' /></>;
}
return (
<>
<td className='expand'>
<ExpanderScroll
className={balance ? '' : '--placeholder'}
renderChildren={renderVoters}
summary={<FormatBalance value={balance} />}
/>
</td>
<td className='number'>
{formatNumber(voters.length)}
{voters
? formatNumber(voters.length)
: <span className='--placeholder'>123</span>
}
</td>
</>
);

View File

@ -7,7 +7,7 @@ import React from 'react';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { useApi, useBestNumber, useCall, useCallMulti } from '@polkadot/react-hooks';
import { BN_ONE, formatNumber } from '@polkadot/util';
import { BN_ONE, BN_THREE, BN_TWO, formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
@ -33,32 +33,41 @@ function Summary ({ referendumCount }: Props): React.ReactElement<Props> {
<SummaryBox>
<section>
<CardSummary label={t<string>('proposals')}>
{formatNumber(activeProposals?.length)}
{activeProposals
? formatNumber(activeProposals.length)
: <span className='--placeholder'>99</span>}
</CardSummary>
<CardSummary label={t<string>('total')}>
{formatNumber(publicPropCount)}
{publicPropCount
? formatNumber(publicPropCount)
: <span className='--placeholder'>99</span>}
</CardSummary>
</section>
<section>
<CardSummary label={t<string>('referenda')}>
{formatNumber(referendumCount || 0)}
{referendumCount !== undefined
? formatNumber(referendumCount)
: <span className='--placeholder'>99</span>}
</CardSummary>
<CardSummary label={t<string>('total')}>
{formatNumber(referendumTotal || 0)}
{referendumTotal
? formatNumber(referendumTotal)
: <span className='--placeholder'>99</span>}
</CardSummary>
</section>
{bestNumber && (
<section className='media--1100'>
<CardSummary
label={t<string>('launch period')}
progress={{
total: api.consts.democracy.launchPeriod,
value: bestNumber.mod(api.consts.democracy.launchPeriod).iadd(BN_ONE),
withTime: true
}}
/>
</section>
)}
<section className='media--1100'>
<CardSummary
label={t<string>('launch period')}
progress={{
isBlurred: !bestNumber,
total: api.consts.democracy.launchPeriod,
value: bestNumber
? bestNumber.mod(api.consts.democracy.launchPeriod).iadd(BN_ONE)
: api.consts.democracy.launchPeriod.mul(BN_TWO).div(BN_THREE),
withTime: true
}}
/>
</section>
</SummaryBox>
);
}

View File

@ -9,7 +9,7 @@ import React from 'react';
import { CardSummary } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { Elapsed } from '@polkadot/react-query';
import { BN_ONE, formatNumber } from '@polkadot/util';
import { BN_THREE, BN_TWO, formatNumber } from '@polkadot/util';
import { useTranslation } from './translate';
@ -26,44 +26,56 @@ function SummarySession ({ className, withEra = true, withSession = true }: Prop
const forcing = useCall<Forcing>(api.query.staking?.forceEra);
const eraLabel = t<string>('era');
const sessionLabel = sessionInfo?.isEpoch
const sessionLabel = api.query.babe
? t<string>('epoch')
: t<string>('session');
const activeEraStart = sessionInfo?.activeEraStart.unwrapOr(null);
return (
<>
{sessionInfo && (
{api.derive.session && (
<>
{withSession && (
sessionInfo.sessionLength.gt(BN_ONE)
api.query.babe
? (
<CardSummary
className={className}
label={sessionLabel}
progress={{
total: sessionInfo.sessionLength,
value: sessionInfo.sessionProgress,
isBlurred: !sessionInfo,
total: sessionInfo?.sessionLength || BN_THREE,
value: sessionInfo?.sessionProgress || BN_TWO,
withTime: true
}}
/>
)
: (
<CardSummary label={sessionLabel}>
#{formatNumber(sessionInfo.currentIndex)}
#{sessionInfo
? formatNumber(sessionInfo.currentIndex)
: <span className='--placeholder'>123</span>}
{withEra && activeEraStart && <div className='isSecondary'>&nbsp;</div>}
</CardSummary>
)
)}
{forcing && !forcing.isForceNone && withEra && (
sessionInfo.sessionLength.gt(BN_ONE)
{withEra && (
api.query.babe
? (
<CardSummary
className={className}
label={eraLabel}
progress={{
total: forcing.isForceAlways ? sessionInfo.sessionLength : sessionInfo.eraLength,
value: forcing.isForceAlways ? sessionInfo.sessionProgress : sessionInfo.eraProgress,
isBlurred: !(sessionInfo && forcing),
total: sessionInfo && forcing
? forcing.isForceAlways
? sessionInfo.sessionLength
: sessionInfo.eraLength
: BN_THREE,
value: sessionInfo && forcing
? forcing.isForceAlways
? sessionInfo.sessionProgress
: sessionInfo.eraProgress
: BN_TWO,
withTime: true
}}
/>
@ -73,10 +85,12 @@ function SummarySession ({ className, withEra = true, withSession = true }: Prop
className={className}
label={eraLabel}
>
#{formatNumber(sessionInfo.activeEra)}
#{sessionInfo
? formatNumber(sessionInfo.activeEra)
: <span className='--placeholder'>123</span>}
{activeEraStart && (
<Elapsed
className='isSecondary'
className={`${sessionInfo ? '' : '--placeholder'} isSecondary`}
value={activeEraStart}
>
&nbsp;{t('elapsed')}

View File

@ -30,12 +30,16 @@ function Summary ({ auctionInfo, className, lastWinners }: Props): React.ReactEl
<SummaryBox className={className}>
<section>
<CardSummary label={t<string>('auctions')}>
{formatNumber(auctionInfo?.numAuctions)}
{auctionInfo
? formatNumber(auctionInfo.numAuctions)
: <span className='--placeholder'>99</span>}
</CardSummary>
<CardSummary label={t<string>('active')}>
{auctionInfo?.leasePeriod
? t<string>('yes')
: t<string>('no')
{auctionInfo
? auctionInfo.leasePeriod
? t<string>('yes')
: t<string>('no')
: <span className='--placeholder'>{t<string>('no')}</span>
}
</CardSummary>
</section>

View File

@ -6,7 +6,7 @@ import type { Campaign, LeasePeriod } from '../types';
import React, { useEffect, useMemo, useState } from 'react';
import { AddressMini, Expander, Icon, ParaLink, Spinner, Table, TxButton } from '@polkadot/react-components';
import { AddressMini, Expander, Icon, ParaLink, Table, TxButton } from '@polkadot/react-components';
import { useAccounts, useApi, useParaEndpoints } from '@polkadot/react-hooks';
import { BlockToTime, FormatBalance } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';
@ -129,9 +129,8 @@ function Fund ({ bestHash, bestNumber, className = '', isOngoing, leasePeriod, v
)}
</td>
<td className='number together media--1100'>
{!hasLoaded
? <Spinner noLabel />
: (
{hasLoaded
? (
<>
{bestHash && (
<Icon
@ -148,7 +147,9 @@ function Fund ({ bestHash, bestNumber, className = '', isOngoing, leasePeriod, v
formatNumber(contributorsHex.length)
)}
</>
)}
)
: <span className='--placeholder'>999</span>
}
</td>
<td className='button media--1000'>
{canWithdraw && contributorsHex.length !== 0 && (

View File

@ -7,7 +7,7 @@ import React from 'react';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { FormatBalance } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';
import { BN_THREE, BN_TWO, formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
@ -15,56 +15,65 @@ interface Props {
activeCap: BN;
activeRaised: BN;
className?: string;
fundCount: number;
fundCount?: number;
isLoading?: boolean;
totalCap: BN;
totalRaised: BN;
}
function Summary ({ activeCap, activeRaised, className, fundCount, totalCap, totalRaised }: Props): React.ReactElement<Props> {
function Summary ({ activeCap, activeRaised, className, fundCount, isLoading, totalCap, totalRaised }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
return (
<SummaryBox className={className}>
<CardSummary label={t<string>('funds')}>
{formatNumber(fundCount)}
{fundCount === undefined
? <span className='--placeholder'>99</span>
: formatNumber(fundCount)}
</CardSummary>
<CardSummary
label={`${t<string>('active raised / cap')}`}
progress={{
hideValue: true,
total: activeCap,
value: activeRaised
isBlurred: isLoading,
total: isLoading ? BN_THREE : activeCap,
value: isLoading ? BN_TWO : activeRaised
}}
>
<FormatBalance
value={activeRaised}
withCurrency={false}
withSi
/>
&nbsp;/&nbsp;
<FormatBalance
value={activeCap}
withSi
/>
<span className={isLoading ? '--placeholder' : ''}>
<FormatBalance
value={activeRaised}
withCurrency={false}
withSi
/>
&nbsp;/&nbsp;
<FormatBalance
value={activeCap}
withSi
/>
</span>
</CardSummary>
<CardSummary
label={`${t<string>('total raised / cap')}`}
progress={{
hideValue: true,
total: totalCap,
value: totalRaised
isBlurred: isLoading,
total: isLoading ? BN_THREE : totalCap,
value: isLoading ? BN_TWO : totalRaised
}}
>
<FormatBalance
value={totalRaised}
withCurrency={false}
withSi
/>
&nbsp;/&nbsp;
<FormatBalance
value={totalCap}
withSi
/>
<span className={isLoading ? '--placeholder' : ''}>
<FormatBalance
value={totalRaised}
withCurrency={false}
withSi
/>
&nbsp;/&nbsp;
<FormatBalance
value={totalCap}
withSi
/>
</span>
</CardSummary>
</SummaryBox>
);

View File

@ -20,7 +20,7 @@ interface Props {
ownedIds: OwnedId[];
}
function Crowdloan ({ auctionInfo, campaigns: { activeCap, activeRaised, funds, totalCap, totalRaised }, className, leasePeriod, ownedIds }: Props): React.ReactElement<Props> {
function Crowdloan ({ auctionInfo, campaigns: { activeCap, activeRaised, funds, isLoading, totalCap, totalRaised }, className, leasePeriod, ownedIds }: Props): React.ReactElement<Props> {
const bestNumber = useBestNumber();
return (
@ -28,7 +28,8 @@ function Crowdloan ({ auctionInfo, campaigns: { activeCap, activeRaised, funds,
<Summary
activeCap={activeCap}
activeRaised={activeRaised}
fundCount={funds ? funds.length : 0}
fundCount={funds?.length}
isLoading={isLoading}
totalCap={totalCap}
totalRaised={totalRaised}
/>

View File

@ -104,23 +104,20 @@ function Parachain ({ bestNumber, className = '', id, lastBacked, lastInclusion,
<ParaLink id={id} />
</td>
<td className='number media--1400'>
{validators && validators[1].length !== 0 && (
<Expander
renderChildren={valRender}
summary={t<string>('Val. Group {{group}} ({{count}})', {
replace: {
count: formatNumber(validators[1].length),
group: validators[0]
}
})}
/>
)}
{nonBacked && (
<Expander
renderChildren={bckRender}
summary={t<string>('Non-voters ({{count}})', { replace: { count: formatNumber(nonBacked.length) } })}
/>
)}
<Expander
className={validators ? '' : '--placeholder'}
renderChildren={valRender}
summary={t<string>('Val. Group {{group}} ({{count}})', {
replace: {
count: formatNumber(validators?.[1]?.length || 0),
group: validators ? validators[0] : 0
}
})}
/>
<Expander
renderChildren={bckRender}
summary={t<string>('Non-voters ({{count}})', { replace: { count: formatNumber(nonBacked.length) } })}
/>
</td>
<td className='start together hash media--1500'>{paraInfo.headHex}</td>
<td className='start'>

View File

@ -8,7 +8,7 @@ import React from 'react';
import SummarySession from '@polkadot/app-explorer/SummarySession';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { BestFinalized } from '@polkadot/react-query';
import { formatNumber, isNumber } from '@polkadot/util';
import { BN_THREE, BN_TWO, formatNumber, isNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
@ -25,19 +25,19 @@ function Summary ({ leasePeriod, parachainCount, proposalCount, upcomingCount }:
return (
<SummaryBox>
<section>
{isNumber(parachainCount) && (
<CardSummary label={t<string>('parachains')}>
{formatNumber(parachainCount)}
</CardSummary>
)}
{isNumber(upcomingCount) && (
<CardSummary
className='media--1000'
label={t<string>('parathreads')}
>
{formatNumber(upcomingCount)}
</CardSummary>
)}
<CardSummary label={t<string>('parachains')}>
{isNumber(parachainCount)
? formatNumber(parachainCount)
: <span className='--placeholder'>99</span>}
</CardSummary>
<CardSummary
className='media--1000'
label={t<string>('parathreads')}
>
{isNumber(upcomingCount)
? formatNumber(upcomingCount)
: <span className='--placeholder'>99</span>}
</CardSummary>
{isNumber(proposalCount) && (
<CardSummary
className='media--1000'
@ -48,22 +48,21 @@ function Summary ({ leasePeriod, parachainCount, proposalCount, upcomingCount }:
)}
</section>
<section>
{leasePeriod && (
<>
<CardSummary label={t<string>('current lease')}>
{formatNumber(leasePeriod.currentPeriod)}
</CardSummary>
<CardSummary
className='media--1200'
label={t<string>('lease period')}
progress={{
total: leasePeriod.length,
value: leasePeriod.progress,
withTime: true
}}
/>
</>
)}
<CardSummary label={t<string>('current lease')}>
{leasePeriod
? formatNumber(leasePeriod.currentPeriod)
: <span className='--placeholder'>99</span>}
</CardSummary>
<CardSummary
className='media--1200'
label={t<string>('lease period')}
progress={{
isBlurred: !leasePeriod,
total: leasePeriod ? leasePeriod.length : BN_THREE,
value: leasePeriod ? leasePeriod.progress : BN_TWO,
withTime: true
}}
/>
</section>
<section>
<CardSummary label={t<string>('finalized')}>

View File

@ -45,6 +45,7 @@ export interface Campaigns {
activeCap: BN;
activeRaised: BN;
funds: Campaign[] | null;
isLoading?: boolean;
totalCap: BN;
totalRaised: BN;
}

View File

@ -19,6 +19,7 @@ const EMPTY: Campaigns = {
activeCap: BN_ZERO,
activeRaised: BN_ZERO,
funds: null,
isLoading: true,
totalCap: BN_ZERO,
totalRaised: BN_ZERO
};

View File

@ -25,15 +25,21 @@ function Preimage ({ className, value }: Props): React.ReactElement<Props> {
<Hash value={value} />
<Call value={info} />
<td className='number media--1000'>
{info?.bytes && formatNumber(info.bytes.length)}
{info?.bytes
? formatNumber(info.bytes.length)
: <span className='--placeholder'>999,999</span>
}
</td>
<td className='preimage-status together media--1200'>
{info && (
<>
<div>{info.status?.type}{info.count !== 0 && <>&nbsp;/&nbsp;{formatNumber(info.count)}</>}</div>
<Free value={info} />
</>
)}
{info
? (
<>
<div>{info.status?.type}{info.count !== 0 && <>&nbsp;/&nbsp;{formatNumber(info.count)}</>}</div>
<Free value={info} />
</>
)
: <span className='--placeholder'>Unrequested</span>
}
</td>
</tr>
);

View File

@ -3,7 +3,7 @@
import React from 'react';
import { CardSummary, Spinner, SummaryBox } from '@polkadot/react-components';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
@ -20,7 +20,7 @@ function Summary ({ className, hashes }: Props): React.ReactElement<Props> {
<SummaryBox className={className}>
<CardSummary label={t<string>('images')}>
{hashes === undefined
? <Spinner noLabel />
? <span className='--placeholder'>99</span>
: formatNumber(hashes.length)
}
</CardSummary>

View File

@ -5,7 +5,7 @@ import type { Member as MemberType } from '../types';
import React from 'react';
import { CardSummary, Spinner, SummaryBox } from '@polkadot/react-components';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
@ -22,7 +22,7 @@ function Summary ({ className, members }: Props): React.ReactElement<Props> {
<SummaryBox className={className}>
<CardSummary label={t<string>('members')}>
{members === undefined
? <Spinner noLabel />
? <span className='--placeholder'>99</span>
: formatNumber(members.length)
}
</CardSummary>

View File

@ -6,7 +6,7 @@ import type { Summary as SummaryType } from '../types';
import React from 'react';
import { CardSummary, Spinner, SummaryBox } from '@polkadot/react-components';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { FormatBalance } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';
@ -29,27 +29,19 @@ function Summary ({ className, issuanceActive, issuanceInactive, issuanceTotal,
<section>
<CardSummary label={t<string>('active')}>
{refActive === undefined
? <Spinner noLabel />
? <span className='--placeholder'>99</span>
: formatNumber(refActive)
}
</CardSummary>
<CardSummary label={t<string>('total')}>
{refCount === undefined
? <Spinner noLabel />
? <span className='--placeholder'>99</span>
: formatNumber(refCount)
}
</CardSummary>
</section>
{withIssuance && (
<section>
{issuanceTotal && (
<CardSummary label={t<string>('total issuance')}>
<FormatBalance
value={issuanceTotal}
withSi
/>
</CardSummary>
)}
{issuanceInactive && (
<CardSummary
className='media--1000'
@ -72,6 +64,13 @@ function Summary ({ className, issuanceActive, issuanceInactive, issuanceTotal,
/>
</CardSummary>
)}
<CardSummary label={t<string>('total issuance')}>
<FormatBalance
className={issuanceTotal ? '' : '--placeholder'}
value={issuanceTotal || 1}
withSi
/>
</CardSummary>
</section>
)}
</SummaryBox>

View File

@ -8,7 +8,7 @@ import type { ListNode, StashNode } from './types';
import React, { useEffect, useState } from 'react';
import { AddressMini, Spinner } from '@polkadot/react-components';
import { AddressMini } from '@polkadot/react-components';
import { FormatBalance } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';
@ -81,7 +81,7 @@ function Bag ({ bagLower, bagUpper, info, nodesOwn }: Props): React.ReactElement
</td>
<td className='number'>
{isLoading
? <Spinner noLabel />
? <span className='--placeholder'>99</span>
: list.length
? formatNumber(list.length)
: null

View File

@ -6,7 +6,7 @@ import type { BagMap } from './types';
import React, { useMemo } from 'react';
import { CardSummary, Spinner, SummaryBox } from '@polkadot/react-components';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { useCall } from '@polkadot/react-hooks';
import { formatNumber, isNumber } from '@polkadot/util';
@ -34,20 +34,20 @@ function Summary ({ bags, className = '', mapOwn }: Props): React.ReactElement<P
<CardSummary label={t<string>('total bags')}>
{bags
? formatNumber(bags.length)
: <Spinner noLabel />
: <span className='--placeholder'>99</span>
}
</CardSummary>
<section>
<CardSummary label={t<string>('total nodes')}>
{mapOwn
? formatNumber(total)
: <Spinner noLabel />
: <span className='--placeholder'>99</span>
}
</CardSummary>
<CardSummary label={t<string>('my nodes')}>
{isNumber(myCount)
? formatNumber(myCount)
: '-'
: <span className='--placeholder'>99</span>
}
</CardSummary>
</section>

View File

@ -8,6 +8,7 @@ import React, { useEffect, useState } from 'react';
import { AddressSmall } from '@polkadot/react-components';
import { BlockToTime, FormatBalance } from '@polkadot/react-query';
import { BN_MILLION } from '@polkadot/util';
import useEraBlocks from './useEraBlocks';
import { createErasString } from './util';
@ -46,7 +47,12 @@ function Stash ({ className = '', historyDepth, payout: { available, rewards, st
<span className='payout-eras'>{eraStr}</span>
</td>
<td className='number'><FormatBalance value={available} /></td>
<td className='number'>{eraBlocks && <BlockToTime value={eraBlocks} />}</td>
<td className='number'>
<BlockToTime
className={eraBlocks ? '' : '--placeholder'}
value={eraBlocks || BN_MILLION}
/>
</td>
<td
className='button'
colSpan={3}

View File

@ -57,12 +57,23 @@ function Pool ({ className = '', members, ownAccounts, params, poolId }: Props):
<tr className={className}>
<Table.Column.Id value={poolId} />
<td className='start'>
{info && (
<div className={isExpanded ? '' : 'clamp'}>{info.metadata}</div>
)}
<div className={`${isExpanded ? '' : 'clamp'}`}>
{info
? info.metadata
: <span className='--placeholder'>This is a pool placeholder</span>}
</div>
</td>
<td className='number media--1100'>
{info
? info.bonded.state.type
: <span className='--placeholder'>Destroying</span>}
</td>
<td className='number'>
<FormatBalance
className={info ? '' : '--placeholder'}
value={info?.bonded.points || 1}
/>
</td>
<td className='number media--1100'>{info && info.bonded.state.type}</td>
<td className='number'>{info && <FormatBalance value={info.bonded.points} />}</td>
<td className='number media--1400'>{info && !info.rewardClaimable.isZero() && <FormatBalance value={info.rewardClaimable} />}</td>
<td className='number'>
{info && info.nominating.length !== 0 && (

View File

@ -10,7 +10,7 @@ import React, { useMemo } from 'react';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';
import { BN_ZERO } from '@polkadot/util';
import { BN_THREE, BN_TWO, BN_ZERO } from '@polkadot/util';
import { useTranslation } from '../translate';
@ -29,6 +29,7 @@ interface Props {
interface ProgressInfo {
hideValue: true;
isBlurred: boolean;
total: BN;
value: BN;
}
@ -38,14 +39,13 @@ const OPT_REWARD = {
optBalance.unwrapOrDefault()
};
function getProgressInfo (value?: BN, total?: BN): ProgressInfo | undefined {
return value && total && !total.isZero()
? {
hideValue: true,
total,
value
}
: undefined;
function getProgressInfo (value?: BN, total?: BN): ProgressInfo {
return {
hideValue: true,
isBlurred: !(value && total),
total: (value && total) ? total : BN_THREE,
value: (value && total) ? value : BN_TWO
};
}
function Summary ({ avgStaked, lastEra, lowStaked, minNominated, minNominatorBond, stakedReturn, totalIssuance, totalStaked }: Props): React.ReactElement<Props> {
@ -66,43 +66,46 @@ function Summary ({ avgStaked, lastEra, lowStaked, minNominated, minNominatorBon
return (
<SummaryBox>
<section className='media--800'>
{progressStake && (
<CardSummary
label={t<string>('total staked')}
progress={progressStake}
>
<FormatBalance
value={totalStaked}
withSi
/>
</CardSummary>
)}
<CardSummary
label={t<string>('total staked')}
progress={progressStake}
>
<FormatBalance
className={progressStake.isBlurred ? '--placeholder' : ''}
value={progressStake.total}
withSi
/>
</CardSummary>
</section>
<section className='media--800'>
{totalIssuance && (stakedReturn > 0) && Number.isFinite(stakedReturn) && (
<CardSummary label={t<string>('returns')}>
{stakedReturn.toFixed(1)}%
</CardSummary>
)}
<CardSummary label={t<string>('returns')}>
{totalIssuance && (stakedReturn > 0)
? Number.isFinite(stakedReturn)
? <>{stakedReturn.toFixed(1)}%</>
: '-.-%'
: <span className='--placeholder'>0.0%</span>
}
</CardSummary>
</section>
<section className='media--1000'>
{progressAvg && (
<CardSummary
label={`${t<string>('lowest / avg staked')}`}
progress={progressAvg}
>
<CardSummary
label={`${t<string>('lowest / avg staked')}`}
progress={progressAvg}
>
<span className={progressAvg.isBlurred ? '--placeholder' : ''}>
<FormatBalance
value={lowStaked}
value={progressAvg.value}
withCurrency={false}
withSi
/>
&nbsp;/&nbsp;
<FormatBalance
value={avgStaked}
className={progressAvg.isBlurred ? '--placeholder' : ''}
value={progressAvg.total}
withSi
/>
</CardSummary>
)}
</span>
</CardSummary>
</section>
<section className='media--1600'>
{minNominated?.gt(BN_ZERO) && (
@ -131,14 +134,13 @@ function Summary ({ avgStaked, lastEra, lowStaked, minNominated, minNominatorBon
)}
</section>
<section>
{lastReward?.gt(BN_ZERO) && (
<CardSummary label={t<string>('last reward')}>
<FormatBalance
value={lastReward}
withSi
/>
</CardSummary>
)}
<CardSummary label={t<string>('last reward')}>
<FormatBalance
className={lastReward ? '' : '--placeholder'}
value={lastReward || 1}
withSi
/>
</CardSummary>
</section>
</SummaryBox>
);

View File

@ -67,30 +67,27 @@ function StakeOther ({ nominators, stakeOther }: Props): React.ReactElement<Prop
return (
<td className='expand all'>
{rewarded && (
<>
<ExpanderScroll
renderChildren={rewarded[1]}
summary={
<FormatBalance
labelPost={` (${rewarded[0]})`}
value={rewardedTotal}
/>
}
<ExpanderScroll
className={rewarded ? '' : '--placeholder'}
renderChildren={rewarded && rewarded[1]}
summary={
<FormatBalance
labelPost={` (${rewarded ? rewarded[0] : '0'})`}
value={rewardedTotal}
/>
{unrewarded && (
<ExpanderScroll
className='stakeOver'
renderChildren={unrewarded[1]}
summary={
<FormatBalance
labelPost={` (${unrewarded[0]})`}
value={unrewardedTotal}
/>
}
}
/>
{unrewarded && (
<ExpanderScroll
className='stakeOver'
renderChildren={unrewarded[1]}
summary={
<FormatBalance
labelPost={` (${unrewarded[0]})`}
value={unrewardedTotal}
/>
)}
</>
}
/>
)}
</td>
);

View File

@ -167,7 +167,7 @@ function Address ({ address, className = '', filterName, hasQueries, isElected,
)
}
<td className='number'>
{commission}
{commission || <span className='--placeholder'>50.00%</span>}
</td>
{isMain && (
<td className='number'>

View File

@ -8,7 +8,7 @@ import React from 'react';
import styled from 'styled-components';
import SummarySession from '@polkadot/app-explorer/SummarySession';
import { CardSummary, Spinner, SummaryBox } from '@polkadot/react-components';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
@ -29,7 +29,7 @@ function Summary ({ className = '', stakingOverview, targets: { counterForNomina
<CardSummary label={t<string>('validators')}>
{stakingOverview
? <>{formatNumber(stakingOverview.validators.length)}&nbsp;/&nbsp;{formatNumber(stakingOverview.validatorCount)}</>
: <Spinner noLabel />
: <span className='--placeholder'>99&nbsp;/&nbsp;99</span>
}
</CardSummary>
<CardSummary
@ -38,7 +38,7 @@ function Summary ({ className = '', stakingOverview, targets: { counterForNomina
>
{waitingIds
? formatNumber(waitingIds.length)
: <Spinner noLabel />
: <span className='--placeholder'>99</span>
}
</CardSummary>
<CardSummary
@ -58,7 +58,7 @@ function Summary ({ className = '', stakingOverview, targets: { counterForNomina
)}
</>
)
: <Spinner noLabel />
: <span className='--placeholder'>99</span>
}
</CardSummary>
</section>

View File

@ -8,7 +8,7 @@ import React, { useMemo } from 'react';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { useApi, useBestNumber, useCall, useTreasury } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';
import { formatNumber } from '@polkadot/util';
import { BN_THREE, BN_TWO, BN_ZERO, formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
@ -29,6 +29,8 @@ function Summary ({ approvalCount, proposalCount }: Props): React.ReactElement<P
[value, pendingBounties, pendingProposals]
);
const hasSpendable = !!(value && spendable);
return (
<SummaryBox>
<section>
@ -36,19 +38,25 @@ function Summary ({ approvalCount, proposalCount }: Props): React.ReactElement<P
className='media--1700'
label={t<string>('open')}
>
{formatNumber(proposalCount)}
{proposalCount === undefined
? <span className='--placeholder'>99</span>
: formatNumber(proposalCount)}
</CardSummary>
<CardSummary
className='media--1600'
label={t<string>('approved')}
>
{formatNumber(approvalCount)}
{approvalCount === undefined
? <span className='--placeholder'>99</span>
: formatNumber(approvalCount)}
</CardSummary>
<CardSummary
className='media--1400'
label={t<string>('total')}
>
{formatNumber(totalProposals || 0)}
{totalProposals === undefined
? totalProposals
: formatNumber(totalProposals)}
</CardSummary>
</section>
<section>
@ -74,41 +82,41 @@ function Summary ({ approvalCount, proposalCount }: Props): React.ReactElement<P
/>
</CardSummary>
)}
{burn && (
<CardSummary
className='media--1300'
label={t<string>('next burn')}
>
<FormatBalance
value={burn}
withSi
/>
</CardSummary>
)}
<CardSummary
className='media--1300'
label={t<string>('next burn')}
>
<FormatBalance
className={burn ? '' : '--placeholder'}
value={burn || 1}
withSi
/>
</CardSummary>
</section>
{value && spendable && (
<section>
<CardSummary
label={t<string>('spendable / available')}
progress={{
hideValue: true,
total: value,
value: spendable
}}
>
<section>
<CardSummary
label={t<string>('spendable / available')}
progress={{
hideValue: true,
isBlurred: !hasSpendable,
total: hasSpendable ? value : BN_THREE,
value: hasSpendable ? spendable : BN_TWO
}}
>
<span className={hasSpendable ? '' : '--placeholder'}>
<FormatBalance
value={spendable}
value={spendable || BN_TWO}
withSi
/>
<>&nbsp;/&nbsp;</>
<FormatBalance
value={value}
value={value || BN_THREE}
withSi
/>
</CardSummary>
</section>
)}
{bestNumber && spendPeriod?.gtn(0) && (
</span>
</CardSummary>
</section>
{bestNumber && spendPeriod.gt(BN_ZERO) && (
<section>
<CardSummary
label={t<string>('spend period')}

View File

@ -3,7 +3,7 @@
import React from 'react';
import { CardSummary, Spinner, SummaryBox } from '@polkadot/react-components';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
@ -20,7 +20,7 @@ function Summary ({ className, hashes }: Props): React.ReactElement<Props> {
<SummaryBox className={className}>
<CardSummary label={t<string>('hashes')}>
{hashes === undefined
? <Spinner noLabel />
? <span className='--placeholder'>99</span>
: formatNumber(hashes.length)
}
</CardSummary>

View File

@ -109,6 +109,9 @@ function lookupLock (lookup: Record<string, string>, lockId: Raw): string {
// skip balances retrieval of none of this matches
function skipBalancesIf ({ withBalance = true, withExtended = false }: Props): boolean {
// NOTE Unsure why we don't have a check for balancesAll in here (check skipStakingIf). adding
// it doesn't break on Accounts/Addresses, but this gets used a lot, so there _may_ be an actual
// reason behind the madness. However, derives are memoized, so no issue overall.
if (withBalance === true || withExtended === true) {
return false;
} else if (isObject(withBalance)) {
@ -231,18 +234,18 @@ function renderValidatorPrefs ({ stakingInfo, withValidatorPrefs = false }: Prop
);
}
function createBalanceItems (formatIndex: number, lookup: Record<string, string>, t: TFunction, { address, balanceDisplay, balancesAll, bestNumber, convictionLocks, democracyLocks, isAllLocked, otherBonded, ownBonded, stakingInfo, votingOf, withBalanceToggle, withLabel }: { address: string; balanceDisplay: BalanceActiveType; balancesAll?: DeriveBalancesAll | DeriveBalancesAccountData; bestNumber: BlockNumber; convictionLocks?: RefLock[]; democracyLocks?: DeriveDemocracyLock[]; isAllLocked: boolean; otherBonded: BN[]; ownBonded: BN; stakingInfo?: DeriveStakingAccount; votingOf?: Voting; withBalanceToggle: boolean, withLabel: boolean }): React.ReactNode {
function createBalanceItems (formatIndex: number, lookup: Record<string, string>, t: TFunction, { address, balanceDisplay, balancesAll, bestNumber, convictionLocks, democracyLocks, isAllLocked, otherBonded, ownBonded, stakingInfo, votingOf, withBalanceToggle, withLabel }: { address: string; balanceDisplay: BalanceActiveType; balancesAll?: DeriveBalancesAll | DeriveBalancesAccountData; bestNumber?: BlockNumber; convictionLocks?: RefLock[]; democracyLocks?: DeriveDemocracyLock[]; isAllLocked: boolean; otherBonded: BN[]; ownBonded: BN; stakingInfo?: DeriveStakingAccount; votingOf?: Voting; withBalanceToggle: boolean, withLabel: boolean }): React.ReactNode {
const allItems: React.ReactNode[] = [];
const deriveBalances = balancesAll as DeriveBalancesAll;
!withBalanceToggle && balancesAll && balanceDisplay.total && allItems.push(
!withBalanceToggle && balanceDisplay.total && allItems.push(
<React.Fragment key={0}>
<Label label={withLabel ? t<string>('total') : ''} />
<FormatBalance
className='result'
className={`result ${balancesAll ? '' : '--placeholder'}`}
formatIndex={formatIndex}
labelPost={<IconVoid />}
value={balancesAll.freeBalance.add(balancesAll.reservedBalance)}
value={balancesAll ? balancesAll.freeBalance.add(balancesAll.reservedBalance) : 1}
/>
</React.Fragment>
);
@ -258,7 +261,7 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
</React.Fragment>
);
if (balanceDisplay.vested && deriveBalances?.isVesting) {
if (bestNumber && balanceDisplay.vested && deriveBalances?.isVesting) {
const allVesting = deriveBalances.vesting.filter(({ endBlock }) => bestNumber.lt(endBlock));
allItems.push(
@ -427,7 +430,7 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
</div>
</React.Fragment>
);
} else if (votingOf && votingOf.isDirect) {
} else if (bestNumber && votingOf && votingOf.isDirect) {
const { prior: [unlockAt, balance] } = votingOf.asDirect;
balance.gt(BN_ZERO) && unlockAt.gt(BN_ZERO) && allItems.push(
@ -440,7 +443,7 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
);
}
if (convictionLocks && convictionLocks.length) {
if (bestNumber && convictionLocks && convictionLocks.length) {
const max = convictionLocks.reduce((max, { total }) => bnMax(max, total), BN_ZERO);
allItems.push(
@ -498,6 +501,7 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
return (
<React.Fragment key={formatIndex}>
<Expander
className={balancesAll ? '' : 'isBlurred'}
summary={
<FormatBalance
formatIndex={formatIndex}
@ -528,7 +532,7 @@ function renderBalances (props: Props, lookup: Record<string, string>, bestNumbe
? DEFAULT_BALANCES
: withBalance || false;
if (!bestNumber || !balanceDisplay) {
if (!balanceDisplay) {
return [null];
}

View File

@ -16,6 +16,7 @@ import Progress from './Progress';
interface ProgressProps {
hideGraph?: boolean;
hideValue?: boolean;
isBlurred?: boolean;
isPercent?: boolean;
total?: BN | UInt;
value?: BN | UInt;
@ -70,7 +71,10 @@ function CardSummary ({ children, className = '', help, label, progress }: Props
progress && !progress.hideValue && (
<>
{isTimed && !children && (
<BlockToTime value={progress.total} />
<BlockToTime
className={progress.isBlurred ? '--placeholder' : ''}
value={progress.total}
/>
)}
<div className={isTimed ? 'isSecondary' : 'isPrimary'}>
{!left || isUndefined(progress.total)

View File

@ -11,6 +11,7 @@ import { bnToBn } from '@polkadot/util';
interface Props {
className?: string;
isBlurred?: boolean;
isDisabled?: boolean;
total?: UInt | BN | number | null;
value?: UInt | BN | number | null;
@ -34,7 +35,7 @@ function DivClip ({ angle, type }: RotateProps): React.ReactElement<RotateProps>
const Clip = React.memo(DivClip);
function Progress ({ className = '', isDisabled, total, value }: Props): React.ReactElement<Props> | null {
function Progress ({ className = '', isBlurred, isDisabled, total, value }: Props): React.ReactElement<Props> | null {
const _total = bnToBn(total || 0);
const angle = _total.gtn(0)
? (bnToBn(value || 0).muln(36000).div(_total).toNumber() / 100)
@ -47,7 +48,7 @@ function Progress ({ className = '', isDisabled, total, value }: Props): React.R
const drawAngle = (angle === 360) ? 360 : angle % 360;
return (
<div className={`ui--Progress${isDisabled ? ' isDisabled' : ''} ${className}`}>
<div className={`ui--Progress ${isDisabled ? 'isDisabled' : ''} ${isBlurred ? '--placeholder' : ''} ${className}`}>
<div className='background highlight--bg' />
<Clip
angle={

View File

@ -20,11 +20,9 @@ function BestFinalized ({ children, className = '', label }: Props): React.React
const bestNumberFinalized = useCall<BlockNumber>(api.derive.chain.bestNumberFinalized);
return (
<div className={className}>
<div className={`${className} ${bestNumberFinalized ? '' : '--placeholder'}`}>
{label || ''}{
bestNumberFinalized
? <Digits value={formatNumber(bestNumberFinalized)} />
: '-'
<Digits value={formatNumber(bestNumberFinalized || 1234)} />
}{children}
</div>
);

View File

@ -22,11 +22,9 @@ function BestNumber ({ children, className = '', isFinalized, label, withPound }
const bestNumber = useCall<BlockNumber>(isApiReady && (isFinalized ? api.derive.chain.bestNumberFinalized : api.derive.chain.bestNumber));
return (
<div className={className}>
<div className={`${className} ${bestNumber ? '' : '--placeholder'}`}>
{label || ''}{withPound && '#'}{
bestNumber
? <Digits value={formatNumber(bestNumber)} />
: '-'
<Digits value={formatNumber(bestNumber || 1234)} />
}{children}
</div>
);

View File

@ -2,9 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
import type { Moment } from '@polkadot/types/interfaces';
import type { BN } from '@polkadot/util';
import React, { useEffect, useState } from 'react';
import React, { useMemo } from 'react';
import { useApi, useCall } from '@polkadot/react-hooks';
@ -17,23 +16,19 @@ interface Props {
value?: Moment;
}
function TimeNow ({ children, className = '', label, value }: Props): React.ReactElement<Props> | null {
function TimeNow ({ children, className = '', label, value }: Props): React.ReactElement<Props> {
const { api } = useApi();
const timestamp = useCall<Moment>(!value && api.query.timestamp?.now);
const [now, setNow] = useState<BN | undefined>();
useEffect((): void => {
setNow(value || timestamp);
}, [timestamp, value]);
if (!now) {
return null;
}
const [now, hasValue] = useMemo(
() => [value || timestamp, !!(value || timestamp)],
[timestamp, value]
);
return (
<div className={className}>
<div className={`${className} ${hasValue ? '' : '--placeholder'}`}>
{label || ''}
<Elapsed value={now} />
<Elapsed value={hasValue ? now : Date.now()} />
{children}
</div>
);

View File

@ -17,15 +17,12 @@ function TotalInactive ({ children, className = '', label }: Props): React.React
const { api } = useApi();
const inactiveIssuance = useCall<string>(api.query.balances?.inactiveIssuance);
if (!inactiveIssuance) {
return null;
}
return (
<div className={className}>
{label || ''}
<FormatBalance
value={inactiveIssuance}
className={inactiveIssuance ? '' : '--placeholder'}
value={inactiveIssuance || 1}
withSi
/>
{children}

View File

@ -13,7 +13,7 @@ interface Props {
label?: React.ReactNode;
}
function TotalIssuance ({ children, className = '', label }: Props): React.ReactElement<Props> {
function TotalIssuance ({ children, className = '', label }: Props): React.ReactElement<Props> | null {
const { api } = useApi();
const totalIssuance = useCall<string>(api.query.balances?.totalIssuance);
@ -21,7 +21,8 @@ function TotalIssuance ({ children, className = '', label }: Props): React.React
<div className={className}>
{label || ''}
<FormatBalance
value={totalIssuance}
className={totalIssuance ? '' : '--placeholder'}
value={totalIssuance || 1}
withSi
/>
{children}