From 52a2aa275a4b3dca61fc535a209f0e2474f3eb18 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 24 Jan 2020 13:34:38 +0100 Subject: [PATCH] Add preimage buttons to proposals (#2192) * Add preimage buttons to proposals * Styling overrides * InputAddress filter --- .../src/Overview/DispatchEntry.tsx | 8 ++++ .../app-democracy/src/Overview/PreImage.tsx | 24 ++++++---- .../src/Overview/PreImageButton.tsx | 47 +++++++++++++++++++ .../app-democracy/src/Overview/Proposal.tsx | 19 +++++--- .../app-democracy/src/Overview/Referendum.tsx | 18 +++++-- packages/react-components/src/Input.tsx | 5 +- .../src/InputAddress/index.tsx | 6 +-- .../react-components/src/styles/semantic.ts | 5 ++ 8 files changed, 107 insertions(+), 25 deletions(-) create mode 100644 packages/app-democracy/src/Overview/PreImageButton.tsx diff --git a/packages/app-democracy/src/Overview/DispatchEntry.tsx b/packages/app-democracy/src/Overview/DispatchEntry.tsx index 0656a34953..c3cb419be0 100644 --- a/packages/app-democracy/src/Overview/DispatchEntry.tsx +++ b/packages/app-democracy/src/Overview/DispatchEntry.tsx @@ -12,6 +12,7 @@ import { formatNumber } from '@polkadot/util'; import { useTranslation } from '../translate'; import ProposalCell from './ProposalCell'; +import PreImageButton from './PreImageButton'; interface Props { blockNumber?: BlockNumber; @@ -47,6 +48,13 @@ export default function DispatchEntry ({ blockNumber, hash, referendumIndex }: P proposalHash={hash} proposal={proposal} /> + + + ); } diff --git a/packages/app-democracy/src/Overview/PreImage.tsx b/packages/app-democracy/src/Overview/PreImage.tsx index 8bde77e93c..85a3183dfc 100644 --- a/packages/app-democracy/src/Overview/PreImage.tsx +++ b/packages/app-democracy/src/Overview/PreImage.tsx @@ -3,6 +3,7 @@ // 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'; @@ -15,25 +16,31 @@ import { useTranslation } from '../translate'; interface Props { className?: string; + isImminent?: boolean; + matchHash?: Hash; onClose: () => void; } const ZERO_HASH = blake2AsHex(''); -function PreImage ({ className, onClose }: Props): React.ReactElement { +function PreImage ({ className, isImminent: propsIsImminent, matchHash, onClose }: Props): React.ReactElement { const { t } = useTranslation(); const { apiDefaultTxSudo } = useApi(); const [accountId, setAccountId] = useState(null); - const [isImminent, setIsImminent] = useState(false); - const [{ hex, hash }, setHash] = useState<{ hex: string; hash: string }>({ hex: '', hash: ZERO_HASH }); + const [isImminent, setIsImminent] = useState(propsIsImminent || false); + const [{ encodedProposal, encodedHash }, setHash] = useState<{ encodedProposal: string; encodedHash: string }>({ encodedProposal: '', encodedHash: ZERO_HASH }); const [proposal, setProposal] = useState(); useEffect((): void => { - const hex = (proposal as SubmittableExtrinsic)?.method.toHex() || ''; + const encodedProposal = (proposal as SubmittableExtrinsic)?.method.toHex() || ''; - setHash({ hex, hash: blake2AsHex(hex) }); + setHash({ encodedProposal, encodedHash: blake2AsHex(encodedProposal) }); }, [proposal]); + const isMatched = matchHash + ? matchHash.eq(encodedHash) + : true; + return ( { { diff --git a/packages/app-democracy/src/Overview/PreImageButton.tsx b/packages/app-democracy/src/Overview/PreImageButton.tsx new file mode 100644 index 0000000000..c3dc888cf9 --- /dev/null +++ b/packages/app-democracy/src/Overview/PreImageButton.tsx @@ -0,0 +1,47 @@ +// 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 { Proposal, Hash } from '@polkadot/types/interfaces'; + +import React from 'react'; +import { Button } from '@polkadot/react-components'; +import { useToggle } from '@polkadot/react-hooks'; + +import { useTranslation } from '../translate'; +import PreImage from './PreImage'; + +interface Props { + hash: Hash; + isImminent?: boolean; + proposal?: Proposal; + withoutOr?: boolean; +} + +export default function PreImageButton ({ hash, isImminent, proposal, withoutOr }: Props): React.ReactElement | null { + const { t } = useTranslation(); + const [isPreimageOpen, togglePreimage] = useToggle(); + + if (proposal) { + return null; + } + + return ( + <> + {!withoutOr && } +