Skip to content

Commit

Permalink
refactor: trim decimal stat
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshift committed Aug 27, 2024
1 parent 2213ac1 commit b955640
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,48 @@ export const DeepNested: Story = {
},
},
};

export const TrimmedDecimal: Story = {
args: {
granteeStat: {
label: 'Some Label',
value: 'Sample non-integer value',
stats: [
{
label: 'New Contributors',
value: '35.023523',
stats: [
{
label: 'Crypto Native',
value: '4.457',
stats: [],
},

{
label: 'Open Source Contributor',
value: '7.55',
stats: [],
},
],
},
{
label: 'Last 6 months',
value: '2.342634263246326',
stats: [
{
label: 'First Half',
value: '2.123421351236236',
stats: [],
},

{
label: 'Last Half',
value: '4.324632463246',
stats: [],
},
],
},
],
},
},
};
12 changes: 11 additions & 1 deletion src/grants/components/grant-stat-item/grantee-stat-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const GranteeStatItem = ({ granteeStat, level = 1 }: Props) => {
<span className="text-13 font-medium leading-tight text-white md:text-2xl md:text-white/60">
{label}
</span>
<span className="text-xl font-medium">{value}</span>
<span className="text-xl font-medium">{trimStat(value)}</span>
</Inner>

{hasChildren && (
Expand Down Expand Up @@ -110,3 +110,13 @@ export const GranteeStatsSkeleton = () => (
<GranteeStatItemSkeleton />
</>
);

export const trimStat = (input: string): string => {
const num = parseFloat(input);

if (!isNaN(num)) {
return num.toFixed(2);
}

return input;
};

0 comments on commit b955640

Please sign in to comment.