2021-12-02 21:35:39 +03:00
|
|
|
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
|
2022-01-13 19:54:08 +03:00
|
|
|
import { useSingleCallResult } from 'lib/hooks/multicall'
|
2021-12-02 21:35:39 +03:00
|
|
|
import { useMemo } from 'react'
|
|
|
|
|
|
|
|
import { useTokenContract } from './useContract'
|
|
|
|
|
|
|
|
export function useTokenAllowance(token?: Token, owner?: string, spender?: string): CurrencyAmount<Token> | undefined {
|
|
|
|
const contract = useTokenContract(token?.address, false)
|
|
|
|
|
|
|
|
const inputs = useMemo(() => [owner, spender], [owner, spender])
|
|
|
|
const allowance = useSingleCallResult(contract, 'allowance', inputs).result
|
|
|
|
|
|
|
|
return useMemo(
|
|
|
|
() => (token && allowance ? CurrencyAmount.fromRawAmount(token, allowance.toString()) : undefined),
|
|
|
|
[token, allowance]
|
|
|
|
)
|
|
|
|
}
|