Skip to content

Commit

Permalink
chore: useCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
thechefpenguin committed Aug 14, 2024
1 parent 66e75c1 commit a88c9e9
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions apps/web/src/views/Predictions/hooks/usePredictionPrice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { BINANCE_DATA_API, PREDICTION_PRICE_API } from 'config/constants/endpoints'
import { PriceApiWhitelistedCurrency } from 'config/constants/prediction/price'
import { useCallback } from 'react'

interface UsePredictionPriceParameters {
/** Default: ETH */
Expand Down Expand Up @@ -33,21 +34,21 @@ const DEFAULT_POLLING_INTERVAL = 5_000
export const usePredictionPriceUpdate = () => {
const queryClient = useQueryClient()

const updatePriceFromSource = async ({
currencyA = DEFAULT_CURRENCY_A,
currencyB = DEFAULT_CURRENCY_B,
}: UsePredictionPriceParameters) =>
fetch(`${BINANCE_DATA_API}/v3/ticker/price?symbol=${currencyA}${currencyB}`)
.then((res) => res.json())
.then((result) => ({
price: parseFloat(result.price),
currencyA,
currencyB,
}))
.then((data) => {
queryClient.setQueryData(['price', currencyA, currencyB], data)
return data
})
const updatePriceFromSource = useCallback(
async ({ currencyA = DEFAULT_CURRENCY_A, currencyB = DEFAULT_CURRENCY_B }: UsePredictionPriceParameters) =>
fetch(`${BINANCE_DATA_API}/v3/ticker/price?symbol=${currencyA}${currencyB}`)
.then((res) => res.json())
.then((result) => ({
price: parseFloat(result.price),
currencyA,
currencyB,
}))
.then((data) => {
queryClient.setQueryData(['price', currencyA, currencyB], data)
return data
}),
[queryClient],
)

return { updatePriceFromSource }
}
Expand Down

0 comments on commit a88c9e9

Please sign in to comment.