fix(trading): key details panel throwing error on batch created market (#5980)
This commit is contained in:
parent
c0942d56a1
commit
2153367258
@ -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<SuccessorMarketProposalDetailsQuery['proposal']>
|
||||
| undefined;
|
||||
let successorConfiguration: SuccessorConfiguration | false = false;
|
||||
|
||||
const successorConfiguration =
|
||||
successorProposal?.terms.change.__typename === 'NewMarket' &&
|
||||
successorProposal.terms.change.successorConfiguration?.__typename ===
|
||||
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' &&
|
||||
successorProposal.terms.change.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<SuccessorMarketProposalDetailsQuery['proposal']>
|
||||
| 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:
|
||||
|
@ -71,6 +71,22 @@ query SuccessorMarketProposalDetails($proposalId: ID!) {
|
||||
}
|
||||
}
|
||||
}
|
||||
... on BatchProposal {
|
||||
id
|
||||
batchTerms {
|
||||
changes {
|
||||
change {
|
||||
... on NewMarket {
|
||||
__typename
|
||||
successorConfiguration {
|
||||
parentMarketId
|
||||
insurancePoolFraction
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
Loading…
Reference in New Issue
Block a user