// Copyright 2017-2020 @polkadot/app-democracy authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. import { SubmittableExtrinsic } from '@polkadot/api/promise/types'; import { Hash } from '@polkadot/types/interfaces'; import React, { useEffect, useState } from 'react'; import styled from 'styled-components'; import { Input, InputAddress, Extrinsic, Modal, Toggle, TxButton } from '@polkadot/react-components'; import { useApi } from '@polkadot/react-hooks'; import { Available } from '@polkadot/react-query'; import { blake2AsHex } from '@polkadot/util-crypto'; import { useTranslation } from '../translate'; interface Props { className?: string; isImminent?: boolean; imageHash?: Hash; onClose: () => void; } const ZERO_HASH = blake2AsHex(''); function PreImage ({ className, imageHash, isImminent: propsIsImminent, onClose }: Props): React.ReactElement { const { t } = useTranslation(); const { apiDefaultTxSudo } = useApi(); const [accountId, setAccountId] = useState(null); const [isImminent, setIsImminent] = useState(propsIsImminent || false); const [{ encodedHash, encodedProposal }, setHash] = useState<{ encodedHash: string; encodedProposal: string }>({ encodedHash: ZERO_HASH, encodedProposal: '' }); const [proposal, setProposal] = useState(); useEffect((): void => { const encodedProposal = (proposal as SubmittableExtrinsic)?.method.toHex() || ''; setHash({ encodedHash: blake2AsHex(encodedProposal), encodedProposal }); }, [proposal]); const isMatched = imageHash ? imageHash.eq(encodedHash) : true; return ( {t('transferrable')}} params={accountId} /> } onChange={setAccountId} type='account' />

{t('This account will pay the fees for the preimage, based on the size thereof.')}

{t('The image (proposal) will be stored on-chain against the hash of the contents.')}

{t('When submitting a proposal the hash needs to be known. Proposals can be submitted with hash-only, but upon dispatch the preimage needs to be available.')}

{t('Only applicable if the proposal has already passed and is ready for dispatch.')}

); } export default React.memo(styled(PreImage)` .toggleImminent { margin: 0.5rem 0; text-align: right; } `);