ghost-keychain/packages/extension-ui/src/components/AccountNamePasswordCreation.tsx
Thibaut Sardan 967b69ffde
Refactor seed import and add explicit derivation path field (#619)
* refactor import from seed

* stray import

* clean up duplicates

* remove unneeded global suri

* wip use AccountNamePassword component

* AccountNamePasswordCreation component and tests

* use in Derive and enhance test

* extract SeedAndPath in dedicated component

* fix disabled button

* pass address

* keep address in component
2021-01-13 10:31:26 +01:00

67 lines
1.7 KiB
TypeScript

// Copyright 2019-2021 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
import React, { useCallback, useState } from 'react';
import { Name, Password } from '../partials';
import { BackButton, ButtonArea, NextStepButton, VerticalSpace } from '.';
interface Props {
buttonLabel: string;
isBusy: boolean;
onBackClick: () => void;
onCreate: (name: string, password: string) => void | Promise<void | boolean>;
onNameChange: (name: string) => void;
}
function AccountNamePasswordCreation ({ buttonLabel, isBusy, onBackClick, onCreate, onNameChange }: Props): React.ReactElement<Props> {
const [name, setName] = useState<string | null>(null);
const [password, setPassword] = useState<string | null>(null);
const _onCreate = useCallback(
() => name && password && onCreate(name, password),
[name, password, onCreate]
);
const _onNameChange = useCallback(
(name: string | null) => {
onNameChange(name || '');
setName(name);
},
[onNameChange]
);
const _onBackClick = useCallback(
() => {
_onNameChange(null);
setPassword(null);
onBackClick();
},
[_onNameChange, onBackClick]
);
return (
<>
<Name
isFocused
onChange={_onNameChange}
/>
<Password onChange={setPassword} />
<VerticalSpace />
<ButtonArea>
<BackButton onClick={_onBackClick} />
<NextStepButton
data-button-action='add new root'
isBusy={isBusy}
isDisabled={!password || !name}
onClick={_onCreate}
>
{buttonLabel}
</NextStepButton>
</ButtonArea>
</>
);
}
export default React.memo(AccountNamePasswordCreation);