vega-frontend-monorepo/apps/trading/components/welcome-dialog/proposed-markets.tsx
macqbat c14e57cfd5
feat(2146): adjust and refactor welcome dialogs (#2384)
* feat: adjust and refactor welcome dialogs

* feat: adjust and refactor welcome dialogs - add int tests

* feat: adjust and refactor welcome dialogs - small fixes and imprvments

* feat: adjust and refactor welcome dialogs - fix a typo

* feat: adjust and refactor welcome dialogs - fix a property name

* feat: adjust and refactor welcome dialogs - fix an unit test
2022-12-13 14:31:28 +01:00

80 lines
2.3 KiB
TypeScript

import { useMemo } from 'react';
import { t, useDataProvider } from '@vegaprotocol/react-helpers';
import { proposalsListDataProvider } from '@vegaprotocol/governance';
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: proposalsListDataProvider,
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(
() => (
<div className="mt-7 pt-8 border-t border-neutral-700">
{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>
),
[newMarkets, tokenLink]
);
};