-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,63 @@ | ||
import { makeObservable, observable, action } from 'mobx'; | ||
import axios from 'axios'; | ||
|
||
// Caching utility, mimicking SWR's caching mechanism | ||
const cache = new Map(); | ||
|
||
const fetcher = async (url: string) => { | ||
const { data } = await axios.get(url); | ||
return data; | ||
}; | ||
|
||
export class ExpiryDateStore { | ||
expiryDates: string[] = []; // Initialized as an array | ||
expiryDates: string[] = []; | ||
isLoading: boolean = false; | ||
|
||
constructor() { | ||
makeObservable(this, { | ||
expiryDates: observable, | ||
isLoading: observable, | ||
setExpiryDates: action, | ||
fetchExpiryDates: action, | ||
fetchExpiryDatesForSymbol: action, // Add this line | ||
fetchExpiryDatesForSymbol: action, | ||
}); | ||
} | ||
|
||
setExpiryDates(dates: string[]): void { | ||
this.expiryDates = dates; | ||
} | ||
|
||
fetchExpiryDates = async () => { | ||
fetchExpiryDatesForSymbol = async (symbol: string = "NIFTY") => { | ||
this.isLoading = true; | ||
|
||
// Fetch expiry dates | ||
const expiryResponse = await axios.get(`https://tradepodapisrv.azurewebsites.net/api/get-expiry/?symbol=NIFTY`); | ||
const expiryData = expiryResponse.data; | ||
if (expiryData && expiryData.expiry_dates) { | ||
this.setExpiryDates(expiryData.expiry_dates); | ||
console.log(this.expiryDates); // Log the expiryDates | ||
} else { | ||
throw new Error('Expiry dates not found'); | ||
|
||
const url = `https://tradepodapisrv.azurewebsites.net/api/get-expiry/?symbol=${encodeURIComponent(symbol)}`; | ||
console.log(`Generated URL for Symbol ${symbol}:`, url); | ||
|
||
if (cache.has(url)) { | ||
this.setExpiryDates(cache.get(url)); | ||
this.isLoading = false; | ||
return; | ||
} | ||
|
||
this.isLoading = false; | ||
}; | ||
|
||
fetchExpiryDatesForSymbol = async (symbol: string) => { | ||
this.isLoading = true; | ||
// Define the API URL based on the environment | ||
const API_URL = process.env.NODE_ENV === 'production' | ||
? process.env.REACT_APP_API_URL_PRODUCTION | ||
: process.env.REACT_APP_API_URL_LOCAL; | ||
// Fetch expiry dates for a specific symbol | ||
const expiryResponse = await axios.get(`${API_URL}/api/get-expiry/?symbol=${encodeURIComponent(symbol)}`); | ||
const expiryData = expiryResponse.data; | ||
if (expiryData && expiryData.expiry_dates) { | ||
this.setExpiryDates(expiryData.expiry_dates); | ||
console.log(this.expiryDates); // Log the expiryDates | ||
} else { | ||
throw new Error('Expiry dates not found'); | ||
try { | ||
const data = await fetcher(url); | ||
|
||
if (data?.expiry_dates?.length) { | ||
this.setExpiryDates(data.expiry_dates); | ||
cache.set(url, data.expiry_dates); // Cache the data | ||
console.log(`Expiry Dates Stored for Symbol ${symbol}:`, this.expiryDates); | ||
} else { | ||
console.error(`Expiry dates not found for symbol: ${symbol}`); | ||
this.setExpiryDates([]); // Clear the expiry dates | ||
} | ||
} catch (error) { | ||
console.error(`Error fetching expiry dates for symbol: ${symbol}`, error); | ||
this.setExpiryDates([]); // Clear the expiry dates in case of an error | ||
} finally { | ||
this.isLoading = false; | ||
} | ||
|
||
this.isLoading = false; | ||
}; | ||
} | ||
|
||
export const initializeExpiryDateStore = (): ExpiryDateStore => { | ||
return new ExpiryDateStore(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bb56da8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
tradepodapp – ./
tradepodapp-suyeshs.vercel.app
tradepodapp.vercel.app
tradepodapp-git-master-suyeshs.vercel.app
bb56da8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
tradepod – ./
tradepod-git-master-suyeshs.vercel.app
tradepod.vercel.app
tradepod-suyeshs.vercel.app