fix: update banner for resume trading

This commit is contained in:
Madalina Raicu 2024-02-26 10:12:47 +00:00
parent 72e0cb76aa
commit cc669029c1
No known key found for this signature in database
GPG Key ID: 688B7B31149C1DCD

View File

@ -2,7 +2,7 @@ import { type ReactNode } from 'react';
import sortBy from 'lodash/sortBy'; import sortBy from 'lodash/sortBy';
import { format, formatDuration, intervalToDuration } from 'date-fns'; import { format, formatDuration, intervalToDuration } from 'date-fns';
import { type MarketViewProposalFieldsFragment } from '@vegaprotocol/proposals'; import { type MarketViewProposalFieldsFragment } from '@vegaprotocol/proposals';
import { ProposalState } from '@vegaprotocol/types'; import { MarketUpdateType, ProposalState } from '@vegaprotocol/types';
import { import {
DApp, DApp,
TOKEN_PROPOSAL, TOKEN_PROPOSAL,
@ -24,6 +24,16 @@ export const MarketUpdateStateBanner = ({
const t = useT(); const t = useT();
const governanceLink = useLinks(DApp.Governance); const governanceLink = useLinks(DApp.Governance);
const openTradingProposals = sortBy(
proposals.filter(
(p) =>
p.terms.change.__typename === 'UpdateMarketState' &&
p.terms.change.updateType ===
MarketUpdateType.MARKET_STATE_UPDATE_TYPE_RESUME
),
(p) => p.terms.enactmentDatetime
);
const openProposals = sortBy( const openProposals = sortBy(
proposals.filter((p) => p.state === ProposalState.STATE_OPEN), proposals.filter((p) => p.state === ProposalState.STATE_OPEN),
(p) => p.terms.enactmentDatetime (p) => p.terms.enactmentDatetime
@ -45,12 +55,32 @@ export const MarketUpdateStateBanner = ({
? governanceLink(TOKEN_PROPOSAL.replace(':id', openProposals[0]?.id)) ? governanceLink(TOKEN_PROPOSAL.replace(':id', openProposals[0]?.id))
: undefined; : undefined;
const openTradingProposalsLink = openTradingProposals[0]?.id
? governanceLink(TOKEN_PROPOSAL.replace(':id', openTradingProposals[0]?.id))
: undefined;
const proposalsLink = const proposalsLink =
openProposals.length > 1 ? governanceLink(TOKEN_PROPOSALS) : undefined; openProposals.length > 1 ? governanceLink(TOKEN_PROPOSALS) : undefined;
let content: ReactNode; let content: ReactNode;
if (passedProposals.length) { if (openTradingProposals.length >= 1) {
content = (
<>
<p className="mb-1">
{t(
'Trading on market {{name}} was suspended by governance. There are open proposals to resume trading on this market.',
{ name }
)}
</p>
<p>
<ExternalLink href={openTradingProposalsLink}>
{t('View proposals')}
</ExternalLink>
</p>
</>
);
} else if (passedProposals.length) {
const { date, duration, price } = getMessageVariables(passedProposals[0]); const { date, duration, price } = getMessageVariables(passedProposals[0]);
content = ( content = (
<> <>