AssetRow.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2019 @polkadot/app-generic-asset 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 React from 'react';
  5. import styled from 'styled-components';
  6. import { CopyButton } from '@polkadot/react-components';
  7. import Row, { styles, RowProps, RowState } from '@polkadot/react-components/Row';
  8. import { I18nProps } from '@polkadot/react-components/types';
  9. import translate from './translate';
  10. type Props = I18nProps & RowProps & {
  11. onSaveName: (name: string) => void;
  12. assetId: string;
  13. }
  14. class AssetRow extends Row<Props, RowState> {
  15. constructor (props: Props) {
  16. super(props);
  17. this.state.name = this.props.defaultName || 'New Asset';
  18. }
  19. public render (): React.ReactNode {
  20. const { className } = this.props;
  21. return (
  22. <div
  23. className={`ui--Row ${className}`}
  24. >
  25. <div className='ui--Row-base'>
  26. <div className='ui--Row-details'>
  27. {this.renderName()}
  28. {this.renderAssetId()}
  29. </div>
  30. {this.renderButtons()}
  31. </div>
  32. </div>
  33. );
  34. }
  35. protected saveName = (): void => {
  36. const { name } = this.state;
  37. const { onSaveName } = this.props;
  38. const trimmedName = name.trim();
  39. onSaveName(trimmedName);
  40. this.setState({ isEditingName: false });
  41. }
  42. private renderAssetId (): React.ReactNode {
  43. const { assetId, t } = this.props;
  44. return (
  45. <div className='ui--Row-details'>
  46. <CopyButton value={assetId}>
  47. <span>{t('Asset ID')}: {assetId}</span>
  48. </CopyButton>
  49. </div>
  50. );
  51. }
  52. }
  53. export default translate(styled(AssetRow)`${styles}`);