Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOK-488: block allocs in distribution #438

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/app/collective-rewards/leaderboard/BuilderLeaderBoard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { BuildersLeaderBoardContent } from '@/app/collective-rewards/leaderboard'
import { CycleContextProvider } from '@/app/collective-rewards/metrics'
import { useReadBackersManager } from '@/app/collective-rewards/shared'
import { Button } from '@/components/Button'
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/Collapsible'
import { Popover } from '@/components/Popover'
import { HeaderTitle } from '@/components/Typography'
import { BuildersLeaderBoardContent } from '@/app/collective-rewards/leaderboard'
import { useRouter } from 'next/navigation'
import { useValidateBackerAllocations } from '@/app/collective-rewards/allocations/hooks'

export const BuildersLeaderBoard = () => {
const router = useRouter()
const { data: isInDistributionPeriod } = useReadBackersManager('onDistributionPeriod')

const onManageAllocations = () => {
router.push('/collective-rewards/allocations')
}
Expand All @@ -20,9 +24,24 @@ export const BuildersLeaderBoard = () => {
<CollapsibleTrigger>
<div className="flex items-center justify-between w-full">
<HeaderTitle className="">Rewards leaderboard</HeaderTitle>
<Button variant="primary" onClick={onManageAllocations} disabled={canManageAllocations}>
Manage Allocations
</Button>

<Popover
content={
<>
<p>Distribution in progress.</p>
</>
}
trigger="hover"
disabled={!isInDistributionPeriod}
>
<Button
variant="primary"
onClick={onManageAllocations}
disabled={!!isInDistributionPeriod || canManageAllocations}
>
Manage Allocations
</Button>
</Popover>
</div>
</CollapsibleTrigger>
<CollapsibleContent>
Expand Down
1 change: 1 addition & 0 deletions src/app/collective-rewards/shared/hooks/index.ts
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 src/app/collective-rewards/shared/hooks/useReadBackersManager.ts
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,
},
})
}
Loading