@@ -11,21 +11,23 @@ import ONYXKEYS from '@src/ONYXKEYS';
1111import ROUTES from '@src/ROUTES' ;
1212
1313/**
14- * Shared magic-code handling for the wallet KYC personal-details flows. Changing an existing phone number is protected
15- * by a magic code because it is used for card 3DS verification, so both flows send the user to a dedicated
16- * confirmation screen to enter the code before the change is submitted.
14+ * Shared magic-code handling for the wallet KYC personal-details flows. Setting a phone number, whether for the first
15+ * time or changing an existing one, is protected by a magic code because it is used for card 3DS verification, so
16+ * both flows send the user to a dedicated confirmation screen to enter the code before the change is submitted.
1717 */
1818function useWalletPhoneMagicCode ( ) {
1919 const [ privatePersonalDetails ] = useOnyx ( ONYXKEYS . PRIVATE_PERSONAL_DETAILS ) ;
2020
21- // Submits the personal details, first routing to the magic-code screen when an existing phone number is changed.
21+ // Submits the personal details, first routing to the magic-code screen when a phone number is being set to a new
22+ // value. Setting a phone for the first time must be protected too: it is used for card 3DS verification, so an
23+ // attacker who gains account access before any phone is on file could otherwise set one without a code.
2224 const submitPersonalDetails = ( personalDetails : UpdatePersonalDetailsForWalletParams ) => {
2325 // The stored phone number keeps its country code, so normalize it the same way as the submitted one before
2426 // comparing, otherwise an unchanged phone would look like a change and wrongly prompt for a magic code.
2527 const storedPhoneNumber = privatePersonalDetails ?. phoneNumber ;
2628 const normalizedStoredPhoneNumber = ( storedPhoneNumber && parsePhoneNumber ( storedPhoneNumber , { regionCode : CONST . COUNTRY . US } ) . number ?. significant ) ?? '' ;
27- const hasPhoneNumberChanged = ! ! normalizedStoredPhoneNumber && personalDetails . phoneNumber !== normalizedStoredPhoneNumber ;
28- if ( hasPhoneNumberChanged ) {
29+ const isSettingPhoneNumber = ! ! personalDetails . phoneNumber && personalDetails . phoneNumber !== normalizedStoredPhoneNumber ;
30+ if ( isSettingPhoneNumber ) {
2931 Navigation . navigate ( ROUTES . SETTINGS_ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE . getRoute ( ) ) ;
3032 return ;
3133 }
0 commit comments