Event.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2017-2020 @polkadot/react-components authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import { Event } from '@polkadot/types/interfaces';
  5. import { Codec, TypeDef } from '@polkadot/types/types';
  6. import { BareProps } from './types';
  7. import React from 'react';
  8. import { getTypeDef } from '@polkadot/types';
  9. import Params from '@polkadot/react-params';
  10. import { classes } from './util';
  11. export interface Props extends BareProps {
  12. children?: React.ReactNode;
  13. value: Event;
  14. }
  15. function EventDisplay ({ children, className, style, value }: Props): React.ReactElement<Props> {
  16. const params = value.typeDef.map(({ type }): { type: TypeDef } => ({
  17. type: getTypeDef(type)
  18. }));
  19. const values = value.data.map((value): { isValid: boolean; value: Codec } => ({
  20. isValid: true,
  21. value
  22. }));
  23. return (
  24. <div
  25. className={classes('ui--Event', className)}
  26. style={style}
  27. >
  28. {children}
  29. <Params
  30. isDisabled
  31. params={params}
  32. values={values}
  33. />
  34. </div>
  35. );
  36. }
  37. export default React.memo(EventDisplay);