Indicate own nominees on targets (#3133)
* Indicate own nominees on targets * icon prop to Badge * AddressName cachin cleanups
This commit is contained in:
parent
17e942649d
commit
ca5a5a95c1
@ -234,7 +234,7 @@ function Account ({ account: { address, meta }, className = '', filter, isFavori
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
info={<Icon icon='shield' />}
|
||||
icon='shield'
|
||||
isInline
|
||||
isTooltip
|
||||
/>
|
||||
|
||||
@ -128,7 +128,7 @@ function Referendum ({ className = '', value: { allAye, allNay, image, imageHash
|
||||
? t<string>('{{threshold}}, passing', { replace: { threshold } })
|
||||
: t<string>('{{threshold}}, not passing', { replace: { threshold } })
|
||||
}
|
||||
info={<Icon icon={isPassing ? 'check' : 'times'} />}
|
||||
icon={isPassing ? 'check' : 'times'}
|
||||
isInline
|
||||
isTooltip
|
||||
/>
|
||||
|
||||
@ -21,7 +21,7 @@ function Status ({ isElected, numNominators, onlineCount, onlineMessage }: Props
|
||||
? (
|
||||
<Badge
|
||||
color='blue'
|
||||
info={<Icon icon='chevron-right' />}
|
||||
icon='chevron-right'
|
||||
isInline
|
||||
/>
|
||||
)
|
||||
|
||||
@ -21,6 +21,7 @@ interface Props {
|
||||
canSelect: boolean;
|
||||
filterName: string;
|
||||
info: ValidatorInfo;
|
||||
isNominated: boolean;
|
||||
isSelected: boolean;
|
||||
toggleFavorite: (accountId: string) => void;
|
||||
toggleSelected: (accountId: string) => void;
|
||||
@ -48,7 +49,7 @@ function checkIdentity (api: ApiPromise, accountInfo: DeriveAccountInfo): boolea
|
||||
return hasIdentity;
|
||||
}
|
||||
|
||||
function Validator ({ canSelect, filterName, info, isSelected, toggleFavorite, toggleSelected, withElected, withIdentity }: Props): React.ReactElement<Props> | null {
|
||||
function Validator ({ canSelect, filterName, info, isNominated, isSelected, toggleFavorite, toggleSelected, withElected, withIdentity }: Props): React.ReactElement<Props> | null {
|
||||
const { api } = useApi();
|
||||
const accountInfo = useCall<DeriveAccountInfo>(api.derive.accounts.info, [info.accountId]);
|
||||
const [isVisible, setVisibility] = useState(true);
|
||||
@ -86,13 +87,36 @@ function Validator ({ canSelect, filterName, info, isSelected, toggleFavorite, t
|
||||
toggleFavorite={toggleFavorite}
|
||||
/>
|
||||
<td className='badge together'>
|
||||
{isElected && (
|
||||
<Badge
|
||||
color='blue'
|
||||
info={<Icon icon='chevron-right' />}
|
||||
isInline
|
||||
/>
|
||||
)}
|
||||
{isNominated
|
||||
? (
|
||||
<Badge
|
||||
color='green'
|
||||
icon='hand-paper'
|
||||
isInline
|
||||
/>
|
||||
)
|
||||
: (
|
||||
<Badge
|
||||
color='transparent'
|
||||
isInline
|
||||
/>
|
||||
)
|
||||
}
|
||||
{isElected
|
||||
? (
|
||||
<Badge
|
||||
color='blue'
|
||||
icon='chevron-right'
|
||||
isInline
|
||||
/>
|
||||
)
|
||||
: (
|
||||
<Badge
|
||||
color='transparent'
|
||||
isInline
|
||||
/>
|
||||
)
|
||||
}
|
||||
<MaxBadge numNominators={numNominators} />
|
||||
</td>
|
||||
<td className='number'>{formatNumber(rankOverall)}</td>
|
||||
|
||||
@ -53,6 +53,7 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { calcWit
|
||||
const ownNominators = useOwnNominators(ownStashes);
|
||||
const [selected, setSelected] = useState<string[]>([]);
|
||||
const [sorted, setSorted] = useState<number[] | undefined>();
|
||||
const [myNominees, setMyNominees] = useState<string[]>([]);
|
||||
const [nameFilter, setNameFilter] = useState<string>('');
|
||||
const [withElected, setWithElected] = useState(false);
|
||||
const [withIdentity, setWithIdentity] = useState(false);
|
||||
@ -64,6 +65,17 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { calcWit
|
||||
);
|
||||
}, [sortBy, sortFromMax, validators]);
|
||||
|
||||
useEffect((): void => {
|
||||
ownNominators && setMyNominees(
|
||||
ownNominators.reduce((myNominees: string[], nominator): string[] =>
|
||||
(nominator.nominating || []).reduce((myNominees: string[], nominee): string[] => {
|
||||
!myNominees.includes(nominee) && myNominees.push(nominee);
|
||||
|
||||
return myNominees;
|
||||
}, myNominees), [])
|
||||
);
|
||||
}, [ownNominators]);
|
||||
|
||||
const _sort = useCallback(
|
||||
(newSortBy: TargetSortBy) => setSortBy(({ sortBy, sortFromMax }) => ({
|
||||
sortBy: newSortBy,
|
||||
@ -188,6 +200,7 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { calcWit
|
||||
canSelect={selected.length < MAX_NOMINATIONS}
|
||||
filterName={nameFilter}
|
||||
info={validators[index]}
|
||||
isNominated={myNominees.includes(validators[index].key)}
|
||||
isSelected={selected.includes(validators[index].key)}
|
||||
key={validators[index].key}
|
||||
toggleFavorite={toggleFavorite}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { IconName } from '@fortawesome/fontawesome-svg-core';
|
||||
import { DeriveAccountInfo, DeriveAccountRegistration } from '@polkadot/api-derive/types';
|
||||
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||
|
||||
@ -14,7 +15,6 @@ import { isFunction, stringToU8a } from '@polkadot/util';
|
||||
|
||||
import { getAddressName } from './util';
|
||||
import Badge from './Badge';
|
||||
import Icon from './Icon';
|
||||
|
||||
interface Props {
|
||||
children?: React.ReactNode;
|
||||
@ -77,7 +77,7 @@ function extractName (address: string, accountIndex?: AccountIndex, defaultName?
|
||||
{isSpecial && (
|
||||
<Badge
|
||||
color='green'
|
||||
info={<Icon icon='archway' />}
|
||||
icon='archway'
|
||||
isInline
|
||||
isSmall
|
||||
/>
|
||||
@ -91,12 +91,12 @@ function extractName (address: string, accountIndex?: AccountIndex, defaultName?
|
||||
);
|
||||
}
|
||||
|
||||
function createIdElem (color: 'green' | 'red' | 'gray', nameElem: React.ReactNode, infoElem: React.ReactNode): React.ReactNode {
|
||||
function createIdElem (nameElem: React.ReactNode, color: 'green' | 'red' | 'gray', icon: IconName): React.ReactNode {
|
||||
return (
|
||||
<div className='via-identity'>
|
||||
<Badge
|
||||
color={color}
|
||||
info={infoElem}
|
||||
icon={icon}
|
||||
isInline
|
||||
isSmall
|
||||
isTooltip
|
||||
@ -113,27 +113,27 @@ function extractIdentity (address: string, identity: DeriveAccountRegistration):
|
||||
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 nameElem = (
|
||||
<span className={`name ${isGood ? 'isGood' : ''}`}>
|
||||
{displayParent
|
||||
? <><span className='top'>{displayParent}</span><span className='sub'>/{displayName}</span></>
|
||||
: displayName
|
||||
}
|
||||
</span>
|
||||
const displayParent = identity.displayParent && (
|
||||
isGood
|
||||
? identity.displayParent
|
||||
: identity.displayParent.replace(/[^\x20-\x7E]/g, '')
|
||||
);
|
||||
const elem = createIdElem(
|
||||
(
|
||||
<span className={`name ${isGood ? 'isGood' : ''}`}>
|
||||
{displayParent
|
||||
? <><span className='top'>{displayParent}</span><span className='sub'>/{displayName}</span></>
|
||||
: displayName
|
||||
}
|
||||
</span>
|
||||
),
|
||||
isGood ? 'green' : (isBad ? 'red' : 'gray'),
|
||||
identity.parent ? 'link' : (isGood ? 'check' : 'minus')
|
||||
);
|
||||
const infoElem = <Icon icon={identity.parent ? 'link' : (isGood ? 'check' : 'minus')} />;
|
||||
const color = isGood ? 'green' : (isBad ? 'red' : 'gray');
|
||||
|
||||
displayCache.set(address, createIdElem(color, nameElem, infoElem));
|
||||
displayCache.set(address, elem);
|
||||
|
||||
return createIdElem(color, nameElem, infoElem);
|
||||
return elem;
|
||||
}
|
||||
|
||||
function AccountName ({ children, className = '', defaultName, label, noLookup, onClick, override, toggle, value, withSidebar }: Props): React.ReactElement<Props> {
|
||||
|
||||
@ -2,15 +2,19 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { IconName } from '@fortawesome/fontawesome-svg-core';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import Icon from './Icon';
|
||||
import Tooltip from './Tooltip';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
color: 'counter' | 'green' | 'blue' | 'gray' | 'normal' | 'purple' | 'red' | 'transparent';
|
||||
hover?: React.ReactNode;
|
||||
icon?: IconName;
|
||||
info?: React.ReactNode;
|
||||
isInline?: boolean;
|
||||
isSmall?: boolean;
|
||||
@ -20,7 +24,7 @@ interface Props {
|
||||
|
||||
let badgeId = 0;
|
||||
|
||||
function Badge ({ className = '', color = 'normal', hover, info, isInline, isSmall, isTooltip, onClick }: Props): React.ReactElement<Props> | null {
|
||||
function Badge ({ className = '', color = 'normal', hover, icon, info, isInline, isSmall, isTooltip, onClick }: Props): React.ReactElement<Props> | null {
|
||||
const [trigger] = useState(`badge-hover-${Date.now()}-${badgeId++}`);
|
||||
const extraProps = isTooltip && hover
|
||||
? { 'data-for': trigger, 'data-tip': true }
|
||||
@ -33,7 +37,7 @@ function Badge ({ className = '', color = 'normal', hover, info, isInline, isSma
|
||||
onClick={onClick}
|
||||
>
|
||||
<div className='badge'>
|
||||
{info}
|
||||
{info || (icon && <Icon icon={icon} />)}
|
||||
</div>
|
||||
<div className='detail'>
|
||||
{hover}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user