Skip to content

Commit 9e03b6a

Browse files
authored
Merge pull request #52082 from NJ-2020/fix/51491-wallet-page
fix wallet phone validation page
2 parents 2199bc8 + 858e0e1 commit 9e03b6a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/libs/GetPhysicalCardUtils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Str} from 'expensify-common';
12
import type {OnyxEntry} from 'react-native-onyx';
23
import ROUTES from '@src/ROUTES';
34
import type {Route} from '@src/ROUTES';
@@ -6,16 +7,19 @@ import type {LoginList, PrivatePersonalDetails} from '@src/types/onyx';
67
import * as LoginUtils from './LoginUtils';
78
import Navigation from './Navigation/Navigation';
89
import * as PersonalDetailsUtils from './PersonalDetailsUtils';
10+
import * as PhoneNumberUtils from './PhoneNumber';
911
import * as UserUtils from './UserUtils';
1012

1113
function getCurrentRoute(domain: string, privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>): Route {
1214
const {legalFirstName, legalLastName, phoneNumber} = privatePersonalDetails ?? {};
1315
const address = PersonalDetailsUtils.getCurrentAddress(privatePersonalDetails);
16+
const phoneNumberWithCountryCode = LoginUtils.appendCountryCode(phoneNumber ?? '');
17+
const parsedPhoneNumber = PhoneNumberUtils.parsePhoneNumber(phoneNumberWithCountryCode);
1418

1519
if (!legalFirstName && !legalLastName) {
1620
return ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_NAME.getRoute(domain);
1721
}
18-
if (!phoneNumber || !LoginUtils.validateNumber(phoneNumber)) {
22+
if (!phoneNumber || !parsedPhoneNumber.possible || !Str.isValidE164Phone(phoneNumberWithCountryCode.slice(0))) {
1923
return ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_PHONE.getRoute(domain);
2024
}
2125
if (!(address?.street && address?.city && address?.state && address?.country && address?.zip)) {

src/pages/settings/Wallet/Card/GetPhysicalCardPhone.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Str} from 'expensify-common';
12
import React from 'react';
23
import {View} from 'react-native';
34
import {useOnyx} from 'react-native-onyx';
@@ -8,6 +9,8 @@ import useLocalize from '@hooks/useLocalize';
89
import useThemeStyles from '@hooks/useThemeStyles';
910
import * as LoginUtils from '@libs/LoginUtils';
1011
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
12+
import * as PhoneNumberUtils from '@libs/PhoneNumber';
13+
import * as ValidationUtils from '@libs/ValidationUtils';
1114
import type {SettingsNavigatorParamList} from '@navigation/types';
1215
import CONST from '@src/CONST';
1316
import ONYXKEYS from '@src/ONYXKEYS';
@@ -40,12 +43,17 @@ function GetPhysicalCardPhone({
4043

4144
const errors: OnValidateResult = {};
4245

43-
if (!LoginUtils.validateNumber(phoneNumberToValidate)) {
44-
errors.phoneNumber = translate('common.error.phoneNumber');
45-
} else if (!phoneNumberToValidate) {
46+
if (!ValidationUtils.isRequiredFulfilled(phoneNumberToValidate)) {
4647
errors.phoneNumber = translate('common.error.fieldRequired');
4748
}
4849

50+
const phoneNumberWithCountryCode = LoginUtils.appendCountryCode(phoneNumberToValidate);
51+
const parsedPhoneNumber = PhoneNumberUtils.parsePhoneNumber(phoneNumberWithCountryCode);
52+
53+
if (!parsedPhoneNumber.possible || !Str.isValidE164Phone(phoneNumberWithCountryCode.slice(0))) {
54+
errors.phoneNumber = translate('bankAccount.error.phoneNumber');
55+
}
56+
4957
return errors;
5058
};
5159

0 commit comments

Comments
 (0)