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

[TS migration] Migrate 'SettingsWalletDetails' page to TypeScript #34257

Merged
merged 26 commits into from
Feb 20, 2024

Conversation

tienifr
Copy link
Contributor

@tienifr tienifr commented Jan 10, 2024

Details

Fixed Issues

$ #32001
PROPOSAL: NA

Tests

  1. Go to Wallet page
  2. Verify the page is displayed correctly
  3. Verify that users can press assigned card/bank account/add bank account
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. Go to Wallet page
  2. Verify the page is displayed correctly
  3. Verify that users can press assigned card/bank account/add bank account
  • Verify that no errors appear in the JS console

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 the expected offline behavior in the Offline steps 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 tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • 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 the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • 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 is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review 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
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • 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.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2024-01-11.at.16.02.25.mov
Android: mWeb Chrome
Screen.Recording.2024-01-11.at.15.32.00.mov
iOS: Native
Screen.Recording.2024-01-11.at.11.38.33.mov
iOS: mWeb Safari
Screen.Recording.2024-01-11.at.11.26.41.mov
MacOS: Chrome / Safari
Screen.Recording.2024-01-11.at.11.21.23.mov
MacOS: Desktop
Screen.Recording.2024-01-11.at.11.28.24.mov

@tienifr tienifr marked this pull request as ready for review January 11, 2024 08:29
@tienifr tienifr requested a review from a team as a code owner January 11, 2024 08:29
@melvin-bot melvin-bot bot requested review from cubuspl42 and removed request for a team January 11, 2024 08:29
Copy link

melvin-bot bot commented Jan 11, 2024

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

src/CONST.ts Outdated Show resolved Hide resolved
src/libs/actions/PaymentMethods.ts Outdated Show resolved Hide resolved
src/pages/settings/Wallet/WalletPage/WalletPage.tsx Outdated Show resolved Hide resolved
src/pages/settings/Wallet/WalletPage/WalletPage.tsx Outdated Show resolved Hide resolved
src/pages/settings/Wallet/WalletPage/WalletPage.tsx Outdated Show resolved Hide resolved
src/pages/settings/Wallet/WalletPage/WalletPage.tsx Outdated Show resolved Hide resolved
@cubuspl42
Copy link
Contributor

Oh my, a lot of changes.

@tienifr
Copy link
Contributor Author

tienifr commented Jan 15, 2024

I updated the PR, there're many places that use || that breaks the lint rule and I just replaced all of them before. I think we shouldn't do that in some cases so I reverted these changes. Sorry about that 🙏

@blazejkustra
Copy link
Contributor

Please update the title of this PR to [TS migration] Migrate 'SettingsWalletDetails' page to TypeScript

