import React, { useContext, useEffect, useState } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { I18nContext } from '../../../contexts/i18n'; import InfoTooltip from '../../ui/info-tooltip'; import SwapsFooter from '../../../pages/swaps/swaps-footer'; import { fetchHistoricalReports, getComplianceHistoricalReportsByAddress, getComplianceTenantSubdomain, } from '../../../ducks/institutional/institutional'; import { formatDate } from '../../../helpers/utils/util'; import Box from '../../ui/box'; import { Text } from '../../component-library'; import { TextColor, TextVariant, JustifyContent, AlignItems, BLOCK_SIZES, DISPLAY, FLEX_DIRECTION, } from '../../../helpers/constants/design-system'; const ComplianceDetails = ({ address, onClose, onGenerate }) => { const t = useContext(I18nContext); const dispatch = useDispatch(); useEffect(() => { dispatch(fetchHistoricalReports(address)); }, [address, dispatch]); const [lastReport, setLastReport] = useState(null); const historicalReports = useSelector( getComplianceHistoricalReportsByAddress(address), ); useEffect(() => { if (historicalReports && historicalReports.length) { setLastReport( historicalReports.reduce((prev, cur) => prev.createTime > cur.createTime ? prev : cur, ), ); } }, [historicalReports]); const complianceTenantSubdomain = useSelector(getComplianceTenantSubdomain); return ( {t('address')} {address} {t('riskRating')} {t('riskRatingTooltip')}} /> {lastReport ? lastReport.risk : t('noReport')} {t('reportLastRun')} {t('reportLastRunTooltip')}} /> {lastReport ? formatDate(new Date(lastReport.createTime).getTime()) : 'N/A'} { onGenerate(address); onClose(); }} submitText={t('runReport')} onCancel={() => global.platform.openTab({ url: `https://${complianceTenantSubdomain}.compliance.codefi.network/app/kyt/addresses/${lastReport.address}/${lastReport.reportId}`, }) } cancelText={t('showReport')} hideCancel={!lastReport} approveActive={lastReport} showTopBorder /> ); }; ComplianceDetails.propTypes = { address: PropTypes.string, onClose: PropTypes.func, onGenerate: PropTypes.func, }; export default ComplianceDetails;