// Copyright 2017-2019 @polkadot/app-toolbox 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 { I18nProps as Props } from '@polkadot/ui-app/types'; import React from 'react'; import { Input, Output, Static } from '@polkadot/ui-app/index'; import { hexToU8a, isHex, stringToU8a } from '@polkadot/util'; import { blake2AsHex } from '@polkadot/util-crypto'; import translate from './translate'; type State = { data: string, hash: string, isHexData: boolean }; class Hash extends React.PureComponent { state: State = { data: '', hash: blake2AsHex(stringToU8a(''), 256), isHexData: false }; render () { return (
{this.renderInput()} {this.renderOutput()}
); } renderInput () { const { t } = this.props; const { data, isHexData } = this.state; return (
); } renderOutput () { const { t } = this.props; const { hash } = this.state; return (
); } onChangeData = (data: string): void => { const isHexData = isHex(data); const hash = blake2AsHex( isHexData ? hexToU8a(data) : stringToU8a(data), 256 ); this.setState({ data, hash, isHexData }); } } export default translate(Hash);