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
17 changes: 17 additions & 0 deletions .github/workflows/checkValidateCodeTerminology.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Check validateCode terminology

on:
pull_request:
types: [opened, synchronize]
branches: [main]
paths: ['**.ts', '**.tsx', '**.md']

jobs:
check:
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout
uses: useblacksmith/checkout@1c9394c220d293645707b625ba9d79685f093a8f # v1

- name: Check validateCode terminology
run: ./scripts/checkValidateCodeTerminology.sh
33 changes: 33 additions & 0 deletions scripts/checkValidateCodeTerminology.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
#
# Enforces validateCode terminology across the codebase:
# - User-facing copy (src/languages) must use "security code" / "security link", not "magic code"
# - Internal identifiers (src, tests) must use validateCode, not magicCode / MagicCode / MAGIC_CODE

set -e

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly ROOT_DIR

# grep output format: path:line:content — filter lines whose content is a pure comment
filter_comments() {
grep -v ":[0-9]*:[[:space:]]*//" | grep -v ":[0-9]*:[[:space:]]*\*"
}

LANG_HITS=$(grep -rni --include="*.ts" "magic.code\|magic code" "$ROOT_DIR/src/languages" 2>/dev/null | filter_comments || true)
CODE_HITS=$(grep -rn --include="*.ts" --include="*.tsx" "magicCode\|MagicCode\|MAGIC_CODE" "$ROOT_DIR/src" "$ROOT_DIR/tests" 2>/dev/null | filter_comments || true)
DOCS_HITS=$(grep -rn --include="*.md" "magic.code\|magic code\|magicCode\|MagicCode\|MAGIC_CODE" "$ROOT_DIR" 2>/dev/null | grep -v "node_modules" || true)

if [[ -z "$LANG_HITS" && -z "$CODE_HITS" && -z "$DOCS_HITS" ]]; then
echo "✅ Validate code terminology check passed."
exit 0
fi

