From ec1267cdba579c30dd61550cd61a39b2d44349ea Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Tue, 7 Jan 2025 16:56:07 +0100 Subject: [PATCH] small fix --- src/routes/stocks/[tickerID]/+layout.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/routes/stocks/[tickerID]/+layout.svelte b/src/routes/stocks/[tickerID]/+layout.svelte index 15af392e..16f5b178 100644 --- a/src/routes/stocks/[tickerID]/+layout.svelte +++ b/src/routes/stocks/[tickerID]/+layout.svelte @@ -276,7 +276,8 @@ let change; let currentDataRowOneDay; - let baseClose = data?.getStockQuote?.previousClose; + let baseClose = + data?.getStockQuote?.previousClose || oneDayPrice?.at(0)?.open; const length = oneDayPrice?.length; for (let i = length - 1; i >= 0; i--) { @@ -288,9 +289,9 @@ // Calculate percentage change if baseClose and currentDataRow are valid const closeValue = - $realtimePrice !== null + $realtimePrice !== null && $realtimePrice !== undefined ? $realtimePrice - : (currentDataRowOneDay?.close ?? currentDataRowOneDay?.value); + : currentDataRowOneDay?.close || currentDataRowOneDay?.value; if (closeValue && baseClose) { change = ((closeValue / baseClose - 1) * 100)?.toFixed(2);