2022-01-12 21:06:22 +03:00
|
|
|
import { BigNumber } from '@ethersproject/bignumber'
|
2022-01-13 19:54:08 +03:00
|
|
|
import { useSingleCallResult } from 'lib/hooks/multicall'
|
2022-03-12 01:56:05 +03:00
|
|
|
import { useMemo } from 'react'
|
2021-12-02 21:35:39 +03:00
|
|
|
|
2021-12-22 22:25:10 +03:00
|
|
|
import { useInterfaceMulticall } from './useContract'
|
2021-12-02 21:35:39 +03:00
|
|
|
|
|
|
|
// gets the current timestamp from the blockchain
|
|
|
|
export default function useCurrentBlockTimestamp(): BigNumber | undefined {
|
2021-12-22 22:25:10 +03:00
|
|
|
const multicall = useInterfaceMulticall()
|
2022-03-12 01:56:05 +03:00
|
|
|
const resultStr: string | undefined = useSingleCallResult(
|
|
|
|
multicall,
|
|
|
|
'getCurrentBlockTimestamp'
|
|
|
|
)?.result?.[0]?.toString()
|
|
|
|
return useMemo(() => (typeof resultStr === 'string' ? BigNumber.from(resultStr) : undefined), [resultStr])
|
2021-12-02 21:35:39 +03:00
|
|
|
}
|