2023-03-09 06:08:37 +01:00
|
|
|
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,
|
2023-05-08 15:36:40 +02:00
|
|
|
OverflowWrap,
|
2023-03-09 06:08:37 +01:00
|
|
|
TextVariant,
|
2023-05-08 15:36:40 +02:00
|
|
|
TextTransform,
|
2023-03-09 06:08:37 +01:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import Box from '../../ui/box';
|
2023-07-20 00:32:35 +02:00
|
|
|
import { Text } from '../../component-library';
|
2023-03-09 06:08:37 +01:00
|
|
|
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 (
|
|
|
|
<Box padding={4}>
|
|
|
|
<Box paddingBottom={3} paddingTop={2}>
|
|
|
|
<Text
|
|
|
|
as="span"
|
2023-05-08 15:36:40 +02:00
|
|
|
textTransform={TextTransform.Uppercase}
|
2023-03-09 06:08:37 +01:00
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
>
|
|
|
|
{`${t('functionType')}:`}
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
as="span"
|
|
|
|
color={Color.textDefault}
|
|
|
|
paddingLeft={1}
|
2023-05-08 15:36:40 +02:00
|
|
|
textTransform={TextTransform.Capitalize}
|
2023-03-09 06:08:37 +01:00
|
|
|
variant={TextVariant.bodySmBold}
|
|
|
|
>
|
|
|
|
{`${functionType} ${functionParams}`}
|
|
|
|
</Text>
|
|
|
|
</Box>
|
|
|
|
{params && (
|
|
|
|
<Box backgroundColor={Color.backgroundAlternative} padding={4}>
|
|
|
|
<Text
|
|
|
|
as="h3"
|
|
|
|
paddingBottom={3}
|
|
|
|
paddingTop={2}
|
2023-05-08 15:36:40 +02:00
|
|
|
textTransform={TextTransform.Uppercase}
|
2023-03-09 06:08:37 +01:00
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
>
|
|
|
|
{`${t('parameters')}:`}
|
|
|
|
</Text>
|
|
|
|
<Text
|
2023-05-08 15:36:40 +02:00
|
|
|
overflowWrap={OverflowWrap.BreakWord}
|
2023-03-09 06:08:37 +01:00
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
>
|
|
|
|
<pre>{JSON.stringify(params, null, 2)}</pre>
|
|
|
|
</Text>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
<Text
|
|
|
|
as="h3"
|
|
|
|
paddingBottom={3}
|
|
|
|
paddingTop={2}
|
2023-05-08 15:36:40 +02:00
|
|
|
textTransform={TextTransform.Uppercase}
|
2023-03-09 06:08:37 +01:00
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
>
|
|
|
|
{`${t('hexData')}: ${toBuffer(txParams?.data).length} bytes`}
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
backgroundColor={Color.backgroundAlternative}
|
2023-05-08 15:36:40 +02:00
|
|
|
overflowWrap={OverflowWrap.BreakWord}
|
2023-03-09 06:08:37 +01:00
|
|
|
padding={4}
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
>
|
|
|
|
{txParams?.data}
|
|
|
|
</Text>
|
|
|
|
<CopyRawData data={txParams?.data} />
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ConfirmHexData.propTypes = {
|
|
|
|
txData: PropTypes.object,
|
|
|
|
dataHexComponent: PropTypes.element,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ConfirmHexData;
|