stacker.news/components/chain-fee.js
st4rgut24 e9a5d22a6e
Add chain fees to price carousel (#658)
* add chain fees to price carousel

* restore check for valid carousel values

* add nym to contributors

---------

Co-authored-by: stargut <stargut@starguts-MacBook-Pro.local>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
2023-12-20 16:06:22 -06:00

30 lines
752 B
JavaScript

import { createContext, useContext, useMemo } from 'react'
import { useQuery } from '@apollo/client'
import { SSR } from '../lib/constants'
import { CHAIN_FEE } from '../fragments/chainFee'
export const ChainFeeContext = createContext({
fee: 0
})
export const useChainFee = () => useContext(ChainFeeContext)
export const ChainFeeProvider = ({ chainFee, children }) => {
const { data } = useQuery(CHAIN_FEE, {
...(SSR
? {}
: {
pollInterval: 30000,
nextFetchPolicy: 'cache-and-network'
})
})
const value = useMemo(() => ({
fee: data?.chainFee ?? chainFee ?? 0
}), [data, chainFee])
return (
<ChainFeeContext.Provider value={value}>
{children}
</ChainFeeContext.Provider>
)
}