Transaction.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2017-2020 @polkadot/react-signer 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 { QueueTx } from '@polkadot/react-components/Status/types';
  5. import BN from 'bn.js';
  6. import React from 'react';
  7. import styled from 'styled-components';
  8. import { registry } from '@polkadot/react-api';
  9. import { Call, Expander, Modal } from '@polkadot/react-components';
  10. import { useTranslation } from './translate';
  11. import PaymentInfo from './PaymentInfo';
  12. interface Props {
  13. className?: string;
  14. currentItem: QueueTx;
  15. isSendable: boolean;
  16. onError: () => void;
  17. tip?: BN;
  18. }
  19. function Transaction ({ className, currentItem: { accountId, extrinsic, isUnsigned, payload }, isSendable, onError, tip }: Props): React.ReactElement<Props> | null {
  20. const { t } = useTranslation();
  21. if (!extrinsic) {
  22. return null;
  23. }
  24. const { meta, method, section } = registry.findMetaCall(extrinsic.callIndex);
  25. const args = meta?.args.map(({ name }) => name).join(', ') || '';
  26. return (
  27. <Modal.Columns className={className}>
  28. <Modal.Column>
  29. <Expander
  30. className='tx-details'
  31. summary={<>{t<string>('Sending transaction')} <span className='highlight'>{section}.{method}({args})</span></>}
  32. summaryMeta={meta}
  33. >
  34. <Call
  35. onError={onError}
  36. value={extrinsic}
  37. withBorder={false}
  38. />
  39. </Expander>
  40. {!isUnsigned && !payload && (
  41. <PaymentInfo
  42. accountId={accountId}
  43. className='tx-details'
  44. extrinsic={extrinsic}
  45. isSendable={isSendable}
  46. tip={tip}
  47. />
  48. )}
  49. </Modal.Column>
  50. <Modal.Column>
  51. <p>{t<string>('The details of the transaction including the type, the description (as available from the chain metadata) as well as any parameters and fee estimations (as available) for the specific type of call.')}</p>
  52. </Modal.Column>
  53. </Modal.Columns>
  54. );
  55. }
  56. export default React.memo(styled(Transaction)`
  57. .tx-details {
  58. .ui--Expander-summary {
  59. font-size: 1.1rem;
  60. margin: 0 0 0.5rem;
  61. }
  62. .highlight {
  63. font-weight: 600;
  64. }
  65. .meta {
  66. margin-bottom: 0.5rem;
  67. margin-left: 2rem;
  68. }
  69. .meta, .mute {
  70. opacity: 0.6;
  71. }
  72. }
  73. `);