uniswap-interface-uncensored/src/hooks/useSocksBalance.ts

20 lines
753 B
TypeScript
Raw Normal View History

import JSBI from 'jsbi'
2020-07-10 19:42:24 +03:00
import { useMemo } from 'react'
import { NEVER_RELOAD, useSingleCallResult } from '../state/multicall/hooks'
import { useActiveWeb3React } from './web3'
2020-07-10 19:42:24 +03:00
import { useSocksController } from './useContract'
export default function useSocksBalance(): JSBI | undefined {
const { account } = useActiveWeb3React()
const socksContract = useSocksController()
const { result } = useSingleCallResult(socksContract, 'balanceOf', [account ?? undefined], NEVER_RELOAD)
2020-07-10 19:42:24 +03:00
const data = result?.[0]
return data ? JSBI.BigInt(data.toString()) : undefined
}
export function useHasSocks(): boolean | undefined {
const balance = useSocksBalance()
return useMemo(() => balance && JSBI.greaterThan(balance, JSBI.BigInt(0)), [balance])
}