Skip to content

Commit 82c600e

Browse files
committed
Send E.164 phone number from the personal bank account update flow
The update flow stripped the calling code with parsePhoneNumber().number.significant, so a UK number was sent as 10 bare digits and the BE read it as NANP. Reuse formatE164PhoneNumber() so this flow matches the add flow.
1 parent 6098cfc commit 82c600e

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

src/pages/settings/Wallet/UpdatePersonalBankAccountPage.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import useThemeStyles from '@hooks/useThemeStyles';
1212

1313
import {getCompletedStepsForBankAccount} from '@libs/BankAccountUtils';
1414
import Log from '@libs/Log';
15+
import {formatE164PhoneNumber} from '@libs/LoginUtils';
1516
import {getCurrentAddress, getStreetLines} from '@libs/PersonalDetailsUtils';
16-
import {parsePhoneNumber} from '@libs/PhoneNumber';
1717

1818
import Navigation from '@navigation/Navigation';
1919

@@ -111,6 +111,7 @@ function UpdatePersonalBankAccountPage() {
111111
const [homeAddressDraft] = useOnyx(ONYXKEYS.FORMS.HOME_ADDRESS_FORM_DRAFT);
112112
const [personalBankAccount, personalBankAccountResult] = useOnyx(ONYXKEYS.PERSONAL_BANK_ACCOUNT);
113113
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
114+
const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE);
114115

115116
const shouldShowSuccess = personalBankAccount?.shouldShowSuccess ?? false;
116117
const bankAccountID = personalBankAccount?.bankAccountID;
@@ -196,9 +197,10 @@ function UpdatePersonalBankAccountPage() {
196197
addressZipCode = '';
197198
}
198199

200+
// The BE reads companyPhone as the Plaid phone_number and assumes +1 for a bare 10 digit value, so send E.164.
201+
// The form draft holds whatever the user typed, which can lack a calling code, so apply the country code here.
199202
const rawPhone = personalBankAccountDraft?.phoneNumber ?? privatePersonalDetails?.phoneNumber ?? existingData?.companyPhone ?? '';
200-
const parsed = parsePhoneNumber(rawPhone, {regionCode: CONST.COUNTRY.US});
201-
const phoneNumber = parsed.number?.significant ?? '';
203+
const phoneNumber = formatE164PhoneNumber(rawPhone, countryCode) ?? '';
202204

203205
updatePersonalBankAccountInfo(personalBankAccount.bankAccountID, {
204206
legalFirstName,

tests/unit/LoginUtilsTest.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
appendCountryCode,
3+
formatE164PhoneNumber,
34
getEmailDomain,
45
getPhoneLogin,
56
getPhoneNumberWithoutSpecialChars,
@@ -57,6 +58,23 @@ describe('LoginUtils', () => {
5758
expect(parsedPhone).toBe('+12345678901');
5859
});
5960
});
61+
describe('formatE164PhoneNumber', () => {
62+
it('Should keep the calling code of a number that already has one', () => {
63+
expect(formatE164PhoneNumber('+442071234567', CONST.DEFAULT_COUNTRY_CODE)).toBe('+442071234567');
64+
});
65+
it('Should prepend the country code to a bare US number', () => {
66+
expect(formatE164PhoneNumber('201 867 5309', CONST.DEFAULT_COUNTRY_CODE)).toBe('+12018675309');
67+
});
68+
it('Should prepend the country code to a bare UK number', () => {
69+
expect(formatE164PhoneNumber('20 7123 4567', 44)).toBe('+442071234567');
70+
});
71+
it('Should keep the calling code when it differs from the country code', () => {
72+
expect(formatE164PhoneNumber('+61255501234', CONST.DEFAULT_COUNTRY_CODE)).toBe('+61255501234');
73+
});
74+
it('Should return undefined for an unparseable number', () => {
75+
expect(formatE164PhoneNumber('abcdefg', CONST.DEFAULT_COUNTRY_CODE)).toBeUndefined();
76+
});
77+
});
6078
describe('isEmailPublicDomain', () => {
6179
it('Should return true if email is from public domain', () => {
6280
const givenEmail = 'test@gmail.com';

tests/unit/ValidationUtilsTest.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
isValidPastDate,
1818
isValidPaymentZipCode,
1919
isValidPersonName,
20+
isValidPhoneNumber,
2021
isValidPIN,
2122
isValidRegistrationNumber,
2223
isValidRoomName,
@@ -595,6 +596,36 @@ describe('ValidationUtils', () => {
595596
});
596597
});
597598

599+
describe('isValidPhoneNumber', () => {
600+
test('Should return true for a US phone number', () => {
601+
expect(isValidPhoneNumber('+12018675309')).toBe(true);
602+
});
603+
604+
test('Should return true for a Canadian phone number', () => {
605+
expect(isValidPhoneNumber('+14165551234')).toBe(true);
606+
});
607+
608+
test('Should return true for a UK phone number', () => {
609+
expect(isValidPhoneNumber('+442071234567')).toBe(true);
610+
});
611+
612+
test('Should return true for an Australian phone number', () => {
613+
expect(isValidPhoneNumber('+61255501234')).toBe(true);
614+
});
615+
616+
test('Should return false for a number that is too short to be possible', () => {
617+
expect(isValidPhoneNumber('123')).toBe(false);
618+
});
619+
620+
test('Should return false for letters', () => {
621+
expect(isValidPhoneNumber('abcdefg')).toBe(false);
622+
});
623+
624+
test('Should return false for an empty string', () => {
625+
expect(isValidPhoneNumber('')).toBe(false);
626+
});
627+
});
628+
598629
describe('isInvalidMerchantValue', () => {
599630
test('Valid merchnt name', () => {
600631
expect(isInvalidMerchantValue('test name')).toBe(false);

0 commit comments

Comments
 (0)