Ensure correct preimage is used for democracy (#8782)
* Ensure correct preimage is used for democracy * Remove cast
This commit is contained in:
parent
ea39392026
commit
20bc11708d
@ -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<Props> {
|
||||
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
|
||||
<td className={`${className} all`}>
|
||||
<CallExpander
|
||||
labelHash={t<string>('proposal hash')}
|
||||
value={proposal}
|
||||
value={displayProposal}
|
||||
withHash={!isTreasury && !isExternal}
|
||||
>
|
||||
{isExternal && (
|
||||
<ExternalCell value={details[0].args[0] as Hash} />
|
||||
<ExternalCell value={displayProposal.args[0] as Hash} />
|
||||
)}
|
||||
{isTreasury && (
|
||||
<TreasuryCell value={details[0].args[0] as Compact<ProposalIndex>} />
|
||||
<TreasuryCell value={displayProposal.args[0] as Compact<ProposalIndex>} />
|
||||
)}
|
||||
</CallExpander>
|
||||
</td>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user