feat(trading): display empty values for funding and countdown if perp market is in auction (#4987)

This commit is contained in:
Bartłomiej Głownia 2023-10-10 17:59:31 +02:00 committed by GitHub
parent 6b10df015d
commit 5f5c45f3b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View File

@ -15,9 +15,11 @@ import {
Last24hVolume, Last24hVolume,
getAsset, getAsset,
getDataSourceSpecForSettlementSchedule, getDataSourceSpecForSettlementSchedule,
isMarketInAuction,
marketInfoProvider, marketInfoProvider,
useFundingPeriodsQuery, useFundingPeriodsQuery,
useFundingRate, useFundingRate,
useMarketTradingMode,
useExternalTwap, useExternalTwap,
} from '@vegaprotocol/markets'; } from '@vegaprotocol/markets';
import { MarketState as State } from '@vegaprotocol/types'; import { MarketState as State } from '@vegaprotocol/types';
@ -187,9 +189,11 @@ const useNow = () => {
}; };
const useEvery = (marketId: string) => { const useEvery = (marketId: string) => {
const { data: marketTradingMode } = useMarketTradingMode(marketId);
const { data: marketInfo } = useDataProvider({ const { data: marketInfo } = useDataProvider({
dataProvider: marketInfoProvider, dataProvider: marketInfoProvider,
variables: { marketId }, variables: { marketId },
skip: !marketTradingMode || isMarketInAuction(marketTradingMode),
}); });
let every: number | undefined = undefined; let every: number | undefined = undefined;
const sourceType = const sourceType =

View File

@ -16,6 +16,7 @@ import type {
MarketDataQueryVariables, MarketDataQueryVariables,
} from './__generated__/market-data'; } from './__generated__/market-data';
import { getMarketPrice } from './get-price'; import { getMarketPrice } from './get-price';
import { isMarketInAuction } from './is-market-in-auction';
export type MarketData = MarketDataFieldsFragment; export type MarketData = MarketDataFieldsFragment;
@ -115,14 +116,25 @@ export const staticMarketDataProvider = makeDerivedDataProvider<
}); });
}); });
export const marketTradingModeProvider = makeDerivedDataProvider<
MarketDataFieldsFragment['marketTradingMode'] | undefined,
never,
MarketDataQueryVariables
>(
[marketDataProvider],
(parts, variables, prevData) =>
(parts[0] as ReturnType<typeof getData>)?.marketTradingMode
);
export const fundingRateProvider = makeDerivedDataProvider< export const fundingRateProvider = makeDerivedDataProvider<
string, string,
never, never,
MarketDataQueryVariables MarketDataQueryVariables
>([marketDataProvider], (parts) => { >([marketDataProvider], (parts) => {
return ( const marketData = parts[0] as ReturnType<typeof getData>;
(parts[0] as ReturnType<typeof getData>)?.productData?.fundingRate || null return marketData && !isMarketInAuction(marketData.marketTradingMode)
); ? marketData?.productData?.fundingRate || null
: null;
}); });
export const useFundingRate = (marketId?: string, skip?: boolean) => export const useFundingRate = (marketId?: string, skip?: boolean) =>
@ -156,3 +168,11 @@ export const useStaticMarketData = (marketId?: string, skip?: boolean) => {
skip: skip || !marketId, skip: skip || !marketId,
}); });
}; };
export const useMarketTradingMode = (marketId?: string, skip?: boolean) => {
return useDataProvider({
dataProvider: marketTradingModeProvider,
variables: { marketId: marketId || '' },
skip: skip || !marketId,
});
};