From 67e9d8225fdf73f64bd1ac0df6f9ca9d019ed229 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sat, 20 Jun 2020 21:33:52 +0200 Subject: [PATCH] Target toggles (#3008) * Additional target toggles * Adjust toggle bar --- .../page-staking/src/Targets/Validator.tsx | 7 ++-- packages/page-staking/src/Targets/index.tsx | 42 ++++++++++--------- packages/page-staking/src/index.tsx | 3 +- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/packages/page-staking/src/Targets/Validator.tsx b/packages/page-staking/src/Targets/Validator.tsx index 8cdd2d6481..e3e4a86606 100644 --- a/packages/page-staking/src/Targets/Validator.tsx +++ b/packages/page-staking/src/Targets/Validator.tsx @@ -22,7 +22,8 @@ interface Props { isSelected: boolean; toggleFavorite: (accountId: string) => void; toggleSelected: (accountId: string) => void; - withoutName: boolean; + withElected: boolean; + withIdentity: boolean; } function checkVisibility (api: ApiPromise, accountInfo: DeriveAccountInfo): boolean { @@ -45,7 +46,7 @@ function checkVisibility (api: ApiPromise, accountInfo: DeriveAccountInfo): bool return isVisible; } -function Validator ({ canSelect, info, isSelected, toggleFavorite, toggleSelected, withoutName }: Props): React.ReactElement | null { +function Validator ({ canSelect, info, isSelected, toggleFavorite, toggleSelected, withElected, withIdentity }: Props): React.ReactElement | null { const { api } = useApi(); const accountInfo = useCall(api.derive.accounts.info, [info.accountId]); const [hasName, setHasName] = useState(true); @@ -71,7 +72,7 @@ function Validator ({ canSelect, info, isSelected, toggleFavorite, toggleSelecte [info.key, toggleSelected] ); - if (!hasName && !withoutName) { + if ((withIdentity && !hasName) || (withElected && !info.isElected)) { return null; } diff --git a/packages/page-staking/src/Targets/index.tsx b/packages/page-staking/src/Targets/index.tsx index 289e647742..3bf1c2c890 100644 --- a/packages/page-staking/src/Targets/index.tsx +++ b/packages/page-staking/src/Targets/index.tsx @@ -51,7 +51,8 @@ function Targets ({ className = '', ownStashes, targets: { calcWith, lastReward, const ownNominators = useOwnNominators(ownStashes); const [selected, setSelected] = useState([]); const [sorted, setSorted] = useState(); - const [withoutName, setWithoutName] = useState(true); + const [withElected, setWithElected] = useState(false); + const [withIdentity, setWithIdentity] = useState(false); const [{ sortBy, sortFromMax }, setSortBy] = useState({ sortBy: 'rankOverall', sortFromMax: true }); useEffect((): void => { @@ -82,14 +83,14 @@ function Targets ({ className = '', ownStashes, targets: { calcWith, lastReward, const _selectProfitable = useCallback( () => setSelected( (validators || []).reduce((result: string[], { hasIdentity, isElected, isFavorite, key, rewardPayout }): string[] => { - if ((result.length < MAX_NOMINATIONS) && (withoutName || hasIdentity) && (isElected || isFavorite) && !rewardPayout.isZero()) { + if ((result.length < MAX_NOMINATIONS) && (hasIdentity || !withIdentity) && (isElected || isFavorite) && !rewardPayout.isZero()) { result.push(key); } return result; }, []) ), - [validators, withoutName] + [validators, withIdentity] ); const labels = useMemo( @@ -127,23 +128,9 @@ function Targets ({ className = '', ownStashes, targets: { calcWith, lastReward, onChange={setCalcWith} value={calcWith} /> -
- {api.query.identity && ( - ('with/without identity') - : t('only with an identity') - } - onChange={setWithoutName} - value={withoutName} - /> - )} -
) - ), [api, calcWith, setCalcWith, sorted, t, withoutName]); + ), [calcWith, setCalcWith, sorted, t]); return (
@@ -154,6 +141,22 @@ function Targets ({ className = '', ownStashes, targets: { calcWith, lastReward, totalStaked={totalStaked} /> + + ('limit to elected')} + onChange={setWithElected} + value={withElected} + /> + {api.query.identity && ( + ('only with an identity')} + onChange={setWithIdentity} + value={withIdentity} + /> + )} +