This commit is contained in:
MuslemRahimi 2024-09-18 22:57:37 +02:00
parent d36a323788
commit bb67104c26

View File

@ -652,46 +652,53 @@ function calculateStats(data) {
const getHistoricalFlow = async () => { const getHistoricalFlow = async () => {
// Create a delay using setTimeout wrapped in a Promise // Create a delay using setTimeout wrapped in a Promise
isLoaded = false; if(data?.user?.tier === 'Pro') {
await new Promise(resolve => setTimeout(resolve, 500)); isLoaded = false;
// Make the POST request after the delay displayRules = allRows?.filter(row => ruleOfList.some(rule => rule.name === row.rule));
const convertDate = new Date(df.format(selectedDate?.toDate())) displayedData = [];
const year = convertDate?.getFullYear(); calculateStats(displayedData);
const month = String(convertDate?.getMonth() + 1).padStart(2, '0');
const day = String(convertDate?.getDate()).padStart(2, '0');
console.log(`${year}-${month}-${day}`) await new Promise(resolve => setTimeout(resolve, 300));
const postData = { 'selectedDate': `${year}-${month}-${day}`}
try { // Make the POST request after the delay
const response = await fetch('/api/options-historical-flow', { const convertDate = new Date(df.format(selectedDate?.toDate()))
method: 'POST', const year = convertDate?.getFullYear();
headers: { const month = String(convertDate?.getMonth() + 1).padStart(2, '0');
"Content-Type": "application/json" const day = String(convertDate?.getDate()).padStart(2, '0');
},
body: JSON.stringify(postData) const postData = { 'selectedDate': `${year}-${month}-${day}`}
});
rawData = await response?.json(); try {
console.log(rawData) const response = await fetch('/api/options-historical-flow', {
if(rawData?.length !== 0) { method: 'POST',
rawData?.forEach((item) => { headers: {
item.dte = daysLeft(item?.date_expiration); "Content-Type": "application/json"
},
body: JSON.stringify(postData)
}); });
shouldLoadWorker.set(true);
} else {
displayRules = allRows?.filter(row => ruleOfList.some(rule => rule.name === row.rule)); rawData = await response?.json();
displayedData = []; if(rawData?.length !== 0) {
calculateStats(displayedData); rawData?.forEach((item) => {
} item.dte = daysLeft(item?.date_expiration);
} catch (error) { });
console.error("Error fetching historical flow:", error); shouldLoadWorker.set(true);
rawData = []; }
} finally { } catch (error) {
isLoaded = true; console.error("Error fetching historical flow:", error);
rawData = [];
} finally {
isLoaded = true;
}
} }
else {
toast.error('Only for Pro Members', {
style: 'border-radius: 200px; background: #333; color: #fff;'
});
}
}; };