Skip to content

Commit

Permalink
refactor: proposal joined date
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Dec 4, 2024
1 parent 731c6bf commit 98425ed
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ export const ActiveBuildersGridItem: FC<ActiveBuildersGridItemProps> = ({
<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
and then we copy the builder name, since the builder name it's generally easier to remember
*/}
<Popover
content={
<div className="text-[12px] font-bold mb-1">
Expand All @@ -67,9 +64,6 @@ export const ActiveBuildersGridItem: FC<ActiveBuildersGridItemProps> = ({
/>
</Typography>
</Popover>
{builderState === 'active' && (
<Paragraph className="text-sm font-light"> Joined {joiningDate}</Paragraph>
)}
</div>
<div className="flex justify-center items-center">
<Badge
Expand All @@ -83,6 +77,7 @@ export const ActiveBuildersGridItem: FC<ActiveBuildersGridItemProps> = ({
<div onClick={() => router.push(`/proposals/${proposalId}`)} className="cursor-pointer">
<Span className="text-base font-semibold">Proposal</Span>
<Span className="text-sm line-clamp-1 text-wrap">{proposalName}</Span>
<Span className="text-sm"> Created on {joiningDate}</Span>
</div>
)
return <Card header={Header} body={Body} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { AddressOrAlias } from '@/components/Address'
import { Badge } from '@/components/Badge'
import { Jdenticon } from '@/components/Header/Jdenticon'
import { Paragraph, Typography } from '@/components/Typography'
import { Typography } from '@/components/Typography'
import { FC } from 'react'
import { Builder, BuilderProposal, BuilderStateFlags } from '@/app/collective-rewards/types'
import { getBuilderInactiveState } from '@/app/collective-rewards/utils'
import { getBuilderInactiveState, isBuilderActive } from '@/app/collective-rewards/utils'

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

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

const haltedClass = 'bg-[#932309] color-text-primary py-1 px-1 text-[12px]'
const haltedStateBadges = {
Paused: <Badge content="Paused" className="bg-[#F9E1FF] text-secondary py-1 px-1 text-[12px]" />,
Expand All @@ -25,8 +21,6 @@ export const BuilderAllocationHeader: FC<BuilderAllocationHeaderProps> = ({
address,
builderName,
stateFlags,
date,
gauge,
}) => {
const state = stateFlags as BuilderStateFlags

Expand All @@ -37,8 +31,8 @@ export const BuilderAllocationHeader: FC<BuilderAllocationHeaderProps> = ({
<Typography tagVariant="label" className="font-semibold line-clamp-1 text-wrap text-base leading-4">
<AddressOrAlias addressOrAlias={builderName || address} className="text-base font-bold leading-4" />
</Typography>
{gauge && isBuilderActive(state) ? (
<Paragraph className="text-sm font-light"> Joined {date}</Paragraph>
{isBuilderActive(state) ? (
<Badge content="Active" className="bg-[#DBFEE5] text-secondary py-1 px-1 text-[12px]" />
) : (
haltedStateBadges[getBuilderInactiveState(state)]
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +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 { getBuilderInactiveState, isBuilderOperational } from '@/app/collective-rewards/utils'
import { getBuilderInactiveState, isBuilderActive } from '@/app/collective-rewards/utils'

export function getFormattedCurrency(value: number, symbol: string) {
const formattedCurrency = formatCurrency(value, symbol)
Expand Down Expand Up @@ -55,21 +55,22 @@ export const LazyRewardCell = memo(RewardCell, ({ rewards: prevReward }, { rewar
type BuilderStatusFlagProps = {
stateFlags: BuilderStateFlags
}
const getStatusColor = (isOperational: boolean, builderInactiveState: string) => {
if (isOperational) return 'transparent'
const getStatusColor = (isActive: boolean, builderInactiveState: string) => {
if (isActive) return 'transparent'
if (builderInactiveState === 'Paused') return '#F9E1FF'
return '#932309'
}

const BuilderStatusFlag: FC<BuilderStatusFlagProps> = ({ stateFlags }) => {
const isOperational = isBuilderOperational(stateFlags)
const builderInactiveState = getBuilderInactiveState(stateFlags)
const isActive = isBuilderActive(stateFlags)

const color = getStatusColor(isOperational, builderInactiveState)
const color = getStatusColor(isActive, builderInactiveState)
const content = builderInactiveState

return (
<Popover
disabled={isOperational}
disabled={isActive}
content={content}
className="font-normal text-sm flex items-center"
size="small"
Expand Down
10 changes: 10 additions & 0 deletions src/app/collective-rewards/utils/isBuilderOperational.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ export const isBuilderOperational = (stateFlags?: BuilderStateFlags) => {
return !!(stateFlags && stateFlags.communityApproved && stateFlags.kycApproved && !stateFlags.paused)
}

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

const inactiveStates = ['Deactivated', 'KYCRevoked', 'Revoked', 'Paused'] as const
type InactiveState = (typeof inactiveStates)[number]
export const getBuilderInactiveState = (state: BuilderStateFlags): InactiveState => {
Expand Down

0 comments on commit 98425ed

Please sign in to comment.