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

Corrected Currency Display: Enforce Two Decimal Places in Amounts #35797

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2169530
Corrected Currency Display: Enforce Two Decimal Places in Amounts
abzokhattab Feb 5, 2024
72d282f
fix the case where there is no decimal value passed
abzokhattab Feb 6, 2024
8e80ffb
cleaning
abzokhattab Feb 6, 2024
8315492
fixing tests
abzokhattab Feb 6, 2024
bf046e2
Merge remote-tracking branch 'origin/main' into preserving-the-transa…
abzokhattab Feb 18, 2024
65f90db
keeping the user input when clicking next
abzokhattab Feb 18, 2024
3fa6bb9
Fixing tests
abzokhattab Feb 18, 2024
45013c3
Merge remote-tracking branch 'origin/main' into preserving-the-transa…
abzokhattab Feb 22, 2024
6c40f80
Removing the amount from the useEffect dependencies
abzokhattab Feb 22, 2024
c9614cc
minor change
abzokhattab Feb 22, 2024
bd68682
Merge remote-tracking branch 'origin/main' into preserving-the-transa…
abzokhattab Feb 29, 2024
c7363b6
Merge remote-tracking branch 'origin/main' into preserving-the-transa…
abzokhattab Mar 10, 2024
4441216
initialize amount only if the form is an edit form
abzokhattab Mar 10, 2024
10e0185
fixing the display of the entered IOU amount
abzokhattab Mar 16, 2024
1288e8f
Merge remote-tracking branch 'origin/main' into preserving-the-transa…
abzokhattab Mar 16, 2024
731ef4d
Merge remote-tracking branch 'origin/main' into preserving-the-transa…
abzokhattab Mar 16, 2024
0a08a01
cleanup
abzokhattab Mar 19, 2024
3ed17ed
Merge remote-tracking branch 'origin/main' into preserving-the-transa…
abzokhattab Mar 19, 2024
f0a071e
Merge remote-tracking branch 'origin/main' into preserving-the-transa…
abzokhattab Mar 28, 2024
0000b2b
Adding edge cases tests
abzokhattab Mar 28, 2024
89d4d77
minor edit
abzokhattab Mar 28, 2024
ad1507b
Merge remote-tracking branch 'origin/main' into preserving-the-transa…
abzokhattab Apr 1, 2024
d4b3764
Merge remote-tracking branch 'origin/main' into preserving-the-transa…
abzokhattab Apr 2, 2024
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
7 changes: 5 additions & 2 deletions src/libs/CurrencyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ function convertToFrontendAmountAsInteger(amountAsInt: number): number {
*
* @note we do not support any currencies with more than two decimal places.
*/
function convertToFrontendAmountAsString(amountAsInt: number): string {
return amountAsInt ? convertToFrontendAmountAsInteger(amountAsInt).toFixed(2) : '';
function convertToFrontendAmountAsString(amountAsInt: number | null | undefined): string {
if (amountAsInt === null || amountAsInt === undefined) {
return '';
}
return convertToFrontendAmountAsInteger(amountAsInt).toFixed(2);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/CurrencyUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@
[2550, '25.50'],
[25, '0.25'],
[2500.5, '25.00'],
])('Correctly converts %s to amount in units handled in frontend as a string', (amount, expectedResult) => {
expect(CurrencyUtils.convertToFrontendAmountAsString(amount)).toBe(expectedResult);
[null, ''],
[undefined, ''],
['', '0.00'],
[0, '0.00'],
])('Correctly converts %s to amount in units handled in frontend as a string', (input, expectedResult) => {
expect(CurrencyUtils.convertToFrontendAmountAsString(input)).toBe(expectedResult);

Check failure on line 131 in tests/unit/CurrencyUtilsTest.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | number | null | undefined' is not assignable to parameter of type 'number | null | undefined'.
});
});
describe('convertToDisplayString', () => {
Expand Down
Loading