// Copyright 2019 @polkadot/extension-ui authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. import React, { useContext, useState } from 'react'; import { ActionContext, Address, Button, Header, TextArea } from '../components'; import { createAccountSuri, validateSeed } from '../messaging'; import { Back, Name, Password } from '../partials'; type Props = {}; export default function Import (): React.ReactElement { const onAction = useContext(ActionContext); const [account, setAccount] = useState(null); const [name, setName] = useState(null); const [password, setPassword] = useState(null); const _onChangeSeed = (suri: string): Promise => validateSeed(suri) .then(setAccount) .catch((): void => setAccount(null)); // FIXME Duplicated between here and Create.tsx const _onCreate = (): void => { // this should always be the case if (name && password && account) { createAccountSuri(name, password, account.suri) .then((): void => onAction('/')) .catch((error: Error) => console.error(error)); } }; return (