diff --git a/packages/app-accounts/src/modals/Create.tsx b/packages/app-accounts/src/modals/Create.tsx index c81ce5b186..3efe6b78f9 100644 --- a/packages/app-accounts/src/modals/Create.tsx +++ b/packages/app-accounts/src/modals/Create.tsx @@ -21,6 +21,7 @@ import { isHex, u8aToHex } from '@polkadot/util'; import { keyExtractSuri, mnemonicGenerate, mnemonicValidate, randomAsU8a } from '@polkadot/util-crypto'; import translate from '../translate'; +import CreateConfirmation from './CreateConfirmation'; interface Props extends ModalProps, ApiProps, I18nProps { seed?: string; @@ -34,20 +35,23 @@ interface SeedOption { value: SeedType; } -interface State { +interface AddressState { address: string; deriveError: string | null; derivePath: string; - isNameValid: boolean; isSeedValid: boolean; + pairType: KeypairType; + seed: string; + seedType: SeedType; +} + +interface State extends AddressState { + isNameValid: boolean; isPassValid: boolean; isValid: boolean; name: string; - pairType: KeypairType; password: string; - seed: string; seedOptions: SeedOption[]; - seedType: SeedType; showWarning: boolean; tags: string[]; } @@ -87,6 +91,30 @@ function addressFromSeed (phrase: string, derivePath: string, pairType: KeypairT .address; } +function generateSeed (_seed: string | null, derivePath: string, seedType: SeedType, pairType: KeypairType): AddressState { + const seed = ((): string => { + switch (seedType) { + case 'bip': + return mnemonicGenerate(); + case 'dev': + return DEV_PHRASE; + default: + return _seed || u8aToHex(randomAsU8a()); + } + })(); + const address = addressFromSeed(seed, derivePath, pairType); + + return { + address, + deriveError: null, + derivePath, + isSeedValid: true, + pairType, + seedType, + seed + }; +} + class Create extends React.PureComponent { public state: State; @@ -103,14 +131,25 @@ class Create extends React.PureComponent { seedOptions.push({ value: 'dev', text: t('Development') }); } + const pairType = type || DEFAULT_TYPE; + const seedType = seed ? 'raw' : 'bip'; + this.state = { - ...(this.emptyState(seed || null, '', type || DEFAULT_TYPE) as State), - seedOptions + ...generateSeed(seed || null, '', seedType, pairType), + isNameValid: true, + isPassValid: false, + isValid: false, + name: 'new account', + password: '', + seedOptions, + showWarning: false, + tags: [] }; } public render (): React.ReactNode { const { className, t } = this.props; + const { address, isValid, showWarning } = this.state; return ( { open > {t('Add an account via seed')} - {this.renderModal()} + {showWarning && ( + + )} {this.renderInput()} - {this.renderButtons()} + + +