fix: proposals list (#2374)
* fix: proposals list * Update apps/token/src/routes/governance/components/proposals-list/proposals-list.tsx
This commit is contained in:
parent
4b86b981b3
commit
22610c2d0a
@ -24,7 +24,6 @@ interface SortedProposalsProps {
|
||||
export const ProposalsList = ({ proposals }: ProposalsListProps) => {
|
||||
const { t } = useTranslation();
|
||||
const [filterString, setFilterString] = useState('');
|
||||
|
||||
const sortedProposals = proposals.reduce(
|
||||
(acc: SortedProposalsProps, proposal) => {
|
||||
if (isFuture(new Date(proposal?.terms.closingDatetime))) {
|
||||
@ -110,7 +109,7 @@ export const ProposalsList = ({ proposals }: ProposalsListProps) => {
|
||||
)}
|
||||
</section>
|
||||
|
||||
<Link className="underline" to={'/governance/rejected'}>
|
||||
<Link className="underline" to={Routes.PROPOSALS_REJECTED}>
|
||||
{t('seeRejectedProposals')}
|
||||
</Link>
|
||||
</>
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { getNotRejectedProposals } from '@vegaprotocol/governance';
|
||||
import { Callout, Intent, Splash } from '@vegaprotocol/ui-toolkit';
|
||||
import { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@ -7,6 +6,35 @@ import { SplashLoader } from '../../../components/splash-loader';
|
||||
import { ProposalsList } from '../components/proposals-list';
|
||||
import { useProposalsQuery } from './__generated__/Proposals';
|
||||
import type { ProposalFieldsFragment } from './__generated__/Proposals';
|
||||
import type { NodeConnection, NodeEdge } from '@vegaprotocol/react-helpers';
|
||||
import { getNodes } from '@vegaprotocol/react-helpers';
|
||||
import flow from 'lodash/flow';
|
||||
import { ProposalState } from '@vegaprotocol/types';
|
||||
|
||||
import orderBy from 'lodash/orderBy';
|
||||
|
||||
const orderByDate = (arr: ProposalFieldsFragment[]) =>
|
||||
orderBy(
|
||||
arr,
|
||||
[
|
||||
(p) => new Date(p?.terms?.enactmentDatetime || 0).getTime(), // has to be defaulted to 0 because new Date(null).getTime() -> NaN which is first when ordered.
|
||||
(p) => new Date(p?.terms?.closingDatetime).getTime(),
|
||||
(p) => p.id,
|
||||
],
|
||||
['desc', 'desc', 'desc']
|
||||
);
|
||||
|
||||
export function getNotRejectedProposals<T extends ProposalFieldsFragment>(
|
||||
data?: NodeConnection<NodeEdge<T>> | null
|
||||
): T[] {
|
||||
return flow([
|
||||
(data) =>
|
||||
getNodes<ProposalFieldsFragment>(data, (p) =>
|
||||
p ? p.state !== ProposalState.STATE_REJECTED : false
|
||||
),
|
||||
orderByDate,
|
||||
])(data);
|
||||
}
|
||||
|
||||
export const ProposalsContainer = () => {
|
||||
const { t } = useTranslation();
|
||||
|
@ -4,9 +4,36 @@ import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { SplashLoader } from '../../../components/splash-loader';
|
||||
import { RejectedProposalsList } from '../components/proposals-list';
|
||||
import { getRejectedProposals } from '@vegaprotocol/governance';
|
||||
import type { ProposalFieldsFragment } from '../proposals/__generated__/Proposals';
|
||||
import { useProposalsQuery } from '../proposals/__generated__/Proposals';
|
||||
import type { NodeConnection, NodeEdge } from '@vegaprotocol/react-helpers';
|
||||
import { getNodes } from '@vegaprotocol/react-helpers';
|
||||
import flow from 'lodash/flow';
|
||||
import orderBy from 'lodash/orderBy';
|
||||
import { ProposalState } from '@vegaprotocol/types';
|
||||
|
||||
const orderByDate = (arr: ProposalFieldsFragment[]) =>
|
||||
orderBy(
|
||||
arr,
|
||||
[
|
||||
(p) => new Date(p?.terms?.enactmentDatetime || 0).getTime(), // has to be defaulted to 0 because new Date(null).getTime() -> NaN which is first when ordered.
|
||||
(p) => new Date(p?.terms?.closingDatetime).getTime(),
|
||||
(p) => p.id,
|
||||
],
|
||||
['desc', 'desc', 'desc']
|
||||
);
|
||||
|
||||
export function getRejectedProposals<T extends ProposalFieldsFragment>(
|
||||
data?: NodeConnection<NodeEdge<ProposalFieldsFragment>> | null
|
||||
): T[] {
|
||||
return flow([
|
||||
(data) =>
|
||||
getNodes<ProposalFieldsFragment>(data, (p) =>
|
||||
p ? p?.state === ProposalState.STATE_REJECTED : false
|
||||
),
|
||||
orderByDate,
|
||||
])(data);
|
||||
}
|
||||
|
||||
export const RejectedProposalsContainer = () => {
|
||||
const { t } = useTranslation();
|
||||
|
@ -4,6 +4,7 @@ export default {
|
||||
VALIDATORS: '/validators',
|
||||
REWARDS: '/rewards',
|
||||
PROPOSALS: '/proposals',
|
||||
PROPOSALS_REJECTED: '/proposals/rejected',
|
||||
NOT_PERMITTED: '/not-permitted',
|
||||
NOT_FOUND: '/not-found',
|
||||
CONTRACTS: '/contracts',
|
||||
|
@ -1,5 +1,4 @@
|
||||
export * from './proposals-hooks';
|
||||
export * from './proposals-queries';
|
||||
export * from './voting-hooks';
|
||||
export * from './proposals-data-provider';
|
||||
export * from './proposals-list';
|
||||
|
@ -1 +0,0 @@
|
||||
export * from './proposals-queries';
|
@ -1,43 +0,0 @@
|
||||
import flow from 'lodash/flow';
|
||||
import orderBy from 'lodash/orderBy';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
import * as Schema from '@vegaprotocol/types';
|
||||
import type { NodeConnection, NodeEdge } from '@vegaprotocol/react-helpers';
|
||||
import { getNodes } from '@vegaprotocol/react-helpers';
|
||||
|
||||
type Proposal = PartialDeep<Schema.Proposal>;
|
||||
|
||||
const orderByDate = (arr: Proposal[]) =>
|
||||
orderBy(
|
||||
arr,
|
||||
[
|
||||
(p) => new Date(p?.terms?.enactmentDatetime || 0).getTime(), // has to be defaulted to 0 because new Date(null).getTime() -> NaN which is first when ordered.
|
||||
(p) => new Date(p?.terms?.closingDatetime).getTime(),
|
||||
(p) => p.id,
|
||||
],
|
||||
['desc', 'desc', 'desc']
|
||||
);
|
||||
|
||||
export function getNotRejectedProposals<T extends Proposal>(
|
||||
data?: NodeConnection<NodeEdge<T>> | null
|
||||
): T[] {
|
||||
return flow([
|
||||
(data) =>
|
||||
getNodes<Proposal>(data?.proposalsConnection, (p) =>
|
||||
p ? p?.state !== Schema.ProposalState.STATE_REJECTED : false
|
||||
),
|
||||
orderByDate,
|
||||
])(data);
|
||||
}
|
||||
|
||||
export function getRejectedProposals<T extends Proposal>(
|
||||
data?: NodeConnection<NodeEdge<Proposal>> | null
|
||||
): T[] {
|
||||
return flow([
|
||||
(data) =>
|
||||
getNodes<Proposal>(data?.proposalsConnection, (p) =>
|
||||
p ? p?.state === Schema.ProposalState.STATE_REJECTED : false
|
||||
),
|
||||
orderByDate,
|
||||
])(data);
|
||||
}
|
Loading…
Reference in New Issue
Block a user