fix: fallback state for 24hr price change

This commit is contained in:
Matthew Russell 2024-02-13 12:48:26 -08:00
parent 224ecf30f5
commit 39b5a6c4ae
2 changed files with 16 additions and 7 deletions

View File

@ -40,7 +40,7 @@ export const MobileMarketHeader = () => {
data-testid="popover-trigger" data-testid="popover-trigger"
className="min-w-0 flex gap-1 items-center" className="min-w-0 flex gap-1 items-center"
> >
<h1 className="flex-grow whitespace-nowrap overflow-hidden text-ellipsis items-center"> <h1 className="whitespace-nowrap overflow-hidden text-ellipsis items-center">
<span className=""> <span className="">
{data {data
? data.tradableInstrument.instrument.code ? data.tradableInstrument.instrument.code
@ -88,6 +88,7 @@ export const MobileMarketHeader = () => {
<Last24hPriceChange <Last24hPriceChange
marketId={data.id} marketId={data.id}
decimalPlaces={data.decimalPlaces} decimalPlaces={data.decimalPlaces}
fallback={<span />} // dont render anything so price is vertically centered
/> />
</span> </span>
</span> </span>

View File

@ -1,3 +1,4 @@
import { type ReactNode } from 'react';
import { import {
addDecimalsFormatNumber, addDecimalsFormatNumber,
formatNumberPercentage, formatNumberPercentage,
@ -14,20 +15,27 @@ import { useT } from '../../use-t';
interface Props { interface Props {
marketId?: string; marketId?: string;
decimalPlaces: number; decimalPlaces: number;
isHeader?: boolean; fallback: ReactNode;
noUpdate?: boolean;
} }
export const Last24hPriceChange = ({ marketId, decimalPlaces }: Props) => { export const Last24hPriceChange = ({
marketId,
decimalPlaces,
fallback,
}: Props) => {
const t = useT(); const t = useT();
const { oneDayCandles, error, fiveDaysCandles } = useCandles({ const { oneDayCandles, error, fiveDaysCandles } = useCandles({
marketId, marketId,
}); });
const fallback = <span>{'-'}</span>; const nonIdeal = fallback || <span>{'-'}</span>;
if (error || !oneDayCandles || !fiveDaysCandles) { if (error || !oneDayCandles || !fiveDaysCandles) {
return fallback; return nonIdeal;
}
if (fiveDaysCandles.length < 24) {
return nonIdeal;
} }
if (oneDayCandles.length < 24) { if (oneDayCandles.length < 24) {
@ -45,7 +53,7 @@ export const Last24hPriceChange = ({ marketId, decimalPlaces }: Props) => {
</span> </span>
} }
> >
{fallback} <span>{nonIdeal}</span>
</Tooltip> </Tooltip>
); );
} }