diff --git a/src/app/collective-rewards/settings/builder/context/BuilderSettingsContext.tsx b/src/app/collective-rewards/settings/builder/context/BuilderSettingsContext.tsx index 8db27951..df654255 100644 --- a/src/app/collective-rewards/settings/builder/context/BuilderSettingsContext.tsx +++ b/src/app/collective-rewards/settings/builder/context/BuilderSettingsContext.tsx @@ -8,7 +8,8 @@ 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 { isBuilderActive } from '@/app/collective-rewards/utils' type BackerRewardsPercentageContext = { update: SetBackerRewardsForBuilder @@ -24,11 +25,13 @@ const BuilderSettingsContext = createContext( 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 isBuilderOperational = builder ? isBuilderActive(builder) : false const contextValue: BackerRewardsPercentageContext = { update, diff --git a/src/app/collective-rewards/settings/builder/hooks/index.ts b/src/app/collective-rewards/settings/builder/hooks/index.ts index 5f40d8f4..880f1170 100644 --- a/src/app/collective-rewards/settings/builder/hooks/index.ts +++ b/src/app/collective-rewards/settings/builder/hooks/index.ts @@ -1,2 +1 @@ export * from './useBuilderConfig' -export * from './useGetIsBuilderOperational' diff --git a/src/app/collective-rewards/settings/builder/hooks/useGetIsBuilderOperational.ts b/src/app/collective-rewards/settings/builder/hooks/useGetIsBuilderOperational.ts deleted file mode 100644 index 54b69a31..00000000 --- a/src/app/collective-rewards/settings/builder/hooks/useGetIsBuilderOperational.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { AVERAGE_BLOCKTIME } from '@/lib/constants' -import { BackersManagerAddress } from '@/lib/contracts' -import { useReadContract } from 'wagmi' -import { BuilderRegistryAbi } from '@/lib/abis/v2/BuilderRegistryAbi' -import { Address } from 'viem' - -export const useGetIsBuilderOperational = (builder: Address) => { - return useReadContract({ - address: BackersManagerAddress, - abi: BuilderRegistryAbi, - functionName: 'isBuilderOperational', - args: [builder], - query: { - refetchInterval: AVERAGE_BLOCKTIME, - }, - }) -} diff --git a/src/app/collective-rewards/shared/components/Table/TableCells.tsx b/src/app/collective-rewards/shared/components/Table/TableCells.tsx index a42430a8..8b44aef8 100644 --- a/src/app/collective-rewards/shared/components/Table/TableCells.tsx +++ b/src/app/collective-rewards/shared/components/Table/TableCells.tsx @@ -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 { isBuilderActive } from '@/app/collective-rewards/utils' export function getFormattedCurrency(value: number, symbol: string) { const formattedCurrency = formatCurrency(value, symbol) @@ -207,12 +208,7 @@ export const ActionCell: FC = ({ tableHeader: { className }, bu 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 isBuilderActive(builder) }, [builder]) const selectBuilder = () => { diff --git a/src/app/collective-rewards/utils/index.ts b/src/app/collective-rewards/utils/index.ts index 9893af85..23994c9a 100644 --- a/src/app/collective-rewards/utils/index.ts +++ b/src/app/collective-rewards/utils/index.ts @@ -4,3 +4,4 @@ export * from './getCoinbaseAddress' export * from './getMostAdvancedProposal' export * from './handleErrors' export * from './removeBrackets' +export * from './isBuilderActive'