import { WarningRounded } from '@mui/icons-material' import clsx from 'clsx' import { useTranslation } from 'react-i18next' import { DaoSplashHeaderProps } from '@dao-dao/types' import { MISCONFIGURED_DAOS, UNDO_PAGE_PADDING_TOP_CLASSES, formatPercentOf100, } from '@dao-dao/utils' import { useDaoNavHelpers } from '../../hooks' import { DaoHeader } from './DaoHeader' export const DaoSplashHeader = ({ dao, follow, ButtonLink, LinkWrapper, parentProposalRecognizeSubDaoHref, proposeUpdateAdminToParentHref, initialActionsVerified, }: DaoSplashHeaderProps) => { const { t } = useTranslation() const { getDaoPath } = useDaoNavHelpers() // Show warning if the DAO is inactive and has an active threshold. const showInactiveWarning = !dao.info.isActive && !!dao.info.activeThreshold // Show warning if user has not verified the initial actions for this DAO and // the DAO was created within the last 30 days. const showInitialActionsNotVerifiedWarning = dao.info.initialActions.length > 0 && !initialActionsVerified && !!dao.info.created && dao.info.created >= Date.now() - 30 * 24 * 60 * 60 * 1_000 // Show warning if the DAO has a parent DAO and the parent DAO is not // recognized. const showSubDaoNotRecognizedWarning = !!dao.info.parentDao && !dao.info.parentDao.registeredSubDao // Show warning if the DAO is its own contract admin but it has a parent DAO // who should be the contract admin. const showParentDaoNotAdminWarning = !!dao.info.parentDao && dao.info.contractAdmin === dao.coreAddress // Show warning and potentially redirect to correct DAO if DAO is // misconfigured and should not be used. const misconfiguredDao = MISCONFIGURED_DAOS.find( (misconfiguredDao) => misconfiguredDao.chainId === dao.chainId && misconfiguredDao.coreAddress === dao.coreAddress ) const warningVisible = showInactiveWarning || showInitialActionsNotVerifiedWarning || showSubDaoNotRecognizedWarning || showParentDaoNotAdminWarning || !!misconfiguredDao return ( <> {warningVisible && (
{/* Show DAO redirect for misconfigured Thorchain Liquidy DAO. */} {misconfiguredDao && (

{t('info.daoMisconfigured', { context: misconfiguredDao.redirectDao ? 'redirect' : undefined, })}

)} {showInactiveWarning && (

{t('error.daoIsInactive', { context: 'percentage' in dao.info.activeThreshold! ? 'percent' : 'absolute', percent: 'percentage' in dao.info.activeThreshold! ? formatPercentOf100( Number(dao.info.activeThreshold.percentage.percent) * 100 ) : undefined, count: 'percentage' in dao.info.activeThreshold! ? undefined : Number(dao.info.activeThreshold!.absolute_count.count), })}

)} {showInitialActionsNotVerifiedWarning && (

{t('error.initialActionsNotVerified')}

)} {showSubDaoNotRecognizedWarning && (

{t('info.subDaoNotYetRecognized', { parent: dao.info.parentDao!.name, child: dao.name, })} {!!parentProposalRecognizeSubDaoHref && ( {' ' + t('button.clickHereToProposeRecognizingIt')} )}

)} {showParentDaoNotAdminWarning && (

{t('info.parentDaoNotAdmin', { parent: dao.info.parentDao!.name, child: dao.name, })} {!!proposeUpdateAdminToParentHref && ( {' ' + t('button.clickHereToProposeSettingAdminToParent', { parent: dao.info.parentDao!.name, })} )}

)}
)} ) }