Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3644,11 +3644,14 @@ const CONST = {
MINIMUM_FEE: 0,
},
},
// Error field used by the magic code prompt shown when changing the phone number protected for card 3DS verification
VALIDATE_CODE_ERROR_FIELD: 'walletPhoneNumber',
ERROR: {
// If these get updated, we need to update the codes on the Web side too
SSN: 'ssnError',
KBA: 'kbaNeeded',
KYC: 'kycFailed',
INCORRECT_MAGIC_CODE: 'incorrectMagicCode',
FULL_SSN_NOT_FOUND: 'Full SSN not found',
MISSING_FIELD: 'Missing required additional details fields',
WRONG_ANSWERS: 'Wrong answers',
Expand Down
4 changes: 4 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,10 @@ const ROUTES = {
return `${base}${pagePart}${subPagePart}${actionPart}` as const;
},
},
SETTINGS_ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE: {
route: 'settings/wallet/enable-payments/confirm-magic-code',
getRoute: () => 'settings/wallet/enable-payments/confirm-magic-code' as const,
},
SETTINGS_WALLET_UNSHARE_BANK_ACCOUNT: {
route: 'settings/wallet/:bankAccountID/unshare-bank-account',
getRoute: (bankAccountID: number | undefined) => `settings/wallet/${bankAccountID}/unshare-bank-account` as const,
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ const SCREENS = {
IMPORT_TRANSACTIONS_SPREADSHEET: 'Settings_Wallet_Import_Transactions_Spreadsheet',
TRANSACTIONS_IMPORTED: 'Settings_Wallet_Transactions_Imported',
ENABLE_PAYMENTS: 'Settings_Wallet_EnablePayments',
ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE: 'Settings_Wallet_EnablePayments_ConfirmMagicCode',
CARD_ACTIVATE: 'Settings_Wallet_Card_Activate',
CARD_CHANGE_PIN: 'Settings_Wallet_Card_Change_PIN',
CARD_CHANGE_PIN_ATM: 'Settings_Wallet_Card_Change_PIN_ATM',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type UpdatePersonalDetailsForWalletParams = {
addressZip: string;
dob: string;
ssn: string;
validateCode?: string;
};

export default UpdatePersonalDetailsForWalletParams;
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.SETTINGS.WALLET.IMPORT_TRANSACTIONS_SPREADSHEET]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/ImportTransactionsSpreadsheetPage').default,
[SCREENS.SETTINGS.WALLET.TRANSACTIONS_IMPORTED]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/TransactionsImportedPage').default,
[SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS]: () => require<ReactComponentModule>('../../../../pages/EnablePayments/Wallet/EnablePayments').default,
[SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE]: () => require<ReactComponentModule>('../../../../pages/EnablePayments/shared/WalletConfirmMagicCodePage').default,
[SCREENS.SETTINGS.WALLET.UNSHARE_BANK_ACCOUNT]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/UnshareBankAccount/UnshareBankAccount').default,
[SCREENS.SETTINGS.WALLET.ENABLE_GLOBAL_REIMBURSEMENTS_BUSINESS]: () =>
require<ReactComponentModule>('../../../../pages/settings/Wallet/EnableGlobalReimbursements/EnableGlobalReimbursementsBusinessPage').default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const SETTINGS_TO_RHP: Partial<Record<keyof SettingsSplitNavigatorParamList, str
SCREENS.SETTINGS.WALLET.IMPORT_TRANSACTIONS_SPREADSHEET,
SCREENS.SETTINGS.WALLET.TRANSACTIONS_IMPORTED,
SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS,
SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE,
SCREENS.SETTINGS.WALLET.UNSHARE_BANK_ACCOUNT,
SCREENS.SETTINGS.WALLET.ENABLE_GLOBAL_REIMBURSEMENTS_BUSINESS,
SCREENS.SETTINGS.WALLET.ENABLE_GLOBAL_REIMBURSEMENTS_AGREEMENTS,
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
path: ROUTES.SETTINGS_ENABLE_PAYMENTS.route,
exact: true,
},
[SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE]: {
path: ROUTES.SETTINGS_ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE.route,
exact: true,
},
[SCREENS.SETTINGS.WALLET.UNSHARE_BANK_ACCOUNT]: {
path: ROUTES.SETTINGS_WALLET_UNSHARE_BANK_ACCOUNT.route,
exact: true,
Expand Down
1 change: 1 addition & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ type SettingsNavigatorParamList = {
subPage?: EnablePaymentsSubPageType;
action?: 'edit';
};
[SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE]: undefined;
[SCREENS.SETTINGS.WALLET.UNSHARE_BANK_ACCOUNT]: {
bankAccountID: string;
};
Expand Down
8 changes: 8 additions & 0 deletions src/libs/actions/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ function resetWalletAdditionalDetailsDraft() {
Onyx.set(ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS_DRAFT, null);
}

/**
* Clears the errors shown while confirming a magic code in the wallet additional-details step
*/
function clearWalletAdditionalDetailsErrors() {
Onyx.merge(ONYXKEYS.WALLET_ADDITIONAL_DETAILS, {errors: null, errorCode: null});
}

function issuerEncryptPayloadCallback(nonce: string, nonceSignature: string, certificates: string[], cardID: number): Promise<IOSEncryptPayload> {
// eslint-disable-next-line rulesdir/no-api-side-effects-method
return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.CREATE_DIGITAL_WALLET, {
Expand Down Expand Up @@ -379,6 +386,7 @@ export {
acceptWalletTerms,
setKYCWallSource,
resetWalletAdditionalDetailsDraft,
clearWalletAdditionalDetailsErrors,
issuerEncryptPayloadCallback,
createDigitalGoogleWallet,
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';

import {extractFirstAndLastNameFromAvailableDetails} from '@libs/PersonalDetailsUtils';
import {parsePhoneNumber} from '@libs/PhoneNumber';
import {
getFieldRequiredErrors,
getInvalidAddressErrorTranslationPath,
Expand All @@ -28,10 +27,12 @@ import {
meetsMinimumAgeRequirement,
} from '@libs/ValidationUtils';

import getWalletPersonalDetailsParams from '@pages/EnablePayments/shared/getWalletPersonalDetailsParams';
import IdologyQuestions from '@pages/EnablePayments/shared/IdologyQuestions';
import useWalletPhoneMagicCode from '@pages/EnablePayments/shared/useWalletPhoneMagicCode';
import AddressFormFields from '@pages/ReimbursementAccount/AddressFormFields';

import {setAdditionalDetailsQuestions, updatePersonalDetails} from '@userActions/Wallet';
import {setAdditionalDetailsQuestions} from '@userActions/Wallet';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -81,6 +82,8 @@ function AdditionalDetailsStep({currentUserPersonalDetails}: AdditionalDetailsSt
const maxDate = subYears(currentDate, CONST.DATE_BIRTH.MIN_AGE_FOR_PAYMENT);
const shouldAskForFullSSN = walletAdditionalDetails?.errorCode === CONST.WALLET.ERROR.SSN;

const {submitPersonalDetails} = useWalletPhoneMagicCode();

const validate = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS>): FormInputErrors<typeof ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS> => {
const errors = getFieldRequiredErrors(values, STEP_FIELDS, translate);

Expand Down Expand Up @@ -119,19 +122,7 @@ function AdditionalDetailsStep({currentUserPersonalDetails}: AdditionalDetailsSt
};

const activateWallet = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS>) => {
const personalDetails = {
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 ?? '',
};
// Attempt to set the personal details
updatePersonalDetails(personalDetails);
submitPersonalDetails(getWalletPersonalDetailsParams(values));
};

if (walletAdditionalDetails?.questions && walletAdditionalDetails.questions.length > 0) {
Expand Down
25 changes: 8 additions & 17 deletions src/pages/EnablePayments/Wallet/PersonalInfo/PersonalInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import useOnyx from '@hooks/useOnyx';
import useSubPage from '@hooks/useSubPage';
import type {SubPageProps} from '@hooks/useSubPage/types';

import {parsePhoneNumber} from '@libs/PhoneNumber';

import getWalletPersonalDetailsParams from '@pages/EnablePayments/shared/getWalletPersonalDetailsParams';
import IdologyQuestions from '@pages/EnablePayments/shared/IdologyQuestions';
import useWalletPhoneMagicCode from '@pages/EnablePayments/shared/useWalletPhoneMagicCode';
import getInitialSubstepForPersonalInfo from '@pages/EnablePayments/Wallet/utils/getInitialSubstepForPersonalInfo';
import getSubstepValues from '@pages/EnablePayments/Wallet/utils/getSubstepValues';

import {setAdditionalDetailsQuestions, updateCurrentStep, updatePersonalDetails} from '@userActions/Wallet';
import {setAdditionalDetailsQuestions, updateCurrentStep} from '@userActions/Wallet';

import CONST from '@src/CONST';
import type {EnablePaymentsSubPageType} from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import INPUT_IDS from '@src/types/form/WalletAdditionalDetailsForm';

import React, {useMemo} from 'react';
import {useMemo} from 'react';

import Address from './substeps/AddressStep';
import Confirmation from './substeps/ConfirmationStep';
Expand Down Expand Up @@ -49,21 +49,12 @@ function PersonalInfoPage() {

const showIdologyQuestions = walletAdditionalDetails?.questions && walletAdditionalDetails?.questions.length > 0;

const {submitPersonalDetails} = useWalletPhoneMagicCode();

const values = useMemo(() => getSubstepValues(PERSONAL_INFO_STEP_KEYS, walletAdditionalDetailsDraft, walletAdditionalDetails), [walletAdditionalDetails, walletAdditionalDetailsDraft]);

const submit = () => {
const personalDetails = {
phoneNumber: (values.phoneNumber && parsePhoneNumber(values.phoneNumber, {regionCode: CONST.COUNTRY.US}).number?.significant) ?? '',
legalFirstName: values?.[PERSONAL_INFO_STEP_KEYS.FIRST_NAME] ?? '',
legalLastName: values?.[PERSONAL_INFO_STEP_KEYS.LAST_NAME] ?? '',
addressStreet: values?.[PERSONAL_INFO_STEP_KEYS.STREET] ?? '',
addressCity: values?.[PERSONAL_INFO_STEP_KEYS.CITY] ?? '',
addressState: values?.[PERSONAL_INFO_STEP_KEYS.STATE] ?? '',
addressZip: values?.[PERSONAL_INFO_STEP_KEYS.ZIP_CODE] ?? '',
dob: values?.[PERSONAL_INFO_STEP_KEYS.DOB] ?? '',
ssn: values?.[PERSONAL_INFO_STEP_KEYS.SSN_LAST_4] ?? '',
};
// Attempt to set the personal details
updatePersonalDetails(personalDetails);
submitPersonalDetails(getWalletPersonalDetailsParams(values));
};

const startFrom = useMemo(() => getInitialSubstepForPersonalInfo(values), [values]);
Expand Down
75 changes: 75 additions & 0 deletions src/pages/EnablePayments/shared/WalletConfirmMagicCodePage.tsx
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}));

Copy link
Copy Markdown
Contributor

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. useWalletPhoneMagicCode is 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-mount container. The SDK renders into the hidden screen, and the visible one stays blank.

}
wasLoading.current = false;
}, [formData?.isLoading, hasErrors]);

return (
<WalletMagicCodePrompt
onConfirm={confirm}
onClose={() => Navigation.goBack()}
/>
);
}

WalletConfirmMagicCodePage.displayName = 'WalletConfirmMagicCodePage';

export default WalletConfirmMagicCodePage;
47 changes: 47 additions & 0 deletions src/pages/EnablePayments/shared/WalletMagicCodePrompt.tsx
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;
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 src/pages/EnablePayments/shared/useWalletPhoneMagicCode.ts
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;
Loading
Loading