Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ const ONYXKEYS = {
/** Whether the user is a member of a policy other than their personal */
HAS_NON_PERSONAL_POLICY: 'hasNonPersonalPolicy',

/** Key under which personal policy id is stored. Returned by OpenApp */
PERSONAL_POLICY_ID: 'personalPolicyID',

/** NVP keys */

/** This NVP contains list of at most 5 recent attendees */
Expand Down Expand Up @@ -1375,6 +1378,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.NVP_REPORT_LAYOUT_GROUP_BY]: string;
[ONYXKEYS.HAS_DENIED_CONTACT_IMPORT_PROMPT]: boolean | undefined;
[ONYXKEYS.IS_OPEN_CONFIRM_NAVIGATE_EXPENSIFY_CLASSIC_MODAL_OPEN]: boolean;
[ONYXKEYS.PERSONAL_POLICY_ID]: string;
};

type OnyxDerivedValuesMapping = {
Expand Down
5 changes: 3 additions & 2 deletions src/components/DistanceRequest/DistanceRequestFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type {OnyxEntry} from 'react-native-onyx';
import Button from '@components/Button';
import DistanceMapView from '@components/DistanceMapView';
import * as Expensicons from '@components/Icon/Expensicons';

Check warning on line 7 in src/components/DistanceRequest/DistanceRequestFooter.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used by a pattern. Direct imports from Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details

Check warning on line 7 in src/components/DistanceRequest/DistanceRequestFooter.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used. Direct imports from @components/Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details
import ImageSVG from '@components/ImageSVG';
import type {WayPoint} from '@components/MapView/MapViewTypes';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
Expand All @@ -14,7 +14,6 @@
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
import {getPersonalPolicy} from '@libs/PolicyUtils';
import {getDistanceInMeters, getWaypointIndex, isCustomUnitRateIDForP2P} from '@libs/TransactionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -45,14 +44,16 @@
const {translate} = useLocalize();
const expensifyIcons = useMemoizedLazyExpensifyIcons(['Location']);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true});
const activePolicy = usePolicy(activePolicyID);
const personalPolicy = usePolicy(personalPolicyID);
const [mapboxAccessToken] = useOnyx(ONYXKEYS.MAPBOX_ACCESS_TOKEN, {canBeMissing: true});

const numberOfWaypoints = Object.keys(waypoints ?? {}).length;
const numberOfFilledWaypoints = Object.values(waypoints ?? {}).filter((waypoint) => waypoint?.address).length;
const lastWaypointIndex = numberOfWaypoints - 1;
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(policy ?? activePolicy);
const policyCurrency = (policy ?? activePolicy)?.outputCurrency ?? getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD;
const policyCurrency = (policy ?? activePolicy ?? personalPolicy)?.outputCurrency ?? CONST.CURRENCY.USD;
const mileageRate = isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(policyCurrency, transaction) : defaultMileageRate;
const {unit} = mileageRate ?? {};

