Create Nominate on-demand (#2556)

This commit is contained in:
Jaco Greeff 2020-04-12 09:31:33 +02:00 committed by GitHub
parent e867b65f8e
commit 66cba71e25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 42 deletions

View File

@ -2,7 +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 React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import styled from 'styled-components';
import { InputAddressMulti, InputAddress, Modal, TxButton } from '@polkadot/react-components';
import { useFavorites } from '@polkadot/react-hooks';
@ -13,7 +13,6 @@ import { useTranslation } from '../../translate';
interface Props {
className?: string;
controllerId: string;
isOpen: boolean;
next?: string[];
nominees?: string[];
onClose: () => void;
@ -23,13 +22,11 @@ interface Props {
const MAX_NOMINEES = 16;
function Nominate ({ className, controllerId, isOpen, next, nominees, onClose, stashId, validators }: Props): React.ReactElement<Props> | null {
function Nominate ({ className, controllerId, next, nominees, onClose, stashId, validators }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const [favorites] = useFavorites(STORE_FAVS_BASE);
const [selection, setSelection] = useState<string[]>([]);
const [available, setAvailable] = useState<string[]>([]);
useEffect((): void => {
const [available] = useState<string[]>((): string[] => {
const shortlist = [
// ensure that the favorite is included in the list of stashes
...favorites.filter((acc) => (validators || []).includes(acc) || (next || []).includes(acc)),
@ -37,16 +34,10 @@ function Nominate ({ className, controllerId, isOpen, next, nominees, onClose, s
...(nominees || []).filter((acc) => !favorites.includes(acc))
];
setAvailable([
...shortlist,
...(validators || []).filter((acc) => !shortlist.includes(acc)),
...(next || []).filter((acc) => !shortlist.includes(acc))
]);
}, [favorites, next, nominees, validators]);
if (!isOpen) {
return null;
}
return shortlist
.concat(...(validators || []).filter((acc) => !shortlist.includes(acc)))
.concat(...(next || []).filter((acc) => !shortlist.includes(acc)));
});
return (
<Modal

View File

@ -135,7 +135,17 @@ function Account ({ allStashes, className, isDisabled, isOwnStash, next, onUpdat
return (
<tr className={className}>
<td className='address'>
{controllerId && (
<AddressSmall value={stashId} />
{isBondExtraOpen && (
<BondExtra
onClose={toggleBondExtra}
stashId={stashId}
/>
)}
{isInjectOpen && (
<InjectKeys onClose={toggleInject} />
)}
{isNominateOpen && controllerId && (
<Nominate
controllerId={controllerId}
isOpen={isNominateOpen}
@ -146,30 +156,6 @@ function Account ({ allStashes, className, isDisabled, isOwnStash, next, onUpdat
validators={validators}
/>
)}
{isUnbondOpen && (
<Unbond
controllerId={controllerId}
onClose={toggleUnbond}
stakingLedger={stakingLedger}
stashId={stashId}
/>
)}
{isValidateOpen && controllerId && (
<Validate
controllerId={controllerId}
onClose={toggleValidate}
stashId={stashId}
/>
)}
{isBondExtraOpen && (
<BondExtra
onClose={toggleBondExtra}
stashId={stashId}
/>
)}
{isInjectOpen && (
<InjectKeys onClose={toggleInject} />
)}
{isSetControllerOpen && controllerId && (
<SetControllerAccount
defaultControllerId={controllerId}
@ -190,7 +176,21 @@ function Account ({ allStashes, className, isDisabled, isOwnStash, next, onUpdat
onClose={toggleSetSession}
/>
)}
<AddressSmall value={stashId} />
{isUnbondOpen && (
<Unbond
controllerId={controllerId}
onClose={toggleUnbond}
stakingLedger={stakingLedger}
stashId={stashId}
/>
)}
{isValidateOpen && controllerId && (
<Validate
controllerId={controllerId}
onClose={toggleValidate}
stashId={stashId}
/>
)}
</td>
<td className='address'>
<AddressMini value={controllerId} />