Staking filter (name, address) (#2110)

* Staking filter (name, address)

* Dislay parent & sub

* Formatting
This commit is contained in:
Jaco Greeff 2020-01-13 14:35:45 +01:00 committed by GitHub
parent b0d5764b94
commit 4362181e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 17 deletions

View File

@ -122,6 +122,7 @@ function Overview ({ className, onStatusChange }: Props): React.ReactElement<Pro
<>
<div className='filter--tags'>
<Input
autoFocus
isFull
label={t('filter by name or tags')}
onChange={setFilter}

View File

@ -62,6 +62,7 @@ function Overview ({ className, onStatusChange }: Props): React.ReactElement<Pro
<>
<div className='filter--tags'>
<Input
autoFocus
isFull
label={t('filter by name or tags')}
onChange={setFilter}

View File

@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, Balance, Points, ValidatorPrefsTo196 } from '@polkadot/types/interfaces';
import { DerivedStakingQuery, DerivedHeartbeats } from '@polkadot/api-derive/types';
import { DeriveAccountInfo, DerivedStakingQuery, DerivedHeartbeats } from '@polkadot/api-derive/types';
import { I18nProps } from '@polkadot/react-components/types';
import { ValidatorFilter } from '../types';
@ -13,6 +13,7 @@ import styled from 'styled-components';
import { AddressMini, AddressSmall, Badge, Icon } from '@polkadot/react-components';
import { useCall, useApi } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';
import keyring from '@polkadot/ui-keyring';
import { formatNumber } from '@polkadot/util';
import translate from '../translate';
@ -23,6 +24,7 @@ interface Props extends I18nProps {
className?: string;
defaultName: string;
filter: ValidatorFilter;
filterName: string;
hasQueries: boolean;
isElected: boolean;
isFavorite: boolean;
@ -48,9 +50,10 @@ interface StakingState {
validatorPayment?: BN;
}
function Address ({ address, authorsMap, className, filter, hasQueries, isElected, isFavorite, lastAuthors, myAccounts, points, recentlyOnline, t, toggleFavorite, withNominations = true }: Props): React.ReactElement<Props> | null {
function Address ({ address, authorsMap, className, filter, filterName, hasQueries, isElected, isFavorite, lastAuthors, myAccounts, points, recentlyOnline, t, toggleFavorite, withNominations = true }: Props): React.ReactElement<Props> | null {
const { api } = useApi();
// FIXME Any horrors, caused by derive type mismatches
const info = useCall<DeriveAccountInfo>(api.derive.accounts.info as any, [address]);
const stakingInfo = useCall<DerivedStakingQuery>(api.derive.staking.query as any, [address]);
const [hasActivity, setHasActivity] = useState(true);
const [{ commission, hasNominators, isNominatorMe, nominators, stashId, stakeOwn, stakeOther, validatorPayment }, setStakingState] = useState<StakingState>({
@ -60,6 +63,7 @@ function Address ({ address, authorsMap, className, filter, hasQueries, isElecte
stashId: address.toString()
});
const [isExpanded, setIsExpanded] = useState(false);
const [isVisible, setIsVisible] = useState(true);
useEffect((): void => {
if (stakingInfo) {
@ -98,14 +102,40 @@ function Address ({ address, authorsMap, className, filter, hasQueries, isElecte
}
}, [recentlyOnline, stashId]);
if ((filter === 'hasNominators' && !hasNominators) ||
(filter === 'noNominators' && hasNominators) ||
(filter === 'hasWarnings' && hasActivity) ||
(filter === 'noWarnings' && !hasActivity) ||
(filter === 'iNominated' && !isNominatorMe) ||
(filter === 'nextSet' && !isElected)) {
return null;
}
useEffect((): void => {
let isVisible = false;
const filterLower = filterName.toLowerCase();
if ((filter === 'hasNominators' && !hasNominators) || (filter === 'noNominators' && hasNominators) || (filter === 'hasWarnings' && hasActivity) || (filter === 'noWarnings' && !hasActivity) || (filter === 'iNominated' && !isNominatorMe) || (filter === 'nextSet' && !isElected)) {
isVisible = true;
} else if (filterLower) {
if (info) {
const { identity, nickname, accountId, accountIndex } = info;
if (accountId?.toString().includes(filterName) || accountIndex?.toString().includes(filterName)) {
isVisible = true;
} else if (api.query.identity?.identityOf) {
if (identity?.display) {
isVisible = identity.display.toLowerCase().includes(filterLower);
}
} else if (nickname) {
isVisible = nickname.toLowerCase().includes(filterLower);
}
}
if (!isVisible) {
const account = keyring.getAddress(address);
isVisible = account?.meta?.name
? account.meta.name.toLowerCase().includes(filterLower)
: false;
}
} else {
isVisible = true;
}
setIsVisible(isVisible);
}, [address, filter, filterName, info]);
const lastBlockNumber = authorsMap[stashId];
const isAuthor = lastAuthors && lastAuthors.includes(stashId);
@ -121,7 +151,7 @@ function Address ({ address, authorsMap, className, filter, hasQueries, isElecte
};
return (
<tr className={`${className} ${isAuthor && 'isHighlight'}`}>
<tr className={`${className} ${isAuthor && 'isHighlight'} ${!isVisible && 'staking--hidden'}`}>
<td className='favorite'>
<Icon
className={`${isFavorite && 'isSelected'}`}

View File

@ -8,7 +8,7 @@ import { AccountId, EraPoints, Points } from '@polkadot/types/interfaces';
import { ValidatorFilter } from '../types';
import React, { useEffect, useState } from 'react';
import { Dropdown, FilterOverlay, Table } from '@polkadot/react-components';
import { Dropdown, FilterOverlay, Input, Table } from '@polkadot/react-components';
import { useAccounts, useApi, useFavorites } from '@polkadot/react-hooks';
import { STORE_FAVS_BASE } from '../constants';
@ -63,6 +63,7 @@ function CurrentList ({ authorsMap, hasQueries, isIntentions, isVisible, lastAut
const [favorites, toggleFavorite] = useFavorites(STORE_FAVS_BASE);
const [filter, setFilter] = useState<ValidatorFilter>('all');
const [{ elected, validators, waiting }, setFiltered] = useState<{ elected: AccountExtend[]; validators: AccountExtend[]; waiting: AccountExtend[] }>({ elected: [], validators: [], waiting: [] });
const [nameFilter, setNameFilter] = useState<string>('');
useEffect((): void => {
if (isVisible && stakingOverview) {
@ -86,6 +87,7 @@ function CurrentList ({ authorsMap, hasQueries, isIntentions, isVisible, lastAut
authorsMap={authorsMap}
defaultName={defaultName}
filter={filter}
filterName={nameFilter}
hasQueries={hasQueries}
isElected={isElected}
isFavorite={isFavorite}
@ -120,6 +122,13 @@ function CurrentList ({ authorsMap, hasQueries, isIntentions, isVisible, lastAut
withLabel={false}
/>
</FilterOverlay>
<Input
autoFocus
isFull
label={t('filter by name, address or index')}
onChange={setNameFilter}
value={nameFilter}
/>
<Table className={isIntentions ? 'staking--hidden' : ''}>
<Table.Body>
{_renderRows(validators, t('validators'), true)}

View File

@ -132,16 +132,16 @@ function AccountName ({ children, className, defaultName, label, onClick, overri
<div>{`${identity.judgements.length ? identity.judgements.length : 'no'} judgement${identity.judgements.length === 1 ? '' : 's'}${identity.judgements.length ? ': ' : ''}${identity.judgements.map(([, judgement]): string => judgement.toString()).join(', ')}`}</div>
<table>
<tbody>
<tr>
<td>{t('display')}</td>
<td>{identity.display}</td>
</tr>
{identity.parent && (
<tr>
<td>{t('parent')}</td>
<td><AddressMini value={identity.parent} /></td>
</tr>
)}
<tr>
<td>{t('display')}</td>
<td>{identity.display}</td>
</tr>
{identity.legal && (
<tr>
<td>{t('legal')}</td>
@ -180,6 +180,13 @@ function AccountName ({ children, className, defaultName, label, onClick, overri
const displayName = isGood
? identity.display
: identity.display.replace(/[^\x20-\x7E]/g, '');
const displayParent = identity.displayParent
? (
isGood
? identity.displayParent
: identity.displayParent.replace(/[^\x20-\x7E]/g, '')
)
: undefined;
const name = (
<div className='via-identity'>
@ -198,7 +205,11 @@ function AccountName ({ children, className, defaultName, label, onClick, overri
: 'gray'
}
/>
<span className={`name ${isGood && 'isGood'}`}>{displayName}</span>
{
displayParent
? <span className={`name ${isGood && 'isGood'}`}>{displayParent}/{displayName}</span>
: <span className={`name ${isGood && 'isGood'}`}>{displayName}</span>
}
</div>
);
@ -307,6 +318,14 @@ export default styled(AccountName)`
&.isLocal {
opacity: 1;
}
.sub {
font-size: 0.75rem;
}
}
div.name {
display: inline-block;
}
> * {