Align noteImminent with Substrate (#2149)

This commit is contained in:
Jaco Greeff 2020-01-19 14:27:30 +01:00 committed by GitHub
parent 0f8dfc4e08
commit 02809a441c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,29 +3,27 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
import { I18nProps } from '@polkadot/react-components/types';
import BN from 'bn.js';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { Button, Input, InputAddress, InputNumber, Extrinsic, Modal, Toggle, TxButton } from '@polkadot/react-components';
import { Button, 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 translate from '../translate';
import { useTranslation } from '../translate';
interface Props extends I18nProps {
interface Props {
className?: string;
onClose: () => void;
}
const ZERO_HASH = blake2AsHex('');
function PreImage ({ className, onClose, t }: Props): React.ReactElement<Props> {
function PreImage ({ className, onClose }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { apiDefaultTxSudo } = useApi();
const [accountId, setAccountId] = useState<string | null>(null);
const [atBlock, setAtBlock] = useState<BN | undefined>();
const [forProposal, setForProposal] = useState<BN | undefined>();
const [isImminent, setIsImminent] = useState(false);
const [{ hex, hash }, setHash] = useState<{ hex: string; hash: string }>({ hex: '', hash: ZERO_HASH });
const [proposal, setProposal] = useState<any>();
@ -67,20 +65,6 @@ function PreImage ({ className, onClose, t }: Props): React.ReactElement<Props>
onChange={setIsImminent}
value={isImminent}
/>
{isImminent && (
<>
<InputNumber
help={t('The blocknumber for the proposal to be enacted at')}
label={t('block number to be enacted at')}
onChange={setAtBlock}
/>
<InputNumber
help={t('The proposal to which this image applies')}
label={t('proposal id')}
onChange={setForProposal}
/>
</>
)}
</Modal.Content>
<Modal.Actions>
<Button.Group>
@ -93,18 +77,12 @@ function PreImage ({ className, onClose, t }: Props): React.ReactElement<Props>
<Button.Or />
<TxButton
accountId={accountId}
isDisabled={!proposal || !accountId || (
isImminent ? !(atBlock?.gtn(0) && forProposal?.gtn(0)) : false
)}
isDisabled={!proposal || !accountId}
isPrimary
label={t('Submit preimage')}
icon='add'
onStart={onClose}
params={
isImminent
? [hex, atBlock, forProposal]
: [hex]
}
params={[hex]}
tx={isImminent ? 'democracy.noteImminentPreimage' : 'democracy.notePreimage'}
withSpinner={false}
/>
@ -114,11 +92,9 @@ function PreImage ({ className, onClose, t }: Props): React.ReactElement<Props>
);
}
export default translate(
styled(PreImage)`
.toggleImminent {
margin: 0.5rem 0;
text-align: right;
}
`
);
export default styled(PreImage)`
.toggleImminent {
margin: 0.5rem 0;
text-align: right;
}
`;