Results.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2017-2018 @polkadot/app-rpc authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the ISC license. See the LICENSE file for details.
  4. import { BareProps } from '@polkadot/ui-app/types';
  5. import { QueueTx } from '@polkadot/ui-signer/types';
  6. import React from 'react';
  7. import Output from '@polkadot/ui-app/Output';
  8. import classes from '@polkadot/ui-app/util/classes';
  9. import isUndefined from '@polkadot/util/is/undefined';
  10. import resultToText from './resultToText';
  11. type Props = BareProps & {
  12. queue: Array<QueueTx>
  13. };
  14. export default function Results ({ className, queue = [], style }: Props) {
  15. const filtered = queue
  16. .filter(({ error, result }) =>
  17. !isUndefined(error) || !isUndefined(result)
  18. )
  19. .reverse();
  20. if (!filtered.length) {
  21. return null;
  22. }
  23. return (
  24. <div
  25. className={classes('rpc--Results', className)}
  26. style={style}
  27. >
  28. {filtered.map(({ error, id, result, rpc: { section, name } }) => (
  29. <Output
  30. isError={!!error}
  31. key={id}
  32. label={`${id}: ${section}.${name}`}
  33. value={
  34. error
  35. ? error.message
  36. : resultToText(result)
  37. }
  38. />
  39. ))}
  40. </div>
  41. );
  42. }