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

[HOLD for payment 2023-08-14] [$1000] Currency changes after refresh although URL has currency params #23436

Closed
1 of 6 tasks
kavimuru opened this issue Jul 23, 2023 · 30 comments
Closed
1 of 6 tasks
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@kavimuru
Copy link

kavimuru commented Jul 23, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Go to the app and open any report
  2. Click on request money
  3. Change currency and notice it has changed in the URL
  4. Copy the URL and open it somewhere or just refresh
  5. The currency param is there in the URL but changed

Expected Result:

Currency should be the one in the URL currency parms.

Actual Result:

It changes to the default currency

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.44-0
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation

bugCurrency-vid.webm
Recording.1323.mp4

Expensify/Expensify Issue URL:
Issue reported by: @makiour
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1690050379038969

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01b122db1f8bca0f1d
  • Upwork Job ID: 1683656595572019200
  • 2023-07-25
  • Automatic offers:
    • | | 0
    • | | 0
    • | | 0
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 23, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 23, 2023

Triggered auto assignment to @sophiepintoraetz (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Jul 23, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@kavimuru
Copy link
Author

Proposal

Please re-state the problem that we are trying to solve in this issue.

The issue here is that we are not keeping the currency selected although we have it in the link parameters
We need to keep the selected currency.

What is the root cause of that problem?

After investigating, there are two main parameters that we need to know when opening money request page:

  1. selectedCurrency: This one refers to the currency we are showing.
    const [selectedCurrencyCode, setSelectedCurrencyCode] = useState(props.iou.currency);
  2. IOU.currency: This one refers to the currency assigned to our profile (it is based on location and comes from BE)
    iou: PropTypes.shape({
    id: PropTypes.string,
    amount: PropTypes.number,
    currency: PropTypes.string,
    participants: PropTypes.arrayOf(

    withOnyx({
    iou: {key: ONYXKEYS.IOU},

    The root cause here is that we are handling selected currency change when it occurs to IOU.currency. So, we are keeping track of the selected currency if it has changed. That's good. However, it always changes the selectedCurrency whenever it has changed even after receiving it through data. To be more clear here,
    The following useEffect are handling the logic of setting the currency:
    useEffect(() => {
    if (!props.route.params.currency) {
    return;
    }
    setSelectedCurrencyCode(props.route.params.currency);
    }, [props.route.params.currency]);
    useEffect(() => {
    setSelectedCurrencyCode(props.iou.currency);
    }, [props.iou.currency]);

    As we can see the first useEffect is handling it correctly and changing the currency when we send it through URL params.
    However, in the other case, in the second useEffect, we don't handle this, which causes the selectedCurrency to always change
    to IOU.currency especially that at first it is initalized to constant.
    We need to handle this in here.

What changes do you think we should make in order to solve the problem?

Option 1:

We can just add a condition inside the useEffect to check if we have currency params within the URL, if this is the case, we return:

useEffect(() => {
setSelectedCurrencyCode(props.iou.currency);
}, [props.iou.currency]);

We can add
if (props.route.params.currency) {
return;
}
before
setSelectedCurrencyCode(props.iou.currency);
To be like that:
useEffect(() => {
if (props.route.params.currency) {
return;
}
setSelectedCurrencyCode(props.iou.currency);
}, [props.iou.currency]);

Option 2: Simpler and Preferred

Since we understand the logic in which the currency changes, and since we know that useEffect hooks are run according to the order they have been put within the React component, the simplest solution here is to just switch the useEffects and put the second one first in the following way:
useEffect(() => {
setSelectedCurrencyCode(props.iou.currency);
}, [props.iou.currency]);

useEffect(() => {
    if (!props.route.params.currency) {
        return;
    }
    setSelectedCurrencyCode(props.route.params.currency);
}, [props.route.params.currency]);

@makiour
Copy link
Contributor

makiour commented Jul 23, 2023

It is the one shared by kavimuru, but with result and better format. Thank you!

Proposal

Please re-state the problem that we are trying to solve in this issue.

The issue here is that we are not keeping the currency selected although we have it in the link parameters
We need to keep the selected currency.

What is the root cause of that problem?

After investigating, there are two main parameters that we need to know when opening money request page:

  1. selectedCurrency: This one refers to the currency we are showing.

const [selectedCurrencyCode, setSelectedCurrencyCode] = useState(props.iou.currency);

  1. IOU.currency: This one refers to the currency assigned to our profile (it is based on location and comes from BE)

iou: PropTypes.shape({
id: PropTypes.string,
amount: PropTypes.number,
currency: PropTypes.string,
participants: PropTypes.arrayOf(

withOnyx({
iou: {key: ONYXKEYS.IOU},

The root cause here is that we are handling selected currency change when it occurs to IOU.currency. So, we are keeping track of the selected currency if it has changed. That's good. However, it always changes the selectedCurrency whenever it has changed even after receiving it through data. To be more clear here,The following useEffect are handling the logic of setting the currency:

useEffect(() => {
if (!props.route.params.currency) {
return;
}
setSelectedCurrencyCode(props.route.params.currency);
}, [props.route.params.currency]);
useEffect(() => {
setSelectedCurrencyCode(props.iou.currency);
}, [props.iou.currency]);

As we can see the first useEffect is handling it correctly and changing the currency when we send it through URL params.
However, in the other case, in the second useEffect, we don't handle this, which causes the selectedCurrency to always change
to IOU.currency especially that at first it is initalized to constant.We need to handle this in here.

What changes do you think we should make in order to solve the problem?

Option 1:

We can just add a condition inside the useEffect to check if we have currency params within the URL, if this is the case, we return:

useEffect(() => {
setSelectedCurrencyCode(props.iou.currency);
}, [props.iou.currency]);

We can add

if (props.route.params.currency) {
            return;
 }

before
setSelectedCurrencyCode(props.iou.currency);

To be like that:

    useEffect(() => {
        if (props.route.params.currency) {
            return;
        }
        setSelectedCurrencyCode(props.iou.currency);
    }, [props.iou.currency]);

Option 2: Simpler and Preferred

Since we understand the logic in which the currency changes, and since we know that useEffect hooks are run according to the order they have been put within the React component, the simplest solution here is to just switch the useEffects and put the second one first in the following way:

     useEffect(() => {
        setSelectedCurrencyCode(props.iou.currency);
    }, [props.iou.currency]);

    useEffect(() => {
        if (!props.route.params.currency) {
            return;
        }
        setSelectedCurrencyCode(props.route.params.currency);
    }, [props.route.params.currency]);

Result

bugCurrency.webm

@sophiepintoraetz
Copy link
Contributor

Yup, able to reproduce!
image

@sophiepintoraetz sophiepintoraetz added the External Added to denote the issue can be worked on by a contributor label Jul 25, 2023
@melvin-bot melvin-bot bot changed the title Currency changes after refresh although URL has currency params [$1000] Currency changes after refresh although URL has currency params Jul 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 25, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01b122db1f8bca0f1d

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 25, 2023

Current assignee @sophiepintoraetz is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Jul 25, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @rushatgabhane (External)

@rushatgabhane
Copy link
Member

rushatgabhane commented Jul 25, 2023

I like @makiour's proposal - option 1 because it's more clear.

I don't like option 2 to change the order of useEffects because it's really easy to forget the fact that order of useEffect matters and someone can cause this bug if they are refactoring the component.

Further, I think we can combine both the useEffects for readability. Because what we're really trying to do is - Always use the currency provided in the request params. If it isn't found, then default to location based currency.

useEffect(() => {
    if (props.route.params.currency) {
        setSelectedCurrencyCode(props.route.params.currency);
        return;
    }
    setSelectedCurrencyCode(props.iou.currency);
}, [props.route.params.currency, props.iou.currency]);

P.S. I'm a noob in hooks. Please let me know if combining hooks will cause any bugs, thanks 🙇

@rushatgabhane
Copy link
Member

rushatgabhane commented Jul 25, 2023

C+ reviewed 🎀 👀 🎀

#23436 (comment)

@melvin-bot
Copy link

melvin-bot bot commented Jul 25, 2023

Triggered auto assignment to @MariaHCD, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@makiour
Copy link
Contributor

makiour commented Jul 26, 2023

I like @makiour's proposal - option 1 because it's more clear.

I don't like option 2 to change the order of useEffects because it's really easy to forget the fact that order of useEffect matters and someone can cause this bug if they are refactoring the component.

Further, I think we can combine both the useEffects for readability. Because what we're really trying to do is - Always use the currency provided in the request params. If it isn't found, then default to location based currency.

useEffect(() => {
    if (props.route.params.currency) {
        setSelectedCurrencyCode(props.route.params.currency);
        return;
    }
    setSelectedCurrencyCode(props.iou.currency);
}, [props.route.params.currency, props.iou.currency]);

P.S. I'm a noob in hooks. Please let me know if combining hooks will cause any bugs, thanks 🙇

Amazing feedback, thank for your comment. I preferred the second for its simplicity, but totally agree with the point of refactoring. We could add a comment, but would not be enough to keep developers attentive.
The first would be straightforwad. Indeed, we can combine the two hooks and use one for readability. The way you suggested is correct. I will consider it as well.

Happy to proceed and submit a PR whenevr you want.

@MariaHCD
Copy link
Contributor

The proposal looks good to me too.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 26, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 26, 2023

📣 @rushatgabhane Please request via NewDot manual requests for the Reviewer role ($1000)

@melvin-bot
Copy link

melvin-bot bot commented Jul 26, 2023

📣 @makiour You have been assigned to this job!
Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs!
Keep in mind: Code of Conduct | Contributing 📖

@melvin-bot
Copy link

melvin-bot bot commented Jul 26, 2023

📣 @makiour We're missing your Upwork ID to automatically send you an offer for the Reporter role.
Once you apply to the Upwork job, your Upwork ID will be stored and you will be automatically hired for future jobs!

@makiour
Copy link
Contributor

makiour commented Jul 26, 2023

@rushatgabhane PR is ready for review!
@MariaHCD I applied to Upwork job!

Thank you all.

@sophiepintoraetz
Copy link
Contributor

Great! Once @MariaHCD has reviewed the PR we can wait for the regression period before releasing payments.

@melvin-bot
Copy link

melvin-bot bot commented Aug 2, 2023

Based on my calculations, the pull request did not get merged within 3 working days of assignment. Please, check out my computations here:

  • when @makiour got assigned: 2023-07-26 11:11:48 Z
  • when the PR got merged: 2023-08-02 12:03:53 UTC
  • days elapsed: 5

On to the next one 🚀

@rushatgabhane
Copy link
Member

rushatgabhane commented Aug 2, 2023

@sophiepintoraetz so we fixed an additional bug that we encountered while testing.

We fixed it in the same PR because it blocked testing of this issue.

Please confirm if you agree that we should pay an additional bounty of $1k

bug report: https://expensify.slack.com/archives/C049HHMV9SM/p1690926235865309

@makiour
Copy link
Contributor

makiour commented Aug 2, 2023

Thank you everyone for your cooperation in solving this issue.
@sophiepintoraetz @MariaHCD Thhere are few things I might need you help with; I basically submitted the PR directly after I got assigned. I finished working on it with all tests and submitted it before three three days. As @rushatgabhane mentionned, we found another issue which we fixed in the same PR while testing. You can check all the dates in the PR to make sure it was finished before.

Also, here is my proposal: https://www.upwork.com/ab/proposals/1684162045300506625, as I haven't received an offer yet in upwork as my upworkID was missing.

Thank you everyone!

@sophiepintoraetz
Copy link
Contributor

@makiour - I appreciate the case and the discretionary effort, I think the bonus payment is effectively captured in the fact that you are being paid for two bug reports - so it did take you a bit longer but I think you are being well compensated for it!

Payouts due (once the regression period passes):

Following payments doubled for fixing two bugs inside this one issue:

Eligible for 50% #urgency bonus? N

@makiour
Copy link
Contributor

makiour commented Aug 4, 2023

I appreciate your time and clarifications Sophie! Thank you so much for your support.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Aug 7, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Currency changes after refresh although URL has currency params [HOLD for payment 2023-08-14] [$1000] Currency changes after refresh although URL has currency params Aug 7, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Aug 7, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 7, 2023

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot
Copy link

melvin-bot bot commented Aug 7, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.50-3 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2023-08-14. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

For reference, here are some details about the assignees on this issue:

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Aug 7, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@rushatgabhane] The PR that introduced the bug has been identified. Link to the PR:
  • [@rushatgabhane] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@rushatgabhane] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@rushatgabhane] Determine if we should create a regression test for this bug.
  • [@rushatgabhane] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@sophiepintoraetz] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@sophiepintoraetz
Copy link
Contributor

sophiepintoraetz commented Aug 14, 2023

Payouts due today!

Issue Reporter: $250 @makiour
Following payments doubled for fixing two bugs inside this one issue:

Contributor: $2000 @makiour (total $2250) - edit - PAID
Contributor+: $2000 @rushatgabhane (once the checklist has been completed)
Eligible for 50% #urgency bonus? N

@rushatgabhane
Copy link
Member

rushatgabhane commented Aug 14, 2023

  1. The PR that introduced the bug has been identified. Link to the PR: migrating MoneyRequestAmountPage to functional component #21005

  2. The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: https://github.com/Expensify/App/pull/21005/files#r1293863455

  3. A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: Missed edge case by PR author and reviewer.

  4. Determine if we should create a regression test for this bug. Sure!

  5. If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again

    1. Open a chat in the app
    2. Open the request money tab
    3. Change the currency and notice it has changed in the URL
    4. Refresh the page
    5. Notice that the currency has not changed

@rushatgabhane
Copy link
Member

created a manual request here - https://staging.new.expensify.com/r/8223080099023677

@JmillsExpensify
Copy link

Reviewed the details for @rushatgabhane. Approved for payment in NewDot based on the BZ summary above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests

6 participants