UNPKG

@smartinvoicexyz/hooks

Version:

Unified source for React hooks used across the Smart Invoice protocol.

20 lines (19 loc) 790 B
import { SMART_INVOICE_FACTORY_ABI } from '@smartinvoicexyz/constants'; import { getInvoiceFactoryAddress } from '@smartinvoicexyz/utils'; import { useReadContract } from 'wagmi'; // Default Resolution Rate pulled from Factory export const useRateForResolver = ({ chainId, resolver, defaultValue = 20, }) => { const address = chainId ? getInvoiceFactoryAddress(chainId) : undefined; const { data, isLoading, error } = useReadContract({ abi: SMART_INVOICE_FACTORY_ABI, address, chainId, functionName: 'resolutionRateOf', args: [resolver], query: { enabled: !!address && !!resolver && !!chainId, }, }); const resolutionRate = Number(data) || defaultValue; return { resolutionRate, isLoading, error }; };