Outcome.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2017-2019 @polkadot/app-contracts 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 { ContractCallOutcome } from '@polkadot/api-contract/types';
  5. import React from 'react';
  6. import styled from 'styled-components';
  7. import { AddressMini, Button, MessageSignature, Output } from '@polkadot/react-components';
  8. interface Props {
  9. className?: string;
  10. onClear?: () => void;
  11. outcome: ContractCallOutcome;
  12. }
  13. function Outcome (props: Props): React.ReactElement<Props> | null {
  14. const { className, onClear, outcome: { message, origin, output, params, isSuccess, time } } = props;
  15. const dateTime = new Date(time);
  16. return (
  17. <div className={className}>
  18. <div className='info'>
  19. <AddressMini
  20. className='origin'
  21. value={origin}
  22. withAddress={false}
  23. isPadded={false}
  24. />
  25. <MessageSignature
  26. message={message}
  27. params={params}
  28. />
  29. <span className='date-time'>
  30. {dateTime.toLocaleDateString()}
  31. {' '}
  32. {dateTime.toLocaleTimeString()}
  33. </span>
  34. <Button
  35. className='icon-button clear-btn'
  36. icon='close'
  37. size='mini'
  38. isPrimary
  39. onClick={onClear}
  40. />
  41. </div>
  42. <Output
  43. isError={!isSuccess}
  44. className='output'
  45. value={(output || '()').toString()}
  46. withCopy
  47. withLabel={false}
  48. />
  49. </div>
  50. );
  51. }
  52. export default styled(Outcome)`
  53. & {
  54. .info {
  55. display: inline-flex;
  56. justify-content: center;
  57. align-items: center;
  58. padding: 0.5rem;
  59. & > *:not(:first-child) {
  60. padding-left: 1.5rem !important;
  61. }
  62. }
  63. .clear-btn {
  64. opacity: 0;
  65. }
  66. .date-time {
  67. color: #aaa;
  68. white-space: nowrap;
  69. }
  70. .origin {
  71. padding-left: 0 !important;
  72. * {
  73. margin-left: 0 !important;
  74. }
  75. }
  76. .output {
  77. font-family: monospace;
  78. margin-left: 3.5rem;
  79. .ui--output {
  80. border-color: #aaa;
  81. margin: 0;
  82. }
  83. }
  84. &:hover {
  85. .clear-btn {
  86. opacity: 1;
  87. }
  88. }
  89. }
  90. `;