fix: incorrect price change values for less than 24h old markets
This commit is contained in:
parent
feddc6d4e1
commit
224ecf30f5
@ -56,7 +56,6 @@ export const MarketHeaderStats = ({ market }: MarketHeaderStatsProps) => {
|
|||||||
<Last24hPriceChange
|
<Last24hPriceChange
|
||||||
marketId={market.id}
|
marketId={market.id}
|
||||||
decimalPlaces={market.decimalPlaces}
|
decimalPlaces={market.decimalPlaces}
|
||||||
fallback={<span>-</span>}
|
|
||||||
/>
|
/>
|
||||||
</HeaderStat>
|
</HeaderStat>
|
||||||
<HeaderStat heading={t('Volume (24h)')} testId="market-volume">
|
<HeaderStat heading={t('Volume (24h)')} testId="market-volume">
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
addDecimalsFormatNumber,
|
addDecimalsFormatNumber,
|
||||||
formatNumberPercentage,
|
formatNumberPercentage,
|
||||||
isNumeric,
|
|
||||||
priceChange,
|
priceChange,
|
||||||
priceChangePercentage,
|
priceChangePercentage,
|
||||||
} from '@vegaprotocol/utils';
|
} from '@vegaprotocol/utils';
|
||||||
@ -14,29 +13,24 @@ import { useT } from '../../use-t';
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
marketId?: string;
|
marketId?: string;
|
||||||
decimalPlaces?: number;
|
decimalPlaces: number;
|
||||||
initialValue?: string[];
|
|
||||||
isHeader?: boolean;
|
isHeader?: boolean;
|
||||||
noUpdate?: boolean;
|
noUpdate?: boolean;
|
||||||
// render prop for no price change
|
|
||||||
fallback?: React.ReactNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Last24hPriceChange = ({
|
export const Last24hPriceChange = ({ marketId, decimalPlaces }: Props) => {
|
||||||
marketId,
|
|
||||||
decimalPlaces,
|
|
||||||
initialValue,
|
|
||||||
fallback,
|
|
||||||
}: Props) => {
|
|
||||||
const t = useT();
|
const t = useT();
|
||||||
const { oneDayCandles, error, fiveDaysCandles } = useCandles({
|
const { oneDayCandles, error, fiveDaysCandles } = useCandles({
|
||||||
marketId,
|
marketId,
|
||||||
});
|
});
|
||||||
if (
|
|
||||||
fiveDaysCandles &&
|
const fallback = <span>{'-'}</span>;
|
||||||
fiveDaysCandles.length > 0 &&
|
|
||||||
(!oneDayCandles || oneDayCandles?.length === 0)
|
if (error || !oneDayCandles || !fiveDaysCandles) {
|
||||||
) {
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oneDayCandles.length < 24) {
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
description={
|
description={
|
||||||
@ -51,16 +45,12 @@ export const Last24hPriceChange = ({
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<span>{fallback}</span>
|
{fallback}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error || !isNumeric(decimalPlaces)) {
|
const candles = oneDayCandles?.map((c) => c.close) || [];
|
||||||
return <span>{fallback}</span>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const candles = oneDayCandles?.map((c) => c.close) || initialValue || [];
|
|
||||||
const change = priceChange(candles);
|
const change = priceChange(candles);
|
||||||
const changePercentage = priceChangePercentage(candles);
|
const changePercentage = priceChangePercentage(candles);
|
||||||
|
|
||||||
|
@ -18,7 +18,12 @@ export const useCandles = ({ marketId }: { marketId?: string }) => {
|
|||||||
skip: !marketId,
|
skip: !marketId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const fiveDaysCandles = data?.filter(Boolean);
|
const fiveDaysCandles = data?.filter((c) => {
|
||||||
|
if (c.open === '' || c.close === '' || c.high === '' || c.close === '') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
const oneDayCandles = fiveDaysCandles?.filter((candle) =>
|
const oneDayCandles = fiveDaysCandles?.filter((candle) =>
|
||||||
isCandleLessThan24hOld(candle, yesterday)
|
isCandleLessThan24hOld(candle, yesterday)
|
||||||
|
Loading…
Reference in New Issue
Block a user