Limit nominees to 16 (#1717)
This commit is contained in:
parent
ed4229c6f2
commit
5328d54294
@ -19,13 +19,24 @@ interface Props extends I18nProps {
|
||||
stashOptions: KeyringSectionOption[];
|
||||
}
|
||||
|
||||
// We only allow a maximum of 16 nominees, negative to slice
|
||||
const MAX_NOMINEES = -16;
|
||||
|
||||
function Nominate ({ controllerId, isOpen, onClose, stashId, stashOptions, t }: Props): React.ReactElement<Props> | null {
|
||||
const [nominees, setNominees] = useState<string[] | undefined>();
|
||||
const [nominees, setNominees] = useState<string[]>([]);
|
||||
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const _onChangeNominees = (_nominees: string[]): void => {
|
||||
const newNominees = _nominees.slice(MAX_NOMINEES);
|
||||
|
||||
if (JSON.stringify(newNominees) !== JSON.stringify(nominees)) {
|
||||
setNominees(newNominees);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
className='staking--Nominating'
|
||||
@ -51,14 +62,15 @@ function Nominate ({ controllerId, isOpen, onClose, stashId, stashOptions, t }:
|
||||
/>
|
||||
<InputAddress
|
||||
className='medium'
|
||||
help={t('Stash accounts that are to be nominated. Block rewards are split between validators and nominators. Only 16 nominees will be taken into account.')}
|
||||
isInput={false}
|
||||
isMultiple
|
||||
help={t('Stash accounts that are to be nominated. Block rewards are split between validators and nominators')}
|
||||
label={t('nominate the following addresses')}
|
||||
onChangeMulti={setNominees}
|
||||
onChangeMulti={_onChangeNominees}
|
||||
options={stashOptions}
|
||||
placeholder={t('select accounts(s) nominate')}
|
||||
type='account'
|
||||
value={nominees}
|
||||
/>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
@ -72,7 +84,7 @@ function Nominate ({ controllerId, isOpen, onClose, stashId, stashOptions, t }:
|
||||
<Button.Or />
|
||||
<TxButton
|
||||
accountId={controllerId}
|
||||
isDisabled={!nominees || nominees.length === 0}
|
||||
isDisabled={nominees.length === 0}
|
||||
isPrimary
|
||||
onClick={onClose}
|
||||
params={[nominees]}
|
||||
|
||||
@ -47,7 +47,7 @@ type ExportedType = React.ComponentType<Props> & {
|
||||
};
|
||||
|
||||
interface State {
|
||||
value?: string;
|
||||
value?: string | string[];
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'options:InputAddress';
|
||||
@ -187,8 +187,8 @@ class InputAddress extends React.PureComponent<Props, State> {
|
||||
}
|
||||
style={style}
|
||||
value={
|
||||
isMultiple
|
||||
? undefined
|
||||
isMultiple && !value
|
||||
? []
|
||||
: value
|
||||
}
|
||||
withEllipsis={withEllipsis}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user