Skip to content

Commit

Permalink
refactor: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Dec 3, 2024
1 parent f089314 commit 8d8af0b
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ import { Badge } from '@/components/Badge'
import { Jdenticon } from '@/components/Header/Jdenticon'
import { Paragraph, Typography } from '@/components/Typography'
import { FC } from 'react'
import { Builder, BuilderProposal, BuilderStateFlags } from '../../types'
import { Builder, BuilderProposal, BuilderStateFlags } from '@/app/collective-rewards/types'
import { isBuilderOperational } from '@/app/collective-rewards/utils'

export type BuilderAllocationHeaderProps = Pick<Builder, 'builderName' | 'address' | 'stateFlags' | 'gauge'> &
Pick<BuilderProposal, 'date'>

const isBuilderActive = ({ communityApproved, kycApproved, paused }: BuilderStateFlags) => {
return communityApproved && kycApproved && !paused
}

export const BuilderAllocationHeader: FC<BuilderAllocationHeaderProps> = ({
address,
builderName,
Expand All @@ -34,7 +31,7 @@ export const BuilderAllocationHeader: FC<BuilderAllocationHeaderProps> = ({
{state.paused && state.communityApproved && (
<Badge content="Paused" className="bg-[#F9E1FF] text-secondary py-1 px-1 text-[12px]" />
)}
{isBuilderActive(state) && <Paragraph className="text-sm font-light"> Joined {date}</Paragraph>}
{isBuilderOperational(state) && <Paragraph className="text-sm font-light"> Joined {date}</Paragraph>}
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const formSchema = z.object({
export const BuilderRewardsSettingsForm: FC = () => {
const router = useRouter()
const [backButtonName, setBackButtonName] = useState('Cancel')
let {
const {
current: { refetch, isLoading: isCurrentRewardsLoading },
update: { isSuccess, setNewReward, isPending },
isBuilderOperational,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {
import { createContext, FC, ReactNode, useContext } from 'react'
import { Address } from 'viem'
import { useAccount } from 'wagmi'
import { useGetIsBuilderOperational } from '@/app/collective-rewards/settings'
import { useBuilderContext } from '@/app/collective-rewards/user'
import { isBuilderOperational } from '@/app/collective-rewards/utils'

type BackerRewardsPercentageContext = {
update: SetBackerRewardsForBuilder
current: BackerRewardResponse
rewardPercentageToApply: RewardPercentageToApply
isBuilderOperational?: boolean
isBuilderOperational: boolean
}

const BuilderSettingsContext = createContext<BackerRewardsPercentageContext>(
Expand All @@ -24,17 +25,19 @@ const BuilderSettingsContext = createContext<BackerRewardsPercentageContext>(
export const useBuilderSettingsContext = () => useContext(BuilderSettingsContext)

export const BuilderSettingsProvider: FC<{ children: ReactNode }> = ({ children }) => {
const { getBuilderByAddress } = useBuilderContext()
const { address } = useAccount()
const current = useGetBackerRewardsForBuilder(address as Address)
const update = useSetBackerRewardsForBuilder()
const rewardPercentageToApply = useGetRewardPercentageToApply(address as Address)
const { data: isBuilderOperational } = useGetIsBuilderOperational(address as Address)
const builder = getBuilderByAddress(address as Address)
const isOperational = builder ? isBuilderOperational(builder.stateFlags) : false

const contextValue: BackerRewardsPercentageContext = {
update,
current,
rewardPercentageToApply,
isBuilderOperational,
isBuilderOperational: isOperational,
}

return <BuilderSettingsContext.Provider value={contextValue}>{children}</BuilderSettingsContext.Provider>
Expand Down
1 change: 0 additions & 1 deletion src/app/collective-rewards/settings/builder/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './useBuilderConfig'
export * from './useGetIsBuilderOperational'

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ProgressBar } from '@/components/ProgressBar'
import { Button } from '@/components/Button'
import { BuilderStateFlags } from '@/app/collective-rewards/types'
import { AllocationsContext } from '@/app/collective-rewards/allocations/context'
import { isBuilderOperational } from '@/app/collective-rewards/utils'

export function getFormattedCurrency(value: number, symbol: string) {
const formattedCurrency = formatCurrency(value, symbol)
Expand Down Expand Up @@ -202,17 +203,12 @@ export const ActionCell: FC<ActionCellProps> = ({ tableHeader: { className }, bu
[selections, builderAddress, isPreallocated],
)

const isBuilderOperational = useMemo(() => {
const isOperational = useMemo(() => {
if (!builder) {
console.log('Builder not found in selection') // TODO: handle this case better
return
}
return (
builder.stateFlags &&
builder.stateFlags.kycApproved &&
builder.stateFlags.communityApproved &&
!builder.stateFlags.paused
)
return isBuilderOperational(builder.stateFlags)
}, [builder])

const selectBuilder = () => {
Expand All @@ -223,7 +219,7 @@ export const ActionCell: FC<ActionCellProps> = ({ tableHeader: { className }, bu
<TableCell className={cn(className, 'border-solid align-center')}>
<Button
variant={isSelected ? 'white' : 'secondary'}
disabled={!isBuilderOperational || isPreallocated}
disabled={!isOperational || isPreallocated}
onClick={selectBuilder}
className="white text-center"
>
Expand Down
4 changes: 2 additions & 2 deletions src/app/collective-rewards/utils/getMostAdvancedProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ProposalState } from '@/shared/types'

const inactiveProposalsStates = [ProposalState.Canceled, ProposalState.Defeated, ProposalState.Expired]
const isActive = (state: ProposalState) => !inactiveProposalsStates.includes(state)
const isBuilderActive = (status?: BuilderStateFlags) =>
!status || status.activated || status.communityApproved
const isBuilderActive = (stateFlags?: BuilderStateFlags) =>
!stateFlags || stateFlags.activated || stateFlags.communityApproved

export const getMostAdvancedProposal = (
proposalsEvent: CreateBuilderProposalEventLog[],
Expand Down
1 change: 1 addition & 0 deletions src/app/collective-rewards/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './getCoinbaseAddress'
export * from './getMostAdvancedProposal'
export * from './handleErrors'
export * from './removeBrackets'
export * from './isBuilderOperational'
7 changes: 0 additions & 7 deletions src/app/collective-rewards/utils/isBuilderActive.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/app/collective-rewards/utils/isBuilderOperational.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { BuilderStateFlags } from '../types'

export const isBuilderOperational = (stateFlags?: BuilderStateFlags) => {
return !!(stateFlags && stateFlags.communityApproved && stateFlags.kycApproved && !stateFlags.paused)
}

0 comments on commit 8d8af0b

Please sign in to comment.