fix(trading): check for batch proposal in trading mode tooltip (#5895)

This commit is contained in:
Matthew Russell 2024-03-01 09:26:29 -05:00 committed by GitHub
parent 28b4593a1d
commit 2d821700bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 20 deletions

View File

@ -1,11 +1,7 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { parseISO, isValid, isAfter } from 'date-fns'; import { parseISO, isValid, isAfter } from 'date-fns';
import classNames from 'classnames'; import classNames from 'classnames';
import { import { useProposalOfMarketQuery } from '@vegaprotocol/proposals';
useProposalOfMarketQuery,
type ProposalOfMarketQuery,
type SingleProposal,
} from '@vegaprotocol/proposals';
import { DocsLinks } from '@vegaprotocol/environment'; import { DocsLinks } from '@vegaprotocol/environment';
import { getDateTimeFormat } from '@vegaprotocol/utils'; import { getDateTimeFormat } from '@vegaprotocol/utils';
import * as Schema from '@vegaprotocol/types'; import * as Schema from '@vegaprotocol/types';
@ -40,15 +36,21 @@ export const TradingModeTooltip = ({
marketTradingMode, marketTradingMode,
}); });
// We only fetch Proposals (and not BatchProposals)
const proposal = proposalData?.proposal as SingleProposal<
ProposalOfMarketQuery['proposal']
>;
if (!market || !marketData) { if (!market || !marketData) {
return null; return null;
} }
const enactmentDate = parseISO(proposal?.terms.enactmentDatetime);
let enactmentDate;
const proposal = proposalData?.proposal;
if (proposal?.__typename === 'Proposal') {
enactmentDate = parseISO(proposal.terms.enactmentDatetime);
} else if (proposal?.__typename === 'BatchProposal') {
const change = proposal.batchTerms?.changes.find(
(c) => c?.change.__typename === 'NewMarket'
);
enactmentDate = change ? parseISO(change.enactmentDatetime) : undefined;
}
const compiledGrid = const compiledGrid =
!skipGrid && compileGridData(t, market, marketData, onSelect); !skipGrid && compileGridData(t, market, marketData, onSelect);
@ -67,14 +69,16 @@ export const TradingModeTooltip = ({
return ( return (
<section data-testid="trading-mode-tooltip"> <section data-testid="trading-mode-tooltip">
<p <p
className={classNames('flex flex-col', { className={classNames('flex flex-col items-start gap-2', {
'mb-4': Boolean(compiledGrid), 'mb-4': Boolean(compiledGrid),
})} })}
> >
{isValid(enactmentDate) && isAfter(new Date(), enactmentDate) ? ( {enactmentDate &&
isValid(enactmentDate) &&
isAfter(new Date(), enactmentDate) ? (
<> <>
<span <span
className="justify-center font-bold my-2" className="justify-center font-bold"
data-testid="opening-auction-sub-status" data-testid="opening-auction-sub-status"
> >
{`${Schema.MarketTradingModeMapping[marketTradingMode]}: ${t( {`${Schema.MarketTradingModeMapping[marketTradingMode]}: ${t(
@ -91,7 +95,7 @@ export const TradingModeTooltip = ({
<> <>
{isValid(enactmentDate) && ( {isValid(enactmentDate) && (
<span <span
className="justify-center font-bold my-2" className="justify-center font-bold"
data-testid="opening-auction-sub-status" data-testid="opening-auction-sub-status"
> >
{`${ {`${
@ -109,10 +113,7 @@ export const TradingModeTooltip = ({
</> </>
)} )}
{DocsLinks && ( {DocsLinks && (
<ExternalLink <ExternalLink href={DocsLinks.AUCTION_TYPE_OPENING}>
href={DocsLinks.AUCTION_TYPE_OPENING}
className="ml-1"
>
{t('Find out more')} {t('Find out more')}
</ExternalLink> </ExternalLink>
)} )}

View File

@ -45,6 +45,19 @@ query ProposalOfMarket($marketId: ID!) {
enactmentDatetime enactmentDatetime
} }
} }
... on BatchProposal {
id
batchTerms {
changes {
enactmentDatetime
change {
... on NewMarket {
__typename
}
}
}
}
}
} }
} }

View File

@ -25,7 +25,7 @@ export type ProposalOfMarketQueryVariables = Types.Exact<{
}>; }>;
export type ProposalOfMarketQuery = { __typename?: 'Query', proposal?: { __typename?: 'BatchProposal' } | { __typename?: 'Proposal', id?: string | null, terms: { __typename?: 'ProposalTerms', enactmentDatetime?: any | null } } | null }; export type ProposalOfMarketQuery = { __typename?: 'Query', proposal?: { __typename?: 'BatchProposal', id?: string | null, batchTerms?: { __typename?: 'BatchProposalTerms', changes: Array<{ __typename?: 'BatchProposalTermsChange', enactmentDatetime?: any | null, change: { __typename?: 'CancelTransfer' } | { __typename?: 'NewAsset' } | { __typename?: 'NewFreeform' } | { __typename: 'NewMarket' } | { __typename?: 'NewSpotMarket' } | { __typename?: 'NewTransfer' } | { __typename?: 'UpdateAsset' } | { __typename?: 'UpdateMarket' } | { __typename?: 'UpdateMarketState' } | { __typename?: 'UpdateNetworkParameter' } | { __typename?: 'UpdateReferralProgram' } | { __typename?: 'UpdateSpotMarket' } | { __typename?: 'UpdateVolumeDiscountProgram' } } | null> } | null } | { __typename?: 'Proposal', id?: string | null, terms: { __typename?: 'ProposalTerms', enactmentDatetime?: any | null } } | null };
export type SuccessorMarketProposalDetailsQueryVariables = Types.Exact<{ export type SuccessorMarketProposalDetailsQueryVariables = Types.Exact<{
proposalId: Types.Scalars['ID']; proposalId: Types.Scalars['ID'];
@ -152,6 +152,19 @@ export const ProposalOfMarketDocument = gql`
enactmentDatetime enactmentDatetime
} }
} }
... on BatchProposal {
id
batchTerms {
changes {
enactmentDatetime
change {
... on NewMarket {
__typename
}
}
}
}
}
} }
} }
`; `;

View File

@ -256,6 +256,8 @@ export type AggregatedLedgerEntry = {
toAccountPartyId?: Maybe<Scalars['ID']>; toAccountPartyId?: Maybe<Scalars['ID']>;
/** Account type, if query was grouped by receiver account type - else null */ /** Account type, if query was grouped by receiver account type - else null */
toAccountType?: Maybe<AccountType>; toAccountType?: Maybe<AccountType>;
/** Transfer ID associated with this aggregated ledger entry */
transferId: Scalars['ID'];
/** Type of the transfer for this ledger entry */ /** Type of the transfer for this ledger entry */
transferType?: Maybe<TransferType>; transferType?: Maybe<TransferType>;
/** RFC3339Nano time from at which this ledger entries records were relevant */ /** RFC3339Nano time from at which this ledger entries records were relevant */