date-fns#Duration TypeScript Examples
The following examples show how to use
date-fns#Duration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: hooks.ts From glide-frontend with GNU General Public License v3.0 | 6 votes |
useTokenPriceData = (
address: string,
interval: number,
timeWindow: Duration,
): PriceChartEntry[] | undefined => {
const dispatch = useDispatch<AppDispatch>()
const token = useSelector((state: AppState) => state.info.tokens.byAddress[address])
const priceData = token.priceData[interval]
const [error, setError] = useState(false)
// construct timestamps and check if we need to fetch more data
const oldestTimestampFetched = token.priceData.oldestFetchedTimestamp
const utcCurrentTime = getUnixTime(new Date()) * 1000
const startTimestamp = getUnixTime(startOfHour(sub(utcCurrentTime, timeWindow)))
useEffect(() => {
const fetch = async () => {
const { data, error: fetchingError } = await fetchTokenPriceData(address, interval, startTimestamp)
if (data) {
dispatch(
updateTokenPriceData({
tokenAddress: address,
secondsInterval: interval,
priceData: data,
oldestFetchedTimestamp: startTimestamp,
}),
)
}
if (fetchingError) {
setError(true)
}
}
if (!priceData && !error) {
fetch()
}
}, [address, dispatch, error, interval, oldestTimestampFetched, priceData, startTimestamp, timeWindow])
return priceData
}
Example #2
Source File: TokenPage.tsx From glide-frontend with GNU General Public License v3.0 | 5 votes |
DEFAULT_TIME_WINDOW: Duration = { weeks: 4 }
Example #3
Source File: TokenPage.tsx From vvs-ui with GNU General Public License v3.0 | 5 votes |
DEFAULT_TIME_WINDOW: Duration = { weeks: 1 }