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

Refactor GetLocalCurrency #9607

Merged
merged 10 commits into from
Jul 16, 2022
Merged

Refactor GetLocalCurrency #9607

merged 10 commits into from
Jul 16, 2022

Conversation

luacmartins
Copy link
Contributor

@luacmartins luacmartins commented Jun 28, 2022

Details

  • Creates OpenApp and ReconnectApp
  • Removes usages of fetchLocalCurrency from App init
  • Removes usages of getCurrencyList since we only want to fetch it on OpenApp

Holding on #9560 and https://github.com/Expensify/Web-Expensify/pull/34151 hitting prod

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/213883

Tests

  1. Pull the changes from https://github.com/Expensify/Web-Expensify/pull/34151
  2. Open the Network tab in the browser console.
  3. Clear cache and browsing history for the App.
  4. Sing in
  5. Verify that OpenApp is fired and that the localCurrencyCode and currencyList are returned
  6. Verify that those values are set in the personalDetails and currencyList keys
  7. Navigate to + > Request money
  8. Verify that your local currency shows up
  9. Click on the currency symbol and verify that you can see the currency list.
  10. Set the App to offline and back online in the browser console.
  11. Verify that the ReconnectApp API request was triggered.
  • Verify that no errors appear in the JS console

PR Review Checklist

Contributor (PR Author) Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there’s a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained “why” the code was doing something instead of only explaining “what” the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named “index.js”. All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose and it is
  • If a new CSS style is added I verified that:
    • A similar style doesn’t already exist
    • The style can’t be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.

PR Reviewer Checklist

  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there’s a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained “why” the code was doing something instead of only explaining “what” the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named “index.js”. All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn’t already exist
    • The style can’t be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.

QA Steps

  1. Clear cache and browsing history for the App.
  2. Sing in
  3. Navigate to + > Request money
  4. Verify that your local currency shows up
  5. Click on the currency symbol and verify that you can see the currency list.
  6. Set the App to offline and back online in the browser console.
  7. Repeat steps 3-5
  • Verify that no errors appear in the JS console

Screenshots

Web

web.mov

Mobile Web

mweb.mov

Desktop

desktop.mov

iOS

ios.mov

Android

android.mov

@luacmartins luacmartins self-assigned this Jun 28, 2022
@melvin-bot
Copy link

melvin-bot bot commented Jun 28, 2022

Looks like you modified deprecatedAPI.js! To be clear, you should not be adding any code to this file.

Instead, all new API commands should use API.js, and follow our guidelines for writing new API commands.

Unsure if your change is okay? Drop a note in #expensify-open-source!

@luacmartins luacmartins changed the title Refactor GetLocalCurrency [Hold Web-E #34151] Refactor GetLocalCurrency Jun 28, 2022
@luacmartins luacmartins marked this pull request as ready for review June 28, 2022 23:32
@luacmartins luacmartins requested a review from a team as a code owner June 28, 2022 23:32
@melvin-bot melvin-bot bot requested review from PauloGasparSv and removed request for a team June 28, 2022 23:32
@PauloGasparSv
Copy link
Contributor

@luacmartins can I test this despite the last comment in here https://github.com/Expensify/Web-Expensify/pull/34151 and the fact it is on hold too?

@luacmartins
Copy link
Contributor Author

I'd wait since this PR might change a bit based on that comment.

@luacmartins luacmartins reopened this Jun 29, 2022
@@ -323,7 +310,6 @@ function fetchLocalCurrency() {
.then((data) => {
currency = data.currency;
})
.then(getCurrencyList)
.then(() => {
Onyx.merge(ONYXKEYS.MY_PERSONAL_DETAILS, {localCurrencyCode: currency});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luacmartins What I mentioned here, this is how we currently store and merge the data about localCurrencyCode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I'm planning on changing this PR based on the changes here

@luacmartins luacmartins force-pushed the cmartins-refactorGetLocalCurrency branch from fa575db to 1dac239 Compare July 13, 2022 00:23
@luacmartins luacmartins changed the title [Hold Web-E #34151] Refactor GetLocalCurrency [Hold Web-E #34151 and App #9560] Refactor GetLocalCurrency Jul 13, 2022
@luacmartins
Copy link
Contributor Author

@mountiny @PauloGasparSv this is ready for review! We are still holding on Web-E hitting prod and the changes to the Onyx key.

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, looks good to me, but there is one unit test, which was implemented for the currency list localization testing.

// This file can get outdated. In that case, you can follow these steps to update it:
// - in src/libs/API.js
// - call: GetCurrencyList().then(data => console.log(data.currencyList));
// - copy the json from console and format it to valid json using some external tool
// - update currencyList.json

The instruction on how to obtain new JSON of the currencies uses our API so we should find a way how to keep this possible to be completed.

I am not sure how though as if we remove the API method from App then they can call it as they need authToken even if we keep the MobileConstants endpoint in the backend (or I mean they could use curl, and add their authToken but that would be quite cumbersome.

The best might be to update the instructions so they ask in the expensify-open-source channel so someone internal helps them retrieve the JSON. What do you think? Or just keep that change internal 🤷

@luacmartins luacmartins changed the title [Hold Web-E #34151 and App #9560] Refactor GetLocalCurrency [Hold App #9560] Refactor GetLocalCurrency Jul 13, 2022
@luacmartins
Copy link
Contributor Author

Thanks for the review @mountiny! I updated the instructions. I think contributors can get the updated list from the OpenApp command right?

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luacmartins Good call, yeah they should!

Thanks for the changes, just one typo.

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the changes!

@PauloGasparSv
Copy link
Contributor

I'm still going to take a little time to review this to make sure this error is my fault and proceed. But right now It's giving me an error when I click to request money right after logging. If I refresh the error stops.
image

@PauloGasparSv
Copy link
Contributor

PauloGasparSv commented Jul 13, 2022

Still have the same error! Can you help me on this @luacmartins?
Did it on the Incognito mode this time but also tested on a normal Chrome session

Screen.Recording.2022-07-13.at.17.28.58.mov

@luacmartins
Copy link
Contributor Author

luacmartins commented Jul 13, 2022

@PauloGasparSv the problem is that #9560 is not merged yet. We set selectedCurrencyCode here, but it expects localCurrencyCode to be in the myPersonalDetails Onyx key. However, that key is now in personalDetails. Once that PR is merged it should fix this issue.

A side note is that this default prop is doing nothing since other keys in props.iou are defined. We should probably fix that.

Copy link
Contributor

@PauloGasparSv PauloGasparSv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! Nice : )
Approving it for now since everything LGTM!
But let's test it again when that P.R. is merged

@luacmartins
Copy link
Contributor Author

#9560 merged! Retested and all is good. Removing hold and merging!

@luacmartins luacmartins changed the title [Hold App #9560] Refactor GetLocalCurrency Refactor GetLocalCurrency Jul 16, 2022
@luacmartins luacmartins merged commit 1fc51f4 into main Jul 16, 2022
@luacmartins luacmartins deleted the cmartins-refactorGetLocalCurrency branch July 16, 2022 02:43
@melvin-bot melvin-bot bot added the Emergency label Jul 16, 2022
@melvin-bot
Copy link

melvin-bot bot commented Jul 16, 2022

@luacmartins looks like this was merged without passing tests. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@luacmartins
Copy link
Contributor Author

Tests passed! Removing emergency label!

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @luacmartins in version: 1.1.85-8 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants