Skip to content

Commit

Permalink
feat: display executed payloads counts on proposal list
Browse files Browse the repository at this point in the history
  • Loading branch information
therealemjy committed Oct 9, 2024
1 parent 34ed5f6 commit e126d10
Show file tree
Hide file tree
Showing 28 changed files with 317 additions and 227 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-hairs-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@venusprotocol/evm": minor
---

display executed payloads counts on proposal list
5 changes: 4 additions & 1 deletion apps/evm/src/__mocks__/models/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ export const proposals: Proposal[] = [
},
endBlock: 33499859,
endDate: new Date('2023-09-20T07:54:35.000Z'),
queuedDate: new Date('2023-09-20T09:54:35.000Z'),
executionEtaDate: new Date('2023-09-21T06:54:35.000Z'),
executedDate: new Date('2023-09-21T07:54:35.000Z'),
forVotesMantissa: new BigNumber('605461000000000000000000'),
proposalId: 98,
proposerAddress: '0x2ce1d0ffd7e869d9df33e28552b12ddded326706',
startDate: new Date('2023-09-20T07:47:05.000Z'),
state: ProposalState.Defeated,
state: ProposalState.Executed,
createdTxHash: '0xb8a70919dbf83e5c63af8efbad418b2a81ca9f4937b12f806482581abaf03b65',
totalVotesMantissa: new BigNumber('605461000000000000000000'),
proposalActions: [],
Expand Down
1 change: 1 addition & 0 deletions apps/evm/src/clients/api/__mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export const useGetCurrentVotes = vi.fn(() =>

export const getProposals = vi.fn(async () => ({
proposals,
total: 100,
}));
export const useGetProposals = vi.fn(() =>
useQuery({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ exports[`useGetCachedProposal > returns proposal from cache when it exists 1`] =
},
"endBlock": 33499859,
"endDate": 2023-09-20T07:54:35.000Z,
"executedDate": 2023-09-21T07:54:35.000Z,
"executionEtaDate": 2023-09-21T06:54:35.000Z,
"forVotes": [
{
"address": "0x2ce1d0ffd7e869d9df33e28552b12ddded326706",
Expand All @@ -29,6 +31,7 @@ exports[`useGetCachedProposal > returns proposal from cache when it exists 1`] =
"proposalId": 98,
"proposalType": 0,
"proposerAddress": "0x2ce1d0ffd7e869d9df33e28552b12ddded326706",
"queuedDate": 2023-09-20T09:54:35.000Z,
"remoteProposals": [
{
"bridgedDate": 2023-02-01T00:00:00.000Z,
Expand Down Expand Up @@ -183,7 +186,7 @@ exports[`useGetCachedProposal > returns proposal from cache when it exists 1`] =
},
],
"startDate": 2023-09-20T07:47:05.000Z,
"state": 3,
"state": 7,
"totalVotesMantissa": "6.05461e+23",
}
`;
25 changes: 25 additions & 0 deletions apps/evm/src/components/LabeledProgressCircle/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { cn } from 'utilities';
import { ProgressCircle } from '../ProgressCircle';

export interface LabeledProgressCircleProps extends React.HTMLAttributes<HTMLDivElement> {
value: number;
total: number;
}

export const LabeledProgressCircle: React.FC<LabeledProgressCircleProps> = ({
className,
value,
total,
...otherProps
}) => (
<div
className={cn('relative ml-3 w-11 h-11 flex items-center justify-center', className)}
{...otherProps}
>
<ProgressCircle className="absolute inset" value={(value * 100) / total} />

<p className="text-sm text-center">
{value}/{total}
</p>
</div>
);
2 changes: 1 addition & 1 deletion apps/evm/src/components/ProgressCircle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ProgressCircle: React.FC<ProgressCircleProps> = ({
}) => {
const theme = useTheme();

const strokeWidthPx = size === 'sm' ? 3 : 4;
const strokeWidthPx = size === 'sm' ? 3 : 6;
const sizePx = size === 'sm' ? 16 : 50;

const { circumference, offset } = useMemo(() => {
Expand Down
6 changes: 3 additions & 3 deletions apps/evm/src/components/ProposalCard/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ export const useStyles = () => {
-webkit-box-orient: vertical;
`,
gridItemRight: css`
padding-left: ${theme.spacing(6)};
padding-left: ${theme.spacing(6)};
border-left: 1px solid ${theme.palette.secondary.light};
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
${theme.breakpoints.down('sm')} {
flex-direction: row;
border-left: none;
border-top: 1px solid ${theme.palette.secondary.light};
padding-top: ${theme.spacing(10)};
padding-bottom: ${theme.spacing(10)};
padding: ${theme.spacing(6, 0)};
}
`,
};
Expand Down
1 change: 1 addition & 0 deletions apps/evm/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * from './Notice';
export * from './Pagination';
export * from './ProgressBar';
export * from './ProgressCircle';
export * from './LabeledProgressCircle';
export * from './ProposalCard';
export * from './Card';
export * from './ProgressBar/AccountHealth';
Expand Down
14 changes: 6 additions & 8 deletions apps/evm/src/libs/translations/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@
},
"proposalState": {
"active": "Active",
"bridged": "Bridged",
"canceled": "Canceled",
"created": "Created",
"defeated": "Defeated",
Expand Down Expand Up @@ -1109,14 +1110,7 @@
"title": "Operations"
},
"status": {
"active": "Active",
"bridged": "Bridged",
"canceled": "Canceled",
"defeated": "Defeated",
"executed": "Executed",
"expired": "Expired",
"pending": "Pending",
"queued": "Queued"
"pending": "Pending"
}
},
"commands": {
Expand Down Expand Up @@ -1151,6 +1145,10 @@
},
"queueButtonLabel": "Queue",
"queuedUntilDate": "Queued until: <Date>{{ date, dd MMM yyyy h:mm a }}</Date>",
"status": {
"executedPayloads": "Executed payloads",
"readyForExecution": "Ready for execution"
},
"statusCard": {
"ariaLabelAbstain": "votes abstain",
"ariaLabelAgainst": "votes against",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Icon, type IconName } from 'components';
import { useMemo } from 'react';
import { type Proposal, ProposalState } from 'types';
import { cn } from 'utilities';

export type IndicatorProps = React.HTMLAttributes<HTMLDivElement> & Pick<Proposal, 'state'>;

export const Indicator: React.FC<IndicatorProps> = ({ state, className, ...otherProps }) => {
const [colorClass, iconName] = useMemo<[string, IconName]>(() => {
let tmpColorClass = 'bg-grey';
let tmpIconName: IconName = 'dots';

if (state === ProposalState.Executed) {
tmpColorClass = 'bg-green';
tmpIconName = 'mark';
} else if (state === ProposalState.Succeeded) {
tmpColorClass = 'bg-orange';
tmpIconName = 'exclamation';
} else if (
state === ProposalState.Defeated ||
state === ProposalState.Expired ||
state === ProposalState.Canceled
) {
tmpColorClass = 'bg-red';
tmpIconName = 'close';
}

return [tmpColorClass, tmpIconName];
}, [state]);

return (
<div
className={cn(
'w-10 h-10 rounded-full mx-auto flex items-center justify-center',
colorClass,
className,
)}
{...otherProps}
>
<Icon name={iconName} className="w-6 h-6 text-offWhite" />
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { LabeledProgressCircle } from 'components';
import { useIsFeatureEnabled } from 'hooks/useIsFeatureEnabled';
import { useTranslation } from 'libs/translations';
import { useMemo } from 'react';
import { ProposalState } from 'types';
import { cn, getProposalStateLabel } from 'utilities';
import { Indicator } from './Indicator';

export interface StatusProps extends React.HTMLAttributes<HTMLDivElement> {
state: ProposalState;
totalPayloadsCount: number;
executedPayloadsCount: number;
}

export const Status: React.FC<StatusProps> = ({
state,
totalPayloadsCount,
executedPayloadsCount,
className,
...otherProps
}) => {
const { t } = useTranslation();
const isMultichainGovernanceFeatureEnabled = useIsFeatureEnabled({
name: 'multichainGovernance',
});

const isFullyExecuted = executedPayloadsCount === totalPayloadsCount;
const shouldShowExecutedPayloadsStatus =
isMultichainGovernanceFeatureEnabled && state === ProposalState.Executed && !isFullyExecuted;

const label = useMemo(() => {
if (shouldShowExecutedPayloadsStatus) {
return t('voteProposalUi.status.executedPayloads');
}

if (state === ProposalState.Succeeded) {
return t('voteProposalUi.status.readyForExecution');
}

return getProposalStateLabel({ state });
}, [t, state, shouldShowExecutedPayloadsStatus]);

return (
<div
className={cn(
'flex items-center gap-3 overflow-hidden text-offWhite sm:flex-col sm:text-center',
className,
)}
{...otherProps}
>
<div className="shrink-0">
{shouldShowExecutedPayloadsStatus ? (
<LabeledProgressCircle
total={totalPayloadsCount}
value={executedPayloadsCount}
className="mx-auto"
/>
) : (
<Indicator state={state} />
)}
</div>

<p className="text-md font-semibold whitespace-nowrap overflow-hidden text-ellipsis flex-grow">
{label}
</p>
</div>
);
};
Loading

0 comments on commit e126d10

Please sign in to comment.