// Copyright 2017-2023 @polkadot/app-democracy authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Option } from '@polkadot/types'; import type { TreasuryProposal as TreasuryProposalType } from '@polkadot/types/interfaces'; import React, { useEffect, useState } from 'react'; import { InputAddress, Labelled, Static } from '@polkadot/react-components'; import { useApi } from '@polkadot/react-hooks'; import { FormatBalance } from '@polkadot/react-query'; import Inset, { InsetProps } from './Inset'; import { useTranslation } from './translate'; interface Props { className?: string; asInset?: boolean; insetProps?: Partial; onClick?: () => void; proposalId?: string; proposal?: TreasuryProposalType | null; withLink?: boolean; } function TreasuryProposal ({ asInset, className = '', insetProps, onClick, proposal, proposalId }: Props): React.ReactElement | null { const { t } = useTranslation(); const [stateProposal, setProposal] = useState(null); const { api } = useApi(); useEffect((): void => { if (!proposal && proposalId) { api.query.treasury .proposals>(proposalId) .then((proposal): TreasuryProposalType | null => proposal.unwrapOr(null)) .catch((): null => null) .then(setProposal) .catch(console.error); } else { setProposal(proposal || null); } }, [api, proposal, proposalId]); if (!stateProposal) { return null; } const { beneficiary, bond, proposer, value } = stateProposal; const inner = ( <> ('proposed by')}> ('beneficiary')}> ('value')}> ('bond')}> ); if (asInset) { return ( {inner} ); } return (
{inner}
); } export default React.memo(TreasuryProposal);