update swap component
This commit is contained in:
parent
0af0e293b2
commit
86f407fc8a
@ -23,27 +23,14 @@
|
|||||||
let activeIdx = 0;
|
let activeIdx = 0;
|
||||||
|
|
||||||
|
|
||||||
function changeTab(index) {
|
function changeTab(index) {
|
||||||
activeIdx = index;
|
activeIdx = index;
|
||||||
switch (activeIdx) {
|
optionsData = getPlotOptions(activeIdx === 0 ? 'effectiveDate' : 'expirationDate');
|
||||||
case 0:
|
}
|
||||||
optionsData = getPlotOptions('effectiveDate');
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
optionsData = getPlotOptions('expirationDate');
|
|
||||||
break;
|
|
||||||
// Default case in case changeType doesn't match any of the specified cases
|
|
||||||
default:
|
|
||||||
// Handle the default case or leave it empty if not needed
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||||
|
|
||||||
let apiURL;
|
let apiURL;
|
||||||
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
|
||||||
|
|
||||||
|
|
||||||
userRegion.subscribe(value => {
|
userRegion.subscribe(value => {
|
||||||
@ -197,73 +184,47 @@ function changeTab(index) {
|
|||||||
return option;
|
return option;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSwapData = async (ticker) => {
|
async function getSwapData(ticker) {
|
||||||
// Get cached data for the specific tickerID
|
|
||||||
const cachedData = getCache(ticker, 'getSwapData');
|
const cachedData = getCache(ticker, 'getSwapData');
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
rawData = cachedData;
|
rawData = cachedData;
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
const postData = {'ticker': ticker};
|
const response = await fetch(`${apiURL}/swap-ticker`, {
|
||||||
// make the POST request to the endpoint
|
method: 'POST',
|
||||||
const response = await fetch(apiURL + '/swap-ticker', {
|
headers: {
|
||||||
method: 'POST',
|
"Content-Type": "application/json",
|
||||||
headers: {
|
"X-API-KEY": import.meta.env.VITE_STOCKNEAR_API_KEY
|
||||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
},
|
||||||
},
|
body: JSON.stringify({ ticker })
|
||||||
body: JSON.stringify(postData)
|
});
|
||||||
});
|
if (!response.ok) throw new Error('API request failed');
|
||||||
|
rawData = await response.json();
|
||||||
rawData = (await response.json());
|
setCache(ticker, rawData, 'getSwapData');
|
||||||
// Cache the data for this specific tickerID with a specific name 'getSwapData'
|
} catch (error) {
|
||||||
setCache(ticker, rawData, 'getSwapData');
|
console.error('Failed to fetch swap data:', error);
|
||||||
|
rawData = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$swapComponent = rawData?.length !== 0;
|
||||||
if(rawData?.length !== 0) {
|
}
|
||||||
$swapComponent = true;
|
|
||||||
} else {
|
|
||||||
$swapComponent = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
$: if ($stockTicker && typeof window !== 'undefined') {
|
||||||
$: {
|
isLoaded = false;
|
||||||
if($stockTicker && typeof window !== 'undefined') {
|
|
||||||
isLoaded=false;
|
|
||||||
activeIdx = 0;
|
activeIdx = 0;
|
||||||
const asyncFunctions = [
|
getSwapData($stockTicker).then(() => {
|
||||||
getSwapData($stockTicker)
|
optionsData = getPlotOptions('effectiveDate');
|
||||||
];
|
isLoaded = true;
|
||||||
Promise.all(asyncFunctions)
|
});
|
||||||
.then((results) => {
|
|
||||||
optionsData = getPlotOptions('effectiveDate');
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('An error occurred:', error);
|
|
||||||
});
|
|
||||||
isLoaded = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let charNumber = 20;
|
|
||||||
|
|
||||||
$: {
|
|
||||||
if($screenWidth < 640)
|
|
||||||
{
|
|
||||||
charNumber = 20;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
charNumber =40;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$: charNumber = $screenWidth < 640 ? 20 : 40;
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<svelte:options immutable />
|
||||||
|
|
||||||
<section class="overflow-hidden text-white h-full pb-8">
|
<section class="overflow-hidden text-white h-full pb-8">
|
||||||
<main class="overflow-hidden ">
|
<main class="overflow-hidden ">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user