import React from 'react'; import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import Preloader from '../../../ui/icon/preloader/preloader-icon.component'; import { Text } from '../../../component-library'; import { AlignItems, FLEX_DIRECTION, JustifyContent, TEXT_ALIGN, TextColor, TextVariant, } from '../../../../helpers/constants/design-system'; import { useI18nContext } from '../../../../hooks/useI18nContext'; import { useTransactionInsightSnap } from '../../../../hooks/snaps/useTransactionInsightSnap'; import Box from '../../../ui/box/box'; import { SnapUIRenderer } from '../../snaps/snap-ui-renderer'; import { SnapDelineator } from '../../snaps/snap-delineator'; import { DelineatorType } from '../../../../helpers/constants/snaps'; import { getSnapName } from '../../../../helpers/utils/util'; import { Copyable } from '../../snaps/copyable'; import { getTargetSubjectMetadata } from '../../../../selectors'; export const SnapInsight = ({ transaction, origin, chainId, selectedSnap }) => { const t = useI18nContext(); const { data: response, error, loading, } = useTransactionInsightSnap({ transaction, chainId, origin, snapId: selectedSnap.id, }); const targetSubjectMetadata = useSelector((state) => getTargetSubjectMetadata(state, selectedSnap.id), ); const snapName = getSnapName(selectedSnap.id, targetSubjectMetadata); const data = response?.content; const hasNoData = !error && (loading || !data || (data && Object.keys(data).length === 0)); return ( {!loading && !error && ( {data && Object.keys(data).length > 0 ? ( ) : ( {t('snapsNoInsight')} )} )} {!loading && error && ( {t('snapsUIError', [{snapName}])} )} {loading && ( <> {t('snapsInsightLoading')} )} ); }; SnapInsight.propTypes = { /* * The transaction data object */ transaction: PropTypes.object, /* * CAIP2 Chain ID */ chainId: PropTypes.string, /* * The origin of the transaction */ origin: PropTypes.string, /* * The insight snap selected */ selectedSnap: PropTypes.object, };