reverting back

This commit is contained in:
MuslemRahimi 2024-09-16 22:35:32 +02:00
parent 051849eaab
commit ab5b5720af
6 changed files with 65 additions and 98 deletions

View File

@ -24,22 +24,17 @@ const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
};
const fetchWatchlist = async (fastifyURL, userId) => {
try {
const postData = { userId: userId };
const response = await fetch(fastifyURL + "/all-watchlists", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(postData),
});
const postData = { userId: userId };
const response = await fetch(fastifyURL + "/all-watchlists", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(postData),
});
const output = (await response.json())?.items;
return output;
} catch (e) {
console.log(e);
return [];
}
const output = (await response.json())?.items;
return output;
};
/*

View File

@ -318,47 +318,45 @@ onMount(async () => {
});
afterUpdate( async () => {
if(previousTicker !== $cryptoTicker && typeof socket !== 'undefined')
{
previousTicker = $cryptoTicker;
//socket.send('close')
socket?.close();
await new Promise((resolve, reject) => {
socket?.addEventListener('close', resolve);
});
if(socket?.readyState === WebSocket?.CLOSED)
{
await websocketRealtimeData()
console.log('connecting again')
}
afterUpdate(async () => {
if (previousTicker !== $cryptoTicker && typeof socket !== "undefined") {
previousTicker = $cryptoTicker;
//socket.send('close')
if (socket?.readyState === WebSocket?.OPEN) {
socket?.close();
}
await new Promise((resolve, reject) => {
socket?.addEventListener("close", resolve);
});
}
if (socket?.readyState === WebSocket?.CLOSED) {
await websocketRealtimeData();
console.log("connecting again");
}
}
});
});
onDestroy(() => {
try {
//socket?.send('close')
if (socket && typeof socket !== "undefined") {
if (socket.readyState === WebSocket.OPEN) {
socket?.close(); // Close the WebSocket connection
}
socket = null; // Ensure socket is set to null
}
}
catch(e) {
console.log(e)
}
onDestroy(() => {
try {
//socket?.send('close')
socket?.close()
}
catch(e) {
console.log(e)
}
//$displayCompanyName = '';
$currentPortfolioPrice = null;
$currentPrice = null;
$priceIncrease = null;
$traded = false
});
//$displayCompanyName = '';
$currentPortfolioPrice = null;
$currentPrice = null;
$priceIncrease = null;
//$traded = false
});

View File

@ -31,18 +31,13 @@ const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
};
const fetchFromFastify = async (fastifyURL, endpoint, userId) => {
try {
const response = await fetch(`${fastifyURL}${endpoint}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userId }),
});
const { items } = await response.json();
return items;
} catch (e) {
console.log(e);
return [];
}
const response = await fetch(`${fastifyURL}${endpoint}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userId }),
});
const { items } = await response.json();
return items;
};
export const load = async ({ params, locals, setHeaders }) => {

View File

@ -336,9 +336,7 @@ async function fetchPortfolio()
{
previousTicker = $etfTicker;
//socket.send('close')
if (socket.readyState === WebSocket.OPEN) {
socket?.close(); // Close the WebSocket connection
}
socket?.close();
await new Promise((resolve, reject) => {
socket.addEventListener('close', resolve);
});
@ -357,12 +355,7 @@ async function fetchPortfolio()
onDestroy(() => {
try {
//socket?.send('close')
if (socket && typeof socket !== "undefined") {
if (socket.readyState === WebSocket.OPEN) {
socket?.close(); // Close the WebSocket connection
}
socket = null; // Ensure socket is set to null
}
socket?.close()
}
catch(e) {
console.log(e)

View File

@ -31,18 +31,13 @@ const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
};
const fetchFromFastify = async (fastifyURL, endpoint, userId) => {
try {
const response = await fetch(`${fastifyURL}${endpoint}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userId }),
});
const { items } = await response.json();
return items;
} catch (e) {
console.log(e);
return [];
}
const response = await fetch(`${fastifyURL}${endpoint}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userId }),
});
const { items } = await response.json();
return items;
};
const fetchCommunitySentiment = async (pb, ticker, cookies) => {

View File

@ -237,10 +237,7 @@ async function fetchPortfolio()
if (previousTicker !== $stockTicker && typeof socket !== "undefined") {
previousTicker = $stockTicker;
//socket.send('close')
if (socket?.readyState === WebSocket?.OPEN) {
socket?.close();
}
socket?.close();
await new Promise((resolve, reject) => {
socket?.addEventListener("close", resolve);
});
@ -255,16 +252,10 @@ async function fetchPortfolio()
onDestroy(() => {
try {
//socket?.send('close')
if (socket && typeof socket !== "undefined") {
if (socket.readyState === WebSocket.OPEN) {
socket?.close(); // Close the WebSocket connection
}
socket = null; // Ensure socket is set to null
}
socket?.close();
} catch (e) {
console.log(e);
}
catch(e) {
console.log(e)
}
//$displayCompanyName = '';
$currentPortfolioPrice = null;
@ -936,4 +927,4 @@ $: {
::-webkit-scrollbar-corner {
background: #09090b;
}
</style>
</style>