Repository navigation
[Payment due @huult] feat(wallet): prompt for magic code when changing wallet phone #95566
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
rafecolton
merged 14 commits into
Expensify:main
from
dukenv0307:fix/623849-wallet-magic-code
Jul 29, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a9b8725
feat(wallet): prompt for magic code when changing wallet phone
jasperhuangg 3c186d8
feat(wallet): prompt for magic code in Settings wallet KYC flow
jasperhuangg 8aa1b72
fix(wallet): normalize stored phone before magic-code change check
jasperhuangg 5d61c46
Merge remote-tracking branch 'origin/main' into jasper/wallet-magic-code
jasperhuangg 86ac964
Merge branch 'main' into fix/623849-wallet-magic-code
dukenv0307 deacc13
update bot comments
dukenv0307 e5eff23
Compare against the wallet phone on file
dukenv0307 f881f56
Merge branch 'main' into fix/623849-wallet-magic-code
dukenv0307 9d6e40c
get stored phonenumber from privatePersonalDetails
dukenv0307 29ded33
add test for useWalletPhoneMagicCode hook
dukenv0307 e006ecb
use new route for confirmation page
dukenv0307 b9061cc
Merge branch 'main' into fix/623849-wallet-magic-code
dukenv0307 29b4539
fix(wallet): require magic code when setting phone for first time
dukenv0307 a9c9540
ts fix
dukenv0307 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
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
75 changes: 75 additions & 0 deletions
75
src/pages/EnablePayments/shared/WalletConfirmMagicCodePage.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,75 @@ | ||
| import useOnyx from '@hooks/useOnyx'; | ||
|
|
||
| import Navigation from '@libs/Navigation/Navigation'; | ||
|
|
||
| import getSubstepValues from '@pages/EnablePayments/Wallet/utils/getSubstepValues'; | ||
|
|
||
| import {clearWalletAdditionalDetailsErrors, updatePersonalDetails} from '@userActions/Wallet'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import INPUT_IDS from '@src/types/form/WalletAdditionalDetailsForm'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
|
|
||
| import {useEffect, useRef} from 'react'; | ||
|
|
||
| import getWalletPersonalDetailsParams from './getWalletPersonalDetailsParams'; | ||
| import WalletMagicCodePrompt from './WalletMagicCodePrompt'; | ||
|
|
||
| const PERSONAL_INFO_STEP_KEYS = INPUT_IDS.PERSONAL_INFO_STEP; | ||
|
|
||
| /** | ||
| * Dedicated screen for entering the magic code that authorizes a wallet phone-number change. Living on its own route | ||
| * (rather than being rendered inline in the step page) keeps the code form stably mounted, so a wrong-code error is | ||
| * not wiped by a remount while the submission response settles. | ||
| */ | ||
| function WalletConfirmMagicCodePage() { | ||
| const [walletAdditionalDetails] = useOnyx(ONYXKEYS.WALLET_ADDITIONAL_DETAILS); | ||
| const [walletAdditionalDetailsDraft] = useOnyx(ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS_DRAFT); | ||
| const [formData] = useOnyx(ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS); | ||
|
|
||
| // The submitted details live in the form draft, so rebuild them here and submit together with the entered code. | ||
| const values = getSubstepValues(PERSONAL_INFO_STEP_KEYS, walletAdditionalDetailsDraft, walletAdditionalDetails); | ||
| const personalDetails = getWalletPersonalDetailsParams(values); | ||
|
|
||
| const confirm = (validateCode: string) => { | ||
| updatePersonalDetails({...personalDetails, validateCode}); | ||
| }; | ||
|
|
||
| useEffect( | ||
| () => () => { | ||
| clearWalletAdditionalDetailsErrors(); | ||
| }, | ||
| [], | ||
| ); | ||
|
|
||
| const hasErrors = !!walletAdditionalDetails?.errorCode || !isEmptyObject(walletAdditionalDetails?.errors); | ||
|
|
||
| const wasLoading = useRef(false); | ||
| useEffect(() => { | ||
| if (formData?.isLoading) { | ||
| wasLoading.current = true; | ||
| return; | ||
| } | ||
| // Once a submission finishes cleanly the code was accepted, so advance to the identity-verification step; | ||
| // EnablePaymentsPage corrects the URL if the real next step differs (e.g. KBA questions). Any error (incorrect | ||
| // code, SSN, or a generic failure) keeps the screen open to retry. | ||
| if (wasLoading.current && !hasErrors) { | ||
| wasLoading.current = false; | ||
| Navigation.navigate(ROUTES.SETTINGS_ENABLE_PAYMENTS.getRoute({page: CONST.ENABLE_PAYMENTS.PAGE_NAMES.VERIFY_IDENTITY})); | ||
| } | ||
| wasLoading.current = false; | ||
| }, [formData?.isLoading, hasErrors]); | ||
|
|
||
| return ( | ||
| <WalletMagicCodePrompt | ||
| onConfirm={confirm} | ||
| onClose={() => Navigation.goBack()} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| WalletConfirmMagicCodePage.displayName = 'WalletConfirmMagicCodePage'; | ||
|
|
||
| export default WalletConfirmMagicCodePage; | ||
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 ValidateCodeActionContent from '@components/ValidateCodeActionModal/ValidateCodeActionContent'; | ||
|
|
||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import usePrimaryContactMethod from '@hooks/usePrimaryContactMethod'; | ||
|
|
||
| import {getLatestErrorMessageField} from '@libs/ErrorUtils'; | ||
|
|
||
| import {requestValidateCodeAction} from '@userActions/User'; | ||
| import {clearWalletAdditionalDetailsErrors} from '@userActions/Wallet'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| type WalletMagicCodePromptProps = { | ||
| /** Called with the entered magic code to confirm the phone number change */ | ||
| onConfirm: (validateCode: string) => void; | ||
|
|
||
| /** Called when the prompt is dismissed */ | ||
| onClose: () => void; | ||
| }; | ||
|
|
||
| /** Magic code prompt shown in the wallet KYC flows when changing the phone number used for card 3DS verification */ | ||
| function WalletMagicCodePrompt({onConfirm, onClose}: WalletMagicCodePromptProps) { | ||
| const {translate} = useLocalize(); | ||
| const [walletAdditionalDetails] = useOnyx(ONYXKEYS.WALLET_ADDITIONAL_DETAILS); | ||
| const [formData] = useOnyx(ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS); | ||
| const primaryLogin = usePrimaryContactMethod(); | ||
|
|
||
| return ( | ||
| <ValidateCodeActionContent | ||
| validateCodeActionErrorField={CONST.WALLET.VALIDATE_CODE_ERROR_FIELD} | ||
| handleSubmitForm={onConfirm} | ||
| isLoading={formData?.isLoading} | ||
| title={translate('delegate.makeSureItIsYou')} | ||
| descriptionPrimary={translate('contacts.enterSecurityCode', primaryLogin ?? '')} | ||
| sendValidateCode={() => requestValidateCodeAction()} | ||
| validateError={getLatestErrorMessageField(walletAdditionalDetails)} | ||
| clearError={clearWalletAdditionalDetailsErrors} | ||
| onClose={onClose} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default WalletMagicCodePrompt; |
27 changes: 27 additions & 0 deletions
27
src/pages/EnablePayments/shared/getWalletPersonalDetailsParams.ts
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,27 @@ | ||
| import type {UpdatePersonalDetailsForWalletParams} from '@libs/API/parameters'; | ||
| import {parsePhoneNumber} from '@libs/PhoneNumber'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import type {PersonalInfoStepProps} from '@src/types/form/WalletAdditionalDetailsForm'; | ||
|
|
||
| /** | ||
| * Builds the wallet personal-details API params from the collected form values. Shared by the personal-info and | ||
| * additional-details flows and by the magic-code confirmation screen so the phone-change check and the | ||
| * code submission always build identical params. The phone number is normalized to significant digits to match how | ||
| * the backend stores it. | ||
| */ | ||
| function getWalletPersonalDetailsParams(values: PersonalInfoStepProps): UpdatePersonalDetailsForWalletParams { | ||
| return { | ||
| phoneNumber: (values.phoneNumber && parsePhoneNumber(values.phoneNumber, {regionCode: CONST.COUNTRY.US}).number?.significant) ?? '', | ||
| legalFirstName: values.legalFirstName ?? '', | ||
| legalLastName: values.legalLastName ?? '', | ||
| addressStreet: values.addressStreet ?? '', | ||
| addressCity: values.addressCity ?? '', | ||
| addressState: values.addressState ?? '', | ||
| addressZip: values.addressZipCode ?? '', | ||
| dob: values.dob ?? '', | ||
| ssn: values.ssn ?? '', | ||
| }; | ||
| } | ||
|
|
||
| export default getWalletPersonalDetailsParams; |
42 changes: 42 additions & 0 deletions
42
src/pages/EnablePayments/shared/useWalletPhoneMagicCode.ts
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,42 @@ | ||
| import useOnyx from '@hooks/useOnyx'; | ||
|
|
||
| import type {UpdatePersonalDetailsForWalletParams} from '@libs/API/parameters'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import {parsePhoneNumber} from '@libs/PhoneNumber'; | ||
|
|
||
| import {updatePersonalDetails} from '@userActions/Wallet'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
|
|
||
| /** | ||
| * Shared magic-code handling for the wallet KYC personal-details flows. Setting a phone number, whether for the first | ||
| * time or changing an existing one, is protected by a magic code because it is used for card 3DS verification, so | ||
| * both flows send the user to a dedicated confirmation screen to enter the code before the change is submitted. | ||
| */ | ||
| function useWalletPhoneMagicCode() { | ||
| const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS); | ||
|
|
||
| // Submits the personal details, first routing to the magic-code screen when a phone number is being set to a new | ||
| // value. Setting a phone for the first time must be protected too: it is used for card 3DS verification, so an | ||
| // attacker who gains account access before any phone is on file could otherwise set one without a code. | ||
| const submitPersonalDetails = (personalDetails: UpdatePersonalDetailsForWalletParams) => { | ||
| // The stored phone number keeps its country code, so normalize it the same way as the submitted one before | ||
| // comparing, otherwise an unchanged phone would look like a change and wrongly prompt for a magic code. | ||
| const storedPhoneNumber = privatePersonalDetails?.phoneNumber; | ||
| const normalizedStoredPhoneNumber = (storedPhoneNumber && parsePhoneNumber(storedPhoneNumber, {regionCode: CONST.COUNTRY.US}).number?.significant) ?? ''; | ||
| const isSettingPhoneNumber = !!personalDetails.phoneNumber && personalDetails.phoneNumber !== normalizedStoredPhoneNumber; | ||
| if (isSettingPhoneNumber) { | ||
| Navigation.navigate(ROUTES.SETTINGS_ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE.getRoute()); | ||
| return; | ||
| } | ||
|
|
||
| // Attempt to set the personal details | ||
| updatePersonalDetails(personalDetails); | ||
| }; | ||
|
|
||
| return {submitPersonalDetails}; | ||
| } | ||
|
|
||
| export default useWalletPhoneMagicCode; |
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.
Coming from #102336, navigation here always opens the Settings wallet identity page after the magic code is accepted.
useWalletPhoneMagicCodeis shared with the IOU pay flow (Pay/AdditionalDetails/AdditionalDetailsStep.tsx), so paying an IOU with a personal bank account lands here too.The pay-flow page stays mounted underneath and also advances to Onfido from
userWallet.currentStep. This page then mounts a second Onfido into the same#onfido-mountcontainer. The SDK renders into the hidden screen, and the visible one stays blank.