import React from 'react'; import PropTypes from 'prop-types'; import Preloader from '../../../ui/icon/preloader/preloader-icon.component'; import Typography from '../../../ui/typography/typography'; import { ALIGN_ITEMS, COLORS, FLEX_DIRECTION, JUSTIFY_CONTENT, TEXT_ALIGN, TYPOGRAPHY, } from '../../../../helpers/constants/design-system'; import { useI18nContext } from '../../../../hooks/useI18nContext'; import { useTransactionInsightSnap } from '../../../../hooks/flask/useTransactionInsightSnap'; import SnapContentFooter from '../../flask/snap-content-footer/snap-content-footer'; import Box from '../../../ui/box/box'; import ActionableMessage from '../../../ui/actionable-message/actionable-message'; export const SnapInsight = ({ transaction, origin, chainId, selectedSnap }) => { const t = useI18nContext(); const { data: response, error, loading, } = useTransactionInsightSnap({ transaction, chainId, origin, snapId: selectedSnap.id, }); const data = response?.insights; const hasNoData = !error && (loading || !data || (data && Object.keys(data).length === 0)); return ( {!loading && !error && ( {data && Object.keys(data).length > 0 ? ( <> {Object.keys(data).map((key, i) => (
{key} {typeof data[key] === 'string' ? ( {data[key]} ) : (
{JSON.stringify(data[key], null, 2)}
)}
))}
) : ( {t('snapsNoInsight')} )}
)} {!loading && error && ( )} {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, };