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

Ensure only latest bank account shows default badge #51437

Merged
merged 16 commits into from
Nov 14, 2024

Conversation

Shahidullah-Muffakir
Copy link
Contributor

Details

Updated logic to ensure only the latest added bank account is marked as default, preventing two accounts from being shown as default without needing a page refresh.

Fixed Issues

$ #50829
PROPOSAL: #50829 (comment)

Tests

  1. Log in to the account that has no bank accounts.
  2. Navigate to Settings > Wallet and click on Add Bank Account > Personal Bank Account.
  3. On the Plaid modal, search and select Wells Fargo bank, enter credentials (e.g., user_good / pass_good), and complete the process.
  4. Verify that the added bank account is not marked as the default(because we are not showing default badge if there is only one bank account)
  5. Repeat the process to add a second bank account by selecting Chase bank.
  6. Verify that only the newly added bank account is marked as default, and the previous account does not show the default badge.
  7. Refresh the page and confirm that the correct default account is still displayed.
  • Verify that no errors appear in the JS console

Offline tests

This feature requires an active internet connection.

QA Steps

  1. Log in to the account that has no bank accounts.
  2. Navigate to Settings > Wallet and click on Add Bank Account > Personal Bank Account.
  3. On the Plaid modal, search and select Wells Fargo bank, enter credentials (e.g., user_good / pass_good), and complete the process.
  4. Verify that the added bank account is not marked as the default(because we are not showing default badge if there is only one bank account)
  5. Repeat the process to add a second bank account by selecting Chase bank.
  6. Verify that only the newly added bank account is marked as default, and the previous account does not show the default badge.
  7. Refresh the page and confirm that the correct default account is still displayed.
  • 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 either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • 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 UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design 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
Android.20native.mp4
Android: mWeb Chrome
Android.20mweb.20chrome.mp4
iOS: Native
iOS.20native.mp4
iOS: mWeb Safari
ios.20mweb.20safari.mp4
MacOS: Chrome / Safari
macos.20safari.mp4
MacOS: Desktop
macos.20desktop.mp4

@Shahidullah-Muffakir Shahidullah-Muffakir requested a review from a team as a code owner October 24, 2024 19:04
@melvin-bot melvin-bot bot requested review from thesahindia and removed request for a team October 24, 2024 19:04
Copy link

melvin-bot bot commented Oct 24, 2024

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

@thesahindia
Copy link
Member

I will review it in a few hours!

@thesahindia
Copy link
Member

Screenshot 2024-10-27 at 2 33 35 AM

When I am adding the second account I am getting an error.
@Shahidullah-Muffakir, could you please check if you are getting same error on main?

@Shahidullah-Muffakir
Copy link
Contributor Author

@thesahindia, I tested now, I could add the 2nd account.
It seems we need to test it with different banks, one time CHASE bank and for the 2nd account with WELLS FARGO.
Thank you.

@thesahindia
Copy link
Member

thesahindia commented Oct 28, 2024

@thesahindia, I tested now, I could add the 2nd account. It seems we need to test it with different banks, one time CHASE bank and for the 2nd account with WELLS FARGO. Thank you.

I did the same. Trying again.
Edit: It was something account specific. I can't repro on a different account.

@thesahindia
Copy link
Member

Screen.Recording.2024-10-28.at.6.46.24.PM.mov

When I add the second account the default badge is appearing on the previously added bank account. @Shahidullah-Muffakir, could you please retest your changes?

@Shahidullah-Muffakir
Copy link
Contributor Author

Screen.Recording.2024-10-28.at.6.46.24.PM.mov

When I add the second account the default badge is appearing on the previously added bank account. @Shahidullah-Muffakir, could you please retest your changes?

@thesahindia, Now I noticed an issue with the created date for each account. I just created two new accounts, but one shows a created date from several months ago, even as far back as 2023.Since we’re using this date to show the default badge on the latest added account, it’s causing incorrect badge assignments.
Could you clarify what the created date represents? Is it the date the user added their bank account to Expensify, or the date the account was initially opened at the bank? Thank you.

First account:
Screenshot 2024-10-29 at 1 27 40 AM

Second account:
Screenshot 2024-10-29 at 1 28 04 AM

@thesahindia
Copy link
Member

Now I noticed an issue with the created date for each account. I just created two new accounts, but one shows a created date from several months ago, even as far back as 2023.Since we’re using this date to show the default badge on the latest added account, it’s causing incorrect badge assignments.
Could you clarify what the created date represents? Is it the date the user added their bank account to Expensify, or the date the account was initially opened at the bank? Thank you.

I think @NikkiWines might be able to answer this.

@NikkiWines
Copy link
Contributor

created should be the date the bank account was added into the DB... so it should reflect the order the accounts were added. If those accounts are the testing plaid accounts there might be some weirdness with the created dates since they're re-used regularly 🤔

@Shahidullah-Muffakir
Copy link
Contributor Author

