Firm up on change controller (#3214)

This commit is contained in:
Jaco Greeff 2020-07-16 18:11:42 +02:00 committed by GitHub
parent 1d25f97798
commit 65db25b254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -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) {

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, { 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<Props> {
const { t } = useTranslation();
const [, setControllerError] = useState<string | null>(null);
const [isFatal, setIsFatal] = useState(false);
const [controllerId, setControllerId] = useState<string | null>(null);
const _setError = useCallback(
(_: string | null, isFatal: boolean) => setIsFatal(isFatal),
[]
);
return (
<Modal
header={t<string>('Change controller account')}
@ -51,7 +56,7 @@ function SetControllerAccount ({ defaultControllerId, onClose, stashId }: Props)
accountId={stashId}
controllerId={controllerId}
defaultController={defaultControllerId}
onError={setControllerError}
onError={_setError}
/>
</Modal.Column>
<Modal.Column>
@ -63,7 +68,7 @@ function SetControllerAccount ({ defaultControllerId, onClose, stashId }: Props)
<TxButton
accountId={stashId}
icon='sign-in-alt'
isDisabled={!controllerId}
isDisabled={!controllerId || isFatal}
isPrimary
label={t<string>('Set controller')}
onStart={onClose}