-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: faster prediction prices #10154
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
6 Skipped Deployments
|
|
export const usePredictionPriceMutation = () => { | ||
const queryClient = useQueryClient() | ||
|
||
return useMutation({ |
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.
Why useMutation hook is used since it is not sending any data to change to api?
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.
@memoyil The mutation function will call Binance API directly to go around our own APIs caching.
This data is set in query data and cached so will be reflected everywhere on the UI where the same queryKey
exists
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.
Yes, but useMutation hook is meant for post/put api's where it change some resources on the server side, since it is a get call this can be done with useQuery by using refetch function of it
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.
I want to use a different data source and refetch function would use the existing api.
I have updated to make the update function a normal async call instead of a mutation
queryClient.setQueryData(['price', currencyA, currencyB], data) | ||
}, | ||
}) | ||
const updatePriceFromSource = async ({ |
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.
usecallback to not return new function on each render, otherwise settimeout will be cleared before getting triggered
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.
thanks. added
export const usePredictionPriceUpdate = () => { | ||
const queryClient = useQueryClient() | ||
|
||
const updatePriceFromSource = useCallback( |
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.
I think it is better to convert this hook to util function that returns promise of this function, the caller side can do the query client update afterwards when there is an answer. In that way multiple components can use this util based on their own needs. Wdyt?
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.
Usually other components would use wallet api for prices and only prediction will use this price source, which is why this isn't a global hook either. I think if we really need this api for other components then can abstract away but for now should be good scoped to prediction
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.
👍
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.
Can you help approve
@thechefpenguin I am thinking that this approach might have issues, imagine :
I think we should create another query hook (which usePredictionPrice uses it) where we can set query function or the link where we can fetch the data, change the link or queryFn when we want to change the resource and then use usePredictionPrice's hooks refetch in the refreshPriceTimeout function. After calling the refetch link/queryfn can be set back to original value. wdyt? |
e0281fa
to
a88c9e9
Compare
20ef0e2
to
05d6cbb
Compare
1932723
to
86084bc
Compare
enabled = true, | ||
}: UsePredictionPriceParameters = {}) => { | ||
const config = useConfig() | ||
|
||
return useQuery<PriceResponse>({ | ||
queryKey: ['price', currencyA, currencyB], |
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.
to ensure smooth price transition and to see the new price all the components that use this hook, the same querykey will be used
PR-Codex overview
This PR introduces an
useAlternateSource
option in the AI prediction config to fetch price data from a different source. It also updates UI elements and refactors code for better performance.Detailed summary
MutableRefObject
interface foruseAlternateSource
in AI prediction configPhishingWarningBanner
andAILiveRoundCard
PredictionConfigProviders
andusePredictionPrice
to support alternate data source for price fetching