diff --git a/src/components/AddressSearch/index.tsx b/src/components/AddressSearch/index.tsx
index 2679a550f72f..c7753dccadd7 100644
--- a/src/components/AddressSearch/index.tsx
+++ b/src/components/AddressSearch/index.tsx
@@ -233,7 +233,7 @@ function AddressSearch(
if (inputID) {
Object.entries(values).forEach(([key, inputValue]) => {
- const inputKey = renamedInputKeys?.[key as keyof Address] ?? key;
+ const inputKey = renamedInputKeys?.[key as keyof Omit
] ?? key;
if (!inputKey) {
return;
}
diff --git a/src/libs/GetPhysicalCardUtils.ts b/src/libs/GetPhysicalCardUtils.ts
index 48c537f0f14c..8dc46204db3c 100644
--- a/src/libs/GetPhysicalCardUtils.ts
+++ b/src/libs/GetPhysicalCardUtils.ts
@@ -9,7 +9,8 @@ import * as PersonalDetailsUtils from './PersonalDetailsUtils';
import * as UserUtils from './UserUtils';
function getCurrentRoute(domain: string, privatePersonalDetails: OnyxEntry): Route {
- const {address, legalFirstName, legalLastName, phoneNumber} = privatePersonalDetails ?? {};
+ const {legalFirstName, legalLastName, phoneNumber} = privatePersonalDetails ?? {};
+ const address = PersonalDetailsUtils.getCurrentAddress(privatePersonalDetails);
if (!legalFirstName && !legalLastName) {
return ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_NAME.getRoute(domain);
@@ -55,7 +56,8 @@ function setCurrentRoute(currentRoute: string, domain: string, privatePersonalDe
* @returns
*/
function getUpdatedDraftValues(draftValues: OnyxEntry, privatePersonalDetails: OnyxEntry, loginList: OnyxEntry): GetPhysicalCardForm {
- const {address, legalFirstName, legalLastName, phoneNumber} = privatePersonalDetails ?? {};
+ const {legalFirstName, legalLastName, phoneNumber} = privatePersonalDetails ?? {};
+ const address = PersonalDetailsUtils.getCurrentAddress(privatePersonalDetails);
return {
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
@@ -78,13 +80,13 @@ function getUpdatedDraftValues(draftValues: OnyxEntry, priv
* @param draftValues
* @returns
*/
-function getUpdatedPrivatePersonalDetails(draftValues: OnyxEntry): PrivatePersonalDetails {
+function getUpdatedPrivatePersonalDetails(draftValues: OnyxEntry, privatePersonalDetails: OnyxEntry): PrivatePersonalDetails {
const {addressLine1, addressLine2, city = '', country = '', legalFirstName, legalLastName, phoneNumber, state = '', zipPostCode = ''} = draftValues ?? {};
return {
legalFirstName,
legalLastName,
phoneNumber,
- address: {street: PersonalDetailsUtils.getFormattedStreet(addressLine1, addressLine2), city, country, state, zip: zipPostCode},
+ addresses: [...(privatePersonalDetails?.addresses ?? []), {street: PersonalDetailsUtils.getFormattedStreet(addressLine1, addressLine2), city, country, state, zip: zipPostCode}],
};
}
diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts
index 9beb3d382696..98b1e2f5608c 100644
--- a/src/libs/PersonalDetailsUtils.ts
+++ b/src/libs/PersonalDetailsUtils.ts
@@ -4,6 +4,7 @@ import Onyx from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {OnyxInputOrEntry, PersonalDetails, PersonalDetailsList, PrivatePersonalDetails} from '@src/types/onyx';
+import type {Address} from '@src/types/onyx/PrivatePersonalDetails';
import type {OnyxData} from '@src/types/onyx/Request';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import * as LocalePhoneNumber from './LocalePhoneNumber';
@@ -224,6 +225,18 @@ function getStreetLines(street = '') {
return [streets[0], streets[1]];
}
+/**
+ * Get the current address from addresses array
+ *
+ * @param privatePersonalDetails - details object
+ * @returns - current address object
+ */
+function getCurrentAddress(privatePersonalDetails: OnyxEntry): Address | undefined {
+ const {addresses} = privatePersonalDetails ?? {};
+ const currentAddress = addresses?.find((address) => address.current);
+ return currentAddress ?? addresses?.[addresses.length - 1];
+}
+
/**
* Formats an address object into an easily readable string
*
@@ -231,7 +244,7 @@ function getStreetLines(street = '') {
* @returns - formatted address
*/
function getFormattedAddress(privatePersonalDetails: OnyxEntry): string {
- const {address} = privatePersonalDetails ?? {};
+ const address = getCurrentAddress(privatePersonalDetails);
const [street1, street2] = getStreetLines(address?.street);
const formattedAddress =
formatPiece(street1) + formatPiece(street2) + formatPiece(address?.city) + formatPiece(address?.state) + formatPiece(address?.zip) + formatPiece(address?.country);
@@ -318,6 +331,7 @@ export {
getAccountIDsByLogins,
getLoginsByAccountIDs,
getPersonalDetailsOnyxDataForOptimisticUsers,
+ getCurrentAddress,
getFormattedAddress,
getFormattedStreet,
getStreetLines,
diff --git a/src/libs/actions/PersonalDetails.ts b/src/libs/actions/PersonalDetails.ts
index 8e2fff3868ae..09fe790811cf 100644
--- a/src/libs/actions/PersonalDetails.ts
+++ b/src/libs/actions/PersonalDetails.ts
@@ -23,7 +23,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {DateOfBirthForm} from '@src/types/form';
-import type {PersonalDetails, PersonalDetailsList} from '@src/types/onyx';
+import type {PersonalDetails, PersonalDetailsList, PrivatePersonalDetails} from '@src/types/onyx';
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
let currentUserEmail = '';
@@ -42,6 +42,12 @@ Onyx.connect({
callback: (val) => (allPersonalDetails = val),
});
+let privatePersonalDetails: OnyxEntry;
+Onyx.connect({
+ key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
+ callback: (val) => (privatePersonalDetails = val),
+});
+
function updatePronouns(pronouns: string) {
if (!currentUserAccountID) {
return;
@@ -170,13 +176,17 @@ function updateAddress(street: string, street2: string, city: string, state: str
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
- address: {
- street: PersonalDetailsUtils.getFormattedStreet(street, street2),
- city,
- state,
- zip,
- country,
- },
+ addresses: [
+ ...(privatePersonalDetails?.addresses ?? []),
+ {
+ street: PersonalDetailsUtils.getFormattedStreet(street, street2),
+ city,
+ state,
+ zip,
+ country,
+ current: true,
+ },
+ ],
},
},
],
diff --git a/src/libs/actions/Wallet.ts b/src/libs/actions/Wallet.ts
index 7ba0fd8d474e..b1f97421eea0 100644
--- a/src/libs/actions/Wallet.ts
+++ b/src/libs/actions/Wallet.ts
@@ -11,6 +11,7 @@ import type {
} from '@libs/API/parameters';
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import type {PrivatePersonalDetails} from '@libs/GetPhysicalCardUtils';
+import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import type CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {WalletAdditionalQuestionDetails} from '@src/types/onyx';
@@ -257,7 +258,8 @@ function answerQuestionsForWallet(answers: WalletQuestionAnswer[], idNumber: str
}
function requestPhysicalExpensifyCard(cardID: number, authToken: string, privatePersonalDetails: PrivatePersonalDetails) {
- const {legalFirstName = '', legalLastName = '', phoneNumber = '', address: {city = '', country = '', state = '', street = '', zip = ''} = {}} = privatePersonalDetails;
+ const {legalFirstName = '', legalLastName = '', phoneNumber = ''} = privatePersonalDetails;
+ const {city = '', country = '', state = '', street = '', zip = ''} = PersonalDetailsUtils.getCurrentAddress(privatePersonalDetails) ?? {};
const requestParams: RequestPhysicalExpensifyCardParams = {
authToken,
diff --git a/src/pages/settings/Profile/PersonalDetails/PersonalAddressPage.tsx b/src/pages/settings/Profile/PersonalDetails/PersonalAddressPage.tsx
index 85402137fe6d..3e5287c82a42 100644
--- a/src/pages/settings/Profile/PersonalDetails/PersonalAddressPage.tsx
+++ b/src/pages/settings/Profile/PersonalDetails/PersonalAddressPage.tsx
@@ -4,6 +4,7 @@ import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
+import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import AddressPage from '@pages/AddressPage';
import * as PersonalDetails from '@userActions/PersonalDetails';
import type {FormOnyxValues} from '@src/components/Form/types';
@@ -37,7 +38,7 @@ function updateAddress(values: FormOnyxValues privatePersonalDetails?.address, [privatePersonalDetails]);
+ const address = useMemo(() => PersonalDetailsUtils.getCurrentAddress(privatePersonalDetails), [privatePersonalDetails]);
return (
{
- const updatedPrivatePersonalDetails = GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(draftValues);
+ const updatedPrivatePersonalDetails = GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(draftValues, privatePersonalDetails);
// If the current step of the get physical card flow is the confirmation page
if (isConfirmation) {
Wallet.requestPhysicalExpensifyCard(cardToBeIssued?.cardID ?? -1, session?.authToken ?? '', updatedPrivatePersonalDetails);
@@ -156,7 +156,7 @@ function BaseGetPhysicalCard({
return;
}
GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, updatedPrivatePersonalDetails);
- }, [cardID, cardToBeIssued?.cardID, domain, draftValues, isConfirmation, session?.authToken]);
+ }, [cardID, cardToBeIssued?.cardID, domain, draftValues, isConfirmation, session?.authToken, privatePersonalDetails]);
return (
goToGetPhysicalCardAddress(domain)}
shouldShowRightIcon
title={PersonalDetailsUtils.getFormattedAddress({
- address: {
- street: PersonalDetailsUtils.getFormattedStreet(addressLine1, addressLine2),
- city,
- state,
- zip: zipPostCode,
- country,
- },
+ addresses: [
+ {
+ street: PersonalDetailsUtils.getFormattedStreet(addressLine1, addressLine2),
+ city,
+ state,
+ zip: zipPostCode,
+ country,
+ },
+ ],
})}
/>
diff --git a/src/pages/settings/Wallet/ExpensifyCardPage.tsx b/src/pages/settings/Wallet/ExpensifyCardPage.tsx
index 81611d3defb0..4fec05f51e13 100644
--- a/src/pages/settings/Wallet/ExpensifyCardPage.tsx
+++ b/src/pages/settings/Wallet/ExpensifyCardPage.tsx
@@ -146,7 +146,7 @@ function ExpensifyCardPage({
FormActions.setDraftValues(ONYXKEYS.FORMS.GET_PHYSICAL_CARD_FORM, updatedDraftValues);
}
- GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(updatedDraftValues));
+ GetPhysicalCardUtils.goToNextPhysicalCardRoute(domain, GetPhysicalCardUtils.getUpdatedPrivatePersonalDetails(updatedDraftValues, privatePersonalDetails));
};
if (isNotFound) {
diff --git a/src/pages/settings/Wallet/ReportCardLostPage.tsx b/src/pages/settings/Wallet/ReportCardLostPage.tsx
index 4a84f0294d78..35b5bc9cd19a 100644
--- a/src/pages/settings/Wallet/ReportCardLostPage.tsx
+++ b/src/pages/settings/Wallet/ReportCardLostPage.tsx
@@ -65,14 +65,16 @@ type ReportCardLostPageProps = ReportCardLostPageOnyxProps & StackScreenProps