-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
#2 - Fix user can submit 10-digit amount and gives an unexpected error #42815
#2 - Fix user can submit 10-digit amount and gives an unexpected error #42815
Conversation
@ikevin127 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Additional recording showing the distance rate with 3 decimals (no trailing zero) is shown Screen.Recording.2024-05-30.at.11.15.40.mov |
Reviewer Checklist
Screenshots/VideosAndroid: Nativeandroid.movAndroid: mWeb Chromeandroid-mweb.moviOS: Nativeios.moviOS: mWeb Safariios-mweb.movMacOS: Chrome / Safariweb.movMacOS: Desktopdesktop.mov |
I have one question, currently, the max digit is 10. In staging (or But in this PR, we can input 8 digits + 2 decimals or 7 digits + 3 decimals. The max. digit before decimal (.) is 8. But we can't input 8 digits + 3 decimals because the max digit is 10, do we want to increase the max digit to 11 for the distance rate? I'm asking this because when I set the distance rate to |
@marcochavezf @francoisl Any input on the comment above ? |
src/libs/MoneyRequestUtils.ts
Outdated
return CONST.IOU.AMOUNT_MAX_LENGTH + 1; | ||
} | ||
|
||
return leadingZeroesLength + (absAmount === '0' ? 2 : absAmount.length); | ||
return leadingZeroesLength + (absAmount === '0' ? 2 : stripDotFromAmount(absAmount).length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, another way to fix this is by passing the removed-dot-amount to the old regex
const amountWithoutDecimalSeparator = stripDotFromAmount(absAmount);
if (/\D/.test(amountWithoutDecimalSeparator)) {
return CONST.IOU.AMOUNT_MAX_LENGTH + 1;
}
Let me know if we want to use this instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I like the current version better, but can we also add unit tests to prevent future regressions please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before adding a test, what do you think about my suggestion here. Do you think we should do it or keep it as it is for now?
If we want to do it, then we don't need the test for this specific function.
@bernhardoj One of the reported deploy-blocker issues (#42780) is still happening on this PR: Note: Same thing happens while online. |
It's happening on |
I found the root cause of the above issue, but I think it should be fixed on a separate issue. We pass an extra 1 decimal to every currency
Then, we validate the amount, however, the BE returns the decimal with trailing zeros (0.700 for example) App/src/components/AmountForm.tsx Lines 129 to 134 in f6aa6c2
so it's not valid because the extra decimal is 1, so the decimals is stripped. |
Interesting, I thought it's coming from our first PR somehow because the testers got back with this #42780 (comment) in which the issue doesn't seem to happen once the PR was reverted. But I guess it's related to the Edit: I tested on current staging and |
Yep, it depends with the currency because IQD doesn't support decimals. Btw, regarding my question here, I just realized that if we increase the max digit to 11, we can then input 9 digits + 2 decimals which is invalid. So, we can't do that. I propose that we refactor App/src/libs/MoneyRequestUtils.ts Lines 58 to 65 in 9e9d8cd
The refactor will fully rely on the regex. So, we will remove Currently, the regex matches this number: 123,123.456 but I don't see any usage in our app that allows the thousand separator(?) in the amount. So, we can update the regex to:
amountMaxLength will be the max length before the decimal. Currently, amountMaxLength is the max length of all digits including the decimals. So for example, for distance rate, amountMaxLength will be 8 and decimals will be 3. For tax rate, the max. value is 100%, so we can set the amountMaxLength to 3. This way, we can flexibly control the max. digit for different use cases. Let me know what you think! |
Please let me know besides the main issue (#42084) this PR fixes, if we're going to cover the other issues as well:
And if so I think it would be a good idea to update the PR description to include the other issues and Tests for each. |
@francoisl oh my bad, turns out it's the FE that formatted the amount to have 3 decimals points. App/src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx Lines 105 to 107 in 5699ae3
Lines 118 to 123 in 5699ae3
|
Ok yeah I think I like the idea in this comment to rely on a regex to validate the max number of digits and decimals. |
I can do it. I will update it on Monday. |
Updated MoneyRequestConfirmationList (distance amount, 8 digits + 2 decimals): distance.amount.movAmountForm create.tax.rate.mov
edit.tax.rate.mov
edit.distance.rate.page.mov
create.distance.rate.page.mov
MoneyRequestAmountInput amount.page.mov
tax.amount.page.mov
individual.split.amount.movindividual split amount input is the only one that formats the amount to have App/src/components/MoneyRequestAmountInput.tsx Lines 147 to 150 in f701c3e
Added a unit test too. |
@francoisl Are you good with the latest changes and behaviour from #42815 (comment) ? Asking in order to confirm whether I should start working on the reviewer checklist. @bernhardoj Follow-up regarding my #42815 (comment), besides the main issue attached in Fixed issues, assuming this PR's changes are addressing the other 2 issues, could you add reviewer / QA tests for those too ? Asking in order know what to test when I'm gonna start working on the reviewer checklist. |
@ikevin127 updated the test step. |
I'll have the reviewer checklist ready by end of day today. @bernhardoj When you get a chance, please solve the conflicts. |
Woops sorry missed that comment – yes the changes in the videos look good to me. |
@bernhardoj I tested both scenarios and found some issues with scenario B, only with the
I think this is the last issue that needs to be addressed before I can ✅ Approve for final review. |
It's the same as this one, right? |
Yes, but it only happens for |
Yeah, it happens with any currency that doesn't support decimals, such as yen. I thought we want to fix it on another issue based on this comment haha. I'm not sure though what would be the best way to handle that. The currency doesn't support decimal, but in FE, we always add 1 extra decimal support, and BE accepts it too. Even the default distance rate has 2 decimals (0.67) for non-decimal (IQD) currency. I think it needs to be discussed on another issue or if we want a temporary fix, we can set the distance rate decimal to always be 3, instead of currency decimal + 1 extra decimal. cc: @francoisl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the above context (#42815 (comment)) and the fact that the only issue left was/is already present on staging and was decided on as out of scope here, I'm approving with the mention that if the out of scope issue will surface post-merge, it will not be considered a regression of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I agree we should handle the edge case for currencies without decimal support as out-of-scope for now
@francoisl all yours
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to production by https://github.com/luacmartins in version: 1.4.81-11 🚀
|
Details
When we select a currency without decimals, we can input up to 10 digit of amount which leads to a BE error. This PR fix it.
Fixed Issues
$ #42084
$ #42780
PROPOSAL: #42084 (comment)
Tests
Same as QA Steps
Offline tests
Same as QA Steps
QA Steps
A.
B.
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Screen.Recording.2024-05-21.at.22.51.32.1.mov
Android: mWeb Chrome
Screen.Recording.2024-05-21.at.22.49.34.mov
iOS: Native
Screen.Recording.2024-05-21.at.22.52.23.1.mov
iOS: mWeb Safari
Screen.Recording.2024-05-21.at.22.55.05.mov
MacOS: Chrome / Safari
Screen.Recording.2024-05-21.at.22.40.12.mov
MacOS: Desktop
Screen.Recording.2024-05-21.at.22.41.23.mov