Skip to content

Commit

Permalink
Align noteImminent with Substrate (polkadot-js#2149)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr authored and KarishmaBothara committed Feb 20, 2020
1 parent b09ad3e commit db731a2
Showing 1 changed file with 14 additions and 38 deletions.
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;
}
`;

0 comments on commit db731a2

Please sign in to comment.