From 65db25b25488f33dbc46c8c090ab7738bebf7a23 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 16 Jul 2020 18:11:42 +0200 Subject: [PATCH] Firm up on change controller (#3214) --- .../Actions/Account/InputValidationController.tsx | 2 +- .../src/Actions/Account/SetControllerAccount.tsx | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/page-staking/src/Actions/Account/InputValidationController.tsx b/packages/page-staking/src/Actions/Account/InputValidationController.tsx index d81cf94cd9..a0599a4edf 100644 --- a/packages/page-staking/src/Actions/Account/InputValidationController.tsx +++ b/packages/page-staking/src/Actions/Account/InputValidationController.tsx @@ -49,7 +49,7 @@ function ValidateController ({ accountId, controllerId, defaultController, onErr let newError: string | null = null; let isFatal = false; - if (bondedId) { + if (bondedId && (controllerId !== accountId)) { isFatal = true; newError = t('A controller account should not map to another stash. This selected controller is a stash, controlled by {{bondedId}}', { replace: { bondedId } }); } else if (stashId) { diff --git a/packages/page-staking/src/Actions/Account/SetControllerAccount.tsx b/packages/page-staking/src/Actions/Account/SetControllerAccount.tsx index d2e03d65b5..5bb9756291 100644 --- a/packages/page-staking/src/Actions/Account/SetControllerAccount.tsx +++ b/packages/page-staking/src/Actions/Account/SetControllerAccount.tsx @@ -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, { useState } from 'react'; +import React, { useCallback, useState } from 'react'; import { InputAddress, Modal, TxButton } from '@polkadot/react-components'; import { useTranslation } from '../../translate'; @@ -16,9 +16,14 @@ interface Props { function SetControllerAccount ({ defaultControllerId, onClose, stashId }: Props): React.ReactElement { const { t } = useTranslation(); - const [, setControllerError] = useState(null); + const [isFatal, setIsFatal] = useState(false); const [controllerId, setControllerId] = useState(null); + const _setError = useCallback( + (_: string | null, isFatal: boolean) => setIsFatal(isFatal), + [] + ); + return ( ('Change controller account')} @@ -51,7 +56,7 @@ function SetControllerAccount ({ defaultControllerId, onClose, stashId }: Props) accountId={stashId} controllerId={controllerId} defaultController={defaultControllerId} - onError={setControllerError} + onError={_setError} /> @@ -63,7 +68,7 @@ function SetControllerAccount ({ defaultControllerId, onClose, stashId }: Props) ('Set controller')} onStart={onClose}