2022-12-13 13:31:28 +00:00
|
|
|
import { useMemo } from 'react';
|
2023-05-08 01:01:07 +00:00
|
|
|
import { useDataProvider } from '@vegaprotocol/data-provider';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { proposalsDataProvider } from '@vegaprotocol/proposals';
|
2022-12-13 13:31:28 +00:00
|
|
|
import take from 'lodash/take';
|
|
|
|
import * as Types from '@vegaprotocol/types';
|
|
|
|
import { ExternalLink } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import {
|
|
|
|
DApp,
|
|
|
|
TOKEN_NEW_MARKET_PROPOSAL,
|
|
|
|
TOKEN_PROPOSAL,
|
|
|
|
TOKEN_PROPOSALS,
|
|
|
|
useLinks,
|
|
|
|
} from '@vegaprotocol/environment';
|
2023-11-16 03:10:39 +00:00
|
|
|
import { useT } from '../../lib/use-t';
|
2022-12-13 13:31:28 +00:00
|
|
|
|
|
|
|
export const ProposedMarkets = () => {
|
2023-11-16 03:10:39 +00:00
|
|
|
const t = useT();
|
2022-12-13 13:31:28 +00:00
|
|
|
const variables = useMemo(() => {
|
|
|
|
return {
|
|
|
|
proposalType: Types.ProposalType.TYPE_NEW_MARKET,
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
const { data } = useDataProvider({
|
2023-02-20 15:53:23 +00:00
|
|
|
dataProvider: proposalsDataProvider,
|
2022-12-13 13:31:28 +00:00
|
|
|
variables,
|
|
|
|
skipUpdates: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const newMarkets = take(
|
|
|
|
(data || []).filter((proposal) =>
|
|
|
|
[
|
|
|
|
Types.ProposalState.STATE_OPEN,
|
|
|
|
Types.ProposalState.STATE_PASSED,
|
|
|
|
Types.ProposalState.STATE_WAITING_FOR_NODE_VOTE,
|
|
|
|
].includes(proposal.state)
|
|
|
|
),
|
|
|
|
3
|
|
|
|
).map((proposal) => ({
|
|
|
|
id: proposal.id,
|
|
|
|
displayName:
|
|
|
|
proposal.terms.change.__typename === 'NewMarket' &&
|
|
|
|
proposal.terms.change.instrument.code,
|
|
|
|
}));
|
|
|
|
|
2023-09-14 20:57:15 +00:00
|
|
|
const tokenLink = useLinks(DApp.Governance);
|
2022-12-13 13:31:28 +00:00
|
|
|
return useMemo(
|
|
|
|
() => (
|
2023-07-24 08:37:18 +00:00
|
|
|
<div className="mt-7 pt-8 border-t border-default">
|
2022-12-13 13:31:28 +00:00
|
|
|
{newMarkets.length > 0 ? (
|
|
|
|
<>
|
|
|
|
<h2 className="font-alpha uppercase text-2xl">
|
|
|
|
{t('Proposed markets')}
|
|
|
|
</h2>
|
|
|
|
<dl data-testid="welcome-notice-proposed-markets" className="py-5">
|
|
|
|
{newMarkets.map(({ displayName, id }, i) => (
|
|
|
|
<div className="pt-1 flex justify-between" key={i}>
|
|
|
|
<dl>{displayName}</dl>
|
|
|
|
<dt>
|
|
|
|
<ExternalLink
|
|
|
|
href={tokenLink(TOKEN_PROPOSAL.replace(':id', id || ''))}
|
|
|
|
>
|
|
|
|
{t('View or vote')}
|
|
|
|
</ExternalLink>
|
|
|
|
</dt>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</dl>
|
|
|
|
<ExternalLink href={tokenLink(TOKEN_PROPOSALS)}>
|
|
|
|
{t('View all proposed markets')}
|
|
|
|
</ExternalLink>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<ExternalLink href={tokenLink(TOKEN_NEW_MARKET_PROPOSAL)}>
|
|
|
|
{t('Propose a market')}
|
|
|
|
</ExternalLink>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
),
|
2023-11-16 03:10:39 +00:00
|
|
|
[newMarkets, tokenLink, t]
|
2022-12-13 13:31:28 +00:00
|
|
|
);
|
|
|
|
};
|