// Copyright 2017-2019 @polkadot/example-react 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, { useEffect, useState } from 'react'; import ReactDOM from 'react-dom'; import Identicon from '@polkadot/react-identicon'; import keyring from '@polkadot/ui-keyring'; import settings from '@polkadot/ui-settings'; import { mnemonicGenerate, cryptoWaitReady } from '@polkadot/util-crypto'; interface Props { className?: string; } const rootElement = document.getElementById('example'); if (!rootElement) { throw new Error('Unable to find element with id \'example\''); } function App ({ className }: Props): React.ReactElement | null { const [address, setAddress] = useState(null); const [phrase, setPhrase] = useState(null); const [ss58Format, setSS58Format] = useState(42); const _onClickNew = (): void => { const phrase = mnemonicGenerate(12); const { address } = keyring.createFromUri(phrase); setAddress(keyring.encodeAddress(address, ss58Format)); setPhrase(phrase); }; const _onChangeSS58Format = ({ currentTarget: { value } }: React.SyntheticEvent): void => { setSS58Format(parseInt(value, 10)); }; useEffect((): void => { _onClickNew(); }, []); useEffect((): void => { address && setAddress(keyring.encodeAddress(address, ss58Format)); }, [address, ss58Format]); if (!address || !phrase) { return null; } return (