From f495761c0bb6d25ed8b3b1d8487b471f05a3057b Mon Sep 17 00:00:00 2001 From: Jaco Date: Mon, 9 Jan 2023 17:37:40 +0200 Subject: [PATCH] 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 --- packages/apps/src/Apps.tsx | 5 ++ .../page-accounts/src/Accounts/Account.tsx | 2 - .../page-accounts/src/Accounts/Summary.tsx | 81 ++++++++--------- .../page-accounts/src/Sidebar/Balances.tsx | 2 +- .../page-addresses/src/Contacts/Address.tsx | 30 +++---- .../page-alliance/src/Members/Summary.tsx | 6 +- .../page-contracts/src/Contracts/Contract.tsx | 1 - .../page-council/src/Overview/Summary.tsx | 30 +++---- packages/page-council/src/Overview/Voters.tsx | 10 +-- .../page-democracy/src/Overview/Summary.tsx | 43 ++++++---- packages/page-explorer/src/SummarySession.tsx | 40 ++++++--- .../page-parachains/src/Auctions/Summary.tsx | 12 ++- .../page-parachains/src/Crowdloan/Fund.tsx | 11 +-- .../page-parachains/src/Crowdloan/Summary.tsx | 65 ++++++++------ .../page-parachains/src/Crowdloan/index.tsx | 5 +- .../src/Overview/Parachain.tsx | 31 +++---- .../page-parachains/src/Overview/Summary.tsx | 59 +++++++------ packages/page-parachains/src/types.ts | 1 + packages/page-parachains/src/useFunds.ts | 1 + .../page-preimages/src/Preimages/Preimage.tsx | 20 +++-- .../page-preimages/src/Preimages/Summary.tsx | 4 +- packages/page-ranked/src/Members/Summary.tsx | 4 +- .../page-referenda/src/Referenda/Summary.tsx | 21 +++-- packages/page-staking/src/Bags/Bag.tsx | 4 +- packages/page-staking/src/Bags/Summary.tsx | 8 +- packages/page-staking/src/Payouts/Stash.tsx | 8 +- packages/page-staking/src/Pools/Pool.tsx | 21 +++-- packages/page-staking/src/Targets/Summary.tsx | 86 ++++++++++--------- .../src/Validators/Address/StakeOther.tsx | 41 ++++----- .../src/Validators/Address/index.tsx | 2 +- .../page-staking/src/Validators/Summary.tsx | 8 +- .../page-treasury/src/Overview/Summary.tsx | 70 ++++++++------- .../page-whitelist/src/Hashes/Summary.tsx | 4 +- packages/react-components/src/AddressInfo.tsx | 20 +++-- packages/react-components/src/CardSummary.tsx | 6 +- packages/react-components/src/Progress.tsx | 5 +- packages/react-query/src/BestFinalized.tsx | 6 +- packages/react-query/src/BestNumber.tsx | 6 +- packages/react-query/src/TimeNow.tsx | 21 ++--- packages/react-query/src/TotalInactive.tsx | 7 +- packages/react-query/src/TotalIssuance.tsx | 5 +- 41 files changed, 439 insertions(+), 373 deletions(-) diff --git a/packages/apps/src/Apps.tsx b/packages/apps/src/Apps.tsx index 24a38fefe3..560307679b 100644 --- a/packages/apps/src/Apps.tsx +++ b/packages/apps/src/Apps.tsx @@ -58,4 +58,9 @@ export default React.memo(styled(Apps)` .--hidden { display: none; } + + .--placeholder { + background: grey; + filter: blur(2px) opacity(0.25); + } `); diff --git a/packages/page-accounts/src/Accounts/Account.tsx b/packages/page-accounts/src/Accounts/Account.tsx index 8c15667bb3..05ed2436da 100644 --- a/packages/page-accounts/src/Accounts/Account.tsx +++ b/packages/page-accounts/src/Accounts/Account.tsx @@ -712,7 +712,6 @@ function Account ({ account: { address, meta }, className = '', delegation, filt address={address} balancesAll={balancesAll} withBalance={BAL_OPTS_DEFAULT} - withExtended={false} /> @@ -728,7 +727,6 @@ function Account ({ account: { address, meta }, className = '', delegation, filt balancesAll={balancesAll} convictionLocks={convictionLocks} withBalance={BAL_OPTS_EXPANDED} - withExtended={false} /> diff --git a/packages/page-accounts/src/Accounts/Summary.tsx b/packages/page-accounts/src/Accounts/Summary.tsx index 96e4edcfa6..baf19160bf 100644 --- a/packages/page-accounts/src/Accounts/Summary.tsx +++ b/packages/page-accounts/src/Accounts/Summary.tsx @@ -19,45 +19,48 @@ function Summary ({ balance, className }: Props) { return ( - {balance && ( - <> - {balance.total.gtn(0) && - ('total balance')}> - - } - {balance.transferrable.gtn(0) && - ('total transferrable')} - > - - } - {balance.locked.gtn(0) && - ('total locked')}> - - } - {balance.bonded.gtn(0) && - ('bonded')} - > - - } - {balance.redeemable.gtn(0) && - ('redeemable')} - > - - } - {balance.unbonding.gtn(0) && - ('unbonding')} - > - - } - )} + ('total balance')}> + + + ('total transferrable')} + > + + + ('total locked')}> + + + {balance?.bonded.gtn(0) && + ('bonded')} + > + + } + {balance?.redeemable.gtn(0) && + ('redeemable')} + > + + } + {balance?.unbonding.gtn(0) && + ('unbonding')} + > + + } ); } diff --git a/packages/page-accounts/src/Sidebar/Balances.tsx b/packages/page-accounts/src/Sidebar/Balances.tsx index ca3a42642e..98dbac3cbd 100644 --- a/packages/page-accounts/src/Sidebar/Balances.tsx +++ b/packages/page-accounts/src/Sidebar/Balances.tsx @@ -26,8 +26,8 @@ function Balances ({ address, className }: Props): React.ReactElement | n diff --git a/packages/page-addresses/src/Contacts/Address.tsx b/packages/page-addresses/src/Contacts/Address.tsx index 2b3aaae3f6..5b410c583b 100644 --- a/packages/page-addresses/src/Contacts/Address.tsx +++ b/packages/page-addresses/src/Contacts/Address.tsx @@ -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 | null { const { t } = useTranslation(); const api = useApi(); @@ -238,8 +238,7 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite @@ -253,8 +252,7 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite diff --git a/packages/page-alliance/src/Members/Summary.tsx b/packages/page-alliance/src/Members/Summary.tsx index 1bf401e1b5..f9ecddbe5b 100644 --- a/packages/page-alliance/src/Members/Summary.tsx +++ b/packages/page-alliance/src/Members/Summary.tsx @@ -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('yes') : t('no') - : + : {t('no')} } ('members')}> {members ? formatNumber(members.length) - : + : 99 } diff --git a/packages/page-contracts/src/Contracts/Contract.tsx b/packages/page-contracts/src/Contracts/Contract.tsx index b65c8d5f86..37fcbb0876 100644 --- a/packages/page-contracts/src/Contracts/Contract.tsx +++ b/packages/page-contracts/src/Contracts/Contract.tsx @@ -101,7 +101,6 @@ function Contract ({ className, contract, index, links, onCall }: Props): React. address={contract.address} withBalance withBalanceToggle - withExtended={false} /> diff --git a/packages/page-council/src/Overview/Summary.tsx b/packages/page-council/src/Overview/Summary.tsx index c5802978a9..8e012bab2e 100644 --- a/packages/page-council/src/Overview/Summary.tsx +++ b/packages/page-council/src/Overview/Summary.tsx @@ -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 | null { const { t } = useTranslation(); - if (!electionsInfo) { - return null; - } - - const { candidateCount, desiredRunnersUp, desiredSeats, members, runnersUp, termDuration, voteCount } = electionsInfo; - return (
('seats')}> - {formatNumber(members.length)}{desiredSeats && <> / {formatNumber(desiredSeats)}} + {electionsInfo + ? <>{formatNumber(electionsInfo.members.length)}{electionsInfo.desiredSeats && <> / {formatNumber(electionsInfo.desiredSeats)}} + : 99} {hasElections && ( <> ('runners up')}> - {formatNumber(runnersUp.length)}{desiredRunnersUp && <> / {formatNumber(desiredRunnersUp)}} + {electionsInfo + ? <>{formatNumber(electionsInfo.runnersUp.length)}{electionsInfo.desiredRunnersUp && <> / {formatNumber(electionsInfo.desiredRunnersUp)}} + : 99} ('candidates')}> - {formatNumber(candidateCount)} + {electionsInfo + ? formatNumber(electionsInfo.candidateCount) + : 99} )}
- {voteCount && ( + {electionsInfo && electionsInfo.voteCount && (
('voting round')}> - #{formatNumber(voteCount)} + #{formatNumber(electionsInfo.voteCount)}
)} - {bestNumber && termDuration && termDuration.gt(BN_ZERO) && ( + {electionsInfo && bestNumber && electionsInfo.termDuration && electionsInfo.termDuration.gt(BN_ZERO) && (
('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 }} /> diff --git a/packages/page-council/src/Overview/Voters.tsx b/packages/page-council/src/Overview/Voters.tsx index fdac826285..676c2db1dd 100644 --- a/packages/page-council/src/Overview/Voters.tsx +++ b/packages/page-council/src/Overview/Voters.tsx @@ -26,20 +26,20 @@ function Voters ({ balance, voters }: Props): React.ReactElement { [voters] ); - if (!balance || !voters || !voters.length) { - return <>; - } - return ( <> } /> - {formatNumber(voters.length)} + {voters + ? formatNumber(voters.length) + : 123 + } ); diff --git a/packages/page-democracy/src/Overview/Summary.tsx b/packages/page-democracy/src/Overview/Summary.tsx index 84368f9831..e080df9f73 100644 --- a/packages/page-democracy/src/Overview/Summary.tsx +++ b/packages/page-democracy/src/Overview/Summary.tsx @@ -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 {
('proposals')}> - {formatNumber(activeProposals?.length)} + {activeProposals + ? formatNumber(activeProposals.length) + : 99} ('total')}> - {formatNumber(publicPropCount)} + {publicPropCount + ? formatNumber(publicPropCount) + : 99}
('referenda')}> - {formatNumber(referendumCount || 0)} + {referendumCount !== undefined + ? formatNumber(referendumCount) + : 99} ('total')}> - {formatNumber(referendumTotal || 0)} + {referendumTotal + ? formatNumber(referendumTotal) + : 99}
- {bestNumber && ( -
- ('launch period')} - progress={{ - total: api.consts.democracy.launchPeriod, - value: bestNumber.mod(api.consts.democracy.launchPeriod).iadd(BN_ONE), - withTime: true - }} - /> -
- )} +
+ ('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 + }} + /> +
); } diff --git a/packages/page-explorer/src/SummarySession.tsx b/packages/page-explorer/src/SummarySession.tsx index d7b6dd8b90..601996401b 100644 --- a/packages/page-explorer/src/SummarySession.tsx +++ b/packages/page-explorer/src/SummarySession.tsx @@ -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(api.query.staking?.forceEra); const eraLabel = t('era'); - const sessionLabel = sessionInfo?.isEpoch + const sessionLabel = api.query.babe ? t('epoch') : t('session'); const activeEraStart = sessionInfo?.activeEraStart.unwrapOr(null); return ( <> - {sessionInfo && ( + {api.derive.session && ( <> {withSession && ( - sessionInfo.sessionLength.gt(BN_ONE) + api.query.babe ? ( ) : ( - #{formatNumber(sessionInfo.currentIndex)} + #{sessionInfo + ? formatNumber(sessionInfo.currentIndex) + : 123} {withEra && activeEraStart &&
 
}
) )} - {forcing && !forcing.isForceNone && withEra && ( - sessionInfo.sessionLength.gt(BN_ONE) + {withEra && ( + api.query.babe ? ( @@ -73,10 +85,12 @@ function SummarySession ({ className, withEra = true, withSession = true }: Prop className={className} label={eraLabel} > - #{formatNumber(sessionInfo.activeEra)} + #{sessionInfo + ? formatNumber(sessionInfo.activeEra) + : 123} {activeEraStart && (  {t('elapsed')} diff --git a/packages/page-parachains/src/Auctions/Summary.tsx b/packages/page-parachains/src/Auctions/Summary.tsx index 0df33c4e5e..100ececc38 100644 --- a/packages/page-parachains/src/Auctions/Summary.tsx +++ b/packages/page-parachains/src/Auctions/Summary.tsx @@ -30,12 +30,16 @@ function Summary ({ auctionInfo, className, lastWinners }: Props): React.ReactEl
('auctions')}> - {formatNumber(auctionInfo?.numAuctions)} + {auctionInfo + ? formatNumber(auctionInfo.numAuctions) + : 99} ('active')}> - {auctionInfo?.leasePeriod - ? t('yes') - : t('no') + {auctionInfo + ? auctionInfo.leasePeriod + ? t('yes') + : t('no') + : {t('no')} }
diff --git a/packages/page-parachains/src/Crowdloan/Fund.tsx b/packages/page-parachains/src/Crowdloan/Fund.tsx index 642355be0c..312cb01b05 100644 --- a/packages/page-parachains/src/Crowdloan/Fund.tsx +++ b/packages/page-parachains/src/Crowdloan/Fund.tsx @@ -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 )} - {!hasLoaded - ? - : ( + {hasLoaded + ? ( <> {bestHash && ( - )} + ) + : 999 + } {canWithdraw && contributorsHex.length !== 0 && ( diff --git a/packages/page-parachains/src/Crowdloan/Summary.tsx b/packages/page-parachains/src/Crowdloan/Summary.tsx index e364e18230..4ec0276a9e 100644 --- a/packages/page-parachains/src/Crowdloan/Summary.tsx +++ b/packages/page-parachains/src/Crowdloan/Summary.tsx @@ -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 { +function Summary ({ activeCap, activeRaised, className, fundCount, isLoading, totalCap, totalRaised }: Props): React.ReactElement { const { t } = useTranslation(); return ( ('funds')}> - {formatNumber(fundCount)} + {fundCount === undefined + ? 99 + : formatNumber(fundCount)} ('active raised / cap')}`} progress={{ hideValue: true, - total: activeCap, - value: activeRaised + isBlurred: isLoading, + total: isLoading ? BN_THREE : activeCap, + value: isLoading ? BN_TWO : activeRaised }} > - -  /  - + + +  /  + + ('total raised / cap')}`} progress={{ hideValue: true, - total: totalCap, - value: totalRaised + isBlurred: isLoading, + total: isLoading ? BN_THREE : totalCap, + value: isLoading ? BN_TWO : totalRaised }} > - -  /  - + + +  /  + + ); diff --git a/packages/page-parachains/src/Crowdloan/index.tsx b/packages/page-parachains/src/Crowdloan/index.tsx index 663aa93a9b..236c85cd19 100644 --- a/packages/page-parachains/src/Crowdloan/index.tsx +++ b/packages/page-parachains/src/Crowdloan/index.tsx @@ -20,7 +20,7 @@ interface Props { ownedIds: OwnedId[]; } -function Crowdloan ({ auctionInfo, campaigns: { activeCap, activeRaised, funds, totalCap, totalRaised }, className, leasePeriod, ownedIds }: Props): React.ReactElement { +function Crowdloan ({ auctionInfo, campaigns: { activeCap, activeRaised, funds, isLoading, totalCap, totalRaised }, className, leasePeriod, ownedIds }: Props): React.ReactElement { const bestNumber = useBestNumber(); return ( @@ -28,7 +28,8 @@ function Crowdloan ({ auctionInfo, campaigns: { activeCap, activeRaised, funds, diff --git a/packages/page-parachains/src/Overview/Parachain.tsx b/packages/page-parachains/src/Overview/Parachain.tsx index 069e742876..88541dca0d 100644 --- a/packages/page-parachains/src/Overview/Parachain.tsx +++ b/packages/page-parachains/src/Overview/Parachain.tsx @@ -104,23 +104,20 @@ function Parachain ({ bestNumber, className = '', id, lastBacked, lastInclusion, - {validators && validators[1].length !== 0 && ( - ('Val. Group {{group}} ({{count}})', { - replace: { - count: formatNumber(validators[1].length), - group: validators[0] - } - })} - /> - )} - {nonBacked && ( - ('Non-voters ({{count}})', { replace: { count: formatNumber(nonBacked.length) } })} - /> - )} + ('Val. Group {{group}} ({{count}})', { + replace: { + count: formatNumber(validators?.[1]?.length || 0), + group: validators ? validators[0] : 0 + } + })} + /> + ('Non-voters ({{count}})', { replace: { count: formatNumber(nonBacked.length) } })} + /> {paraInfo.headHex} diff --git a/packages/page-parachains/src/Overview/Summary.tsx b/packages/page-parachains/src/Overview/Summary.tsx index 74486bc392..ea5b6a4185 100644 --- a/packages/page-parachains/src/Overview/Summary.tsx +++ b/packages/page-parachains/src/Overview/Summary.tsx @@ -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 (
- {isNumber(parachainCount) && ( - ('parachains')}> - {formatNumber(parachainCount)} - - )} - {isNumber(upcomingCount) && ( - ('parathreads')} - > - {formatNumber(upcomingCount)} - - )} + ('parachains')}> + {isNumber(parachainCount) + ? formatNumber(parachainCount) + : 99} + + ('parathreads')} + > + {isNumber(upcomingCount) + ? formatNumber(upcomingCount) + : 99} + {isNumber(proposalCount) && (
- {leasePeriod && ( - <> - ('current lease')}> - {formatNumber(leasePeriod.currentPeriod)} - - ('lease period')} - progress={{ - total: leasePeriod.length, - value: leasePeriod.progress, - withTime: true - }} - /> - - )} + ('current lease')}> + {leasePeriod + ? formatNumber(leasePeriod.currentPeriod) + : 99} + + ('lease period')} + progress={{ + isBlurred: !leasePeriod, + total: leasePeriod ? leasePeriod.length : BN_THREE, + value: leasePeriod ? leasePeriod.progress : BN_TWO, + withTime: true + }} + />
('finalized')}> diff --git a/packages/page-parachains/src/types.ts b/packages/page-parachains/src/types.ts index 187cbe7c54..a7fae1895d 100644 --- a/packages/page-parachains/src/types.ts +++ b/packages/page-parachains/src/types.ts @@ -45,6 +45,7 @@ export interface Campaigns { activeCap: BN; activeRaised: BN; funds: Campaign[] | null; + isLoading?: boolean; totalCap: BN; totalRaised: BN; } diff --git a/packages/page-parachains/src/useFunds.ts b/packages/page-parachains/src/useFunds.ts index 5b2667b9a6..110d860875 100644 --- a/packages/page-parachains/src/useFunds.ts +++ b/packages/page-parachains/src/useFunds.ts @@ -19,6 +19,7 @@ const EMPTY: Campaigns = { activeCap: BN_ZERO, activeRaised: BN_ZERO, funds: null, + isLoading: true, totalCap: BN_ZERO, totalRaised: BN_ZERO }; diff --git a/packages/page-preimages/src/Preimages/Preimage.tsx b/packages/page-preimages/src/Preimages/Preimage.tsx index 99a25aa3f9..9fddac97cf 100644 --- a/packages/page-preimages/src/Preimages/Preimage.tsx +++ b/packages/page-preimages/src/Preimages/Preimage.tsx @@ -25,15 +25,21 @@ function Preimage ({ className, value }: Props): React.ReactElement { - {info?.bytes && formatNumber(info.bytes.length)} + {info?.bytes + ? formatNumber(info.bytes.length) + : 999,999 + } - {info && ( - <> -
{info.status?.type}{info.count !== 0 && <> / {formatNumber(info.count)}}
- - - )} + {info + ? ( + <> +
{info.status?.type}{info.count !== 0 && <> / {formatNumber(info.count)}}
+ + + ) + : Unrequested + } ); diff --git a/packages/page-preimages/src/Preimages/Summary.tsx b/packages/page-preimages/src/Preimages/Summary.tsx index 08f0736bde..69c132a115 100644 --- a/packages/page-preimages/src/Preimages/Summary.tsx +++ b/packages/page-preimages/src/Preimages/Summary.tsx @@ -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 { ('images')}> {hashes === undefined - ? + ? 99 : formatNumber(hashes.length) } diff --git a/packages/page-ranked/src/Members/Summary.tsx b/packages/page-ranked/src/Members/Summary.tsx index fab86ad49a..eeab37f316 100644 --- a/packages/page-ranked/src/Members/Summary.tsx +++ b/packages/page-ranked/src/Members/Summary.tsx @@ -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 { ('members')}> {members === undefined - ? + ? 99 : formatNumber(members.length) } diff --git a/packages/page-referenda/src/Referenda/Summary.tsx b/packages/page-referenda/src/Referenda/Summary.tsx index d0beeffdc8..dced4adf73 100644 --- a/packages/page-referenda/src/Referenda/Summary.tsx +++ b/packages/page-referenda/src/Referenda/Summary.tsx @@ -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,
('active')}> {refActive === undefined - ? + ? 99 : formatNumber(refActive) } ('total')}> {refCount === undefined - ? + ? 99 : formatNumber(refCount) }
{withIssuance && (
- {issuanceTotal && ( - ('total issuance')}> - - - )} {issuanceInactive && ( )} + ('total issuance')}> + +
)}
diff --git a/packages/page-staking/src/Bags/Bag.tsx b/packages/page-staking/src/Bags/Bag.tsx index 75f5fb9a85..2d49b8d758 100644 --- a/packages/page-staking/src/Bags/Bag.tsx +++ b/packages/page-staking/src/Bags/Bag.tsx @@ -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 {isLoading - ? + ? 99 : list.length ? formatNumber(list.length) : null diff --git a/packages/page-staking/src/Bags/Summary.tsx b/packages/page-staking/src/Bags/Summary.tsx index bcb71dbff2..65d46a4336 100644 --- a/packages/page-staking/src/Bags/Summary.tsx +++ b/packages/page-staking/src/Bags/Summary.tsx @@ -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

('total bags')}> {bags ? formatNumber(bags.length) - : + : 99 }

('total nodes')}> {mapOwn ? formatNumber(total) - : + : 99 } ('my nodes')}> {isNumber(myCount) ? formatNumber(myCount) - : '-' + : 99 }
diff --git a/packages/page-staking/src/Payouts/Stash.tsx b/packages/page-staking/src/Payouts/Stash.tsx index 6667492728..f2cb7bb3cc 100644 --- a/packages/page-staking/src/Payouts/Stash.tsx +++ b/packages/page-staking/src/Payouts/Stash.tsx @@ -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 {eraStr} - {eraBlocks && } + + + - {info && ( -
{info.metadata}
- )} +
+ {info + ? info.metadata + : This is a pool placeholder} +
+ + + {info + ? info.bonded.state.type + : Destroying} + + + - {info && info.bonded.state.type} - {info && } {info && !info.rewardClaimable.isZero() && } {info && info.nominating.length !== 0 && ( diff --git a/packages/page-staking/src/Targets/Summary.tsx b/packages/page-staking/src/Targets/Summary.tsx index f723c68d40..6ceb199334 100644 --- a/packages/page-staking/src/Targets/Summary.tsx +++ b/packages/page-staking/src/Targets/Summary.tsx @@ -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 { @@ -66,43 +66,46 @@ function Summary ({ avgStaked, lastEra, lowStaked, minNominated, minNominatorBon return (
- {progressStake && ( - ('total staked')} - progress={progressStake} - > - - - )} + ('total staked')} + progress={progressStake} + > + +
- {totalIssuance && (stakedReturn > 0) && Number.isFinite(stakedReturn) && ( - ('returns')}> - {stakedReturn.toFixed(1)}% - - )} + ('returns')}> + {totalIssuance && (stakedReturn > 0) + ? Number.isFinite(stakedReturn) + ? <>{stakedReturn.toFixed(1)}% + : '-.-%' + : 0.0% + } +
- {progressAvg && ( - ('lowest / avg staked')}`} - progress={progressAvg} - > + ('lowest / avg staked')}`} + progress={progressAvg} + > +  /  - - )} + +
{minNominated?.gt(BN_ZERO) && ( @@ -131,14 +134,13 @@ function Summary ({ avgStaked, lastEra, lowStaked, minNominated, minNominatorBon )}
- {lastReward?.gt(BN_ZERO) && ( - ('last reward')}> - - - )} + ('last reward')}> + +
); diff --git a/packages/page-staking/src/Validators/Address/StakeOther.tsx b/packages/page-staking/src/Validators/Address/StakeOther.tsx index 66d8ad6b9d..ae4919c35f 100644 --- a/packages/page-staking/src/Validators/Address/StakeOther.tsx +++ b/packages/page-staking/src/Validators/Address/StakeOther.tsx @@ -67,30 +67,27 @@ function StakeOther ({ nominators, stakeOther }: Props): React.ReactElement - {rewarded && ( - <> - - } + - {unrewarded && ( - - } + } + /> + {unrewarded && ( + - )} - + } + /> )} ); diff --git a/packages/page-staking/src/Validators/Address/index.tsx b/packages/page-staking/src/Validators/Address/index.tsx index 5f69b4eb34..df5ec0041f 100644 --- a/packages/page-staking/src/Validators/Address/index.tsx +++ b/packages/page-staking/src/Validators/Address/index.tsx @@ -167,7 +167,7 @@ function Address ({ address, className = '', filterName, hasQueries, isElected, ) } - {commission} + {commission || 50.00%} {isMain && ( diff --git a/packages/page-staking/src/Validators/Summary.tsx b/packages/page-staking/src/Validators/Summary.tsx index 77e7d57b0f..ed1440e77d 100644 --- a/packages/page-staking/src/Validators/Summary.tsx +++ b/packages/page-staking/src/Validators/Summary.tsx @@ -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 ('validators')}> {stakingOverview ? <>{formatNumber(stakingOverview.validators.length)} / {formatNumber(stakingOverview.validatorCount)} - : + : 99 / 99 } {waitingIds ? formatNumber(waitingIds.length) - : + : 99 } ) - : + : 99 }
diff --git a/packages/page-treasury/src/Overview/Summary.tsx b/packages/page-treasury/src/Overview/Summary.tsx index 7d6edde596..8a3c8cee87 100644 --- a/packages/page-treasury/src/Overview/Summary.tsx +++ b/packages/page-treasury/src/Overview/Summary.tsx @@ -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