echo "❌ Validate code terminology violations found."
echo " User-facing copy: use 'security code' / 'security link'."
echo " Internal identifiers: use 'validateCode'."
echo ""
[[ -n "$LANG_HITS" ]] && echo "$LANG_HITS"
[[ -n "$CODE_HITS" ]] && echo "$CODE_HITS"
[[ -n "$DOCS_HITS" ]] && echo "$DOCS_HITS"
exit 1
4 changes: 2 additions & 2 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3651,14 +3651,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
// Error field used by the validateCode 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',
INCORRECT_VALIDATE_CODE: 'incorrectValidateCode',
FULL_SSN_NOT_FOUND: 'Full SSN not found',
MISSING_FIELD: 'Missing required additional details fields',
WRONG_ANSWERS: 'Wrong answers',
Expand Down
6 changes: 3 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1799,9 +1799,9 @@ 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_ENABLE_PAYMENTS_CONFIRM_VALIDATE_CODE: {
route: 'settings/wallet/enable-payments/confirm-validate-code',
getRoute: () => 'settings/wallet/enable-payments/confirm-validate-code' as const,
},
SETTINGS_WALLET_UNSHARE_BANK_ACCOUNT: {
route: 'settings/wallet/:bankAccountID/unshare-bank-account',
Expand Down
2 changes: 1 addition & 1 deletion src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,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',
ENABLE_PAYMENTS_CONFIRM_VALIDATE_CODE: 'Settings_Wallet_EnablePayments_ConfirmValidateCode',
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 @@ -120,7 +120,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {
selector: delegateEmailSelector,
});
// Sends an unvalidated user to the verify-account (magic code) screen and resumes the stored payment once they validate.
// Sends an unvalidated user to the verify-account (security code) screen and resumes the stored payment once they validate.
const {isUserValidated, verifyAccountAndResume} = useVerifyAccountAndResume((retry?: () => void) => retry?.());
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,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.ENABLE_PAYMENTS_CONFIRM_VALIDATE_CODE]: () => require<ReactComponentModule>('../../../../pages/EnablePayments/shared/WalletConfirmValidateCodePage').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,7 +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.ENABLE_PAYMENTS_CONFIRM_VALIDATE_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: 2 additions & 2 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ 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,
[SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS_CONFIRM_VALIDATE_CODE]: {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Register the renamed screen constant before using it

SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS_CONFIRM_VALIDATE_CODE is not defined in src/SCREENS.ts (the navigator/types/RHP relation still use ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE). In the transpiled app this creates an undefined key in the linking config, so settings/wallet/enable-payments/confirm-validate-code is not mapped to the mounted wallet confirmation screen and navigation to the new URL cannot resolve correctly.

Useful? React with 👍 / 👎.

path: ROUTES.SETTINGS_ENABLE_PAYMENTS_CONFIRM_VALIDATE_CODE.route,
exact: true,
},
[SCREENS.SETTINGS.WALLET.UNSHARE_BANK_ACCOUNT]: {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ type SettingsNavigatorParamList = {
subPage?: EnablePaymentsSubPageType;
action?: 'edit';
};
[SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS_CONFIRM_MAGIC_CODE]: undefined;
[SCREENS.SETTINGS.WALLET.ENABLE_PAYMENTS_CONFIRM_VALIDATE_CODE]: undefined;
[SCREENS.SETTINGS.WALLET.UNSHARE_BANK_ACCOUNT]: {
bankAccountID: string;
};
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function resetWalletAdditionalDetailsDraft() {
}

/**
* Clears the errors shown while confirming a magic code in the wallet additional-details step
* Clears the errors shown while confirming a validateCode in the wallet additional-details step
*/
function clearWalletAdditionalDetailsErrors() {
Onyx.merge(ONYXKEYS.WALLET_ADDITIONAL_DETAILS, {errors: null, errorCode: null});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore the renamed wallet validation modules

This new import points at @pages/EnablePayments/shared/useWalletPhoneValidateCode, but this commit deletes useWalletPhoneMagicCode.ts without adding a useWalletPhoneValidateCode.ts replacement (the shared directory in the reviewed tree has no such file). As soon as the enable-payments personal-details pages or the updated unit test are loaded, module resolution fails and the KYC flow cannot render.

Useful? React with 👍 / 👎.

import AddressFormFields from '@pages/ReimbursementAccount/AddressFormFields';

import {setAdditionalDetailsQuestions} from '@userActions/Wallet';
Expand Down Expand Up @@ -82,7 +82,7 @@ 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 {submitPersonalDetails} = useWalletPhoneValidateCode();

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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {SubPageProps} from '@hooks/useSubPage/types';

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

Expand Down Expand Up @@ -49,7 +49,7 @@ function PersonalInfoPage() {

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

const {submitPersonalDetails} = useWalletPhoneMagicCode();
const {submitPersonalDetails} = useWalletPhoneValidateCode();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {useEffect, useRef} from 'react';

import getWalletPersonalDetailsParams from './getWalletPersonalDetailsParams';
import WalletMagicCodePrompt from './WalletMagicCodePrompt';
import WalletValidateCodePrompt from './WalletValidateCodePrompt';

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
* Dedicated screen for entering the validateCode 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() {
function WalletConfirmValidateCodePage() {
const [walletAdditionalDetails] = useOnyx(ONYXKEYS.WALLET_ADDITIONAL_DETAILS);
const [walletAdditionalDetailsDraft] = useOnyx(ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS_DRAFT);
const [formData] = useOnyx(ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS);
Expand Down Expand Up @@ -63,13 +63,13 @@ function WalletConfirmMagicCodePage() {
}, [formData?.isLoading, hasErrors]);

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

WalletConfirmMagicCodePage.displayName = 'WalletConfirmMagicCodePage';
WalletConfirmValidateCodePage.displayName = 'WalletConfirmValidateCodePage';

export default WalletConfirmMagicCodePage;
export default WalletConfirmValidateCodePage;
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import ONYXKEYS from '@src/ONYXKEYS';

import React from 'react';

type WalletMagicCodePromptProps = {
/** Called with the entered magic code to confirm the phone number change */
type WalletValidateCodePromptProps = {
/** Called with the entered validateCode 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) {
/** ValidateCode prompt shown in the wallet KYC flows when changing the phone number used for card 3DS verification */
function WalletValidateCodePrompt({onConfirm, onClose}: WalletValidateCodePromptProps) {
const {translate} = useLocalize();
const [walletAdditionalDetails] = useOnyx(ONYXKEYS.WALLET_ADDITIONAL_DETAILS);
const [formData] = useOnyx(ONYXKEYS.FORMS.WALLET_ADDITIONAL_DETAILS);
Expand All @@ -44,4 +44,4 @@ function WalletMagicCodePrompt({onConfirm, onClose}: WalletMagicCodePromptProps)
);
}

export default WalletMagicCodePrompt;
export default WalletValidateCodePrompt;
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ 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
* time or changing an existing one, is protected by a validateCode 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() {
function useWalletPhoneValidateCode() {
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.
// comparing, otherwise an unchanged phone would look like a change and wrongly prompt for a validateCode.
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());
Navigation.navigate(ROUTES.SETTINGS_ENABLE_PAYMENTS_CONFIRM_VALIDATE_CODE.getRoute());
return;
}

Expand All @@ -39,4 +39,4 @@ function useWalletPhoneMagicCode() {
return {submitPersonalDetails};
}

export default useWalletPhoneMagicCode;
export default useWalletPhoneValidateCode;
2 changes: 1 addition & 1 deletion tests/ui/ValidateLoginPageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('ValidateLoginPage', () => {
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.HOME, {forceReplace: true});
});

it('Should hand off to exitTo (not redirect Home) for a first-time invitee opening an exitTo magic link', async () => {
it('Should hand off to exitTo (not redirect Home) for a first-time invitee opening an exitTo security link', async () => {
// Regression for #94549: an invited member opens `/v/<id>/<code>?exitTo=<destination>` with no
// cached `login` and JUST_SIGNED_IN. Before the fix `isUserClickedSignIn` matched this exactly and
// its focus effect force-redirected Home, clobbering the exitTo navigation. Excluding `exitTo`
Expand Down
Loading
Loading