Staking performance updates (#1670)

* Staking performance updates

* More default on props
This commit is contained in:
Jaco Greeff 2019-09-26 22:21:16 +02:00 committed by GitHub
parent 637e50fefe
commit 5ee21ae275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 66 deletions

View File

@ -22,7 +22,7 @@ interface Props extends BareProps, I18nProps {
staking_intentions?: AccountId[];
}
function SummaryBar ({ balances_totalIssuance, chain_bestNumber, chain_bestNumberLag, staking_intentions = [], session_validators = [] }: Props): React.ReactElement<Props> {
function SummaryBar ({ balances_totalIssuance, chain_bestNumber, chain_bestNumberLag, staking_intentions, session_validators }: Props): React.ReactElement<Props> {
const { api, systemChain, systemName, systemVersion } = useContext(ApiContext);
const [nextUp, setNextUp] = useState<AccountId[]>([]);
@ -52,7 +52,7 @@ function SummaryBar ({ balances_totalIssuance, chain_bestNumber, chain_bestNumbe
{formatNumber(chain_bestNumber)} ({formatNumber(chain_bestNumberLag)} lag)
</Bubble>
<Bubble icon='chess queen' label='validators'>{
session_validators.map((accountId, index): React.ReactNode => (
(session_validators || []).map((accountId, index): React.ReactNode => (
<IdentityIcon key={index} value={accountId} size={20} />
))
}</Bubble>

View File

@ -36,11 +36,11 @@ async function queryLedger (): Promise<void> {
}
}
function Overview ({ accounts = [], onStatusChange, t }: Props): React.ReactElement<Props> {
function Overview ({ accounts, onStatusChange, t }: Props): React.ReactElement<Props> {
const [isCreateOpen, setIsCreateOpen] = useState(false);
const [isImportOpen, setIsImportOpen] = useState(false);
const [isQrOpen, setIsQrOpen] = useState(false);
const emptyScreen = !(isCreateOpen || isImportOpen || isQrOpen) && (Object.keys(accounts).length === 0);
const emptyScreen = !(isCreateOpen || isImportOpen || isQrOpen) && accounts && (Object.keys(accounts).length === 0);
const _toggleCreate = (): void => setIsCreateOpen(!isCreateOpen);
const _toggleImport = (): void => setIsImportOpen(!isImportOpen);
@ -105,7 +105,7 @@ function Overview ({ accounts = [], onStatusChange, t }: Props): React.ReactElem
onStatusChange={onStatusChange}
/>
)}
{Object.keys(accounts).map((address): React.ReactNode => (
{accounts && Object.keys(accounts).map((address): React.ReactNode => (
<Account
address={address}
key={address}

View File

@ -18,7 +18,7 @@ interface Props extends I18nProps {
council_proposals?: Hash[];
}
function Proposals ({ council_proposals = [], t }: Props): React.ReactElement<Props> {
function Proposals ({ council_proposals, t }: Props): React.ReactElement<Props> {
return (
<CardGrid
emptyText={t('No council motions')}
@ -27,7 +27,7 @@ function Proposals ({ council_proposals = [], t }: Props): React.ReactElement<Pr
<Propose />
}
>
{council_proposals.map((hash: Hash): React.ReactNode => (
{council_proposals && council_proposals.map((hash: Hash): React.ReactNode => (
<Motion
hash={hash.toHex()}
key={hash.toHex()}

View File

@ -18,21 +18,19 @@ interface Props extends I18nProps {
democracy_publicProps?: [BN, Proposal][];
}
function Proposals ({ democracy_publicProps = [], t }: Props): React.ReactElement<Props> {
function Proposals ({ democracy_publicProps, t }: Props): React.ReactElement<Props> {
return (
<Column
emptyText={t('No available proposals')}
headerText={t('proposals')}
>
{
democracy_publicProps.map(([idNumber, proposal]): React.ReactNode => (
<ProposalDisplay
idNumber={idNumber}
key={idNumber.toString()}
value={proposal}
/>
))
}
{democracy_publicProps && democracy_publicProps.map(([idNumber, proposal]): React.ReactNode => (
<ProposalDisplay
idNumber={idNumber}
key={idNumber.toString()}
value={proposal}
/>
))}
</Column>
);
}

View File

@ -18,23 +18,22 @@ interface Props extends I18nProps {
democracy_referendums?: Option<ReferendumInfoExtended>[];
}
function Referendums ({ democracy_referendums = [], t }: Props): React.ReactElement<Props> {
function Referendums ({ democracy_referendums, t }: Props): React.ReactElement<Props> {
return (
<Column
emptyText={t('No available referendums')}
headerText={t('referendum')}
>
{
democracy_referendums
.filter((opt): boolean => opt.isSome)
.map((opt): ReferendumInfoExtended => opt.unwrap())
.map((referendum): React.ReactNode => (
<Referendum
idNumber={referendum.index}
key={referendum.index.toString()}
value={referendum}
/>
))
{democracy_referendums && democracy_referendums
.filter((opt): boolean => opt.isSome)
.map((opt): ReferendumInfoExtended => opt.unwrap())
.map((referendum): React.ReactNode => (
<Referendum
idNumber={referendum.index}
key={referendum.index.toString()}
value={referendum}
/>
))
}
</Column>
);

View File

@ -17,19 +17,15 @@ interface Props extends I18nProps {
parachains_parachains?: BN[];
}
function Parachains ({ parachains_parachains = [], t }: Props): React.ReactElement<Props> {
function Parachains ({ parachains_parachains, t }: Props): React.ReactElement<Props> {
return (
<Column
emptyText={t('no deployed parachains')}
headerText={t('parachains')}
>
{
parachains_parachains.length
? parachains_parachains.map((paraId): React.ReactNode =>
<Parachain key={paraId.toString()} paraId={paraId} />
)
: null
}
{parachains_parachains && parachains_parachains.map((paraId): React.ReactNode =>
<Parachain key={paraId.toString()} paraId={paraId} />
)}
</Column>
);
}

View File

@ -24,9 +24,7 @@ interface Props extends I18nProps {
next: string[];
}
function Summary (props: Props): React.ReactElement<Props> {
const { className, currentValidators, lastAuthor, lastBlock, next, style, staking_validatorCount, t } = props;
function Summary ({ className, currentValidators, lastAuthor, lastBlock, next, style, staking_validatorCount, t }: Props): React.ReactElement<Props> {
return (
<SummaryBox
className={className}

View File

@ -37,40 +37,45 @@ interface State {
allControllers: string[];
allStashes: string[];
currentValidators: string[];
recentlyOnline: Record<string, BlockNumber>;
}
function App ({ allAccounts, allStashesAndControllers = [[], []], bestNumber, className, currentValidatorsControllersV1OrStashesV2 = [], basePath, recentlyOnline: propsRecentlyOnline, t }: Props): React.ReactElement<Props> {
const [{ allControllers, allStashes, currentValidators, recentlyOnline }, setState] = useState<State>({
function App ({ allAccounts, allStashesAndControllers, bestNumber, className, currentValidatorsControllersV1OrStashesV2, basePath, recentlyOnline: propsRecentlyOnline, t }: Props): React.ReactElement<Props> {
const [{ allControllers, allStashes, currentValidators }, setState] = useState<State>({
allControllers: [],
allStashes: [],
currentValidators: [],
recentlyOnline: {}
currentValidators: []
});
const [recentlyOnline, setRecentlyOnline] = useState<Record<string, BlockNumber>>({});
useEffect((): void => {
const [_stashes, _controllers] = (allStashesAndControllers || [[], []]);
const _validators = currentValidatorsControllersV1OrStashesV2 || [];
setState({
allControllers: allStashesAndControllers[1]
allControllers: _controllers
.filter((optId): boolean => optId.isSome)
.map((accountId): string => accountId.unwrap().toString()),
allStashes: allStashesAndControllers[0]
allStashes: _stashes
.filter((): boolean => true)
.map((accountId): string => accountId.toString()),
currentValidators: currentValidatorsControllersV1OrStashesV2.map((authorityId): string =>
currentValidators: _validators.map((authorityId): string =>
authorityId.toString()
),
recentlyOnline: {
...(recentlyOnline || {}),
...(propsRecentlyOnline || []).reduce(
(result: Record<string, BlockNumber>, authorityId): Record<string, BlockNumber> => ({
...result,
[authorityId.toString()]: bestNumber || createType('BlockNumber', new BN(0))
}),
{}
)
}
)
});
}, [allStashesAndControllers, bestNumber, currentValidatorsControllersV1OrStashesV2]);
}, [allStashesAndControllers, currentValidatorsControllersV1OrStashesV2]);
useEffect((): void => {
setRecentlyOnline({
...(recentlyOnline || {}),
...(propsRecentlyOnline || []).reduce(
(result: Record<string, BlockNumber>, authorityId): Record<string, BlockNumber> => ({
...result,
[authorityId.toString()]: bestNumber || createType('BlockNumber', new BN(0))
}),
{}
)
});
}, [bestNumber, propsRecentlyOnline]);
const _renderComponent = (Component: React.ComponentType<ComponentProps>): () => React.ReactNode => {
// eslint-disable-next-line react/display-name

View File

@ -19,8 +19,7 @@ interface Props extends I18nProps {
treasury_pot?: BN;
}
function Summary (props: Props): React.ReactElement<Props> {
const { treasury_proposalCount = new BN(0), treasury_approvals = [] as BN[], treasury_pot = new BN(0), t } = props;
function Summary ({ treasury_proposalCount, treasury_approvals, treasury_pot, t }: Props): React.ReactElement<Props> {
const value = treasury_pot
? treasury_pot.toString()
: null;
@ -39,7 +38,7 @@ function Summary (props: Props): React.ReactElement<Props> {
<CardSummary label={t('pot')}>
{
value
? `${formatBalance(value, false)}${treasury_pot.gtn(0) ? formatBalance.calcSi(value).value : ''}`
? `${formatBalance(value, false)}${treasury_pot && treasury_pot.gtn(0) ? formatBalance.calcSi(value).value : ''}`
: '-'
}
</CardSummary>

View File

@ -27,7 +27,7 @@ interface Props extends I18nProps {
let prevEventHash: string;
function Status ({ optionsAll, queueAction, stqueue, system_events = [], t, txqueue }: Props): React.ReactElement<Props> {
function Status ({ optionsAll, queueAction, stqueue, system_events, t, txqueue }: Props): React.ReactElement<Props> {
useEffect((): void => {
const eventHash = xxhashAsHex(stringToU8a(JSON.stringify(system_events)));
@ -38,7 +38,7 @@ function Status ({ optionsAll, queueAction, stqueue, system_events = [], t, txqu
prevEventHash = eventHash;
const addresses = optionsAll.account.map((account): string | null => account.value);
const statusses = system_events
const statusses = system_events && system_events
.map(({ event: { data, method, section } }): ActionStatus | null => {
if (section === 'balances' && method === 'Transfer') {
const account = data[1].toString();
@ -69,7 +69,7 @@ function Status ({ optionsAll, queueAction, stqueue, system_events = [], t, txqu
})
.filter((item): boolean => !!item) as ActionStatus[];
statusses.length && queueAction(statusses);
statusses && statusses.length && queueAction(statusses);
}, [system_events]);
return (