// Copyright 2017-2019 @polkadot/app-explorer 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 } from '@polkadot/ui-app/types'; import React from 'react'; import { DigestItem, Struct, Tuple, U8a, Vector, getTypeDef } from '@polkadot/types'; import Params from '@polkadot/ui-params/index'; import translate from '../translate'; type Props = I18nProps & { value?: Array }; class Logs extends React.PureComponent { render () { const { t, value } = this.props; if (!value || !value.length) { return null; } return (

{t('logs')}

{value.map(this.renderItem)}
); } private renderItem = (item: DigestItem, index: number) => { let content: React.ReactNode; if (item.value instanceof Struct) { content = this.formatStruct(item.value); } else if (item.value instanceof Tuple) { content = this.formatTuple(item.value); } else if (item.value instanceof Vector) { content = this.formatVector(item.value); } else if (item.value instanceof U8a) { content = this.formatU8a(item.value); } else { content =
{item.value.toString().split(',').join(', ')}
; } return (

{item.type.toString()}

Details {content}
); } private formatU8a (value: U8a) { return ( ); } private formatStruct (struct: Struct) { const types: { [index: string]: string } = struct.Type; const params = Object.keys(types).map((name) => ({ name, type: getTypeDef(types[name]) })); const values = struct.toArray().map((value) => ({ isValid: true, value })); return ( ); } private formatTuple (tuple: Tuple) { const types = tuple.Types; const params = types.map((type) => ({ type: getTypeDef(type) })); const values = tuple.toArray().map((value) => ({ isValid: true, value })); return ( ); } private formatVector (vector: Vector) { const type = getTypeDef(vector.Type); const values = vector.toArray().map((value) => ({ isValid: true, value })); const params = values.map((_, index) => ({ name: `${index}`, type })); return ( ); } } export default translate(Logs);