import { useMemo } from 'react'; import { t } from '@vegaprotocol/i18n'; import { useDataProvider } from '@vegaprotocol/react-helpers'; import { proposalsDataProvider } from '@vegaprotocol/proposals'; 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'; export const ProposedMarkets = () => { const variables = useMemo(() => { return { proposalType: Types.ProposalType.TYPE_NEW_MARKET, }; }, []); const { data } = useDataProvider({ dataProvider: proposalsDataProvider, 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, })); const tokenLink = useLinks(DApp.Token); return useMemo( () => (
{newMarkets.length > 0 ? ( <>

{t('Proposed markets')}

{newMarkets.map(({ displayName, id }, i) => (
{displayName}
{t('View or vote')}
))}
{t('View all proposed markets')} ) : ( {t('Propose a market')} )}
), [newMarkets, tokenLink] ); };