created should be the date the bank account was added into the DB... so it should reflect the order the accounts were added. If those accounts are the testing plaid accounts there might be some weirdness with the created dates since they're re-used regularly 🤔

Thanks for explaining! If the created date is the date the bank account was added to the database, then that should work fine for what we need. I also think that the issue might be because of the test accounts. I noticed that when I re-added the same test account, it showed the correct created date as today’s date and time. So, it seems like the old dates we’re seeing could be because these test accounts.

@Shahidullah-Muffakir
Copy link
Contributor Author

I noticed something during testing:

  1. I added a Chase Bank account (“Plaid Checking”).
  2. Then, I added another account, WELLS FARGO (“Plaid Saving”).
  3. I deleted the Chase Bank account from Step 1.
  4. I re-added the Chase Bank account from Step 1.

When I re-added the account in Step 4, I saw that it kept the original created date from Step 1, rather than updating to the current date. It seems like we aren’t updating the created date if a user re-adds a deleted payment method.

@NikkiWines , do we update the created date for real payment methods in production when a user re-adds a deleted method, or is this just an issue with test accounts? If we can confirm this, I think we will be good to proceed with our PR.

@thesahindia , based on this, we can test our approach by using a new user account. If we add two accounts with a new user, the most recently added should correctly show as the default.

Thank you.

@NikkiWines
Copy link
Contributor

NikkiWines commented Nov 1, 2024

@NikkiWines , do we update the created date for real payment methods in production when a user re-adds a deleted method, or is this just an issue with test accounts? If we can confirm this, I think we will be good to proceed with our PR.

Sorry for the delay, I can confirm that when re-adding a deleted account, the original created is used - it's not updated to reflect the most recent time the account was added (for both test and non-test accounts)

@Shahidullah-Muffakir
Copy link
Contributor Author

@NikkiWines , do we update the created date for real payment methods in production when a user re-adds a deleted method, or is this just an issue with test accounts? If we can confirm this, I think we will be good to proceed with our PR.

Sorry for the delay, I can confirm that when re-adding a deleted account, the original created is used - it's not updated to reflect the most recent time the account was added (for both test and non-test accounts)

Thanks for confirming! Considering this, our current approach won’t work as expected. We’ll need to find another solution, maybe we can store the ID of the latest payment method in Onyx and use that ID to determine which account shows the default badge.

@thesahindia
Copy link
Member

@Shahidullah-Muffakir, any progress on the new solution?

@Shahidullah-Muffakir
Copy link
Contributor Author

@Shahidullah-Muffakir, any progress on the new solution?

@thesahindia, will push the changes in few hours.

@Shahidullah-Muffakir
Copy link
Contributor Author

@thesahindia Changes are complete. Let me know if anything else is needed, Thank you.

Copy link
Contributor

@NikkiWines NikkiWines left a comment

Choose a reason for hiding this comment

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

Sorry to do this, since I know there's been a fair amount of back and forth on this issue already... But after doing some digging, I think we actually need to set the default badge according to the bankAccountID saved in userWallet.walletLinkedAccountID, as that's the value we reference on the backend to determine the default account.

Additionally, some bankAccounts are not added via plaid, so relying on that value may b unreliable.

Sorry!! Let me know if that doesn't make sense

@Shahidullah-Muffakir
Copy link
Contributor Author

Sorry to do this, since I know there's been a fair amount of back and forth on this issue already... But after doing some digging, I think we actually need to set the default badge according to the bankAccountID saved in userWallet.walletLinkedAccountID, as that's the value we reference on the backend to determine the default account.

Additionally, some bankAccounts are not added via plaid, so relying on that value may b unreliable.

Sorry!! Let me know if that doesn't make sense

No issue, I’ll make the update. Thanks for explaining! We’ll use bankAccountID || fundID since that’s what’s stored in walletLinkedAccountID here:

walletLinkedAccountID: bankAccountID || fundID,

@Shahidullah-Muffakir
Copy link
Contributor Author

Sorry to do this, since I know there's been a fair amount of back and forth on this issue already... But after doing some digging, I think we actually need to set the default badge according to the bankAccountID saved in userWallet.walletLinkedAccountID, as that's the value we reference on the backend to determine the default account.

Additionally, some bankAccounts are not added via plaid, so relying on that value may b unreliable.

Sorry!! Let me know if that doesn't make sense

@NikkiWines , Just to confirm, should the key be named LATEST_ADDED_WALLET_LINKED_ACCOUNT_ID, or do you prefer something else? Thanks!

/** The ID of the latest added wallet linked account */
   LATEST_ADDED_WALLET_LINKED_ACCOUNT_ID: 'latestAddedWalletLinkedAccountID',

@NikkiWines
Copy link
Contributor

I think you could just use walletLinkedAccountID which is what we use elsewhere in the product, but you shouldn't need a new onyx key for this. You should be able to get the value from the USER_WALLET onyx key.

@Shahidullah-Muffakir
Copy link
Contributor Author

