Skip to content

Commit

Permalink
refactor: disable manage allocations button
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Dec 5, 2024
1 parent dae6b11 commit 0eb88d9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
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>
)

0 comments on commit 0eb88d9

Please sign in to comment.