diff --git a/packages/page-preimages/src/Preimages/Add.tsx b/packages/page-preimages/src/Preimages/Add.tsx deleted file mode 100644 index 80a1964103..0000000000 --- a/packages/page-preimages/src/Preimages/Add.tsx +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2017-2022 @polkadot/app-preimages authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { SubmittableExtrinsic } from '@polkadot/api/types'; - -import React, { useEffect, useState } from 'react'; - -import { Button, Extrinsic, InputAddress, InputBalance, Modal, Static, TxButton } from '@polkadot/react-components'; -import { useApi, useToggle } from '@polkadot/react-hooks'; -import { Available } from '@polkadot/react-query'; -import { BN, BN_ZERO } from '@polkadot/util'; -import { blake2AsHex } from '@polkadot/util-crypto'; - -import { useTranslation } from '../translate'; - -interface Props { - className?: string; - imageHash?: string; -} - -interface HashState { - encodedHash: string; - encodedLength: number; - encodedProposal: string; - storageFee: BN; -} - -const ZERO_HASH = blake2AsHex(''); - -function Add ({ className, imageHash }: Props): React.ReactElement { - const { t } = useTranslation(); - const { api, apiDefaultTxSudo } = useApi(); - const [isAddOpen, toggleAdd] = useToggle(); - const [accountId, setAccountId] = useState(null); - const [{ encodedHash, encodedLength, encodedProposal, storageFee }, setHash] = useState({ encodedHash: ZERO_HASH, encodedLength: 0, encodedProposal: '', storageFee: BN_ZERO }); - const [proposal, setProposal] = useState>(); - - useEffect((): void => { - // get the proposal in hex format, i.e. we don't want the length prefix - const encodedProposal = (proposal as SubmittableExtrinsic<'promise'>)?.method.toHex() || ''; - - // we are dealing with hex values here, so subtrack the prefix (+ 2 chars per byte) - const encodedLength = Math.max(0, Math.round((encodedProposal.length - 2) / 2)); - - // we currently don't have a constant exposed, or rather, maybe somewhere else... - // const storageFee = api.consts.democracy.preimageByteDeposit.mul( - // encodedProposal - // ? new BN((encodedProposal.length - 2) / 2) - // : BN_ZERO - // ); - - setHash({ encodedHash: blake2AsHex(encodedProposal), encodedLength, encodedProposal, storageFee: BN_ZERO }); - }, [api, proposal]); - - const isMatched = imageHash - ? imageHash === encodedHash - : true; - - return ( - <> - {isAddOpen && ( - ('Submit preimage')} - onClose={toggleAdd} - size='large' - > - - ('This account will pay the fees for the preimage, based on the size thereof.')}> - ('The account you want to register the preimage from')} - label={t('send from account')} - labelExtra={ - {t('transferrable')}} - params={accountId} - /> - } - onChange={setAccountId} - type='account' - /> - - -

{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.')}

- - } - > - ('propose')} - onChange={setProposal} - /> - ('The hash of the selected proposal, use it for submitting the proposal')} - label={t('preimage hash')} - value={encodedHash} - withCopy - /> - ('The encoded length of the selected proposal, as available on-chain')} - label={t('preimage length')} - value={encodedLength.toString()} - withCopy - /> -
- {!storageFee.isZero() && ( - ('The calculated storage costs based on the size and the per-bytes fee.')}> - ('The amount reserved to store this image')} - isDisabled - label={t('calculated storage fee')} - /> - - )} -
- - ('Submit preimage')} - onStart={toggleAdd} - params={[encodedProposal]} - tx={api.tx.preimage.notePreimage} - /> - -
- )} -