Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix percentage changes when balance is zero #25550

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,13 @@ describe('PercentageChange Component', () => {
expect(percentageElement).toBeInTheDocument();
expect(numberElement).toBeInTheDocument();
});

it('displays zero percentage with number in default color if balance is zero', () => {
mockGetSelectedAccountCachedBalance.mockReturnValue('0x0');
render(<PercentageAndAmountChange value={-1.234} />);
const percentageElement = screen.getByText('(+0.00%)');
const numberElement = screen.getByText('+$0.00');
expect(percentageElement).toBeInTheDocument();
expect(numberElement).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ export const PercentageAndAmountChange = ({

let color = TextColor.textDefault;

if (isValidAmount(value)) {
if ((value as number) === 0) {
if (isValidAmount(balanceChange)) {
if ((balanceChange as number) === 0) {
color = TextColor.textDefault;
} else if ((value as number) > 0) {
} else if ((balanceChange as number) > 0) {
color = TextColor.successDefault;
} else {
color = TextColor.errorDefault;
}
}

const formattedValue = formatValue(value, true);
const formattedValue = formatValue(balanceChange === 0 ? 0 : value, true);

const formattedValuePrice = isValidAmount(balanceChange)
? `${(balanceChange as number) >= 0 ? '+' : ''}${Intl.NumberFormat(locale, {
Expand Down
Loading