import React from 'react'; import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import { toBuffer } from '../../../../shared/modules/buffer-utils'; import { getKnownMethodData } from '../../../selectors'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { useTransactionFunctionType } from '../../../hooks/useTransactionFunctionType'; import { Color, OVERFLOW_WRAP, TextVariant, TEXT_TRANSFORM, } from '../../../helpers/constants/design-system'; import Box from '../../ui/box'; import { Text } from '../../component-library'; import CopyRawData from '../transaction-decoding/components/ui/copy-raw-data'; const ConfirmHexData = ({ txData, dataHexComponent }) => { const t = useI18nContext(); const { txParams = {} } = txData; const methodData = useSelector( (state) => getKnownMethodData(state, txParams.data) || {}, ); const { functionType } = useTransactionFunctionType(txData); if (dataHexComponent) { return dataHexComponent; } if (!txParams.data || !txParams.to) { return null; } const { params } = methodData; const functionParams = params?.length ? `(${params.map(({ type }) => type).join(', ')})` : ''; return ( {`${t('functionType')}:`} {`${functionType} ${functionParams}`} {params && ( {`${t('parameters')}:`}
{JSON.stringify(params, null, 2)}
)} {`${t('hexData')}: ${toBuffer(txParams?.data).length} bytes`} {txParams?.data}
); }; ConfirmHexData.propTypes = { txData: PropTypes.object, dataHexComponent: PropTypes.element, }; export default ConfirmHexData;