Skip to content

Commit

Permalink
chore: review pending work
Browse files Browse the repository at this point in the history
  • Loading branch information
antomor committed Nov 13, 2024
1 parent f2dff2a commit 04fe1fe
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
5 changes: 2 additions & 3 deletions src/app/collective-rewards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BuilderInfo['status'], 'In progress - mvp' | 'Active - mvp'>
export type BuilderStatusShown = Exclude<BuilderInfo['status'], 'In progress - mvp'>

export type BuilderInfo = {
address: Address
Expand Down
3 changes: 1 addition & 2 deletions src/app/collective-rewards/user/context/BuilderContext.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -37,7 +37,6 @@ export const BuilderContext = createContext<BuilderContextValue>({
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'
Expand Down
29 changes: 17 additions & 12 deletions src/app/collective-rewards/user/hooks/useGetBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +28,20 @@ export type BuildersLoader = Omit<BuilderLoader, 'data'> & {
type BuilderStatusMap = Record<Address, BuilderStatus>

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
Expand Down Expand Up @@ -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)
Expand All @@ -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<BuilderInfo>(([builder, proposals]) => ({
address: getAddress(builder),
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
1 change: 0 additions & 1 deletion src/app/collective-rewards/whitelist/WhitelistSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const WhitelistSection = () => {
<CollapsibleContent>
<WhitelistSearch />

{/* TODO: We should show an empty table (not considered in the design yet) on error */}
{isLoading && <LoadingSpinner />}
{!isLoading && <WhitelistGrid items={builders} />}
</CollapsibleContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -33,7 +33,7 @@ export const WhitelistGridItem: FC<WhitelistGridItemProps> = ({
const router = useRouter()
const shortenAddress = shortAddress(address as Address)
const Header = (
<div className="flex flex-row w-full items-center gap-x-3">
<div className="flex flex-row w-full items-center gap-x-3 min-h-11">
<Jdenticon className="rounded-md bg-white" value={address} size="32" />
<div className="flex-1 min-w-0">
{/* TODO: To be reviewed, it's weird that we show the address in the tooltip
Expand All @@ -58,7 +58,9 @@ export const WhitelistGridItem: FC<WhitelistGridItemProps> = ({
/>
</Typography>
</Popover>
<Paragraph className="text-sm font-light"> Joined {joiningDate}</Paragraph>
{status === BuilderStatusActive && (
<Paragraph className="text-sm font-light"> Joined {joiningDate}</Paragraph>
)}
</div>
<div className="flex justify-center items-center">
<Badge content={status} className={`${crStatusColorClasses[status]} py-1 px-2`} />
Expand Down

0 comments on commit 04fe1fe

Please sign in to comment.