@@ -36,19 +38,25 @@ function Summary ({ approvalCount, proposalCount }: Props): React.ReactElement

('open')} > - {formatNumber(proposalCount)} + {proposalCount === undefined + ? 99 + : formatNumber(proposalCount)} ('approved')} > - {formatNumber(approvalCount)} + {approvalCount === undefined + ? 99 + : formatNumber(approvalCount)} ('total')} > - {formatNumber(totalProposals || 0)} + {totalProposals === undefined + ? totalProposals + : formatNumber(totalProposals)}

@@ -74,41 +82,41 @@ function Summary ({ approvalCount, proposalCount }: Props): React.ReactElement

)} - {burn && ( - ('next burn')} - > - - - )} + ('next burn')} + > + +

- {value && spendable && ( -
- ('spendable / available')} - progress={{ - hideValue: true, - total: value, - value: spendable - }} - > +
+ ('spendable / available')} + progress={{ + hideValue: true, + isBlurred: !hasSpendable, + total: hasSpendable ? value : BN_THREE, + value: hasSpendable ? spendable : BN_TWO + }} + > + <> /  - -
- )} - {bestNumber && spendPeriod?.gtn(0) && ( + +
+
+ {bestNumber && spendPeriod.gt(BN_ZERO) && (
('spend period')} diff --git a/packages/page-whitelist/src/Hashes/Summary.tsx b/packages/page-whitelist/src/Hashes/Summary.tsx index 75ca1dc6d4..5427cc1ff8 100644 --- a/packages/page-whitelist/src/Hashes/Summary.tsx +++ b/packages/page-whitelist/src/Hashes/Summary.tsx @@ -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 { ('hashes')}> {hashes === undefined - ? + ? 99 : formatNumber(hashes.length) } diff --git a/packages/react-components/src/AddressInfo.tsx b/packages/react-components/src/AddressInfo.tsx index b680f4cc64..3b4de0e0d8 100644 --- a/packages/react-components/src/AddressInfo.tsx +++ b/packages/react-components/src/AddressInfo.tsx @@ -109,6 +109,9 @@ function lookupLock (lookup: Record, 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, 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, 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( ); @@ -258,7 +261,7 @@ function createBalanceItems (formatIndex: number, lookup: Record ); - 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 ); - } 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 ); } - 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 return ( , bestNumbe ? DEFAULT_BALANCES : withBalance || false; - if (!bestNumber || !balanceDisplay) { + if (!balanceDisplay) { return [null]; } diff --git a/packages/react-components/src/CardSummary.tsx b/packages/react-components/src/CardSummary.tsx index b0bf15b60b..d46d9c8958 100644 --- a/packages/react-components/src/CardSummary.tsx +++ b/packages/react-components/src/CardSummary.tsx @@ -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 && ( - + )}
{!left || isUndefined(progress.total) diff --git a/packages/react-components/src/Progress.tsx b/packages/react-components/src/Progress.tsx index 6a55472f1d..e81f1dd6b7 100644 --- a/packages/react-components/src/Progress.tsx +++ b/packages/react-components/src/Progress.tsx @@ -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 const Clip = React.memo(DivClip); -function Progress ({ className = '', isDisabled, total, value }: Props): React.ReactElement | null { +function Progress ({ className = '', isBlurred, isDisabled, total, value }: Props): React.ReactElement | 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 ( -
+
(api.derive.chain.bestNumberFinalized); return ( -
+
{label || ''}{ - bestNumberFinalized - ? - : '-' + }{children}
); diff --git a/packages/react-query/src/BestNumber.tsx b/packages/react-query/src/BestNumber.tsx index 846916bafc..fc5cdf2809 100644 --- a/packages/react-query/src/BestNumber.tsx +++ b/packages/react-query/src/BestNumber.tsx @@ -22,11 +22,9 @@ function BestNumber ({ children, className = '', isFinalized, label, withPound } const bestNumber = useCall(isApiReady && (isFinalized ? api.derive.chain.bestNumberFinalized : api.derive.chain.bestNumber)); return ( -
+
{label || ''}{withPound && '#'}{ - bestNumber - ? - : '-' + }{children}
); diff --git a/packages/react-query/src/TimeNow.tsx b/packages/react-query/src/TimeNow.tsx index efc04cda1c..827a696118 100644 --- a/packages/react-query/src/TimeNow.tsx +++ b/packages/react-query/src/TimeNow.tsx @@ -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 | null { +function TimeNow ({ children, className = '', label, value }: Props): React.ReactElement { const { api } = useApi(); const timestamp = useCall(!value && api.query.timestamp?.now); - const [now, setNow] = useState(); - useEffect((): void => { - setNow(value || timestamp); - }, [timestamp, value]); - - if (!now) { - return null; - } + const [now, hasValue] = useMemo( + () => [value || timestamp, !!(value || timestamp)], + [timestamp, value] + ); return ( -
+
{label || ''} - + {children}
); diff --git a/packages/react-query/src/TotalInactive.tsx b/packages/react-query/src/TotalInactive.tsx index 79554d7bb3..f4733a3d66 100644 --- a/packages/react-query/src/TotalInactive.tsx +++ b/packages/react-query/src/TotalInactive.tsx @@ -17,15 +17,12 @@ function TotalInactive ({ children, className = '', label }: Props): React.React const { api } = useApi(); const inactiveIssuance = useCall(api.query.balances?.inactiveIssuance); - if (!inactiveIssuance) { - return null; - } - return (
{label || ''} {children} diff --git a/packages/react-query/src/TotalIssuance.tsx b/packages/react-query/src/TotalIssuance.tsx index 82f8fb1c53..7e1836b733 100644 --- a/packages/react-query/src/TotalIssuance.tsx +++ b/packages/react-query/src/TotalIssuance.tsx @@ -13,7 +13,7 @@ interface Props { label?: React.ReactNode; } -function TotalIssuance ({ children, className = '', label }: Props): React.ReactElement { +function TotalIssuance ({ children, className = '', label }: Props): React.ReactElement | null { const { api } = useApi(); const totalIssuance = useCall(api.query.balances?.totalIssuance); @@ -21,7 +21,8 @@ function TotalIssuance ({ children, className = '', label }: Props): React.React
{label || ''} {children}