Extend confirmation referendum graph display (#8586)
* Extend confirmation referendum graph display * Adjust * ProposedAction with expander * Expander with left arrow * Adjust header
This commit is contained in:
parent
21a4378e72
commit
364e289504
@ -113,7 +113,10 @@ function Logs ({ value }: Props): React.ReactElement<Props> | null {
|
||||
{value?.map((log, index) => (
|
||||
<tr key={`log:${index}`}>
|
||||
<td className='overflow'>
|
||||
<Expander summary={log.type.toString()}>
|
||||
<Expander
|
||||
isLeft
|
||||
summary={log.type.toString()}
|
||||
>
|
||||
{formatItem(log)}
|
||||
</Expander>
|
||||
</td>
|
||||
|
||||
@ -18,6 +18,7 @@ function Event ({ className = '', value: { event } }: Props): React.ReactElement
|
||||
return (
|
||||
<Expander
|
||||
className={className}
|
||||
isLeft
|
||||
summary={eventName}
|
||||
summaryMeta={event.meta}
|
||||
>
|
||||
|
||||
@ -61,6 +61,7 @@ interface ChartResultExt extends ChartResult {
|
||||
changeX: number;
|
||||
currentY: number;
|
||||
endConfirm: BN | null;
|
||||
points: BN[];
|
||||
since: BN;
|
||||
}
|
||||
|
||||
@ -99,7 +100,7 @@ function createTitleCallback (t: TFunction, bestNumber: BN, blockInterval: BN, e
|
||||
};
|
||||
}
|
||||
|
||||
function getChartResult (totalEligible: BN, isConvictionVote: boolean, info: PalletReferendaReferendumInfoConvictionVotingTally | PalletReferendaReferendumInfoRankedCollectiveTally, trackGraph: CurveGraph): ChartResultExt[] | null {
|
||||
function getChartResult (totalEligible: BN, isConvictionVote: boolean, info: PalletReferendaReferendumInfoConvictionVotingTally | PalletReferendaReferendumInfoRankedCollectiveTally, track: PalletReferendaTrackInfo, trackGraph: CurveGraph): ChartResultExt[] | null {
|
||||
if (totalEligible && isConvictionVote && info.isOngoing) {
|
||||
const ongoing = info.asOngoing;
|
||||
|
||||
@ -121,9 +122,11 @@ function getChartResult (totalEligible: BN, isConvictionVote: boolean, info: Pal
|
||||
: tally.ayes.mul(BN_THOUSAND).div(tally.ayes.add(tally.nays)).toNumber() / 10;
|
||||
let appx = -1;
|
||||
let supx = -1;
|
||||
const points: BN[] = [];
|
||||
|
||||
for (let i = 0; i < approval.length; i++) {
|
||||
labels.push(formatNumber(since.add(x[i])));
|
||||
points.push(x[i]);
|
||||
|
||||
const appr = approval[i].div(BN_MILLION).toNumber() / 10;
|
||||
const appn = appc < appr;
|
||||
@ -140,9 +143,35 @@ function getChartResult (totalEligible: BN, isConvictionVote: boolean, info: Pal
|
||||
supx = (supn || supx !== -1) ? supx : i;
|
||||
}
|
||||
|
||||
const step = x[1].sub(x[0]);
|
||||
const lastIndex = x.length - 1;
|
||||
const lastBlock = endConfirm?.add(track.minEnactmentPeriod);
|
||||
|
||||
// if the confirmation end is later than shown on our graph, we extend it
|
||||
if (lastBlock?.gt(since.add(x[lastIndex]))) {
|
||||
let currentBlock = x[lastIndex].add(since).add(step);
|
||||
|
||||
do {
|
||||
labels.push(formatNumber(currentBlock));
|
||||
points.push(currentBlock.sub(since));
|
||||
|
||||
// adjust approvals (no curve adjustment)
|
||||
// values[0][0].push(values[0][0][lastIndex]);
|
||||
values[0][1].push(values[0][1][lastIndex]);
|
||||
values[0][2].push(values[0][2][lastIndex]);
|
||||
|
||||
// // adjust support
|
||||
// values[1][0].push(values[1][0][lastIndex]);
|
||||
values[1][1].push(values[1][1][lastIndex]);
|
||||
values[1][2].push(values[1][2][lastIndex]);
|
||||
|
||||
currentBlock = currentBlock.add(step);
|
||||
} while (currentBlock.lt(lastBlock));
|
||||
}
|
||||
|
||||
return [
|
||||
{ changeX: appx, currentY: appc, endConfirm, labels, progress: { percent: appc, total: ongoing.tally.ayes.add(ongoing.tally.nays), value: ongoing.tally.ayes }, since, values: values[0] },
|
||||
{ changeX: supx, currentY: supc, endConfirm, labels, progress: { percent: supc, total: totalEligible, value: currentSupport }, since, values: values[1] }
|
||||
{ changeX: appx, currentY: appc, endConfirm, labels, points, progress: { percent: appc, total: ongoing.tally.ayes.add(ongoing.tally.nays), value: ongoing.tally.ayes }, since, values: values[0] },
|
||||
{ changeX: supx, currentY: supc, endConfirm, labels, points, progress: { percent: supc, total: totalEligible, value: currentSupport }, since, values: values[1] }
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -150,14 +179,14 @@ function getChartResult (totalEligible: BN, isConvictionVote: boolean, info: Pal
|
||||
return null;
|
||||
}
|
||||
|
||||
function getChartProps (bestNumber: BN, blockInterval: BN, chartProps: ChartResultExt[], refId: BN, track: PalletReferendaTrackInfo, { x }: CurveGraph, t: TFunction): ChartProps[] {
|
||||
function getChartProps (bestNumber: BN, blockInterval: BN, chartProps: ChartResultExt[], refId: BN, track: PalletReferendaTrackInfo, t: TFunction): ChartProps[] {
|
||||
const changeXMax = chartProps.reduce((max, { changeX }) =>
|
||||
max === -1 || changeX === -1
|
||||
? -1
|
||||
: Math.max(max, changeX),
|
||||
0);
|
||||
|
||||
return chartProps.map(({ changeX, currentY, endConfirm, labels, progress, since, values }, index): ChartProps => {
|
||||
return chartProps.map(({ changeX, currentY, endConfirm, labels, points, progress, since, values }, index): ChartProps => {
|
||||
const maxX = labels.length;
|
||||
const maxY = index === 0
|
||||
? 100
|
||||
@ -165,13 +194,13 @@ function getChartProps (bestNumber: BN, blockInterval: BN, chartProps: ChartResu
|
||||
|
||||
const blockToX = (value: BN) =>
|
||||
Math.max(0, Math.min(maxX, maxX * (
|
||||
value.sub(since).toNumber() / x[x.length - 1].toNumber()
|
||||
value.sub(since).toNumber() / points[points.length - 1].toNumber()
|
||||
)));
|
||||
|
||||
const swapX = changeX === -1
|
||||
? -1
|
||||
: maxX * (changeX / x.length);
|
||||
const enactX = changeXMax !== -1 && bnMax(bestNumber, x[changeXMax].add(since));
|
||||
: maxX * (changeX / points.length);
|
||||
const enactX = changeXMax !== -1 && bnMax(bestNumber, points[changeXMax].add(since));
|
||||
const confirmX = endConfirm
|
||||
? [endConfirm.sub(track.confirmPeriod), endConfirm, endConfirm.add(track.minEnactmentPeriod)]
|
||||
: enactX
|
||||
@ -300,15 +329,15 @@ function Referendum (props: Props): React.ReactElement<Props> {
|
||||
);
|
||||
|
||||
const chartResult = useMemo(
|
||||
() => activeIssuance && trackGraph &&
|
||||
getChartResult(activeIssuance, isConvictionVote, info, trackGraph),
|
||||
[activeIssuance, info, isConvictionVote, trackGraph]
|
||||
() => activeIssuance && track && trackGraph &&
|
||||
getChartResult(activeIssuance, isConvictionVote, info, track, trackGraph),
|
||||
[activeIssuance, info, isConvictionVote, track, trackGraph]
|
||||
);
|
||||
|
||||
const chartProps = useMemo(
|
||||
() => bestNumber && chartResult && isExpanded && track && trackGraph &&
|
||||
getChartProps(bestNumber, blockInterval, chartResult, id, track, trackGraph, t),
|
||||
[bestNumber, blockInterval, chartResult, id, isExpanded, t, track, trackGraph]
|
||||
() => bestNumber && chartResult && isExpanded && track &&
|
||||
getChartProps(bestNumber, blockInterval, chartResult, id, track, t),
|
||||
[bestNumber, blockInterval, chartResult, id, isExpanded, t, track]
|
||||
);
|
||||
|
||||
const chartLegend = useMemo(
|
||||
|
||||
@ -5,6 +5,7 @@ import type { Call, Extrinsic } from '@polkadot/types/interfaces';
|
||||
import type { BN } from '@polkadot/util';
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import CallDisplay from './Call';
|
||||
import Expander from './Expander';
|
||||
@ -12,9 +13,12 @@ import Expander from './Expander';
|
||||
interface Props {
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
idString?: string;
|
||||
isHeader?: boolean;
|
||||
labelHash?: React.ReactNode;
|
||||
labelSignature?: React.ReactNode;
|
||||
mortality?: string;
|
||||
stringId?: string;
|
||||
tip?: BN;
|
||||
value?: Call | Extrinsic | null;
|
||||
withBorder?: boolean;
|
||||
@ -22,7 +26,7 @@ interface Props {
|
||||
withSignature?: boolean;
|
||||
}
|
||||
|
||||
function CallExpander ({ children, className = '', labelHash, labelSignature, mortality, tip, value, withBorder, withHash, withSignature }: Props): React.ReactElement<Props> | null {
|
||||
function CallExpander ({ children, className = '', isHeader, labelHash, labelSignature, mortality, stringId, tip, value, withBorder, withHash, withSignature }: Props): React.ReactElement<Props> | null {
|
||||
const call = useMemo(
|
||||
() => value && value.callIndex
|
||||
? value.registry.findMetaCall(value.callIndex)
|
||||
@ -40,7 +44,12 @@ function CallExpander ({ children, className = '', labelHash, labelSignature, mo
|
||||
return (
|
||||
<div className={`ui--CallExpander ${className}`}>
|
||||
<Expander
|
||||
summaryHead={<div>{callName}</div>}
|
||||
isLeft
|
||||
summaryHead={
|
||||
isHeader
|
||||
? <h1>{stringId && `#${stringId}: `}{callName}</h1>
|
||||
: <div>{stringId && `#${stringId}: `}{callName}</div>
|
||||
}
|
||||
summaryMeta={meta}
|
||||
>
|
||||
<CallDisplay
|
||||
@ -60,4 +69,11 @@ function CallExpander ({ children, className = '', labelHash, labelSignature, mo
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(CallExpander);
|
||||
export default React.memo(styled(CallExpander)`
|
||||
.ui--Expander-summary-header {
|
||||
h1 {
|
||||
font-size: 1.25rem;
|
||||
text-transform: none;
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
@ -22,6 +22,7 @@ export interface Props {
|
||||
help?: string;
|
||||
helpIcon?: IconName;
|
||||
isOpen?: boolean;
|
||||
isLeft?: boolean;
|
||||
isPadded?: boolean;
|
||||
onClick?: (isOpen: boolean) => void;
|
||||
renderChildren?: () => React.ReactNode;
|
||||
@ -60,7 +61,7 @@ function formatMeta (meta?: Meta): React.ReactNode | null {
|
||||
return <>{parts.map((part, index) => index % 2 ? <em key={index}>[{part}]</em> : <span key={index}>{part}</span>)} </>;
|
||||
}
|
||||
|
||||
function Expander ({ children, className = '', help, helpIcon, isOpen, isPadded, onClick, renderChildren, summary, summaryHead, summaryMeta, summarySub, withBreaks, withHidden }: Props): React.ReactElement<Props> {
|
||||
function Expander ({ children, className = '', help, helpIcon, isLeft, isOpen, isPadded, onClick, renderChildren, summary, summaryHead, summaryMeta, summarySub, withBreaks, withHidden }: Props): React.ReactElement<Props> {
|
||||
const [isExpanded, toggleExpanded] = useToggle(isOpen, onClick);
|
||||
|
||||
const demandChildren = useMemo(
|
||||
@ -78,12 +79,31 @@ function Expander ({ children, className = '', help, helpIcon, isOpen, isPadded,
|
||||
[children, renderChildren]
|
||||
);
|
||||
|
||||
const icon = useMemo(
|
||||
() => (
|
||||
<Icon
|
||||
color={
|
||||
hasContent
|
||||
? undefined
|
||||
: 'transparent'
|
||||
}
|
||||
icon={
|
||||
isExpanded
|
||||
? 'caret-up'
|
||||
: 'caret-down'
|
||||
}
|
||||
/>
|
||||
),
|
||||
[hasContent, isExpanded]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={`ui--Expander${isExpanded ? ' isExpanded' : ''}${isPadded ? ' isPadded' : ''}${hasContent ? ' hasContent' : ''}${withBreaks ? ' withBreaks' : ''} ${className}`}>
|
||||
<div
|
||||
className='ui--Expander-summary'
|
||||
className={`ui--Expander-summary${isLeft ? ' isLeft' : ''}`}
|
||||
onClick={toggleExpanded}
|
||||
>
|
||||
{isLeft && icon}
|
||||
<div className='ui--Expander-summary-header'>
|
||||
{help && (
|
||||
<LabelHelp
|
||||
@ -97,14 +117,7 @@ function Expander ({ children, className = '', help, helpIcon, isOpen, isPadded,
|
||||
<div className='ui--Expander-summary-header-sub'>{headerSub}</div>
|
||||
)}
|
||||
</div>
|
||||
<Icon
|
||||
color={hasContent ? undefined : 'transparent'}
|
||||
icon={
|
||||
isExpanded
|
||||
? 'caret-up'
|
||||
: 'caret-down'
|
||||
}
|
||||
/>
|
||||
{!isLeft && icon}
|
||||
</div>
|
||||
{hasContent && (isExpanded || withHidden) && (
|
||||
<div className='ui--Expander-content'>{children || demandChildren}</div>
|
||||
@ -153,10 +166,17 @@ export default React.memo(styled(Expander)`
|
||||
}
|
||||
|
||||
.ui--Icon {
|
||||
margin-left: 0.75rem;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
&:not(.isLeft) > .ui--Icon {
|
||||
margin-left: 0.75rem;
|
||||
}
|
||||
|
||||
&.isLeft > .ui--Icon {
|
||||
margin-right: 0.75rem;
|
||||
}
|
||||
|
||||
.ui--LabelHelp {
|
||||
.ui--Icon {
|
||||
margin-left: 0;
|
||||
|
||||
@ -9,11 +9,8 @@ import styled from 'styled-components';
|
||||
|
||||
import { formatNumber, isString, isUndefined } from '@polkadot/util';
|
||||
|
||||
import CallDisplay from './Call';
|
||||
import Expander from './Expander';
|
||||
import CallExpander from './CallExpander';
|
||||
import { useTranslation } from './translate';
|
||||
import TreasuryProposal from './TreasuryProposal';
|
||||
import { isTreasuryProposalVote } from './util';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
@ -23,7 +20,7 @@ interface Props {
|
||||
expandNested?: boolean;
|
||||
}
|
||||
|
||||
function ProposedAction ({ className = '', expandNested, idNumber, proposal, withLinks }: Props): React.ReactElement<Props> {
|
||||
function ProposedAction ({ className = '', idNumber, proposal }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const stringId = isString(idNumber) || isUndefined(idNumber)
|
||||
? idNumber
|
||||
@ -31,32 +28,21 @@ function ProposedAction ({ className = '', expandNested, idNumber, proposal, wit
|
||||
|
||||
if (!proposal) {
|
||||
return (
|
||||
<h3>{stringId ? `#${stringId}: ` : ''}{t<string>('No execution details available for this proposal')}</h3>
|
||||
<div className={`ui--ProposedAction ${className}`}>
|
||||
<h1>{stringId ? `#${stringId}: ` : ''}{t<string>('No execution details available for this proposal')}</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const { meta, method, section } = proposal.registry.findMetaCall(proposal.callIndex);
|
||||
const header = `${stringId ? `#${stringId}: ` : ''}${section}.${method}`;
|
||||
|
||||
return (
|
||||
<div className={`ui--ProposedAction ${className}`}>
|
||||
<h3>{header}</h3>
|
||||
<Expander summaryMeta={meta}>
|
||||
{(isTreasuryProposalVote(proposal) && expandNested)
|
||||
? (
|
||||
<TreasuryProposal
|
||||
asInset={withLinks}
|
||||
insetProps={{
|
||||
withBottomMargin: true,
|
||||
withTopMargin: true,
|
||||
...(withLinks ? { href: '/treasury' } : {})
|
||||
}}
|
||||
proposalId={proposal.args[0].toString()}
|
||||
/>
|
||||
)
|
||||
: <CallDisplay value={proposal} />
|
||||
}
|
||||
</Expander>
|
||||
<CallExpander
|
||||
isHeader
|
||||
labelHash={t<string>('preimage')}
|
||||
stringId={stringId}
|
||||
value={proposal}
|
||||
withHash
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -64,6 +50,11 @@ function ProposedAction ({ className = '', expandNested, idNumber, proposal, wit
|
||||
export default React.memo(styled(ProposedAction)`
|
||||
margin-left: 2rem;
|
||||
|
||||
> h1 {
|
||||
font-size: 1.25rem;
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
.ui--ProposedAction-extrinsic {
|
||||
> .ui--Params-Content {
|
||||
padding-left: 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user