Expand Down
3 changes: 3 additions & 0 deletions src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useLocalize from '@hooks/useLocalize';
import useOnboardingMessages from '@hooks/useOnboardingMessages';
import useOnyx from '@hooks/useOnyx';
import usePersonalPolicy from '@hooks/usePersonalPolicy';
import {
initMoneyRequest,
setMoneyRequestAmount,
Expand Down Expand Up @@ -46,6 +47,7 @@ function EmployeeTestDriveModal() {
const [isLoading, setIsLoading] = useState(false);
const {testDrive} = useOnboardingMessages();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const personalPolicy = usePersonalPolicy();
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
const hasOnlyPersonalPolicies = useMemo(() => hasOnlyPersonalPoliciesUtil(allPolicies), [allPolicies]);

Expand Down Expand Up @@ -75,6 +77,7 @@ function EmployeeTestDriveModal() {

initMoneyRequest({
reportID,
personalPolicy,
isFromGlobalCreate: false,
newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
report,
Expand Down
14 changes: 5 additions & 9 deletions src/hooks/usePersonalPolicy.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import {createPoliciesSelector} from '@selectors/Policy';
import {useMemo} from 'react';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import type {OnyxEntry} from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type Policy from '@src/types/onyx/Policy';
import useOnyx from './useOnyx';

type PolicySelector = Pick<Policy, 'id' | 'type' | 'autoReporting'>;
type PolicySelector = Pick<Policy, 'id' | 'type' | 'autoReporting' | 'outputCurrency'>;

const policySelector = (policy: OnyxEntry<Policy>): PolicySelector =>
(policy && {
id: policy.id,
type: policy.type,
autoReporting: policy.autoReporting,
outputCurrency: policy.outputCurrency,
}) as PolicySelector;

const allPoliciesSelector = (policies: OnyxCollection<Policy>) => createPoliciesSelector(policies, policySelector);

function usePersonalPolicy() {
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: allPoliciesSelector, canBeMissing: true});
const personalPolicy = useMemo(() => Object.values(allPolicies ?? {}).find((policy) => policy?.type === CONST.POLICY.TYPE.PERSONAL), [allPolicies]);
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true});
const [personalPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${personalPolicyID}`, {selector: policySelector, canBeMissing: true});
return personalPolicy;
}

Expand Down
3 changes: 3 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

let allPolicies: OnyxCollection<Policy>;

Onyx.connect({

Check warning on line 63 in src/libs/PolicyUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
Expand Down Expand Up @@ -928,6 +928,7 @@
return reimburserEmail ? (getAccountIDsByLogins([reimburserEmail]).at(0) ?? -1) : -1;
}

/** @deprecated Please use ONYXKEYS.PERSONAL_POLICY_ID to find the personal policyID */
function getPersonalPolicy() {
return Object.values(allPolicies ?? {}).find((policy) => policy?.type === CONST.POLICY.TYPE.PERSONAL);
}
Expand Down Expand Up @@ -1700,6 +1701,8 @@
getMemberAccountIDsForWorkspace,
getNumericValue,
isMultiLevelTags,
// This will be fixed as part of https://github.com/Expensify/App/issues/66397
// eslint-disable-next-line @typescript-eslint/no-deprecated
getPersonalPolicy,
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
Expand Down
6 changes: 2 additions & 4 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
getMemberAccountIDsForWorkspace,
getPerDiemCustomUnit,
getPerDiemRateCustomUnitRate,
getPersonalPolicy,
getPolicy,
getSubmitToAccountID,
hasDependentTags,
Expand Down Expand Up @@ -290,6 +289,7 @@
type InitMoneyRequestParams = {
reportID: string;
policy?: OnyxEntry<OnyxTypes.Policy>;
personalPolicy: Pick<OnyxTypes.Policy, 'id' | 'type' | 'autoReporting' | 'outputCurrency'> | undefined;
isFromGlobalCreate?: boolean;
currentIouRequestType?: IOURequestType | undefined;
newIouRequestType: IOURequestType | undefined;
Expand Down Expand Up @@ -753,7 +753,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 756 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -849,7 +849,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 852 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -863,7 +863,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 866 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -872,7 +872,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 875 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -886,7 +886,7 @@
});

let allNextSteps: NonNullable<OnyxCollection<OnyxTypes.ReportNextStepDeprecated>> = {};
Onyx.connect({

Check warning on line 889 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.NEXT_STEP,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -898,14 +898,14 @@
// `allRecentlyUsedTags` was moved here temporarily from `src/libs/actions/Policy/Tag.ts` during the `Deprecate Onyx.connect` refactor.
// All uses of this variable should be replaced with `useOnyx`.
let allRecentlyUsedTags: OnyxCollection<RecentlyUsedTags> = {};
Onyx.connect({

Check warning on line 901 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS,
waitForCollectionCallback: true,
callback: (val) => (allRecentlyUsedTags = val),
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 908 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1049,6 +1049,7 @@
function initMoneyRequest({
reportID,
policy,
personalPolicy,
isFromGlobalCreate,
currentIouRequestType,
newIouRequestType,
Expand All @@ -1060,9 +1061,6 @@
hasOnlyPersonalPolicies,
}: InitMoneyRequestParams) {
// Generate a brand new transactionID
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const personalPolicy = getPolicy(getPersonalPolicy()?.id);
const newTransactionID = CONST.IOU.OPTIMISTIC_TRANSACTION_ID;
const currency = policy?.outputCurrency ?? personalPolicy?.outputCurrency ?? CONST.CURRENCY.USD;

Expand Down
1 change: 1 addition & 0 deletions src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ function SearchPage({route}: SearchPageProps) {
const initialTransaction = initMoneyRequest({
isFromGlobalCreate: true,
reportID: newReportID,
personalPolicy,
newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
report: newReport,
parentReport: newParentReport,
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePersonalPolicy from '@hooks/usePersonalPolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useThemeStyles from '@hooks/useThemeStyles';
import type {GpsPoint} from '@libs/actions/IOU';
Expand Down Expand Up @@ -64,6 +65,7 @@ function SubmitDetailsPage({
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});

const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const personalPolicy = usePersonalPolicy();
const [startLocationPermissionFlow, setStartLocationPermissionFlow] = useState(false);

const [errorTitle, setErrorTitle] = useState<string | undefined>(undefined);
Expand All @@ -89,6 +91,7 @@ function SubmitDetailsPage({
initMoneyRequest({
reportID: reportOrAccountID,
policy,
personalPolicy,
currentIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
report,
Expand All @@ -97,7 +100,7 @@ function SubmitDetailsPage({
currentUserPersonalDetails,
hasOnlyPersonalPolicies,
});
}, [reportOrAccountID, policy, report, parentReport, currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies]);
}, [reportOrAccountID, policy, personalPolicy, report, parentReport, currentDate, currentUserPersonalDetails, hasOnlyPersonalPolicies]);

const selectedParticipants = unknownUserDetails ? [unknownUserDetails] : getMoneyRequestParticipantsFromReport(report, currentUserPersonalDetails.accountID);
const participants = selectedParticipants.map((participant) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {OnyxEntry} from 'react-native-onyx';
import useFilesValidation from '@hooks/useFilesValidation';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePersonalPolicy from '@hooks/usePersonalPolicy';
import {cleanFileObject, cleanFileObjectName, getFilesFromClipboardEvent} from '@libs/fileDownload/FileUtils';
import {hasOnlyPersonalPolicies as hasOnlyPersonalPoliciesUtil} from '@libs/PolicyUtils';
import {isSelfDM} from '@libs/ReportUtils';
Expand Down Expand Up @@ -52,6 +53,7 @@ function useAttachmentUploadValidation({
}: AttachmentUploadValidationProps) {
const {translate} = useLocalize();
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policy?.id}`, {canBeMissing: true});
const personalPolicy = usePersonalPolicy();
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
const hasOnlyPersonalPolicies = useMemo(() => hasOnlyPersonalPoliciesUtil(allPolicies), [allPolicies]);

Expand Down Expand Up @@ -92,6 +94,7 @@ function useAttachmentUploadValidation({

const initialTransaction = initMoneyRequest({
reportID,
personalPolicy,
newIouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
report,
parentReport: newParentReport,
Expand Down
4 changes: 4 additions & 0 deletions src/pages/iou/request/DistanceRequestStartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePersonalPolicy from '@hooks/usePersonalPolicy';
import usePolicy from '@hooks/usePolicy';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -64,6 +65,7 @@ function DistanceRequestStartPage({

const hasOnlyPersonalPolicies = useMemo(() => hasOnlyPersonalPoliciesUtil(allPolicies), [allPolicies]);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const personalPolicy = usePersonalPolicy();

const tabTitles = {
[CONST.IOU.TYPE.REQUEST]: translate('iou.trackDistance'),
Expand Down Expand Up @@ -107,6 +109,7 @@ function DistanceRequestStartPage({
initMoneyRequest({
reportID,
policy,
personalPolicy,
isFromGlobalCreate,
currentIouRequestType: transaction?.iouRequestType,
newIouRequestType: newIOUType,
Expand All @@ -122,6 +125,7 @@ function DistanceRequestStartPage({
transaction?.iouRequestType,
reportID,
policy,
personalPolicy,
isFromGlobalCreate,
report,
parentReport,
Expand Down
4 changes: 4 additions & 0 deletions src/pages/iou/request/IOURequestStartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePersonalPolicy from '@hooks/usePersonalPolicy';
import usePolicy from '@hooks/usePolicy';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -65,6 +66,7 @@ function IOURequestStartPage({
const {translate} = useLocalize();
const shouldUseTab = iouType !== CONST.IOU.TYPE.SEND && iouType !== CONST.IOU.TYPE.PAY && iouType !== CONST.IOU.TYPE.INVOICE;
const [isDraggingOver, setIsDraggingOver] = useState(false);
const personalPolicy = usePersonalPolicy();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true});
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {canBeMissing: true});
const policy = usePolicy(report?.policyID);
Expand Down Expand Up @@ -147,6 +149,7 @@ function IOURequestStartPage({
initMoneyRequest({
reportID,
policy,
personalPolicy,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this value is not loaded, it caused a bug detailed in #78741

isFromGlobalCreate: transaction?.isFromGlobalCreate ?? isFromGlobalCreate,
currentIouRequestType: transaction?.iouRequestType,
newIouRequestType: newIOUType,
Expand All @@ -163,6 +166,7 @@ function IOURequestStartPage({
transaction?.isFromGlobalCreate,
reportID,
policy,
personalPolicy,
isFromGlobalCreate,
report,
parentReport,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {getLatestErrorField} from '@libs/ErrorUtils';
import {navigateToParticipantPage, shouldUseTransactionDraft} from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils';
import {getPersonalPolicy, getPolicy, isPaidGroupPolicy} from '@libs/PolicyUtils';
import {getPolicy, isPaidGroupPolicy} from '@libs/PolicyUtils';
import {getPolicyExpenseChat, isArchivedReport, isPolicyExpenseChat as isPolicyExpenseChatUtil} from '@libs/ReportUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {getDistanceInMeters, getRateID, getRequestType, getValidWaypoints, hasRoute, isCustomUnitRateIDForP2P} from '@libs/TransactionUtils';
Expand Down Expand Up @@ -167,7 +167,7 @@ function IOURequestStepDistance({
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const IOUpolicy = getPolicy(report?.policyID ?? IOUpolicyID);
const policyCurrency = policy?.outputCurrency ?? getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD;
const policyCurrency = policy?.outputCurrency ?? personalPolicy?.outputCurrency ?? CONST.CURRENCY.USD;

const mileageRates = DistanceRequestUtils.getMileageRates(IOUpolicy);
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(IOUpolicy);
Expand All @@ -187,7 +187,7 @@ function IOURequestStepDistance({
setSplitShares(transaction, amount, currency ?? '', participantAccountIDs ?? []);
}
},
[report, allReports, transaction, transactionID, isSplitRequest, policy?.outputCurrency, reportID, customUnitRateID],
[report, allReports, transaction, transactionID, isSplitRequest, policy?.outputCurrency, reportID, customUnitRateID, personalPolicy?.outputCurrency],
);

// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace
Expand Down
6 changes: 3 additions & 3 deletions src/pages/iou/request/step/IOURequestStepDistanceMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {getLatestErrorField} from '@libs/ErrorUtils';
import {navigateToParticipantPage, shouldUseTransactionDraft} from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils';
import {getPersonalPolicy, getPolicy, isPaidGroupPolicy} from '@libs/PolicyUtils';
import {getPolicy, isPaidGroupPolicy} from '@libs/PolicyUtils';
import {getPolicyExpenseChat, isArchivedReport, isPolicyExpenseChat as isPolicyExpenseChatUtil} from '@libs/ReportUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {getDistanceInMeters, getRateID, getRequestType, getValidWaypoints, hasRoute, isCustomUnitRateIDForP2P} from '@libs/TransactionUtils';
Expand Down Expand Up @@ -169,7 +169,7 @@ function IOURequestStepDistanceMap({
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const IOUpolicy = getPolicy(report?.policyID ?? IOUpolicyID);
const policyCurrency = policy?.outputCurrency ?? getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD;
const policyCurrency = policy?.outputCurrency ?? personalPolicy?.outputCurrency ?? CONST.CURRENCY.USD;

const mileageRates = DistanceRequestUtils.getMileageRates(IOUpolicy);
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(IOUpolicy);
Expand All @@ -189,7 +189,7 @@ function IOURequestStepDistanceMap({
setSplitShares(transaction, amount, currency ?? '', participantAccountIDs ?? []);
}
},
[report, allReports, transaction, transactionID, isSplitRequest, policy?.outputCurrency, reportID, customUnitRateID],
[report, allReports, transaction, transactionID, isSplitRequest, policy?.outputCurrency, reportID, customUnitRateID, personalPolicy?.outputCurrency],
);

// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace
Expand Down
5 changes: 3 additions & 2 deletions src/pages/settings/Preferences/PaymentCurrencyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
import {updateGeneralSettings} from '@libs/actions/Policy/Policy';
import Navigation from '@libs/Navigation/Navigation';
import {getPersonalPolicy} from '@libs/PolicyUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import KeyboardUtils from '@src/utils/keyboard';

function PaymentCurrencyPage() {
const styles = useThemeStyles();
const {translate} = useLocalize();
const personalPolicyID = getPersonalPolicy()?.id;
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true});
const personalPolicy = usePolicy(personalPolicyID);

const paymentCurrency = personalPolicy?.outputCurrency ?? CONST.CURRENCY.USD;
Expand Down
5 changes: 3 additions & 2 deletions src/pages/settings/Preferences/PreferencesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {getCurrencySymbol} from '@libs/CurrencyUtils';
import getPlatform from '@libs/getPlatform';
import type Platform from '@libs/getPlatform/types';
import Navigation from '@libs/Navigation/Navigation';
import {getPersonalPolicy} from '@libs/PolicyUtils';
import colors from '@styles/theme/colors';
import CONST from '@src/CONST';
import {isFullySupportedLocale, LOCALE_TO_LANGUAGE_STRING} from '@src/CONST/LOCALES';
Expand All @@ -38,7 +37,9 @@ function PreferencesPage() {
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: false});
const [preferredTheme] = useOnyx(ONYXKEYS.PREFERRED_THEME, {canBeMissing: true});
const [preferredLocale] = useOnyx(ONYXKEYS.NVP_PREFERRED_LOCALE, {canBeMissing: true});
const personalPolicy = usePolicy(getPersonalPolicy()?.id);
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true});

const personalPolicy = usePolicy(personalPolicyID);

const paymentCurrency = personalPolicy?.outputCurrency ?? CONST.CURRENCY.USD;

Expand Down
Loading
Loading