Skip to content

Commit

Permalink
fix: fix builder name and rewards leaderboard name alignment (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
antomor authored Nov 25, 2024
1 parent 1aa0dd2 commit 0809b62
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 21 deletions.
40 changes: 21 additions & 19 deletions src/app/collective-rewards/shared/components/Table/TableCells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,27 @@ export const BuilderNameCell: FC<BuilderCellProps> = ({
<div className="flex flex-row gap-x-1">
<BuilderStatusFlag stateFlags={stateFlags} />
<Jdenticon className="rounded-md bg-white min-w-6" value={builderName} size="24" />
<Popover
content={
<div className="text-[12px] font-bold mb-1">
<p data-testid="builderAddressTooltip">{shortenAddress}</p>
</div>
}
size="small"
trigger="hover"
disabled={!builderName || isAddress(builderName)}
>
<Typography tagVariant="label" className="font-semibold line-clamp-1 text-wrap min-w-28">
<AddressOrAliasWithCopy
addressOrAlias={builderName || address}
clipboard={address}
clipboardAnimationText={shortenAddress}
className="text-sm"
/>
</Typography>
</Popover>
<div className="w-32">
<Popover
content={
<div className="text-[12px] font-bold mb-1">
<p data-testid="builderAddressTooltip">{shortenAddress}</p>
</div>
}
size="small"
trigger="hover"
disabled={!builderName || isAddress(builderName)}
>
<Typography tagVariant="label" className="font-semibold line-clamp-1 text-wrap min-w-28">
<AddressOrAliasWithCopy
addressOrAlias={builderName || address}
clipboard={address}
clipboardAnimationText={shortenAddress}
className="text-sm"
/>
</Typography>
</Popover>
</div>
</div>
</TableCell>
)
Expand Down
4 changes: 2 additions & 2 deletions src/app/collective-rewards/user/hooks/useGetBuilders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Builder, BuilderStateFlags } from '@/app/collective-rewards/types'
import { useGetGaugesArray } from '@/app/collective-rewards/user/hooks/useGetGaugesArray'
import { getMostAdvancedProposal } from '@/app/collective-rewards/utils'
import { getMostAdvancedProposal, removeBrackets } from '@/app/collective-rewards/utils'
import { RawBuilderState } from '@/app/collective-rewards/utils/getBuilderGauge'
import { useGetProposalsState } from '@/app/collective-rewards/user'
import { useFetchCreateBuilderProposals } from '@/app/proposals/hooks/useFetchLatestProposals'
Expand Down Expand Up @@ -135,7 +135,7 @@ export const useGetBuilders: UseGetBuilders = () => {
stateFlags: statusByBuilder[address],
gauge: builderToGauge && builderToGauge[address],
address,
builderName,
builderName: removeBrackets(builderName),
}
}

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 './getBuilderState'
export * from './getCoinbaseAddress'
export * from './getMostAdvancedProposal'
export * from './handleErrors'
export * from './removeBrackets'
46 changes: 46 additions & 0 deletions src/app/collective-rewards/utils/removeBrackets.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { describe, it, expect } from 'vitest'
import { removeBrackets } from './removeBrackets'

describe('formatBuilderName', () => {
it('should remove the initial text enclosed with []', () => {
const input = '[Initial Text] Remaining Text'
const expectedOutput = 'Remaining Text'
expect(removeBrackets(input)).toBe(expectedOutput)
})

it('should return the same string if no text is enclosed with []', () => {
const input = 'No brackets here'
const expectedOutput = 'No brackets here'
expect(removeBrackets(input)).toBe(expectedOutput)
})

it('should handle strings with multiple brackets correctly', () => {
const input = '[Initial] [Text] Remaining Text'
const expectedOutput = '[Text] Remaining Text'
expect(removeBrackets(input)).toBe(expectedOutput)
})

it('should not remove the chars after the bracket if it is not an empty space', () => {
const input = '[Initial][Text] Remaining Text'
const expectedOutput = '[Text] Remaining Text'
expect(removeBrackets(input)).toBe(expectedOutput)
})

it('should handle empty strings correctly', () => {
const input = ''
const expectedOutput = ''
expect(removeBrackets(input)).toBe(expectedOutput)
})

it('should handle strings with only brackets correctly', () => {
const input = '[]'
const expectedOutput = ''
expect(removeBrackets(input)).toBe(expectedOutput)
})

it('should handle undefined also', () => {
const input = undefined
const expectedOutput = ''
expect(removeBrackets(input)).toBe(expectedOutput)
})
})
10 changes: 10 additions & 0 deletions src/app/collective-rewards/utils/removeBrackets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const removeBrackets = (name?: string) => {
if (!name) {
return ''
}
const bracketIndex = name.indexOf(']')
if (bracketIndex !== -1) {
return name.slice(bracketIndex + 1).trimStart()
}
return name
}

0 comments on commit 0809b62

Please sign in to comment.