From 20bc11708d52a968ef387262747f51a142fa859a Mon Sep 17 00:00:00 2001 From: Jaco Date: Fri, 13 Jan 2023 09:54:29 +0200 Subject: [PATCH] Ensure correct preimage is used for democracy (#8782) * Ensure correct preimage is used for democracy * Remove cast --- .../src/Overview/ProposalCell.tsx | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/page-democracy/src/Overview/ProposalCell.tsx b/packages/page-democracy/src/Overview/ProposalCell.tsx index 60d93ca1d4..c2a3cbeb55 100644 --- a/packages/page-democracy/src/Overview/ProposalCell.tsx +++ b/packages/page-democracy/src/Overview/ProposalCell.tsx @@ -10,6 +10,7 @@ import styled from 'styled-components'; import usePreimage from '@polkadot/app-preimages/usePreimage'; import { CallExpander } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; import ExternalCell from './ExternalCell'; @@ -26,15 +27,15 @@ const METHOD_TREA = ['approveProposal', 'rejectProposal']; function ProposalCell ({ className = '', imageHash, proposal }: Props): React.ReactElement { const { t } = useTranslation(); + const { api } = useApi(); const preimage = usePreimage(imageHash); - const details = proposal - ? [proposal, proposal.registry.findMetaCall(proposal.callIndex)] - : preimage?.proposal - ? [preimage.proposal, preimage.registry.findMetaCall(preimage.proposal.callIndex)] - : null; + // while we still have this endpoint, democracy will use it + const displayProposal = api.query.democracy.preimages + ? proposal + : preimage?.proposal; - if (!details) { + if (!displayProposal) { const textHash = imageHash.toString(); return ( @@ -44,7 +45,7 @@ function ProposalCell ({ className = '', imageHash, proposal }: Props): React.Re ); } - const { method, section } = details[1]; + const { method, section } = displayProposal.registry.findMetaCall(displayProposal.callIndex); const isTreasury = section === 'treasury' && METHOD_TREA.includes(method); const isExternal = section === 'democracy' && METHOD_EXTE.includes(method); @@ -52,14 +53,14 @@ function ProposalCell ({ className = '', imageHash, proposal }: Props): React.Re ('proposal hash')} - value={proposal} + value={displayProposal} withHash={!isTreasury && !isExternal} > {isExternal && ( - + )} {isTreasury && ( - } /> + } /> )}