// Copyright 2017-2021 @polkadot/app-treasury authors & contributors // SPDX-License-Identifier: Apache-2.0 import BN from 'bn.js'; import React, { useMemo, useState } from 'react'; import { Button, InputAddress, InputBalance, MarkWarning, Modal, Static, TxButton } from '@polkadot/react-components'; import { useApi, useToggle } from '@polkadot/react-hooks'; import { BN_HUNDRED, BN_MILLION } from '@polkadot/util'; import { useTranslation } from '../translate'; interface Props { className?: string; } function Propose ({ className }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); const [accountId, setAccountId] = useState(null); const [beneficiary, setBeneficiary] = useState(null); const [isOpen, toggleOpen] = useToggle(); const [value, setValue] = useState(); const hasValue = value?.gtn(0); const bondPercentage = useMemo( () => `${api.consts.treasury.proposalBond.mul(BN_HUNDRED).div(BN_MILLION).toNumber().toFixed(2)}%`, [api] ); return ( <> {isOpen && ( ('Submit treasury proposal')} size='large' > ('This account will make the proposal and be responsible for the bond.')}> ('Select the account you wish to submit the proposal from.')} label={t('submit with account')} onChange={setAccountId} type='account' withLabel /> ('The beneficiary will receive the full amount if the proposal passes.')}> ('The account to which the proposed balance will be transferred if approved')} label={t('beneficiary')} onChange={setBeneficiary} type='allPlus' />

{t('The value is the amount that is being asked for and that will be allocated to the beneficiary if the proposal is approved.')}

{t('Of the beneficiary amount, at least {{bondPercentage}} would need to be put up as collateral. The maximum of this and the minimum bond will be used to secure the proposal, refundable if it passes.', { replace: { bondPercentage } })}

}> ('The amount that will be allocated from the treasury pot')} isError={!hasValue} label={t('value')} onChange={setValue} /> ('The on-chain percentage for the treasury')} label={t('proposal bond')} > {bondPercentage} ('The minimum amount that will be bonded')} isDisabled label={t('minimum bond')} /> ('Be aware that once submitted the proposal will be put to a council vote. If the proposal is rejected due to a lack of info, invalid requirements or non-benefit to the network as a whole, the full bond posted (as describe above) will be lost.')} />
('Submit proposal')} onStart={toggleOpen} params={[value, beneficiary]} tx={api.tx.treasury.proposeSpend} />
)}