Shahidullah-Muffakir commented Nov 13, 2024

I think you could just use walletLinkedAccountID which is what we use elsewhere in the product, but you shouldn't need a new onyx key for this. You should be able to get the value from the USER_WALLET onyx key.

Currently, when we add a new payment method with addPersonalBankAccount, the userWallet.walletLinkedAccountID is not updated. walletLinkedAccountID only gets updated in two cases:

  1. when a user manually sets a payment method as default by clicking 'Make default payment method,'
  2. or when the OpenPaymentsPage API runs (only triggered when the Wallet page opens).
Screenshot 2024-11-13 at 5 19 41 AM

Given the current issue, relying on these alone won’t work.

So, considering this, we have a couple of options:

  1. When we add a new payment method via addPersonalBankAccount, the backend could save userWallet.walletLinkedAccountID as the latest added account if isDefault is true. This would be similar to how OpenPaymentsPage returns userWallet.walletLinkedAccountID . Then, we could use this to show the default.
    we will still need to add the same changes, as I added in the last approach in the shouldShowDefaultBadge function.
  2. Alternatively, a more straightforward approach would be to call the OpenPaymentsPage endpoint right after a user adds a new payment method. Since OpenPaymentsPage returns only one isDefault true.
    We need to add bankAccountList in deps array of this useEffect:
    useEffect(() => {
    if (network.isOffline) {
    return;
    }
    PaymentMethods.openWalletPage();
    }, [network.isOffline]);
  3. If two bank accounts have isDefault: true, we could show the default badge only for the account whose ID does not match walletLinkedAccountID, since that ID hasn't updated yet.
    I think this third approach could work best.

@Shahidullah-Muffakir
Copy link
Contributor Author

Additionally, some bankAccounts are not added via plaid, so relying on that value may b unreliable.

When I click on 'Add Bank Account,' it directly opens the Plaid modal, and I couldn’t find any other way to add a bank account. Could you clarify how bank accounts might be added without Plaid. Thank you.

@NikkiWines
Copy link
Contributor

Currently, when we add a new payment method with addPersonalBankAccount, the userWallet.walletLinkedAccountID is not updated. walletLinkedAccountID only gets updated in two cases:

Oh, hmm. We do update it on the backend but the onyx key isn't appropriately updated currently. I can push up a change that will fix that.

When I click on 'Add Bank Account,' it directly opens the Plaid modal, and I couldn’t find any other way to add a bank account. Could you clarify how bank accounts might be added without Plaid. Thank you.

Users can add personal bank accouns without plaid via Expensify Classic.

image

@Shahidullah-Muffakir
Copy link
Contributor Author

Oh, hmm. We do update it on the backend but the onyx key isn't appropriately updated currently. I can push up a change that will fix that.

Okay, that sounds great, this change should work then. Thanks

Users can add personal bank accouns without plaid via Expensify Classic.

Got it, thanks for clarifying.

@NikkiWines
Copy link
Contributor

PR is up to resolve this, I'll update here when it's live but for now you can proceed as though we'll use the walletLinkedAccountID from the USER_WALLET key to determine the default

@NikkiWines
Copy link
Contributor

Backend PR has been merged, should be on production by thursday

@Shahidullah-Muffakir
Copy link
Contributor Author

Backend PR has been merged, should be on production by thursday

Thank you! I’ll test it with the backend changes on Thursday and push the updates afterward.

@Shahidullah-Muffakir
Copy link
Contributor Author

I added changes to use userWallet.walletLinkedAccountID.
Not sure if the failing test is related, as it seems unrelated to the changes made.

@NikkiWines
Copy link
Contributor

Hmm yeah the failing test does seem unrelated, try merging main again @Shahidullah-Muffakir?

@Shahidullah-Muffakir
Copy link
Contributor Author

Hmm yeah the failing test does seem unrelated, try merging main again @Shahidullah-Muffakir?

@NikkiWines, Thank you, Merging main fixed the issue.

@NikkiWines
Copy link
Contributor

Backend changes are live! You should be getting the updated walletLinkedAccountID now

@Shahidullah-Muffakir
Copy link
Contributor Author

Yes, I tested it with the new backend changes, and it’s working well. Thanks.

Copy link
Contributor

@NikkiWines NikkiWines left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for the perserverence here 🙇

@NikkiWines NikkiWines merged commit b0d785c into Expensify:main Nov 14, 2024
16 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.

Copy link
Contributor

🚀 Deployed to staging by https://github.com/NikkiWines in version: 9.0.63-1 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅
🤖🔄 android HybridApp 🤖🔄 success ✅
🍎🔄 iOS HybridApp 🍎🔄 failure ❌

Copy link
Contributor

🚀 Deployed to production by https://github.com/chiragsalian in version: 9.0.63-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅
🤖🔄 android HybridApp 🤖🔄 failure ❌
🍎🔄 iOS HybridApp 🍎🔄 failure ❌

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