8784a761d6
* feat: mv block number to atom * fix: add block updater * fix: fast forward dep * refactor: mv multicall to lib * feat: add multicall to widget * chore: update widget deps * nit: pluralize updaters * chore: minimize deps
18 lines
676 B
TypeScript
18 lines
676 B
TypeScript
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
|
|
import { useSingleCallResult } from 'lib/hooks/multicall'
|
|
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]
|
|
)
|
|
}
|