From 2153367258bd6fba797c541a30a685a1f61cacb8 Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Tue, 12 Mar 2024 13:56:18 +0000 Subject: [PATCH] fix(trading): key details panel throwing error on batch created market (#5980) --- .../market-info/market-info-panels.tsx | 64 +++++++++++++------ .../src/lib/proposals-hooks/Proposal.graphql | 16 +++++ .../proposals-hooks/__generated__/Proposal.ts | 18 +++++- 3 files changed, 77 insertions(+), 21 deletions(-) diff --git a/libs/markets/src/lib/components/market-info/market-info-panels.tsx b/libs/markets/src/lib/components/market-info/market-info-panels.tsx index 679b9cdb5..45221a851 100644 --- a/libs/markets/src/lib/components/market-info/market-info-panels.tsx +++ b/libs/markets/src/lib/components/market-info/market-info-panels.tsx @@ -48,6 +48,7 @@ import { LiquidityFeeMethodMappingDescription, MarketStateMapping, MarketTradingModeMapping, + type SuccessorConfiguration, } from '@vegaprotocol/types'; import { DApp, @@ -68,11 +69,7 @@ import { useSuccessorMarketIdsQuery, useSuccessorMarketQuery, } from '../../__generated__'; -import { - useSuccessorMarketProposalDetailsQuery, - type SuccessorMarketProposalDetailsQuery, - type SingleProposal, -} from '@vegaprotocol/proposals'; +import { useSuccessorMarketProposalDetailsQuery } from '@vegaprotocol/proposals'; import { getQuoteName, getAsset } from '../../market-utils'; import classNames from 'classnames'; import compact from 'lodash/compact'; @@ -253,15 +250,27 @@ export const KeyDetailsInfoPanel = ({ skip: !featureFlags.SUCCESSOR_MARKETS || !market.proposal?.id, }); - const successorProposal = successorProposalDetails?.proposal as - | SingleProposal - | undefined; + let successorConfiguration: SuccessorConfiguration | false = false; - const successorConfiguration = - successorProposal?.terms.change.__typename === 'NewMarket' && - successorProposal.terms.change.successorConfiguration?.__typename === - 'SuccessorConfiguration' && - successorProposal.terms.change.successorConfiguration; + if (successorProposalDetails?.proposal?.__typename === 'Proposal') { + successorConfiguration = + successorProposalDetails.proposal.terms.change.__typename === + 'NewMarket' && + successorProposalDetails.proposal.terms.change.successorConfiguration + ?.__typename === 'SuccessorConfiguration' && + successorProposalDetails.proposal.terms.change.successorConfiguration; + } else if ( + successorProposalDetails?.proposal?.__typename === 'BatchProposal' + ) { + const subTerms = successorProposalDetails.proposal.batchTerms?.changes.find( + (c) => c?.change.__typename === 'NewMarket' + ); + successorConfiguration = + subTerms?.change.__typename === 'NewMarket' && + subTerms?.change.successorConfiguration?.__typename === + 'SuccessorConfiguration' && + subTerms?.change?.successorConfiguration; + } // The following queries are needed as the parent market could also have been a successor market. // Note: the parent market is only passed to this component if the successor markets flag is enabled, @@ -280,9 +289,27 @@ export const KeyDetailsInfoPanel = ({ }, skip: !parentMarket?.proposal?.id, }); - const parentProposal = parentSuccessorProposalDetails?.proposal as - | SingleProposal - | undefined; + + let parentSuccessorConfig: SuccessorConfiguration | undefined = undefined; + + if (parentSuccessorProposalDetails?.proposal?.__typename === 'Proposal') { + const parentProposal = parentSuccessorProposalDetails?.proposal; + parentSuccessorConfig = + parentProposal.terms.change.__typename === 'NewMarket' + ? parentProposal.terms.change.successorConfiguration || undefined + : undefined; + } else if ( + parentSuccessorProposalDetails?.proposal?.__typename === 'BatchProposal' + ) { + const subTerms = + parentSuccessorProposalDetails.proposal.batchTerms?.changes.find( + (c) => c?.change.__typename === 'NewMarket' + ); + parentSuccessorConfig = + subTerms?.change.__typename === 'NewMarket' + ? subTerms.change.successorConfiguration || undefined + : undefined; + } const assetDecimals = getAsset(market).decimals; @@ -336,10 +363,7 @@ export const KeyDetailsInfoPanel = ({ parentMarket && { name: parentMarket?.tradableInstrument?.instrument?.name, parentMarketID: grandparentMarketIdData?.market?.parentMarketID, - insurancePoolFraction: - parentProposal?.terms.change.__typename === 'NewMarket' && - parentProposal?.terms.change.successorConfiguration - ?.insurancePoolFraction, + insurancePoolFraction: parentSuccessorConfig?.insurancePoolFraction, status: parentMarket?.state && MarketStateMapping[parentMarket.state], tradingMode: diff --git a/libs/proposals/src/lib/proposals-hooks/Proposal.graphql b/libs/proposals/src/lib/proposals-hooks/Proposal.graphql index 81d5fa647..1bcc6b82d 100644 --- a/libs/proposals/src/lib/proposals-hooks/Proposal.graphql +++ b/libs/proposals/src/lib/proposals-hooks/Proposal.graphql @@ -71,6 +71,22 @@ query SuccessorMarketProposalDetails($proposalId: ID!) { } } } + ... on BatchProposal { + id + batchTerms { + changes { + change { + ... on NewMarket { + __typename + successorConfiguration { + parentMarketId + insurancePoolFraction + } + } + } + } + } + } } } diff --git a/libs/proposals/src/lib/proposals-hooks/__generated__/Proposal.ts b/libs/proposals/src/lib/proposals-hooks/__generated__/Proposal.ts index 40fadb768..13d75fac6 100644 --- a/libs/proposals/src/lib/proposals-hooks/__generated__/Proposal.ts +++ b/libs/proposals/src/lib/proposals-hooks/__generated__/Proposal.ts @@ -32,7 +32,7 @@ export type SuccessorMarketProposalDetailsQueryVariables = Types.Exact<{ }>; -export type SuccessorMarketProposalDetailsQuery = { __typename?: 'Query', proposal?: { __typename?: 'BatchProposal' } | { __typename?: 'Proposal', id?: string | null, terms: { __typename?: 'ProposalTerms', change: { __typename?: 'CancelTransfer' } | { __typename?: 'NewAsset' } | { __typename?: 'NewFreeform' } | { __typename?: 'NewMarket', successorConfiguration?: { __typename?: 'SuccessorConfiguration', parentMarketId: string, insurancePoolFraction: string } | null } | { __typename?: 'NewSpotMarket' } | { __typename?: 'NewTransfer' } | { __typename?: 'UpdateAsset' } | { __typename?: 'UpdateMarket' } | { __typename?: 'UpdateMarketState' } | { __typename?: 'UpdateNetworkParameter' } | { __typename?: 'UpdateReferralProgram' } | { __typename?: 'UpdateSpotMarket' } | { __typename?: 'UpdateVolumeDiscountProgram' } } } | null }; +export type SuccessorMarketProposalDetailsQuery = { __typename?: 'Query', proposal?: { __typename?: 'BatchProposal', id?: string | null, batchTerms?: { __typename?: 'BatchProposalTerms', changes: Array<{ __typename?: 'BatchProposalTermsChange', change: { __typename?: 'CancelTransfer' } | { __typename?: 'NewAsset' } | { __typename?: 'NewFreeform' } | { __typename: 'NewMarket', successorConfiguration?: { __typename?: 'SuccessorConfiguration', parentMarketId: string, insurancePoolFraction: string } | null } | { __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', change: { __typename?: 'CancelTransfer' } | { __typename?: 'NewAsset' } | { __typename?: 'NewFreeform' } | { __typename?: 'NewMarket', successorConfiguration?: { __typename?: 'SuccessorConfiguration', parentMarketId: string, insurancePoolFraction: string } | null } | { __typename?: 'NewSpotMarket' } | { __typename?: 'NewTransfer' } | { __typename?: 'UpdateAsset' } | { __typename?: 'UpdateMarket' } | { __typename?: 'UpdateMarketState' } | { __typename?: 'UpdateNetworkParameter' } | { __typename?: 'UpdateReferralProgram' } | { __typename?: 'UpdateSpotMarket' } | { __typename?: 'UpdateVolumeDiscountProgram' } } } | null }; export type InstrumentDetailsQueryVariables = Types.Exact<{ marketId: Types.Scalars['ID']; @@ -207,6 +207,22 @@ export const SuccessorMarketProposalDetailsDocument = gql` } } } + ... on BatchProposal { + id + batchTerms { + changes { + change { + ... on NewMarket { + __typename + successorConfiguration { + parentMarketId + insurancePoolFraction + } + } + } + } + } + } } } `;