Skip to content

Commit

Permalink
Merge pull request #36056 from callstack-internal/pac-guerreiro/issue…
Browse files Browse the repository at this point in the history
…/34426-wallet-invalid-phone-number-bug

[ECard Settings] Wallet - Clicking on Address does nothing after submitting empty phone number
  • Loading branch information
grgia authored Feb 21, 2024
2 parents badd227 + 3b40be2 commit 86a91bb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 54 deletions.
28 changes: 14 additions & 14 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,28 @@ const ROUTES = {
SETTINGS_APP_DOWNLOAD_LINKS: 'settings/about/app-download-links',
SETTINGS_WALLET: 'settings/wallet',
SETTINGS_WALLET_DOMAINCARD: {
route: '/settings/wallet/card/:domain',
getRoute: (domain: string) => `/settings/wallet/card/${domain}` as const,
route: 'settings/wallet/card/:domain',
getRoute: (domain: string) => `settings/wallet/card/${domain}` as const,
},
SETTINGS_REPORT_FRAUD: {
route: '/settings/wallet/card/:domain/report-virtual-fraud',
getRoute: (domain: string) => `/settings/wallet/card/${domain}/report-virtual-fraud` as const,
route: 'settings/wallet/card/:domain/report-virtual-fraud',
getRoute: (domain: string) => `settings/wallet/card/${domain}/report-virtual-fraud` as const,
},
SETTINGS_WALLET_CARD_GET_PHYSICAL_NAME: {
route: '/settings/wallet/card/:domain/get-physical/name',
getRoute: (domain: string) => `/settings/wallet/card/${domain}/get-physical/name` as const,
route: 'settings/wallet/card/:domain/get-physical/name',
getRoute: (domain: string) => `settings/wallet/card/${domain}/get-physical/name` as const,
},
SETTINGS_WALLET_CARD_GET_PHYSICAL_PHONE: {
route: '/settings/wallet/card/:domain/get-physical/phone',
getRoute: (domain: string) => `/settings/wallet/card/${domain}/get-physical/phone` as const,
route: 'settings/wallet/card/:domain/get-physical/phone',
getRoute: (domain: string) => `settings/wallet/card/${domain}/get-physical/phone` as const,
},
SETTINGS_WALLET_CARD_GET_PHYSICAL_ADDRESS: {
route: '/settings/wallet/card/:domain/get-physical/address',
getRoute: (domain: string) => `/settings/wallet/card/${domain}/get-physical/address` as const,
route: 'settings/wallet/card/:domain/get-physical/address',
getRoute: (domain: string) => `settings/wallet/card/${domain}/get-physical/address` as const,
},
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,
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',
Expand All @@ -117,8 +117,8 @@ const ROUTES = {
SETTINGS_WALLET_TRANSFER_BALANCE: 'settings/wallet/transfer-balance',
SETTINGS_WALLET_CHOOSE_TRANSFER_ACCOUNT: 'settings/wallet/choose-transfer-account',
SETTINGS_WALLET_REPORT_CARD_LOST_OR_DAMAGED: {
route: '/settings/wallet/card/:domain/report-card-lost-or-damaged',
getRoute: (domain: string) => `/settings/wallet/card/${domain}/report-card-lost-or-damaged` as const,
route: 'settings/wallet/card/:domain/report-card-lost-or-damaged',
getRoute: (domain: string) => `settings/wallet/card/${domain}/report-card-lost-or-damaged` as const,
},
SETTINGS_WALLET_CARD_ACTIVATE: {
route: 'settings/wallet/card/:domain/activate',
Expand Down
13 changes: 7 additions & 6 deletions src/libs/GetPhysicalCardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import type {GetPhysicalCardForm} from '@src/types/form';
import type {LoginList, PrivatePersonalDetails} from '@src/types/onyx';
import * as LoginUtils from './LoginUtils';
import Navigation from './Navigation/Navigation';
import * as PersonalDetailsUtils from './PersonalDetailsUtils';
import * as UserUtils from './UserUtils';

function getCurrentRoute(domain: string, privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>, loginList: OnyxEntry<LoginList>): Route {
function getCurrentRoute(domain: string, privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>): Route {
const {address, legalFirstName, legalLastName, phoneNumber} = privatePersonalDetails ?? {};

if (!legalFirstName && !legalLastName) {
return ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_NAME.getRoute(domain);
}
if (!phoneNumber && !UserUtils.getSecondaryPhoneLogin(loginList)) {
if (!phoneNumber || !LoginUtils.validateNumber(phoneNumber)) {
return ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_PHONE.getRoute(domain);
}
if (!(address?.street && address?.city && address?.state && address?.country && address?.zip)) {
Expand All @@ -23,8 +24,8 @@ function getCurrentRoute(domain: string, privatePersonalDetails: OnyxEntry<Priva
return ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_CONFIRM.getRoute(domain);
}

function goToNextPhysicalCardRoute(domain: string, privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>, loginList: OnyxEntry<LoginList>) {
Navigation.navigate(getCurrentRoute(domain, privatePersonalDetails, loginList));
function goToNextPhysicalCardRoute(domain: string, privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>) {
Navigation.navigate(getCurrentRoute(domain, privatePersonalDetails));
}

/**
Expand All @@ -35,8 +36,8 @@ function goToNextPhysicalCardRoute(domain: string, privatePersonalDetails: OnyxE
* @param loginList
* @returns
*/
function setCurrentRoute(currentRoute: string, domain: string, privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>, loginList: OnyxEntry<LoginList>) {
const expectedRoute = getCurrentRoute(domain, privatePersonalDetails, loginList);
function setCurrentRoute(currentRoute: string, domain: string, privatePersonalDetails: OnyxEntry<PrivatePersonalDetails>) {
const expectedRoute = getCurrentRoute(domain, privatePersonalDetails);

// If the user is on the current route or the current route is confirmation, then he's allowed to stay on the current step
if ([currentRoute, ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_CONFIRM.getRoute(domain)].includes(expectedRoute)) {
Expand Down
7 changes: 3 additions & 4 deletions src/pages/settings/Wallet/Card/BaseGetPhysicalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ function BaseGetPhysicalCard({
}

// Redirect user to previous steps of the flow if he hasn't finished them yet
const updatedPrivatePersonalDetails = GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(draftValues);
GetPhysicalCardUtils.setCurrentRoute(currentRoute, domain, updatedPrivatePersonalDetails, loginList);
GetPhysicalCardUtils.setCurrentRoute(currentRoute, domain, GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(draftValues));
isRouteSet.current = true;
}, [cardList, currentRoute, domain, draftValues, loginList, privatePersonalDetails]);

Expand All @@ -159,8 +158,8 @@ function BaseGetPhysicalCard({
Navigation.navigate(ROUTES.SETTINGS_WALLET_DOMAINCARD.getRoute(domain));
return;
}
GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, updatedPrivatePersonalDetails, loginList);
}, [cardList, domain, draftValues, isConfirmation, loginList, session?.authToken]);
GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, updatedPrivatePersonalDetails);
}, [cardList, domain, draftValues, isConfirmation, session?.authToken]);
return (
<ScreenWrapper
shouldEnablePickerAvoiding={false}
Expand Down
5 changes: 2 additions & 3 deletions src/pages/settings/Wallet/Card/GetPhysicalCardPhone.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type {StackScreenProps} from '@react-navigation/stack';
import Str from 'expensify-common/lib/str';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import InputWrapper from '@components/Form/InputWrapper';
import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
import {parsePhoneNumber} from '@libs/PhoneNumber';
import * as LoginUtils from '@libs/LoginUtils';
import type {SettingsNavigatorParamList} from '@navigation/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -42,7 +41,7 @@ function GetPhysicalCardPhone({

const errors: OnValidateResult = {};

if (!(parsePhoneNumber(phoneNumberToValidate).possible && Str.isValidPhone(phoneNumberToValidate))) {
if (!LoginUtils.validateNumber(phoneNumberToValidate)) {
errors.phoneNumber = 'common.error.phoneNumber';
} else if (!phoneNumberToValidate) {
errors.phoneNumber = 'common.error.fieldRequired';
Expand Down
41 changes: 14 additions & 27 deletions src/pages/settings/Wallet/ExpensifyCardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import * as FormActions from '@libs/actions/FormActions';
import * as CardUtils from '@libs/CardUtils';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import FormUtils from '@libs/FormUtils';
Expand Down Expand Up @@ -88,37 +89,16 @@ const propTypes = {

const defaultProps = {
cardList: null,
draftValues: {
addressLine1: '',
addressLine2: '',
city: '',
state: '',
country: '',
zipPostCode: '',
phoneNumber: '',
legalFirstName: '',
legalLastName: '',
},
loginList: {},
privatePersonalDetails: {
legalFirstName: '',
legalLastName: '',
phoneNumber: null,
address: {
street: '',
city: '',
state: '',
zip: '',
country: '',
},
},
draftValues: null,
loginList: null,
privatePersonalDetails: null,
};

function ExpensifyCardPage({
cardList,
draftValues,
loginList,
privatePersonalDetails,
loginList,
route: {
params: {domain},
},
Expand Down Expand Up @@ -160,9 +140,16 @@ function ExpensifyCardPage({
};

const goToGetPhysicalCardFlow = () => {
const updatedDraftValues = GetPhysicalCardUtils.getUpdatedDraftValues(draftValues, privatePersonalDetails, loginList);
let updatedDraftValues = draftValues;

if (!draftValues) {
updatedDraftValues = GetPhysicalCardUtils.getUpdatedDraftValues(null, privatePersonalDetails, loginList);
// Form draft data needs to be initialized with the private personal details
// If no draft data exists
FormActions.setDraftValues(ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM, updatedDraftValues);
}

GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(updatedDraftValues), loginList);
GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(updatedDraftValues));
};

const hasDetectedDomainFraud = _.some(domainCards, (card) => card.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN);
Expand Down

0 comments on commit 86a91bb

Please sign in to comment.