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

refactor: disable manage allocations button #432

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
2 changes: 2 additions & 0 deletions src/app/collective-rewards/allocations/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './useBackerTotalAllocation'
export * from './useGetVotingPower'
export * from './useActivatedBuildersWithGauge'
export * from './useBuildersWithBackerRewardPercentage'
export * from './useValidateBackerAllocations'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useContext } from 'react'
import { AllocationsContext } from '@/app/collective-rewards/allocations/context'

export const useValidateBackerAllocations = () => {
const {
state: { selections, allocations },
} = useContext(AllocationsContext)

const isSelectionsEmpty = Object.values(selections).every(value => !value)
const isAllocationsEmpty = !Object.keys(allocations).length

return isSelectionsEmpty && isAllocationsEmpty
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/component
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 onManageAllocations = () => {
router.push('/collective-rewards/allocations')
}

const canManageAllocations = useValidateBackerAllocations()

return (
<>
<Collapsible defaultOpen>
<CollapsibleTrigger>
<div className="flex items-center justify-between w-full">
<HeaderTitle className="">Rewards leaderboard</HeaderTitle>
<Button variant="primary" onClick={onManageAllocations}>
<Button variant="primary" onClick={onManageAllocations} disabled={canManageAllocations}>
Manage Allocations
</Button>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/app/collective-rewards/rewards/MyRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Address, getAddress, zeroAddress } from 'viem'
import { BackerRewardsTable } from './backers/BackerRewardsTable'
import { useRouter } from 'next/navigation'
import { Link } from '@/components/Link'
import { useValidateBackerAllocations } from '@/app/collective-rewards/allocations/hooks'

const SubText = () => {
return (
Expand All @@ -36,6 +37,7 @@ export const Rewards: FC<{ builder: Address }> = ({ builder }) => {
const router = useRouter()
const { data: gauges, error: gaugesError } = useGetGaugesArray()
const { data: gauge, error: gaugeError } = useGetBuilderToGauge(builder)
const canManageAllocations = useValidateBackerAllocations()

const error = gaugesError ?? gaugeError

Expand Down Expand Up @@ -80,6 +82,7 @@ export const Rewards: FC<{ builder: Address }> = ({ builder }) => {
}}
title="Backer Rewards"
subtext={<SubText />}
settingsDisabled={canManageAllocations}
/>
<BackerRewards {...data} />
<BackerRewardsTable {...data} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ export type RewardsSectionHeader = {
title: string
subtext: ReactNode
onSettingsOpen: ButtonProps['onClick']
settingsDisabled?: boolean
}
export const RewardsSectionHeader: FC<RewardsSectionHeader> = ({ title, subtext, onSettingsOpen }) => (
export const RewardsSectionHeader: FC<RewardsSectionHeader> = ({
title,
subtext,
onSettingsOpen,
settingsDisabled,
}) => (
<div className="flex justify-between w-full items-center gap-2.5">
<div className="flex flex-col items-start w-full">
<HeaderTitle className="uppercase text-2xl leading-7 font-normal">{title}</HeaderTitle>
<Typography tagVariant="p" className="text-sm leading-7 font-normal font-rootstock-sans">
{subtext}
</Typography>
</div>
<SettingsButton onClick={onSettingsOpen} />
<SettingsButton onClick={onSettingsOpen} disabled={settingsDisabled} />
</div>
)
Loading