// Copyright 2017-2021 @polkadot/app-democracy authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Compact } from '@polkadot/types'; import type { Hash, Proposal, ProposalIndex } from '@polkadot/types/interfaces'; import React from 'react'; import { CallExpander } from '@polkadot/react-components'; import { useTranslation } from '../translate'; import ExternalCell from './ExternalCell'; import TreasuryCell from './TreasuryCell'; interface Props { className?: string; imageHash: Hash | string; proposal?: Proposal | null; } const METHOD_EXTE = ['externalPropose', 'externalProposeDefault', 'externalProposeMajority']; const METHOD_TREA = ['approveProposal', 'rejectProposal']; function ProposalCell ({ className = '', imageHash, proposal }: Props): React.ReactElement { const { t } = useTranslation(); if (!proposal) { const textHash = imageHash.toString(); return ( {t('preimage {{hash}}', { replace: { hash: `${textHash.slice(0, 8)}…${textHash.slice(-8)}` } })} ); } const { method, section } = proposal.registry.findMetaCall(proposal.callIndex); const isTreasury = section === 'treasury' && METHOD_TREA.includes(method); const isExternal = section === 'democracy' && METHOD_EXTE.includes(method); return ( ('proposal hash')} value={proposal} withHash={!isTreasury && !isExternal} > {isExternal && ( )} {isTreasury && ( } /> )} ); } export default React.memo(ProposalCell);