Skip to content
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

fix: Wallet error when all the address fields are manually entered #56305

Merged
merged 7 commits into from
Feb 14, 2025
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: 0 additions & 3 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,6 @@ const ONYXKEYS = {
REPORT_PHYSICAL_CARD_FORM_DRAFT: 'requestPhysicalCardFormDraft',
REPORT_VIRTUAL_CARD_FRAUD: 'reportVirtualCardFraudForm',
REPORT_VIRTUAL_CARD_FRAUD_DRAFT: 'reportVirtualCardFraudFormDraft',
GET_PHYSICAL_CARD_FORM: 'getPhysicalCardForm',
GET_PHYSICAL_CARD_FORM_DRAFT: 'getPhysicalCardFormDraft',
REPORT_FIELDS_EDIT_FORM: 'reportFieldsEditForm',
REPORT_FIELDS_EDIT_FORM_DRAFT: 'reportFieldsEditFormDraft',
REIMBURSEMENT_ACCOUNT_FORM: 'reimbursementAccount',
Expand Down Expand Up @@ -815,7 +813,6 @@ type OnyxFormValuesMapping = {
[ONYXKEYS.FORMS.INTRO_SCHOOL_PRINCIPAL_FORM]: FormTypes.IntroSchoolPrincipalForm;
[ONYXKEYS.FORMS.REPORT_VIRTUAL_CARD_FRAUD]: FormTypes.ReportVirtualCardFraudForm;
[ONYXKEYS.FORMS.REPORT_PHYSICAL_CARD_FORM]: FormTypes.ReportPhysicalCardForm;
[ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM]: FormTypes.GetPhysicalCardForm;
[ONYXKEYS.FORMS.REPORT_FIELDS_EDIT_FORM]: FormTypes.ReportFieldsEditForm;
[ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM]: FormTypes.ReimbursementAccountForm;
[ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM]: FormTypes.PersonalBankAccountForm;
Expand Down
16 changes: 0 additions & 16 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,6 @@ const ROUTES = {
route: 'settings/card/:cardID/report-virtual-fraud',
getRoute: (cardID: string) => `settings/card/${cardID}/report-virtual-fraud` as const,
},
SETTINGS_WALLET_CARD_GET_PHYSICAL_NAME: {
route: 'settings/wallet/card/:domain/get-physical/name',
getRoute: (domain: string, backTo?: string) => getUrlWithBackToParam(`settings/wallet/card/${domain}/get-physical/name`, backTo),
},
SETTINGS_WALLET_CARD_GET_PHYSICAL_PHONE: {
route: 'settings/wallet/card/:domain/get-physical/phone',
getRoute: (domain: string, backTo?: string) => getUrlWithBackToParam(`settings/wallet/card/${domain}/get-physical/phone`, backTo),
},
SETTINGS_WALLET_CARD_GET_PHYSICAL_ADDRESS: {
route: 'settings/wallet/card/:domain/get-physical/address',
getRoute: (domain: string, backTo?: string) => getUrlWithBackToParam(`settings/wallet/card/${domain}/get-physical/address`, backTo),
},
SETTINGS_WALLET_CARD_GET_PHYSICAL_CONFIRM: {
route: 'settings/wallet/card/:domain/get-physical/confirm',
getRoute: (domain: string) => `settings/wallet/card/${domain}/get-physical/confirm` as const,
},
SETTINGS_ADD_DEBIT_CARD: 'settings/wallet/add-debit-card',
SETTINGS_ADD_BANK_ACCOUNT: 'settings/wallet/add-bank-account',
SETTINGS_ADD_US_BANK_ACCOUNT: 'settings/wallet/add-us-bank-account',
Expand Down
6 changes: 0 additions & 6 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ const SCREENS = {
WALLET: {
ROOT: 'Settings_Wallet',
DOMAIN_CARD: 'Settings_Wallet_DomainCard',
CARD_GET_PHYSICAL: {
NAME: 'Settings_Card_Get_Physical_Name',
PHONE: 'Settings_Card_Get_Physical_Phone',
ADDRESS: 'Settings_Card_Get_Physical_Address',
CONFIRM: 'Settings_Card_Get_Physical_Confirm',
},
TRANSFER_BALANCE: 'Settings_Wallet_Transfer_Balance',
CHOOSE_TRANSFER_ACCOUNT: 'Settings_Wallet_Choose_Transfer_Account',
ENABLE_PAYMENTS: 'Settings_Wallet_EnablePayments',
Expand Down
16 changes: 8 additions & 8 deletions src/components/AddressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, {useCallback} from 'react';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as ValidationUtils from '@libs/ValidationUtils';
import {addErrorMessage} from '@libs/ErrorUtils';
import {isRequiredFulfilled} from '@libs/ValidationUtils';
import type {Country} from '@src/CONST';
import CONST from '@src/CONST';
import type ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -46,7 +46,7 @@ type AddressFormProps = {
onAddressChanged?: (value: unknown, key: unknown) => void;

/** Callback which is executed when the user submits his address changes */
onSubmit: (values: FormOnyxValues<typeof ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM | typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM>) => void;
onSubmit: (values: FormOnyxValues<typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM>) => void;

/** Whether or not should the form data should be saved as draft */
shouldSaveDraft?: boolean;
Expand All @@ -55,7 +55,7 @@ type AddressFormProps = {
submitButtonText?: string;

/** A unique Onyx key identifying the form */
formID: typeof ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM | typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM;
formID: typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM;
};

function AddressForm({
Expand Down Expand Up @@ -88,7 +88,7 @@ function AddressForm({
*/

const validator = useCallback(
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM | typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM>): Errors => {
(values: FormOnyxValues<typeof ONYXKEYS.FORMS.HOME_ADDRESS_FORM>): Errors => {
const errors: Errors & {
zipPostCode?: string | string[];
} = {};
Expand All @@ -102,7 +102,7 @@ function AddressForm({
// Add "Field required" errors if any required field is empty
requiredFields.forEach((fieldKey) => {
const fieldValue = values[fieldKey] ?? '';
if (ValidationUtils.isRequiredFulfilled(fieldValue)) {
if (isRequiredFulfilled(fieldValue)) {
return;
}

Expand All @@ -116,11 +116,11 @@ function AddressForm({
const countrySpecificZipRegex = countryRegexDetails?.regex;
const countryZipFormat = countryRegexDetails?.samples ?? '';

ErrorUtils.addErrorMessage(errors, 'firstName', translate('bankAccount.error.firstName'));
addErrorMessage(errors, 'firstName', translate('bankAccount.error.firstName'));

if (countrySpecificZipRegex) {
if (!countrySpecificZipRegex.test(values.zipPostCode?.trim().toUpperCase())) {
if (ValidationUtils.isRequiredFulfilled(values.zipPostCode?.trim())) {
if (isRequiredFulfilled(values.zipPostCode?.trim())) {
errors.zipPostCode = translate('privatePersonalDetails.error.incorrectZipFormat', {zipFormat: countryZipFormat});
} else {
errors.zipPostCode = translate('common.error.fieldRequired');
Expand Down
9 changes: 5 additions & 4 deletions src/components/SubStepForms/DateOfBirthStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import type {SubStepProps} from '@hooks/useSubStep/types';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ValidationUtils from '@libs/ValidationUtils';
import {getFieldRequiredErrors, isValidPastDate, meetsMaximumAgeRequirement, meetsMinimumAgeRequirement} from '@libs/ValidationUtils';
import CONST from '@src/CONST';
import type {OnyxFormValuesMapping} from '@src/ONYXKEYS';

Expand Down Expand Up @@ -57,14 +57,14 @@ function DateOfBirthStep<TFormID extends keyof OnyxFormValuesMapping>({

const validate = useCallback(
(values: FormOnyxValues<TFormID>): FormInputErrors<TFormID> => {
const errors = ValidationUtils.getFieldRequiredErrors(values, stepFields);
const errors = getFieldRequiredErrors(values, stepFields);

const valuesToValidate = values[dobInputID as keyof FormOnyxValues<TFormID>] as string;
if (valuesToValidate) {
if (!ValidationUtils.isValidPastDate(valuesToValidate) || !ValidationUtils.meetsMaximumAgeRequirement(valuesToValidate)) {
if (!isValidPastDate(valuesToValidate) || !meetsMaximumAgeRequirement(valuesToValidate)) {
// @ts-expect-error type mismatch to be fixed
errors[dobInputID] = translate('bankAccount.error.dob');
} else if (!ValidationUtils.meetsMinimumAgeRequirement(valuesToValidate)) {
} else if (!meetsMinimumAgeRequirement(valuesToValidate)) {
// @ts-expect-error type mismatch to be fixed
errors[dobInputID] = translate('bankAccount.error.age');
}
Expand All @@ -83,6 +83,7 @@ function DateOfBirthStep<TFormID extends keyof OnyxFormValuesMapping>({
onSubmit={onSubmit}
style={[styles.mh5, styles.flexGrow2, styles.justifyContentBetween]}
submitButtonStyles={[styles.mb0]}
enabledWhenOffline
>
<Text style={[styles.textHeadlineLineHeightXXL, styles.mb5]}>{formTitle}</Text>
<InputWrapper
Expand Down
13 changes: 7 additions & 6 deletions src/components/SubStepForms/FullNameStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
import type {SubStepProps} from '@hooks/useSubStep/types';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ValidationUtils from '@libs/ValidationUtils';
import {getFieldRequiredErrors, isRequiredFulfilled, isValidLegalName} from '@libs/ValidationUtils';
import HelpLinks from '@pages/ReimbursementAccount/PersonalInfo/HelpLinks';
import CONST from '@src/CONST';
import type {OnyxFormValuesMapping} from '@src/ONYXKEYS';
Expand Down Expand Up @@ -70,13 +70,13 @@ function FullNameStep<TFormID extends keyof OnyxFormValuesMapping>({

const validate = useCallback(
(values: FormOnyxValues<TFormID>): FormInputErrors<TFormID> => {
const errors = ValidationUtils.getFieldRequiredErrors(values, stepFields);
const errors = getFieldRequiredErrors(values, stepFields);

const firstName = values[firstNameInputID as keyof FormOnyxValues<TFormID>] as string;
if (!ValidationUtils.isRequiredFulfilled(firstName)) {
if (!isRequiredFulfilled(firstName)) {
// @ts-expect-error type mismatch to be fixed
errors[firstNameInputID] = translate('common.error.fieldRequired');
} else if (!ValidationUtils.isValidLegalName(firstName)) {
} else if (!isValidLegalName(firstName)) {
// @ts-expect-error type mismatch to be fixed
errors[firstNameInputID] = translate('privatePersonalDetails.error.hasInvalidCharacter');
} else if (firstName.length > CONST.LEGAL_NAME.MAX_LENGTH) {
Expand All @@ -88,10 +88,10 @@ function FullNameStep<TFormID extends keyof OnyxFormValuesMapping>({
}

const lastName = values[lastNameInputID as keyof FormOnyxValues<TFormID>] as string;
if (!ValidationUtils.isRequiredFulfilled(lastName)) {
if (!isRequiredFulfilled(lastName)) {
// @ts-expect-error type mismatch to be fixed
errors[lastNameInputID] = translate('common.error.fieldRequired');
} else if (!ValidationUtils.isValidLegalName(lastName)) {
} else if (!isValidLegalName(lastName)) {
// @ts-expect-error type mismatch to be fixed
errors[lastNameInputID] = translate('privatePersonalDetails.error.hasInvalidCharacter');
} else if (lastName.length > CONST.LEGAL_NAME.MAX_LENGTH) {
Expand All @@ -113,6 +113,7 @@ function FullNameStep<TFormID extends keyof OnyxFormValuesMapping>({
validate={customValidate ?? validate}
onSubmit={onSubmit}
style={[styles.mh5, styles.flexGrow1]}
enabledWhenOffline
>
<View>
<Text style={[styles.textHeadlineLineHeightXXL, styles.mb6]}>{formTitle}</Text>
Expand Down
5 changes: 5 additions & 0 deletions src/components/SubStepForms/SingleFieldStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type SingleFieldStepProps<TFormID extends keyof OnyxFormValuesMapping> = SubStep

/** Max length of the field */
maxLength?: number;

/** Should the submit button be enabled when offline */
enabledWhenOffline?: boolean;
};

function SingleFieldStep<TFormID extends keyof OnyxFormValuesMapping>({
Expand All @@ -61,6 +64,7 @@ function SingleFieldStep<TFormID extends keyof OnyxFormValuesMapping>({
isEditing,
shouldShowHelpLinks = true,
maxLength,
enabledWhenOffline,
}: SingleFieldStepProps<TFormID>) {
const {translate} = useLocalize();
const styles = useThemeStyles();
Expand All @@ -73,6 +77,7 @@ function SingleFieldStep<TFormID extends keyof OnyxFormValuesMapping>({
onSubmit={onSubmit}
style={[styles.mh5, styles.flexGrow1]}
submitButtonStyles={[styles.mb0]}
enabledWhenOffline={enabledWhenOffline}
>
<View>
<Text style={[styles.textHeadlineLineHeightXXL]}>{formTitle}</Text>
Expand Down
14 changes: 0 additions & 14 deletions src/libs/API/parameters/RequestPhysicalExpensifyCardParams.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export type {default as ReferTeachersUniteVolunteerParams} from './ReferTeachers
export type {default as ReportVirtualExpensifyCardFraudParams} from './ReportVirtualExpensifyCardFraudParams';
export type {default as RequestContactMethodValidateCodeParams} from './RequestContactMethodValidateCodeParams';
export type {default as RequestNewValidateCodeParams} from './RequestNewValidateCodeParams';
export type {default as RequestPhysicalExpensifyCardParams} from './RequestPhysicalExpensifyCardParams';
export type {default as RequestReplacementExpensifyCardParams} from './RequestReplacementExpensifyCardParams';
export type {default as RequestUnlinkValidationLinkParams} from './RequestUnlinkValidationLinkParams';
export type {default as RequestAccountValidationLinkParams} from './RequestAccountValidationLinkParams';
Expand Down
2 changes: 0 additions & 2 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const WRITE_COMMANDS = {
VERIFY_IDENTITY: 'VerifyIdentity',
ACCEPT_WALLET_TERMS: 'AcceptWalletTerms',
ANSWER_QUESTIONS_FOR_WALLET: 'AnswerQuestionsForWallet',
REQUEST_PHYSICAL_EXPENSIFY_CARD: 'RequestPhysicalExpensifyCard',
LOG_OUT: 'LogOut',
REQUEST_ACCOUNT_VALIDATION_LINK: 'RequestAccountValidationLink',
REQUEST_NEW_VALIDATE_CODE: 'RequestNewValidateCode',
Expand Down Expand Up @@ -533,7 +532,6 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.VERIFY_IDENTITY]: Parameters.VerifyIdentityParams;
[WRITE_COMMANDS.ACCEPT_WALLET_TERMS]: Parameters.AcceptWalletTermsParams;
[WRITE_COMMANDS.ANSWER_QUESTIONS_FOR_WALLET]: Parameters.AnswerQuestionsForWalletParams;
[WRITE_COMMANDS.REQUEST_PHYSICAL_EXPENSIFY_CARD]: Parameters.RequestPhysicalExpensifyCardParams;
[WRITE_COMMANDS.LOG_OUT]: Parameters.LogOutParams;
[WRITE_COMMANDS.REQUEST_ACCOUNT_VALIDATION_LINK]: Parameters.RequestAccountValidationLinkParams;
[WRITE_COMMANDS.REQUEST_NEW_VALIDATE_CODE]: Parameters.RequestNewValidateCodeParams;
Expand Down
94 changes: 0 additions & 94 deletions src/libs/GetPhysicalCardUtils.ts

This file was deleted.

Loading
Loading