Don't allow controllers same as stash (#869)

This commit is contained in:
Jaco Greeff 2019-03-29 14:10:16 +01:00 committed by GitHub
parent d9b6112ead
commit bc77204e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,7 +20,8 @@ type Props = I18nProps & {
type State = {
bondValue?: BN,
controllerId: string | null,
destination: number
destination: number,
isValidController: boolean
};
const stashOptions = [
@ -32,13 +33,14 @@ const stashOptions = [
class Bonding extends React.PureComponent<Props, State> {
state: State = {
controllerId: null,
destination: 0
destination: 0,
isValidController: false
};
render () {
const { accountId, isOpen, onClose, t } = this.props;
const { bondValue, controllerId, destination } = this.state;
const canSubmit = !!bondValue && bondValue.gtn(0) && controllerId;
const { bondValue, controllerId, destination, isValidController } = this.state;
const canSubmit = isValidController && !!bondValue && bondValue.gtn(0) && controllerId;
if (!isOpen) {
return null;
@ -77,7 +79,7 @@ class Bonding extends React.PureComponent<Props, State> {
private renderContent () {
const { accountId, bondedId, t } = this.props;
const { controllerId } = this.state;
const { controllerId, isValidController } = this.state;
return (
<>
@ -98,6 +100,13 @@ class Bonding extends React.PureComponent<Props, State> {
onChange={this.onChangeController}
value={controllerId}
/>
{
isValidController
? null
: (
<article className='error'>{t('Select a controller account which is not the same as you stash account. Controllers are responsible for making any actions to contol the bonded funds.')}</article>
)
}
<InputBalance
autoFocus
className='medium'
@ -117,7 +126,12 @@ class Bonding extends React.PureComponent<Props, State> {
}
private onChangeController = (controllerId: string) => {
this.setState({ controllerId });
const { accountId } = this.props;
this.setState({
controllerId,
isValidController: controllerId !== accountId
});
}
private onChangeDestination = (destination: number) => {