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,
|
LiquidityFeeMethodMappingDescription,
|
||||||
MarketStateMapping,
|
MarketStateMapping,
|
||||||
MarketTradingModeMapping,
|
MarketTradingModeMapping,
|
||||||
|
type SuccessorConfiguration,
|
||||||
} from '@vegaprotocol/types';
|
} from '@vegaprotocol/types';
|
||||||
import {
|
import {
|
||||||
DApp,
|
DApp,
|
||||||
@ -68,11 +69,7 @@ import {
|
|||||||
useSuccessorMarketIdsQuery,
|
useSuccessorMarketIdsQuery,
|
||||||
useSuccessorMarketQuery,
|
useSuccessorMarketQuery,
|
||||||
} from '../../__generated__';
|
} from '../../__generated__';
|
||||||
import {
|
import { useSuccessorMarketProposalDetailsQuery } from '@vegaprotocol/proposals';
|
||||||
useSuccessorMarketProposalDetailsQuery,
|
|
||||||
type SuccessorMarketProposalDetailsQuery,
|
|
||||||
type SingleProposal,
|
|
||||||
} from '@vegaprotocol/proposals';
|
|
||||||
import { getQuoteName, getAsset } from '../../market-utils';
|
import { getQuoteName, getAsset } from '../../market-utils';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import compact from 'lodash/compact';
|
import compact from 'lodash/compact';
|
||||||
@ -253,15 +250,27 @@ export const KeyDetailsInfoPanel = ({
|
|||||||
skip: !featureFlags.SUCCESSOR_MARKETS || !market.proposal?.id,
|
skip: !featureFlags.SUCCESSOR_MARKETS || !market.proposal?.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const successorProposal = successorProposalDetails?.proposal as
|
let successorConfiguration: SuccessorConfiguration | false = false;
|
||||||
| SingleProposal<SuccessorMarketProposalDetailsQuery['proposal']>
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
const successorConfiguration =
|
if (successorProposalDetails?.proposal?.__typename === 'Proposal') {
|
||||||
successorProposal?.terms.change.__typename === 'NewMarket' &&
|
successorConfiguration =
|
||||||
successorProposal.terms.change.successorConfiguration?.__typename ===
|
successorProposalDetails.proposal.terms.change.__typename ===
|
||||||
'SuccessorConfiguration' &&
|
'NewMarket' &&
|
||||||
successorProposal.terms.change.successorConfiguration;
|
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.
|
// 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,
|
// 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,
|
skip: !parentMarket?.proposal?.id,
|
||||||
});
|
});
|
||||||
const parentProposal = parentSuccessorProposalDetails?.proposal as
|
|
||||||
| SingleProposal<SuccessorMarketProposalDetailsQuery['proposal']>
|
let parentSuccessorConfig: SuccessorConfiguration | undefined = 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;
|
const assetDecimals = getAsset(market).decimals;
|
||||||
|
|
||||||
@ -336,10 +363,7 @@ export const KeyDetailsInfoPanel = ({
|
|||||||
parentMarket && {
|
parentMarket && {
|
||||||
name: parentMarket?.tradableInstrument?.instrument?.name,
|
name: parentMarket?.tradableInstrument?.instrument?.name,
|
||||||
parentMarketID: grandparentMarketIdData?.market?.parentMarketID,
|
parentMarketID: grandparentMarketIdData?.market?.parentMarketID,
|
||||||
insurancePoolFraction:
|
insurancePoolFraction: parentSuccessorConfig?.insurancePoolFraction,
|
||||||
parentProposal?.terms.change.__typename === 'NewMarket' &&
|
|
||||||
parentProposal?.terms.change.successorConfiguration
|
|
||||||
?.insurancePoolFraction,
|
|
||||||
status:
|
status:
|
||||||
parentMarket?.state && MarketStateMapping[parentMarket.state],
|
parentMarket?.state && MarketStateMapping[parentMarket.state],
|
||||||
tradingMode:
|
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<{
|
export type InstrumentDetailsQueryVariables = Types.Exact<{
|
||||||
marketId: Types.Scalars['ID'];
|
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