diff --git a/src/app/collective-rewards/types.ts b/src/app/collective-rewards/types.ts index c6168b6d..f5a63c8f 100644 --- a/src/app/collective-rewards/types.ts +++ b/src/app/collective-rewards/types.ts @@ -8,12 +8,11 @@ export const BuilderStatusProposalCreatedMVP = 'In progress - mvp' export const builderStatusOptions = [ BuilderStatusActive, BuilderStatusInProgress, - BuilderStatusProposalCreatedMVP, + BuilderStatusProposalCreatedMVP ] as const export type BuilderStatus = (typeof builderStatusOptions)[number] - -export type BuilderStatusShown = Exclude +export type BuilderStatusShown = Exclude export type BuilderInfo = { address: Address diff --git a/src/app/collective-rewards/user/context/BuilderContext.tsx b/src/app/collective-rewards/user/context/BuilderContext.tsx index bf871eb2..af7118cf 100644 --- a/src/app/collective-rewards/user/context/BuilderContext.tsx +++ b/src/app/collective-rewards/user/context/BuilderContext.tsx @@ -1,6 +1,6 @@ import { createContext, FC, ReactNode, useContext, useMemo } from 'react' import { Address } from 'viem' -import { BuilderStatus, BuilderStatusProposalCreatedMVP, MVPBuilderStatuses } from '@/app/collective-rewards/types' +import { BuilderStatus, BuilderStatusProposalCreatedMVP } from '@/app/collective-rewards/types' import { useGetProposalsState } from '@/app/collective-rewards/whitelist/hooks/useGetProposalsState' import { useGetBuilders } from '@/app/collective-rewards/user' import { getMostAdvancedProposal } from '@/app/collective-rewards/utils/getMostAdvancedProposal' @@ -37,7 +37,6 @@ export const BuilderContext = createContext({ interface BuilderProviderProps { children: ReactNode } - const getBuilderStatus = (status: BuilderStatus) => { // we show all the v1 builders with "In progress" because, they're filtered out later on, if the proposal is executed if (BuilderStatusProposalCreatedMVP === status) return 'In progress' diff --git a/src/app/collective-rewards/user/hooks/useGetBuilders.ts b/src/app/collective-rewards/user/hooks/useGetBuilders.ts index f0bf1e4d..17869005 100644 --- a/src/app/collective-rewards/user/hooks/useGetBuilders.ts +++ b/src/app/collective-rewards/user/hooks/useGetBuilders.ts @@ -12,8 +12,8 @@ import { BackersManagerAddress } from '@/lib/contracts' import { useMemo } from 'react' import { Address, getAddress } from 'viem' import { useReadContracts } from 'wagmi' -import { useGetGaugesArray } from './useGetGaugesArray' -import { BuilderStateStruct } from '../../utils/getBuilderGauge' +import { useGetGaugesArray } from '@/app/collective-rewards/user/hooks/useGetGaugesArray' +import { BuilderStateStruct } from '@/app/collective-rewards/utils/getBuilderGauge' export type BuilderLoader = { data?: BuilderInfo @@ -28,6 +28,20 @@ export type BuildersLoader = Omit & { type BuilderStatusMap = Record const EXCLUDED_BUILDER_STATUS = 'X' +type BuilderStatusWithExcluded = BuilderStatus | 'X' + +const getCombinedBuilderStatus = (builderState: BuilderStateStruct): BuilderStatusWithExcluded => { + // TODO: to review it + const [activated, kycApproved, whitelisted, , revoked, ,] = builderState + return revoked + ? BuilderStatusActive + : activated && kycApproved && whitelisted + ? BuilderStatusActive + : kycApproved || whitelisted + ? BuilderStatusInProgress + : EXCLUDED_BUILDER_STATUS // used to filter out builders +} + export const useGetBuilders = (): BuildersLoader => { /* * get Gauges @@ -79,17 +93,9 @@ export const useGetBuilders = (): BuildersLoader => { const builderStatusMap = builders ?.map((builder, index) => { - const [activated, kycApproved, whitelisted, paused, , ,] = builderStates?.[index] ?? [] return { address: builder, - // TODO: to be refactored in a function - status: paused - ? BuilderStatusActive - : activated && kycApproved && whitelisted - ? BuilderStatusActive - : kycApproved || whitelisted - ? BuilderStatusInProgress - : EXCLUDED_BUILDER_STATUS, // used to filter out builders + status: getCombinedBuilderStatus((builderStates?.[index] ?? []) as BuilderStateStruct), } }) .filter(builder => builder.status !== EXCLUDED_BUILDER_STATUS) @@ -105,7 +111,6 @@ export const useGetBuilders = (): BuildersLoader => { } = useFetchCreateBuilderProposals() const data = useMemo(() => { - // TODO: To check here v1 and v2 builders return Object.entries(buildersProposalsMap ?? {}).map(([builder, proposals]) => ({ address: getAddress(builder), status: diff --git a/src/app/collective-rewards/utils/getMostAdvancedProposal.ts b/src/app/collective-rewards/utils/getMostAdvancedProposal.ts index 379d4044..3885be5d 100644 --- a/src/app/collective-rewards/utils/getMostAdvancedProposal.ts +++ b/src/app/collective-rewards/utils/getMostAdvancedProposal.ts @@ -20,7 +20,6 @@ export const getMostAdvancedProposal = ( .sort(({ timeStamp: a }, { timeStamp: b }) => b - a) .find(({ args: { proposalId } }) => { const state = proposalsStateMap[proposalId.toString()] - // TODO: To be refactored // Get the proposal only if the Builder is Active or In Progress const isExecuted = ProposalState.Executed === state if (isBuilderInProgress(status)) { diff --git a/src/app/collective-rewards/whitelist/WhitelistSection.tsx b/src/app/collective-rewards/whitelist/WhitelistSection.tsx index 035073aa..b0b5332a 100644 --- a/src/app/collective-rewards/whitelist/WhitelistSection.tsx +++ b/src/app/collective-rewards/whitelist/WhitelistSection.tsx @@ -31,7 +31,6 @@ export const WhitelistSection = () => { - {/* TODO: We should show an empty table (not considered in the design yet) on error */} {isLoading && } {!isLoading && } diff --git a/src/app/collective-rewards/whitelist/components/Grid/WhitelistGridItem.tsx b/src/app/collective-rewards/whitelist/components/Grid/WhitelistGridItem.tsx index 7d13c608..00fdab91 100644 --- a/src/app/collective-rewards/whitelist/components/Grid/WhitelistGridItem.tsx +++ b/src/app/collective-rewards/whitelist/components/Grid/WhitelistGridItem.tsx @@ -8,9 +8,9 @@ import { FC, ReactNode } from 'react' import { Jdenticon } from '@/components/Header/Jdenticon' import { shortAddress } from '@/lib/utils' import { isAddress, Address } from 'viem' -import { BuilderStatusShown } from '@/app/collective-rewards/types' +import { BuilderStatusActive, BuilderStatusShown } from '@/app/collective-rewards/types' -type WhitelistGridItemProps = BuilderProposal & { status: BuilderStatusShown } +type WhitelistGridItemProps = BuilderProposal & { status: BuilderStatusShown } const Card = ({ header, body }: { header: ReactNode; body: ReactNode }) => { return ( @@ -33,7 +33,7 @@ export const WhitelistGridItem: FC = ({ const router = useRouter() const shortenAddress = shortAddress(address as Address) const Header = ( -
+
{/* TODO: To be reviewed, it's weird that we show the address in the tooltip @@ -58,7 +58,9 @@ export const WhitelistGridItem: FC = ({ /> - Joined {joiningDate} + {status === BuilderStatusActive && ( + Joined {joiningDate} + )}