// Copyright 2017-2018 Jaco Greeff // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. // @flow import type { I18nProps } from '@polkadot/ui-app/types'; import React from 'react'; import Button from '@polkadot/ui-app/Button'; import Input from '@polkadot/ui-app/Input'; import Password from '@polkadot/ui-app/Password'; import classes from '@polkadot/ui-app/util/classes'; import keyring from '@polkadot/ui-keyring'; import isHex from '@polkadot/util/is/hex'; import hexToU8a from '@polkadot/util/hex/toU8a'; import u8aFromString from '@polkadot/util/u8a/fromString'; import u8aToHex from '@polkadot/util/u8a/toHex'; import keypairFromSeed from '@polkadot/util-crypto/nacl/keypair/fromSeed'; import randomBytes from '@polkadot/util-crypto/random/asU8a'; import addressEncode from '@polkadot/util-keyring/address/encode'; import Address from './Address'; import translate from './translate'; type Props = I18nProps & { onBack: () => void }; type State = { address: string, isNameValid: boolean, isSeedValid: boolean, isPassValid: boolean, isValid: boolean, name: string, password: string, seed: string } function formatSeed (seed: string): Uint8Array { return isHex(seed) ? hexToU8a(seed) : u8aFromString(seed.padEnd(32, ' ')); } function addressFromSeed (seed: string): string { return addressEncode( keypairFromSeed( formatSeed(seed) ).publicKey ); } class Creator extends React.PureComponent { state: State; constructor (props: Props) { super(props); this.state = this.emptyState(); } render (): React$Node { const { className, style } = this.props; const { address, isSeedValid } = this.state; return (
{this.renderInput()}
{this.renderButtons()}
); } renderButtons (): React$Node { const { t } = this.props; const { isValid } = this.state; return (