Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 14 additions & 38 deletions packages/app-democracy/src/Overview/PreImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -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>
Expand All @@ -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}
/>
Expand All @@ -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;
}
`;