bugfixing display price correctly
This commit is contained in:
parent
034c4664f4
commit
5fca62a986
@ -43,7 +43,6 @@ export const clearCache = () => {
|
|||||||
clientSideCache.set({});
|
clientSideCache.set({});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const displayLegend = writable(<Array<any>>{});
|
|
||||||
|
|
||||||
|
|
||||||
export const showCookieConsent = writable(<boolean>false);
|
export const showCookieConsent = writable(<boolean>false);
|
||||||
|
|||||||
@ -13,10 +13,7 @@
|
|||||||
priceIncrease,
|
priceIncrease,
|
||||||
stockTicker,
|
stockTicker,
|
||||||
displayCompanyName,
|
displayCompanyName,
|
||||||
displayLegend,
|
|
||||||
isOpen,
|
isOpen,
|
||||||
isBeforeMarketOpen,
|
|
||||||
isWeekend,
|
|
||||||
shouldUpdatePriceChart,
|
shouldUpdatePriceChart,
|
||||||
priceChartData,
|
priceChartData,
|
||||||
} from "$lib/store";
|
} from "$lib/store";
|
||||||
@ -24,13 +21,14 @@
|
|||||||
import { onMount, onDestroy, afterUpdate } from "svelte";
|
import { onMount, onDestroy, afterUpdate } from "svelte";
|
||||||
import { page } from "$app/stores";
|
import { page } from "$app/stores";
|
||||||
import toast from "svelte-french-toast";
|
import toast from "svelte-french-toast";
|
||||||
|
import { convertTimestamp } from "$lib/utils";
|
||||||
import Markethour from "$lib/components/Markethour.svelte";
|
import Markethour from "$lib/components/Markethour.svelte";
|
||||||
import AIScore from "$lib/components/AIScore.svelte";
|
import AIScore from "$lib/components/AIScore.svelte";
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
let prePostData = data?.getPrePostQuote || {};
|
let prePostData = data?.getPrePostQuote || {};
|
||||||
$: $realtimePrice = data?.getStockQuote?.price?.toFixed(2);
|
$: $realtimePrice = data?.getStockQuote?.price?.toFixed(2);
|
||||||
|
let oneDayPrice = [];
|
||||||
let previousRealtimePrice = null;
|
let previousRealtimePrice = null;
|
||||||
let previousTicker;
|
let previousTicker;
|
||||||
let socket;
|
let socket;
|
||||||
@ -45,6 +43,7 @@
|
|||||||
//let availableCash = 0;
|
//let availableCash = 0;
|
||||||
|
|
||||||
let displaySection = "";
|
let displaySection = "";
|
||||||
|
let displayLegend = {};
|
||||||
|
|
||||||
function shareContent(url) {
|
function shareContent(url) {
|
||||||
if (navigator.share) {
|
if (navigator.share) {
|
||||||
@ -62,23 +61,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
function handleTypeOfTrade(state:string)
|
|
||||||
{
|
|
||||||
if (state === 'buy')
|
|
||||||
{
|
|
||||||
const closePopup = document.getElementById("buyTradeModal");
|
|
||||||
closePopup?.dispatchEvent(new MouseEvent('click'))
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (state === 'sell')
|
|
||||||
{
|
|
||||||
const closePopup = document.getElementById("sellTradeModal");
|
|
||||||
closePopup?.dispatchEvent(new MouseEvent('click'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
function changeSection(state) {
|
function changeSection(state) {
|
||||||
const sectionMap = {
|
const sectionMap = {
|
||||||
insider: "/insider",
|
insider: "/insider",
|
||||||
@ -282,6 +264,64 @@ function handleTypeOfTrade(state:string)
|
|||||||
|
|
||||||
$currentPortfolioPrice = data?.getStockQuote?.price;
|
$currentPortfolioPrice = data?.getStockQuote?.price;
|
||||||
prePostData = data?.getPrePostQuote || {};
|
prePostData = data?.getPrePostQuote || {};
|
||||||
|
const output = [...data?.getOneDayPrice] ?? [];
|
||||||
|
oneDayPrice = output?.map((item) => ({
|
||||||
|
time: Date?.parse(item?.time + "Z") / 1000,
|
||||||
|
open: item?.open !== null ? item?.open : NaN,
|
||||||
|
high: item?.high !== null ? item?.high : NaN,
|
||||||
|
low: item?.low !== null ? item?.low : NaN,
|
||||||
|
close: item?.close !== null ? item?.close : NaN,
|
||||||
|
}));
|
||||||
|
|
||||||
|
let change;
|
||||||
|
let currentDataRowOneDay;
|
||||||
|
let baseClose = data?.getStockQuote?.previousClose;
|
||||||
|
|
||||||
|
const length = oneDayPrice?.length;
|
||||||
|
for (let i = length - 1; i >= 0; i--) {
|
||||||
|
if (!isNaN(oneDayPrice[i]?.close)) {
|
||||||
|
currentDataRowOneDay = oneDayPrice[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate percentage change if baseClose and currentDataRow are valid
|
||||||
|
const closeValue =
|
||||||
|
$realtimePrice !== null
|
||||||
|
? $realtimePrice
|
||||||
|
: (currentDataRowOneDay?.close ?? currentDataRowOneDay?.value);
|
||||||
|
|
||||||
|
if (closeValue && baseClose) {
|
||||||
|
change = ((closeValue / baseClose - 1) * 100)?.toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format date
|
||||||
|
const date = new Date(currentDataRowOneDay?.time * 1000);
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
day: "2-digit",
|
||||||
|
month: "short",
|
||||||
|
year: "numeric",
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
timeZone: "UTC",
|
||||||
|
};
|
||||||
|
|
||||||
|
const formattedDate = date?.toLocaleString("en-US", options);
|
||||||
|
|
||||||
|
const safeFormattedDate =
|
||||||
|
formattedDate === "Invalid Date"
|
||||||
|
? convertTimestamp(data?.getStockQuote?.timestamp)
|
||||||
|
: formattedDate;
|
||||||
|
|
||||||
|
// Set display legend
|
||||||
|
displayLegend = {
|
||||||
|
close:
|
||||||
|
currentDataRowOneDay?.close?.toFixed(2) ??
|
||||||
|
data?.getStockQuote?.price?.toFixed(2),
|
||||||
|
date: safeFormattedDate,
|
||||||
|
change,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,22 +751,22 @@ function handleTypeOfTrade(state:string)
|
|||||||
<div
|
<div
|
||||||
class="text-3xl sm:text-4xl font-bold block sm:inline"
|
class="text-3xl sm:text-4xl font-bold block sm:inline"
|
||||||
>
|
>
|
||||||
{$displayLegend?.close}
|
{displayLegend?.close}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="font-semibold block text-lg xs:text-xl sm:inline sm:text-2xl {$displayLegend?.change >=
|
class="font-semibold block text-lg xs:text-xl sm:inline sm:text-2xl {displayLegend?.change >=
|
||||||
0
|
0
|
||||||
? "before:content-['+'] text-[#00FC50]"
|
? "before:content-['+'] text-[#00FC50]"
|
||||||
: 'text-[#FF2F1F]'}"
|
: 'text-[#FF2F1F]'}"
|
||||||
>
|
>
|
||||||
{$displayLegend?.change}%
|
{displayLegend?.change}%
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-0.5 text-xs sm:text-sm">
|
<div class="mt-0.5 text-xs sm:text-sm">
|
||||||
<span
|
<span
|
||||||
class="block font-semibold sm:inline mb-0.5 sm:mb-0"
|
class="block font-semibold sm:inline mb-0.5 sm:mb-0"
|
||||||
>At close:</span
|
>At close:</span
|
||||||
>
|
>
|
||||||
{$displayLegend?.date}
|
{displayLegend?.date}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if Object?.keys(prePostData)?.length !== 0}
|
{#if Object?.keys(prePostData)?.length !== 0}
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
priceIncrease,
|
priceIncrease,
|
||||||
wsBidPrice,
|
wsBidPrice,
|
||||||
wsAskPrice,
|
wsAskPrice,
|
||||||
displayLegend,
|
|
||||||
currentPortfolioPrice,
|
currentPortfolioPrice,
|
||||||
stockTicker,
|
stockTicker,
|
||||||
displayCompanyName,
|
displayCompanyName,
|
||||||
@ -129,7 +128,6 @@
|
|||||||
timeZone: "UTC",
|
timeZone: "UTC",
|
||||||
};
|
};
|
||||||
|
|
||||||
//const formattedDate = (displayData === '1D' || displayData === '1W' || displayData === '1M') ? date.toLocaleString('en-GB', options).replace(/\//g, '.') : date.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' }).replace(/\//g, '.');
|
|
||||||
const formattedDate = date?.toLocaleString("en-US", options);
|
const formattedDate = date?.toLocaleString("en-US", options);
|
||||||
|
|
||||||
const safeFormattedDate =
|
const safeFormattedDate =
|
||||||
@ -138,7 +136,7 @@
|
|||||||
: formattedDate;
|
: formattedDate;
|
||||||
|
|
||||||
// Set display legend
|
// Set display legend
|
||||||
$displayLegend = {
|
displayLegend = {
|
||||||
close:
|
close:
|
||||||
currentDataRowOneDay?.close?.toFixed(2) ??
|
currentDataRowOneDay?.close?.toFixed(2) ??
|
||||||
data?.getStockQuote?.price?.toFixed(2),
|
data?.getStockQuote?.price?.toFixed(2),
|
||||||
@ -418,7 +416,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$displayLegend = { close: "-", date: "-" };
|
let displayLegend = { close: "-", date: "-" };
|
||||||
|
|
||||||
let displayLastLogicalRangeValue;
|
let displayLastLogicalRangeValue;
|
||||||
|
|
||||||
@ -961,11 +959,11 @@
|
|||||||
class="flex shrink flex-row space-x-1 pr-1 text-sm sm:text-[1rem]"
|
class="flex shrink flex-row space-x-1 pr-1 text-sm sm:text-[1rem]"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class={$displayLegend?.graphChange >= 0
|
class={displayLegend?.graphChange >= 0
|
||||||
? "before:content-['+'] text-[#00FC50]"
|
? "before:content-['+'] text-[#00FC50]"
|
||||||
: "text-[#FF2F1F]"}
|
: "text-[#FF2F1F]"}
|
||||||
>
|
>
|
||||||
{$displayLegend?.graphChange}%
|
{displayLegend?.graphChange}%
|
||||||
</span>
|
</span>
|
||||||
<span class="hidden text-gray-200 sm:block"
|
<span class="hidden text-gray-200 sm:block"
|
||||||
>({displayData})</span
|
>({displayData})</span
|
||||||
|
|||||||
@ -677,7 +677,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if rawData?.length === insiderTradingList?.length && data?.user?.tier === "Pro"}
|
{#if rawData?.length > 5 && rawData?.length === insiderTradingList?.length && data?.user?.tier === "Pro"}
|
||||||
<label
|
<label
|
||||||
on:click={backToTop}
|
on:click={backToTop}
|
||||||
class="w-32 py-1.5 mt-10 hover:bg-white hover:bg-opacity-[0.05] cursor-pointer m-auto flex justify-center items-center border border-slate-800 rounded-full"
|
class="w-32 py-1.5 mt-10 hover:bg-white hover:bg-opacity-[0.05] cursor-pointer m-auto flex justify-center items-center border border-slate-800 rounded-full"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export const load = async ({ locals, params }) => {
|
export const load = async ({ locals, params, setHeaders }) => {
|
||||||
|
|
||||||
const getSimilarStocks = async () => {
|
const getSimilarStocks = async () => {
|
||||||
const { apiKey, apiURL } = locals;
|
const { apiKey, apiURL } = locals;
|
||||||
@ -17,6 +17,7 @@ export const load = async ({ locals, params }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const output = await response.json();
|
const output = await response.json();
|
||||||
|
setHeaders({ "cache-control": "public, max-age=60*15" });
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export const load = async ({ locals, params }) => {
|
export const load = async ({ locals, params, setHeaders }) => {
|
||||||
const getHistoryEmployee = async () => {
|
const getHistoryEmployee = async () => {
|
||||||
const { apiKey, apiURL } = locals;
|
const { apiKey, apiURL } = locals;
|
||||||
const postData = {
|
const postData = {
|
||||||
@ -16,6 +16,7 @@ export const load = async ({ locals, params }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const output = await response.json();
|
const output = await response.json();
|
||||||
|
setHeaders({ "cache-control": "public, max-age=60*15" });
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export const load = async ({ locals, params }) => {
|
export const load = async ({ locals, params, setHeaders }) => {
|
||||||
const getHistoricalMarketCap = async () => {
|
const getHistoricalMarketCap = async () => {
|
||||||
const { apiKey, apiURL } = locals;
|
const { apiKey, apiURL } = locals;
|
||||||
const postData = {
|
const postData = {
|
||||||
@ -16,6 +16,7 @@ export const load = async ({ locals, params }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const output = await response.json();
|
const output = await response.json();
|
||||||
|
setHeaders({ "cache-control": "public, max-age=60*15" });
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user