-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cr): block allocs in distribution
- Loading branch information
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './useReporting' | ||
export * from './useGaugesGetFunction' | ||
export * from './useReadBackersManager' |
37 changes: 37 additions & 0 deletions
37
src/app/collective-rewards/shared/hooks/useReadBackersManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { BackersManagerAbi } from '@/lib/abis/v2/BackersManagerAbi' | ||
import { AVERAGE_BLOCKTIME } from '@/lib/constants' | ||
import { BackersManagerAddress } from '@/lib/contracts' | ||
import { AbiFunction, ContractFunctionArgs } from 'viem' | ||
import { useReadContract, UseReadContractParameters, UseReadContractReturnType } from 'wagmi' | ||
|
||
// TODO: add type narrowing to return only the type related to the functionName | ||
type FunctionEntry = Extract<(typeof BackersManagerAbi)[number], AbiFunction> | ||
type ViewFunctionEntry = Extract< | ||
FunctionEntry, | ||
{ | ||
stateMutability: 'view' | ||
} | ||
> | ||
type BackersManagerViewFunction = Exclude<ViewFunctionEntry['name'], 'UPGRADE_INTERFACE_VERSION'> | ||
type FunctionParams<Name extends ViewFunctionEntry['name'] = BackersManagerViewFunction> = | ||
ContractFunctionArgs<typeof BackersManagerAbi, 'view', Name> | ||
|
||
type UseReadBackersManager<Name extends ViewFunctionEntry['name'] = BackersManagerViewFunction> = | ||
UseReadContractReturnType<typeof BackersManagerAbi, Name> | ||
|
||
export const useReadBackersManager = ( | ||
functionName: BackersManagerViewFunction, | ||
functionParams?: FunctionParams<BackersManagerViewFunction>, | ||
query?: UseReadContractParameters<typeof BackersManagerAbi, BackersManagerViewFunction>['query'], | ||
): UseReadBackersManager<BackersManagerViewFunction> => { | ||
return useReadContract({ | ||
functionName, | ||
abi: BackersManagerAbi, | ||
address: BackersManagerAddress, | ||
args: functionParams, | ||
query: { | ||
refetchInterval: AVERAGE_BLOCKTIME, | ||
...query, | ||
}, | ||
}) | ||
} |