src/components/Popover/types.ts Outdated Show resolved Hide resolved
src/pages/settings/Wallet/PaymentMethodList.tsx Outdated Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/naming-convention
onSuccessfulKYC={(_iouPaymentType: string, source: string) => navigateToWalletOrTransferBalancePage(source)}
onSelectPaymentMethod={(selectedPaymentMethod: string) => {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
if (hasActivatedWallet || selectedPaymentMethod !== CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not ??? (check all cases - in all of them you can use ?? instead of disabling rules)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned here, we need to preserve ||

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this specific linter silencing needed?

The typing is: const hasActivatedWallet: boolean, so why would it trigger the linter?

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that all 3 cases of // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing left in the code are related to using || with trivial booleans. Are they actually necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's necessary. We all know false || true is different from false ?? true. So I believe we need || in these cases

Copy link
Contributor

Choose a reason for hiding this comment

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

To be on the same page, I'm asking whether this specific linter silencing is necessary, not whether using the || operator is necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, aren't both sides simply of type boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, understand your mean. I removed these linters silencing

@cubuspl42
Copy link
Contributor

@tienifr

Please resolve conflicts

@cubuspl42
Copy link
Contributor

cubuspl42 commented Jan 18, 2024

I think there's some confusion with ?? vs ||. I hope I didn't create confusion with a few laconic comments like "?".

?? means fall back to right-hand side when left-hand side is "absent" (null or undefined).

|| is a logical "or" inside the messy world of JS logic. You have to catch up with what's truthy and what's not in the JS world when doing TS migrations. You can check this video and also some more serious materials.

When we work with (potentially) empty strings and (potentially) zero-valued numbers, etc., || can be preferred even when ?? is tempting to use. We had some regresions related to this.

So, when migrating, you must ask yourself whether we're working with values like A | null | undefined where A is a type with potentially falsy values (arrays, numbers, strings...) and it might realistically have such a falsy value in a given context.

@blazejkustra
Copy link
Contributor

@cubuspl42 Thanks! 💯

Ideally we should use undefined to signalise 'empty values' across the project, then ?? would just work 😄 The prblem is that we often use empty strings instead of undefined.

@tienifr tienifr changed the title migrate to ts [TS migration] Migrate 'SettingsWalletDetails' page to TypeScript Jan 19, 2024
@tienifr
Copy link
Contributor Author

tienifr commented Jan 19, 2024

Waiting for response from #33714 (comment)

@blazejkustra
Copy link
Contributor

@tienifr Go ahead and adjust KYCWall type 😄

@cubuspl42
Copy link
Contributor

@tienifr I can see we have good progress here! 👍

Please reply to all threads

@cubuspl42
Copy link
Contributor

TypeScript Checks are failing

@cubuspl42
Copy link
Contributor

@tienifr Bad luck; conflicts

Comment on lines 178 to 182
const assignedCards = _.chain(cardList)
// Filter by physical, active cards associated with a domain
.filter((card) => !card.isVirtual && card.domainName && CONST.EXPENSIFY_CARD.ACTIVE_STATES.includes(card.state))
.filter((card) => !card.isVirtual && !!card.domainName && CONST.EXPENSIFY_CARD.ACTIVE_STATES.includes(card.state ?? 0))
.sortBy((card) => !CardUtils.isExpensifyCard(card.cardID))
.value();
Copy link
Contributor

Choose a reason for hiding this comment

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

Although the name is a bit weird, actually a standard equivalent is toSorted(compareFn). Let's use that!

@@ -318,10 +280,12 @@ function PaymentMethodList({
icon={item.icon}
disabled={item.disabled}
displayInDefaultIconColor
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
iconHeight={item.iconHeight || item.iconSize}
Copy link
Contributor

Choose a reason for hiding this comment

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

@filip-solecki What do you think? Should we reflect the old code directly, or assume that the original authors only meant to check for undefined with ||?

@tienifr Did you search for the usages? Do we have a convention to pass 0 as height/length meaning "not set"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Imo we should check only for undefined, 0 should be passed intentionally, but don't know what is the convention you mentioned

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean that there's sometimes a convention that 0 could mean "not set", like in the case of some IDs. Then, silencing the linter would make sense, and we could use || on purpose. If it's not the case, I think we should migrate to ?? and not silence the linter in this specific case.

Copy link
Contributor

Choose a reason for hiding this comment

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

@tienifr Let's adjust as @cubuspl42 suggested, and let's continue the work to ship it!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for bumping, and I agree that we should wrap things up!

@tienifr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been OOO. I'll handle this tomorrow morning.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated. TY!

@cubuspl42
Copy link
Contributor

Conflicts

@tienifr
Copy link
Contributor Author

tienifr commented Feb 15, 2024

@cubuspl42 Thanks for pointing that out. I'm updating the PR

@tienifr
Copy link
Contributor Author

tienifr commented Feb 15, 2024

@cubuspl42 I resolved the conflicts

@cubuspl42
Copy link
Contributor

Please take a look: #34257 (comment)

@blazejkustra
Copy link
Contributor

@tienifr Bump 😅

@tienifr
Copy link
Contributor Author

tienifr commented Feb 20, 2024

I'm updating

@tienifr
Copy link
Contributor Author

tienifr commented Feb 20, 2024

@cubuspl42 @blazejkustra updated to use toSorted

@cubuspl42
Copy link
Contributor

@tienifr Linter.

@cubuspl42
Copy link
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • 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 included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • 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 the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • 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 is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review 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 other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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 */
    • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • 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.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
wallet-ts-android-compressed.mp4
Android: mWeb Chrome
wallet-ts-android-web-compressed.mp4
iOS: Native
wallet-ts-ios-compressed.mp4
iOS: mWeb Safari
wallet-ts-ios-web-compressed.mp4
MacOS: Chrome / Safari
wallet-ts-web-converted.mp4
MacOS: Desktop

Copy link
Contributor

@cubuspl42 cubuspl42 left a comment

Choose a reason for hiding this comment

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

Please fix the linter and let's finally merge this

@tienifr
Copy link
Contributor Author

tienifr commented Feb 20, 2024

fixed

@melvin-bot melvin-bot bot requested a review from Julesssss February 20, 2024 10:00
@Julesssss Julesssss merged commit 661d5c2 into Expensify:main Feb 20, 2024
17 checks passed
@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.

.sortBy((card) => !CardUtils.isExpensifyCard(card.cardID))
.value();
.filter((card) => !card.isVirtual && !!card.domainName && CONST.EXPENSIFY_CARD.ACTIVE_STATES.includes(card.state ?? 0))
.toSorted((card1, card2) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this fully tested on all platforms? I am getting crash on iOS

https://stackoverflow.com/questions/76006398/tosorted-works-only-in-a-browser

Screenshot 2024-02-21 at 5 27 00 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

The platforms were tested, I wonder if it's due to another recently merged PR which conflicts with the changes (not a code conflict, but something that breaks due to these TS changes)

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that this code path wasn't triggered during our tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a conflict; this method isn't available on iOS. I'm not sure why we didn't catch this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fixing this right now

Copy link
Contributor

@cubuspl42 cubuspl42 Feb 22, 2024

Choose a reason for hiding this comment

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

#37073

Edit: I have some weird issues with ESLint on this PR, likely because of the changes in packages-lock.json. I don't have time to fix that, I'm pivoting.

Copy link
Contributor Author

@tienifr tienifr Feb 22, 2024

Choose a reason for hiding this comment

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

Why don't we just use sort? I tested and verified it achieved the same result. sort also returns the sorted result, the only difference is that it's sorted in-place.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because using sort together with React can lead to very difficult to debug bugs (as it's mutating the original array). I've seen buggy code related to sort in the Expensify code.

Using sort in this specific case would work, though. Still, I'd personally prefer to have some linter rule completely banning the usage of sort inside React components.

Copy link
Contributor

Choose a reason for hiding this comment

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

I closed the first PR (see explanation).

Second PR, switching back to _.sortBy: #37078

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/Julesssss in version: 1.4.44-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 1.4.44-13 🚀

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.

7 participants