-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
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 { DateTime } from 'luxon' | ||
import { useRouter } from 'next/navigation' | ||
|
||
export const BuildersLeaderBoard = () => { | ||
const router = useRouter() | ||
const { data: isInDistributionPeriod } = useReadBackersManager('onDistributionPeriod') | ||
const { data: distributionEndTimestamp } = useReadBackersManager('endDistributionWindow', [ | ||
BigInt(DateTime.now().toUnixInteger()), | ||
]) | ||
|
||
const onManageAllocations = () => { | ||
router.push('/collective-rewards/allocations') | ||
} | ||
|
@@ -17,9 +25,25 @@ export const BuildersLeaderBoard = () => { | |
<CollapsibleTrigger> | ||
<div className="flex items-center justify-between w-full"> | ||
<HeaderTitle className="">Rewards leaderboard</HeaderTitle> | ||
<Button variant="primary" onClick={onManageAllocations}> | ||
Manage Allocations | ||
</Button> | ||
|
||
<Popover | ||
content={ | ||
<> | ||
<p>Distribution in progress.</p> | ||
<p>Ends on: {DateTime.fromSeconds(Number(distributionEndTimestamp)).toLocaleString()}</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not necessarily true; once the distribution started, it depends on when the last distribute method is called, so I don't think we can predict it. |
||
</> | ||
} | ||
trigger="hover" | ||
disabled={!isInDistributionPeriod} | ||
> | ||
<Button | ||
variant="primary" | ||
onClick={onManageAllocations} | ||
disabled={isInDistributionPeriod as boolean} | ||
> | ||
Manage Allocations | ||
</Button> | ||
</Popover> | ||
</div> | ||
</CollapsibleTrigger> | ||
<CollapsibleContent> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './useReporting' | ||
export * from './useGaugesGetFunction' | ||
export * from './useReadBackersManager' |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although I like the idea, I think it's more practical using specific named hooks because:
|
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, | ||
}, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we already have
useGetEndDistributionWindow