From bc77204e627b1e73f693842f32978fb78e77da2b Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 29 Mar 2019 14:10:16 +0100 Subject: [PATCH] Don't allow controllers same as stash (#869) --- packages/app-staking/src/Account/Bonding.tsx | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/app-staking/src/Account/Bonding.tsx b/packages/app-staking/src/Account/Bonding.tsx index efa2d4d3a2..cd4028e460 100644 --- a/packages/app-staking/src/Account/Bonding.tsx +++ b/packages/app-staking/src/Account/Bonding.tsx @@ -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 { 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 { 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 { onChange={this.onChangeController} value={controllerId} /> + { + isValidController + ? null + : ( +
{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.')}
+ ) + } { } private onChangeController = (controllerId: string) => { - this.setState({ controllerId }); + const { accountId } = this.props; + + this.setState({ + controllerId, + isValidController: controllerId !== accountId + }); } private onChangeDestination = (destination: number) => {