-
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
Updated total amount when change the different currency #35880
Conversation
@cubuspl42 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] |
TypeScript Checks are failing |
src/libs/actions/IOU.ts
Outdated
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.reportID}`, | ||
value: {pendingAction: null}, | ||
}); | ||
let diff = 0; |
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.
Could you refactor this not to use let
? Maybe we could extract a local or non-local helper function.
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.
@cubuspl42 I updated to create a local function.
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'm sorry, I wasn't clear enough. My suggestion was quite technical. I asked specifically whether we could refactor the code not to use the let
, i.e. whether the code could be expressed without introducing a mutable variable.
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.
got it . I will re-update soon.
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.
Previously, we defined diff
like: const diff = ...
.
I'm suggesting to keep it like this. The easiest way to keep the const
is to introduce a helper function for calculating the difference. It can even be local and take no arguments; it's up to you.
function computeDiff() {
if (someCondition1) {
return anything;
} else if (someCondition2) {
return something;
} else {
return somethingElse;
}
}
const diff = computeDiff();
I think it's best to introduce as few mutable variables to the code as possible.
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.
Thanks, that is the current ideal I will re-update.
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.
By "local" I actually meant local in the most-inner surrounding scope. It could also be understood as module-local, as opposed to exported from a module; I didn't mean that.
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.
getUpdateMoneyRequestParams
function is very complex so I think we should create an outside function.
@dukenv0307 ☝️ |
It's fixed now. |
src/libs/actions/IOU.ts
Outdated
|
||
if (updatedCurrency === iouReport?.currency && currentCurrency !== iouReport?.currency) { | ||
// add the diff with the total if we change the currency from different currency to the currency of the iou report | ||
return TransactionUtils.getAmount(updatedTransaction, isExpenseReport); |
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.
Could you add new helper const
s above the if
blocks, like...
const oldAmount = TransactionUtils.getAmount(transaction, isExpenseReport);
const updateAmount = TransactionUtils.getAmount(updatedTransaction, isExpenseReport);
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.
Updated with two variables before the if
blocks.
src/libs/actions/IOU.ts
Outdated
/** | ||
* Compute the diff amount when we update the transaction | ||
*/ | ||
function computeDiffAmount(iouReport: OnyxEntry<OnyxTypes.Report>, updatedTransaction: OnyxEntry<OnyxTypes.Transaction>, transaction: OnyxEntry<OnyxTypes.Transaction>): number { |
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 like this change! It clearly separates the computation of the diff from the surrounding logic of getUpdateMoneyRequestParams
. That function is already long enough.
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.
Actually, would you have anything against changing this name to calculateDiffAmount
? "Calculation" is "computing" but with numbers. I should have suggested this name in the first place.
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 agree.
src/libs/actions/IOU.ts
Outdated
const currentCurrency = TransactionUtils.getCurrency(transaction); | ||
|
||
if (updatedCurrency === iouReport?.currency && currentCurrency !== iouReport?.currency) { | ||
// add the diff with the total if we change the currency from different currency to the currency of the iou report |
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.
Add the diff to the total if we change the currency from a different currency to the currency of the IOU report
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.
If English is not your native language, it can be very hard to use "a" and "the" correctly. In general, we use "a"/"an" if we talk about an entity/person/object from a group/set/category, without having a specific instance in mind (jn the given context). We use "the" when we talk about a specific instance (in the given context).
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.
Thanks for your knowledge, noted it and will improve in the future.
src/libs/actions/IOU.ts
Outdated
return -TransactionUtils.getAmount(updatedTransaction, isExpenseReport); | ||
} | ||
if (updatedCurrency === iouReport?.currency && updatedTransaction?.modifiedAmount) { | ||
// get the diff between the updated amount and the current amount if we change the amount and the currency of the transaction is the currency of the report |
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 can't spot any language mistakes! 😃
I suggested to start the other comment with a capital letter, so we could do this here, too, for consistency. We could also say "calculate", as it's more specific than "get".
Calculate the diff between the updated amount and the current amount if we change the amount and the currency of the transaction is the currency of the report
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 updated this comment.
src/libs/actions/IOU.ts
Outdated
return TransactionUtils.getAmount(updatedTransaction, isExpenseReport); | ||
} | ||
if (updatedCurrency !== iouReport?.currency && currentCurrency === iouReport?.currency) { | ||
// subtract the diff with the total if we change the currency from the currency of iou report to different currency |
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.
Subtract the diff from the total if we change the currency from the currency of IOU report to a different currency
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 updated this comment.
@dukenv0307 Bump! |
@dukenv0307 Bump again |
I'm on the traditional holiday until February 15th |
All possible checks are failing, so let's fix that 🙂 |
I missed resolving a conflict. |
@cubuspl42 All checks are fixed now. |
It doesn't look right. The sum should be 100 PLN, not 120 PLN. total-after-currency-change-issue-1-web-converted.mp4 |
Thanks, I missed this case. |
@cubuspl42 I updated to fix the case above and also fix the case when deleting the request. |
Reviewer Checklist
Screenshots/VideosAndroid: Nativefix-total-amount-android-compressed.mp4Android: mWeb Chromefix-total-amount-android-web-compressed.mp4iOS: Nativefix-total-amount-ios-compressed.mp4iOS: mWeb Safarifix-total-amount-ios-web-compressed.mp4MacOS: Chrome / Safarifix-total-amount-web-converted.mp4MacOS: Desktopfix-total-amount-desktop-converted.mp4 |
✋ 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 staging by https://github.com/tylerkaraszewski in version: 1.4.43-0 🚀
|
🚀 Deployed to production by https://github.com/puneetlath in version: 1.4.43-20 🚀
|
Details
Only amount of the first request is displayed in total
Fixed Issues
$ #35209
PROPOSAL: #35209 (comment)
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.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 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
android.mov
Android: mWeb Chrome
android-mweb.mov
iOS: Native
ios.mov
iOS: mWeb Safari
ios.mov
MacOS: Chrome / Safari
web-resize.mp4
MacOS: Desktop
desktop-resize.mp4