Skip to content

Commit

Permalink
rename for clarity and better comment
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabib committed Jan 17, 2025
1 parent b064eaf commit f6e2b8b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
16 changes: 9 additions & 7 deletions frontend/src/lib/utils/portfolio.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,23 @@ export const getTopStakedTokens = ({

/**
* Determines whether to show an info row in a card based on specific display rules.
* This ensures both cards have consistent heights by filling empty space
* with a message instead of leaving a blank space.
* Rules for showing the info row:
* 1. When the other card has more tokens than the current card
* 2. When the other card is empty (has 0 tokens)
* 3. When both cards have fewer than 3 tokens (for visual balance)
*/
export const shouldShowInfoRow = ({
currentCardTokens,
otherCardTokens,
currentCardNumberOfTokens,
otherCardNumberOfTokens,
}: {
currentCardTokens: number;
otherCardTokens: number;
currentCardNumberOfTokens: number;
otherCardNumberOfTokens: number;
}) => {
return (
otherCardTokens - currentCardTokens > 0 ||
otherCardTokens === 0 ||
(currentCardTokens < 3 && otherCardTokens < 3)
otherCardNumberOfTokens - currentCardNumberOfTokens > 0 ||
otherCardNumberOfTokens === 0 ||
(currentCardNumberOfTokens < 3 && otherCardNumberOfTokens < 3)
);
};
24 changes: 12 additions & 12 deletions frontend/src/tests/lib/utils/portfolio.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,49 +330,49 @@ describe("Portfolio utils", () => {
it("should show info row when other card has more tokens", () => {
expect(
shouldShowInfoRow({
currentCardTokens: 1,
otherCardTokens: 4,
currentCardNumberOfTokens: 1,
otherCardNumberOfTokens: 4,
})
).toBe(true);
});

it("should show info row when other card is empty", () => {
expect(
shouldShowInfoRow({
currentCardTokens: 2,
otherCardTokens: 0,
currentCardNumberOfTokens: 2,
otherCardNumberOfTokens: 0,
})
).toBe(true);
});

it("should show info row when both cards have fewer than 3 tokens", () => {
expect(
shouldShowInfoRow({
currentCardTokens: 2,
otherCardTokens: 2,
currentCardNumberOfTokens: 2,
otherCardNumberOfTokens: 2,
})
).toBe(true);

expect(
shouldShowInfoRow({
currentCardTokens: 1,
otherCardTokens: 2,
currentCardNumberOfTokens: 1,
otherCardNumberOfTokens: 2,
})
).toBe(true);
});

it("should not show info row when both cards have 3 or more tokens", () => {
expect(
shouldShowInfoRow({
currentCardTokens: 3,
otherCardTokens: 3,
currentCardNumberOfTokens: 3,
otherCardNumberOfTokens: 3,
})
).toBe(false);

expect(
shouldShowInfoRow({
currentCardTokens: 4,
otherCardTokens: 3,
currentCardNumberOfTokens: 4,
otherCardNumberOfTokens: 3,
})
).toBe(false);
});
Expand Down

0 comments on commit f6e2b8b

Please sign in to comment.