// Copyright 2017-2021 @polkadot/react-params authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Codec } from '@polkadot/types/types'; import type { RawParam } from '../types'; import React from 'react'; import styled from 'styled-components'; import { Static } from '@polkadot/react-components'; import { useTranslation } from '../translate'; import Bare from './Bare'; interface Props { asHex?: boolean; children?: React.ReactNode; childrenPre?: React.ReactNode; className?: string; defaultValue: RawParam; label?: React.ReactNode; withLabel?: boolean; } function StaticParam ({ asHex, children, childrenPre, className = '', defaultValue, label }: Props): React.ReactElement { const { t } = useTranslation(); const value = defaultValue && (defaultValue.value as string) && ( asHex ? (defaultValue.value as Codec).toHex() : JSON.stringify( (defaultValue.value as { toHuman?: () => unknown }).toHuman ? (defaultValue.value as Codec).toHuman() : defaultValue.value, null, 2 ).replace(/"/g, '').replace(/\\/g, '').replace(/\],\[/g, '],\n[') ); return ( {childrenPre} {value || t('')}} /> {children} ); } export default React.memo(styled(StaticParam)` pre { margin: 0; overflow: hidden; text-overflow: ellipsis; } .ui--Static { margin-bottom: 0 !important; } `);