From 988489b4b0af27fc6a14ad31330b2c807ee20f9f Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Tue, 13 Feb 2024 12:55:39 -0800 Subject: [PATCH] fix: add fallback data if market is young --- libs/i18n/src/locales/en/markets.json | 1 + .../last-24h-price-change.tsx | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/libs/i18n/src/locales/en/markets.json b/libs/i18n/src/locales/en/markets.json index 0623dd78e..274683414 100644 --- a/libs/i18n/src/locales/en/markets.json +++ b/libs/i18n/src/locales/en/markets.json @@ -3,6 +3,7 @@ "{{probability}} probability price bounds": "{{probability}} probability price bounds", "24 hour change is unavailable at this time. The price change in the last 120 hours is:": "24 hour change is unavailable at this time. The price change in the last 120 hours is:", "24 hour change is unavailable at this time. The volume change in the last 120 hours is {{candleVolumeValue}}": "24 hour change is unavailable at this time. The volume change in the last 120 hours is {{candleVolumeValue}}", + "Market has not been active for 24 hours. The price change between {{start}} and {{end}} is:": "Market has not been active for 24 hours. The price change between {{start}} and {{end}} is:", "A concept derived from traditional markets. It is a calculated value for the ‘current market price’ on a market.": "A concept derived from traditional markets. It is a calculated value for the ‘current market price’ on a market.", "A number that will be calculated by an appropriate stochastic risk model, dependent on the type of risk model used and its parameters.": "A number that will be calculated by an appropriate stochastic risk model, dependent on the type of risk model used and its parameters.", "A sliding penalty for how much an LP bond is slashed if an LP fails to reach the minimum SLA. This is a network parameter.": "A sliding penalty for how much an LP bond is slashed if an LP fails to reach the minimum SLA. This is a network parameter.", diff --git a/libs/markets/src/lib/components/last-24h-price-change/last-24h-price-change.tsx b/libs/markets/src/lib/components/last-24h-price-change/last-24h-price-change.tsx index a5a985a4a..5e7cb7112 100644 --- a/libs/markets/src/lib/components/last-24h-price-change/last-24h-price-change.tsx +++ b/libs/markets/src/lib/components/last-24h-price-change/last-24h-price-change.tsx @@ -2,6 +2,7 @@ import { type ReactNode } from 'react'; import { addDecimalsFormatNumber, formatNumberPercentage, + getDateTimeFormat, priceChange, priceChangePercentage, } from '@vegaprotocol/utils'; @@ -35,7 +36,33 @@ export const Last24hPriceChange = ({ } if (fiveDaysCandles.length < 24) { - return nonIdeal; + return ( + + {t( + 'Market has not been active for 24 hours. The price change between {{start}} and {{end}} is:', + { + start: getDateTimeFormat().format( + new Date(fiveDaysCandles[0].periodStart) + ), + end: getDateTimeFormat().format( + new Date( + fiveDaysCandles[fiveDaysCandles.length - 1].periodStart + ) + ), + } + )} + c.close) || []} + decimalPlaces={decimalPlaces} + /> + + } + > + {nonIdeal} + + ); } if (oneDayCandles.length < 24) {