Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
558 B
3
Indexable
Never
import { useEffect } from "react"
import useSWR from "swr"



export const handler =  (web3, account, contract) => () =>{

    const {data, mutate, ...rest} = useSWR (() => {

        web3 && contract  ? "web3/transactions" : null,
        async () => {
            const txCount = await contract.methods.getTransactionCount().call()
            return txCount
        }
    })

    useEffect(() => {
        account,
        txCount => (mutate(txCount ?? null))
    }, [account])

    return {
        data, 
        mutate,
        ...rest
    }
        
}