17 lines
690 B
TypeScript
17 lines
690 B
TypeScript
import { BigNumber } from '@ethersproject/bignumber'
|
|
import { Token, TokenAmount } from '@pancakeswap/sdk'
|
|
import { useTokenContract } from './useContract'
|
|
import { useSingleCallResult } from '../state/multicall/hooks'
|
|
|
|
// returns undefined if input token is undefined, or fails to get token contract,
|
|
// or contract total supply cannot be fetched
|
|
function useTotalSupply(token?: Token): TokenAmount | undefined {
|
|
const contract = useTokenContract(token?.address, false)
|
|
|
|
const totalSupply: BigNumber = useSingleCallResult(contract, 'totalSupply')?.result?.[0]
|
|
|
|
return token && totalSupply ? new TokenAmount(token, totalSupply.toString()) : undefined
|
|
}
|
|
|
|
export default useTotalSupply
|