Display derive unlock error (#2866)

This commit is contained in:
Jaco Greeff 2020-06-01 12:55:38 +02:00 committed by GitHub
parent 8f82eecc1a
commit 46d7743111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,11 @@ interface DeriveAddress {
deriveError: string | null;
}
interface LockState {
isLocked: boolean;
lockedError: string | null;
}
function deriveValidate (suri: string, pairType: KeypairType): string | null {
try {
const { path } = keyExtractPath(suri);
@ -73,7 +78,7 @@ function Derive ({ className = '', from, onClose }: Props): React.ReactElement {
const [source] = useState(keyring.getPair(from));
const [{ address, deriveError }, setDerive] = useState<DeriveAddress>({ address: null, deriveError: null });
const [isConfirmationOpen, toggleConfirmation] = useToggle();
const [isLocked, setIsLocked] = useState(source.isLocked);
const [{ isLocked, lockedError }, setIsLocked] = useState<LockState>({ isLocked: source.isLocked, lockedError: null });
const [{ isNameValid, name }, setName] = useState({ isNameValid: false, name: '' });
const [{ isPassValid, password }, setPassword] = useState({ isPassValid: false, password: '' });
const [{ isPass2Valid, password2 }, setPassword2] = useState({ isPass2Valid: false, password2: '' });
@ -83,7 +88,7 @@ function Derive ({ className = '', from, onClose }: Props): React.ReactElement {
const isValid = !!address && !deriveError && isNameValid && isPassValid && isPass2Valid;
useEffect((): void => {
setIsLocked(source.isLocked);
setIsLocked({ isLocked: source.isLocked, lockedError: null });
}, [source]);
useEffect((): void => {
@ -120,11 +125,11 @@ function Derive ({ className = '', from, onClose }: Props): React.ReactElement {
(): void => {
try {
source.decodePkcs8(rootPass);
setIsLocked({ isLocked: source.isLocked, lockedError: null });
} catch (error) {
console.error(error);
setIsLocked({ isLocked: true, lockedError: (error as Error).message });
}
setIsLocked(source.isLocked);
},
[rootPass, source]
);
@ -173,6 +178,7 @@ function Derive ({ className = '', from, onClose }: Props): React.ReactElement {
<Password
autoFocus
help={t<string>('The password to unlock the selected account.')}
isError={!!lockedError}
label={t<string>('password')}
onChange={setRootPass}
value={rootPass}