-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expensify card page uses navigation for magic code #70736
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
Merged
mountiny
merged 11 commits into
Expensify:main
from
software-mansion-labs:feat/expensify-card-page-uses-navigation-for-magic-code
Oct 2, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
471e326
Expensify card page uses navigation for magic code
jmusial f4c792b
prettier
jmusial aeaa6cd
fix typo
jmusial a09a27d
move cotext hook to be closer to usage, fix comment
jmusial 6d4ccc3
add a display name
jmusial 86d9bc5
Merge branch 'main' into feat/expensify-card-page-uses-navigation-for…
jmusial 92a8e2c
fix var naming & remove unused code
jmusial 9d2fc00
update file name
jmusial 7c6ba66
Merge branch 'main' into feat/expensify-card-page-uses-navigation-for…
jmusial 4672a5c
reset card details on page exit
jmusial 0495109
Merge branch 'main' into feat/expensify-card-page-uses-navigation-for…
jmusial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/pages/settings/Wallet/ExpensifyCardPage/ExpensifyCardContextProvider.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import type {PropsWithChildren} from 'react'; | ||
| import React, {createContext, useMemo, useState} from 'react'; | ||
| import type {ExpensifyCardDetails} from '@src/types/onyx/Card'; | ||
|
|
||
| type ExpensifyCardContextProviderProps = { | ||
| cardsDetails: Record<number, ExpensifyCardDetails | null>; | ||
| setCardsDetails: React.Dispatch<React.SetStateAction<Record<number, ExpensifyCardDetails | null>>>; | ||
| isCardDetailsLoading: Record<number, boolean>; | ||
| setIsCardDetailsLoading: React.Dispatch<React.SetStateAction<Record<number, boolean>>>; | ||
| cardsDetailsErrors: Record<number, string>; | ||
| setCardsDetailsErrors: React.Dispatch<React.SetStateAction<Record<number, string>>>; | ||
| }; | ||
|
|
||
| const ExpensifyCardContext = createContext<ExpensifyCardContextProviderProps>({ | ||
| cardsDetails: {}, | ||
| setCardsDetails: () => {}, | ||
| isCardDetailsLoading: {}, | ||
| setIsCardDetailsLoading: () => {}, | ||
| cardsDetailsErrors: {}, | ||
| setCardsDetailsErrors: () => {}, | ||
| }); | ||
|
|
||
| /** | ||
| * Context to display revealed expensify card data and pass it between screens. | ||
| */ | ||
| function ExpensifyCardContextProvider({children}: PropsWithChildren) { | ||
| const [cardsDetails, setCardsDetails] = useState<Record<number, ExpensifyCardDetails | null>>({}); | ||
| const [isCardDetailsLoading, setIsCardDetailsLoading] = useState<Record<number, boolean>>({}); | ||
| const [cardsDetailsErrors, setCardsDetailsErrors] = useState<Record<number, string>>({}); | ||
|
|
||
| const value = useMemo( | ||
| () => ({ | ||
| cardsDetails, | ||
| setCardsDetails, | ||
| isCardDetailsLoading, | ||
| setIsCardDetailsLoading, | ||
| cardsDetailsErrors, | ||
| setCardsDetailsErrors, | ||
| }), | ||
| [cardsDetails, setCardsDetails, isCardDetailsLoading, setIsCardDetailsLoading, cardsDetailsErrors, setCardsDetailsErrors], | ||
| ); | ||
|
|
||
| return <ExpensifyCardContext.Provider value={value}>{children}</ExpensifyCardContext.Provider>; | ||
| } | ||
|
|
||
| export default ExpensifyCardContextProvider; | ||
| export {ExpensifyCardContext}; |
79 changes: 79 additions & 0 deletions
79
src/pages/settings/Wallet/ExpensifyCardPage/ExpensifyCardVerifyAccountPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import React, {useState} from 'react'; | ||
| import ValidateCodeActionContent from '@components/ValidateCodeActionModal/ValidateCodeActionContent'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import {revealVirtualCardDetails} from '@libs/actions/Card'; | ||
| import {requestValidateCodeAction, resetValidateActionCodeSent} from '@libs/actions/User'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; | ||
| import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type SCREENS from '@src/SCREENS'; | ||
| import type {ExpensifyCardDetails} from '@src/types/onyx/Card'; | ||
| import type {Errors} from '@src/types/onyx/OnyxCommon'; | ||
| import useExpensifyCardContext from './useExpensifyCardContext'; | ||
|
|
||
| type ExpensifyCardVerifyAccountPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.WALLET.DOMAIN_CARD_CONFIRM_MAGIC_CODE>; | ||
|
|
||
| function ExpensifyCardVerifyAccountPage({ | ||
| route: { | ||
| params: {cardID = ''}, | ||
| }, | ||
| }: ExpensifyCardVerifyAccountPageProps) { | ||
| const {translate} = useLocalize(); | ||
| const [validateError, setValidateError] = useState<Errors>({}); | ||
| const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false}); | ||
| const primaryLogin = account?.primaryLogin ?? ''; | ||
| const {setIsCardDetailsLoading, setCardsDetails, setCardsDetailsErrors} = useExpensifyCardContext(); | ||
|
|
||
| const handleRevealCardDetails = (validateCode: string) => { | ||
| setIsCardDetailsLoading((prevState: Record<number, boolean>) => ({ | ||
| ...prevState, | ||
| [cardID]: true, | ||
| })); | ||
| // We can't store the response in Onyx for security reasons. | ||
| // That is why this action is handled manually and the response is stored in a local state. | ||
| // Hence eslint disable here. | ||
| // eslint-disable-next-line rulesdir/no-thenable-actions-in-views | ||
| revealVirtualCardDetails(Number.parseInt(cardID, 10), validateCode) | ||
| .then((value) => { | ||
| setCardsDetails((prevState: Record<number, ExpensifyCardDetails | null>) => ({...prevState, [cardID]: value})); | ||
| setCardsDetailsErrors((prevState) => ({ | ||
| ...prevState, | ||
| [cardID]: '', | ||
| })); | ||
| Navigation.goBack(ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(cardID)); | ||
| }) | ||
| .catch((error: string) => { | ||
| // Displaying magic code errors is handled in the modal, no need to set it on the card | ||
| setCardsDetailsErrors((prevState) => ({ | ||
| ...prevState, | ||
| [cardID]: error, | ||
| })); | ||
| }) | ||
| .finally(() => { | ||
| setIsCardDetailsLoading((prevState: Record<number, boolean>) => ({...prevState, [cardID]: false})); | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <ValidateCodeActionContent | ||
| title={translate('cardPage.validateCardTitle')} | ||
| descriptionPrimary={translate('cardPage.enterMagicCode', {contactMethod: primaryLogin})} | ||
| sendValidateCode={() => requestValidateCodeAction()} | ||
| validateCodeActionErrorField="revealExpensifyCardDetails" | ||
| handleSubmitForm={handleRevealCardDetails} | ||
| validateError={validateError} | ||
| clearError={() => setValidateError({})} | ||
| onClose={() => { | ||
| resetValidateActionCodeSent(); | ||
| Navigation.goBack(ROUTES.SETTINGS_WALLET_DOMAIN_CARD.getRoute(cardID)); | ||
| }} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| ExpensifyCardVerifyAccountPage.displayName = 'ExpensifyCardVerifyAccountPage'; | ||
|
|
||
| export default ExpensifyCardVerifyAccountPage; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the card details were stored in the component state, so when the RHP was closed the user had to re-enter the magic code. Now, the details are stored in the app context, meaning they persist until a hard refresh. Are we okay with this change in behavior?
Would love your input here, @mountiny.
Screen.Recording.2025-09-19.at.2.07.29.AM.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gentle bump @mountiny
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the RHP is closed and reopened, is new code always sent?
If yes we should reset it
if no, if you start a different flow that will need the magic code, that reset the form, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Common
Old behaviour:
8. You need to go through 3 - 5 to see the card details (card details stored in
state)New behaviour:
8. You can see the card details (stored in
context)Common:
9. Close the Card details RHP
10. Click on card Bdetails
11. You need to go through 3 - 5 to see the card details
I'll reset it on closing to align with old behaviour
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooh you mean card details like PAN and pic, ok I do think that was in state only on purpose. Why do you need to add it to the context to share it across screens? I believe we want this data to be as safe and secure as possible so the previous approach was safer imho