Skip to content

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

Closed

Description

@kavimuru

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

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jul 23, 2023
  2. melvin-bot commented on Jul 23, 2023

    @melvin-bot

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

  3. melvin-bot commented on Jul 23, 2023

    @melvin-bot

    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
  4. kavimuru commented on Jul 23, 2023

    @kavimuru
    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]);
    
  5. makiour commented on Jul 23, 2023

    @makiour
    Contributor

    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
  6. sophiepintoraetz commented on Jul 25, 2023

    @sophiepintoraetz
    Contributor

    Yup, able to reproduce!
    image

  7. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jul 25, 2023
  8. changed the title [-]Currency changes after refresh although URL has currency params [/-] [+][$1000] Currency changes after refresh although URL has currency params [/+] on Jul 25, 2023
  9. melvin-bot commented on Jul 25, 2023

    @melvin-bot
  10. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jul 25, 2023
  11. melvin-bot commented on Jul 25, 2023

    @melvin-bot

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

  12. melvin-bot commented on Jul 25, 2023

    @melvin-bot

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

  13. 19 remaining items

  14. sophiepintoraetz commented on Aug 4, 2023

    @sophiepintoraetz
    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

  15. makiour commented on Aug 4, 2023

    @makiour
    Contributor

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

  16. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Aug 7, 2023
  17. 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 [/+] on Aug 7, 2023
  18. melvin-bot commented on Aug 7, 2023

    @melvin-bot

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

  19. melvin-bot commented on Aug 7, 2023

    @melvin-bot

    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
  20. melvin-bot commented on Aug 7, 2023

    @melvin-bot

    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:
  21. sophiepintoraetz commented on Aug 14, 2023

    @sophiepintoraetz
    Contributor

    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

  22. rushatgabhane commented on Aug 14, 2023

    @rushatgabhane
    Member
    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
  23. rushatgabhane commented on Aug 14, 2023

    @rushatgabhane
    Member
  24. JmillsExpensify commented on Aug 16, 2023

    @JmillsExpensify
    Contributor

    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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions