From a555fd3dffab634bc565536ca066c97da30a87d9 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Wed, 7 Feb 2024 18:30:46 +0000 Subject: [PATCH 1/3] fix: wrong route format causing console errors --- src/ROUTES.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 016e4267803b..b40f75cf8e8e 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -85,28 +85,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', @@ -118,8 +118,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', From 9332a29db3e0474562415663b88289860e2a3c62 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Wed, 7 Feb 2024 18:32:01 +0000 Subject: [PATCH 2/3] fix: invalid phone number bypassing get physical card flow --- src/libs/GetPhysicalCardUtils.ts | 13 +++++++------ .../settings/Wallet/Card/BaseGetPhysicalCard.js | 3 +-- .../settings/Wallet/Card/GetPhysicalCardPhone.js | 5 ++--- src/pages/settings/Wallet/ExpensifyCardPage.js | 6 +----- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/libs/GetPhysicalCardUtils.ts b/src/libs/GetPhysicalCardUtils.ts index 139297a26513..7d2f3752fdc3 100644 --- a/src/libs/GetPhysicalCardUtils.ts +++ b/src/libs/GetPhysicalCardUtils.ts @@ -1,5 +1,6 @@ import ROUTES from '@src/ROUTES'; import type {Login} from '@src/types/onyx'; +import * as LoginUtils from './LoginUtils'; import Navigation from './Navigation/Navigation'; import * as PersonalDetailsUtils from './PersonalDetailsUtils'; import * as UserUtils from './UserUtils'; @@ -32,7 +33,7 @@ type LoginList = Record; * @param loginList * @returns */ -function getCurrentRoute(domain: string, privatePersonalDetails: PrivatePersonalDetails, loginList: LoginList) { +function getCurrentRoute(domain: string, privatePersonalDetails: PrivatePersonalDetails) { const { address: {street, city, state, country, zip}, legalFirstName, @@ -43,7 +44,7 @@ function getCurrentRoute(domain: string, privatePersonalDetails: PrivatePersonal 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 (!(street && city && state && country && zip)) { @@ -60,8 +61,8 @@ function getCurrentRoute(domain: string, privatePersonalDetails: PrivatePersonal * @param loginList * @returns */ -function goToNextPhysicalCardRoute(domain: string, privatePersonalDetails: PrivatePersonalDetails, loginList: LoginList) { - Navigation.navigate(getCurrentRoute(domain, privatePersonalDetails, loginList)); +function goToNextPhysicalCardRoute(domain: string, privatePersonalDetails: PrivatePersonalDetails) { + Navigation.navigate(getCurrentRoute(domain, privatePersonalDetails)); } /** @@ -72,8 +73,8 @@ function goToNextPhysicalCardRoute(domain: string, privatePersonalDetails: Priva * @param loginList * @returns */ -function setCurrentRoute(currentRoute: string, domain: string, privatePersonalDetails: PrivatePersonalDetails, loginList: LoginList) { - const expectedRoute = getCurrentRoute(domain, privatePersonalDetails, loginList); +function setCurrentRoute(currentRoute: string, domain: string, privatePersonalDetails: 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)) { diff --git a/src/pages/settings/Wallet/Card/BaseGetPhysicalCard.js b/src/pages/settings/Wallet/Card/BaseGetPhysicalCard.js index ade598608f50..c50c6d15509a 100644 --- a/src/pages/settings/Wallet/Card/BaseGetPhysicalCard.js +++ b/src/pages/settings/Wallet/Card/BaseGetPhysicalCard.js @@ -176,8 +176,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]); diff --git a/src/pages/settings/Wallet/Card/GetPhysicalCardPhone.js b/src/pages/settings/Wallet/Card/GetPhysicalCardPhone.js index 27897c08d125..55702b9d8062 100644 --- a/src/pages/settings/Wallet/Card/GetPhysicalCardPhone.js +++ b/src/pages/settings/Wallet/Card/GetPhysicalCardPhone.js @@ -1,4 +1,3 @@ -import Str from 'expensify-common/lib/str'; import PropTypes from 'prop-types'; import React from 'react'; import {withOnyx} from 'react-native-onyx'; @@ -7,7 +6,7 @@ import InputWrapper from '@components/Form/InputWrapper'; import TextInput from '@components/TextInput'; import useLocalize from '@hooks/useLocalize'; import FormUtils from '@libs/FormUtils'; -import {parsePhoneNumber} from '@libs/PhoneNumber'; +import * as LoginUtils from '@libs/LoginUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -47,7 +46,7 @@ function GetPhysicalCardPhone({ const onValidate = (values) => { const errors = {}; - if (!(parsePhoneNumber(values.phoneNumber).possible && Str.isValidPhone(values.phoneNumber))) { + if (!LoginUtils.validateNumber(values.phoneNumber)) { errors.phoneNumber = 'common.error.phoneNumber'; } else if (_.isEmpty(values.phoneNumber)) { errors.phoneNumber = 'common.error.fieldRequired'; diff --git a/src/pages/settings/Wallet/ExpensifyCardPage.js b/src/pages/settings/Wallet/ExpensifyCardPage.js index cacf35db22a6..e62b821b7a72 100644 --- a/src/pages/settings/Wallet/ExpensifyCardPage.js +++ b/src/pages/settings/Wallet/ExpensifyCardPage.js @@ -116,8 +116,6 @@ const defaultProps = { function ExpensifyCardPage({ cardList, draftValues, - loginList, - privatePersonalDetails, route: { params: {domain}, }, @@ -159,9 +157,7 @@ function ExpensifyCardPage({ }; const goToGetPhysicalCardFlow = () => { - const updatedDraftValues = GetPhysicalCardUtils.getUpdatedDraftValues(draftValues, privatePersonalDetails, loginList); - - GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(updatedDraftValues), loginList); + GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(draftValues)); }; const hasDetectedDomainFraud = _.some(domainCards, (card) => card.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN); From 033be5001e10da21a67980659651609fb42d6cef Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Tue, 13 Feb 2024 21:44:16 +0000 Subject: [PATCH 3/3] fix: draft values not being properly set when entering get physical card flow from expensify card page --- .../settings/Wallet/ExpensifyCardPage.js | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/pages/settings/Wallet/ExpensifyCardPage.js b/src/pages/settings/Wallet/ExpensifyCardPage.js index 93b3efd8aa2e..38d8b5f13adb 100644 --- a/src/pages/settings/Wallet/ExpensifyCardPage.js +++ b/src/pages/settings/Wallet/ExpensifyCardPage.js @@ -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'; @@ -88,35 +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, + privatePersonalDetails, + loginList, route: { params: {domain}, }, @@ -158,7 +140,16 @@ function ExpensifyCardPage({ }; const goToGetPhysicalCardFlow = () => { - GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(draftValues)); + 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)); }; const hasDetectedDomainFraud = _.some(domainCards, (card) => card.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN);