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
7 changes: 3 additions & 4 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
import {createWorkspace, isCurrencySupportedForDirectReimbursement} from '@libs/actions/Policy/Policy';
import {createWorkspace, isCurrencySupportedForDirectReimbursement, isCurrencySupportedForGlobalReimbursement} from '@libs/actions/Policy/Policy';
import {navigateToBankAccountRoute} from '@libs/actions/ReimbursementAccount';
import {getLastPolicyBankAccountID, getLastPolicyPaymentMethod} from '@libs/actions/Search';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -55,7 +55,6 @@ type KYCFlowEvent = GestureResponderEvent | KeyboardEvent | undefined;
type TriggerKYCFlow = (params: ContinueActionParams) => void;

type CurrencyType = TupleToUnion<typeof CONST.DIRECT_REIMBURSEMENT_CURRENCIES>;

function SettlementButton({
addDebitCardRoute = ROUTES.IOU_SEND_ADD_DEBIT_CARD,
kycWallAnchorAlignment = {
Expand Down Expand Up @@ -250,7 +249,7 @@ function SettlementButton({
disabled: !!shouldDisableApproveButton,
};

const canUseWallet = !isExpenseReport && !isInvoiceReport && currency === CONST.CURRENCY.USD;
const canUseWallet = !isExpenseReport && !isInvoiceReport && isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const canUseBusinessBankAccount = isExpenseReport || (isIOUReport(iouReport) && reportID && !hasRequestFromCurrentAccount(reportID, accountID ?? CONST.DEFAULT_NUMBER_ID));

const canUsePersonalBankAccount = shouldShowPersonalBankAccountOption || isIOUReport(iouReport);
Expand Down Expand Up @@ -322,9 +321,9 @@ function SettlementButton({
}

if (isInvoiceReport) {
const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const hasActivePolicyAsAdmin = !!activePolicy && isPolicyAdmin(activePolicy) && isPaidGroupPolicy(activePolicy);

const isCurrencySupported = isCurrencySupportedForDirectReimbursement(currency as CurrencyType);
const isActivePolicyCurrencySupported = isCurrencySupportedForDirectReimbursement(activePolicy?.outputCurrency ?? '');
const isUserCurrencySupported = isCurrencySupportedForDirectReimbursement(localCurrencyCode ?? '');
const isInvoiceReceiverPolicyCurrencySupported = isCurrencySupportedForDirectReimbursement(invoiceReceiverPolicy?.outputCurrency ?? '');
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useBulkPayOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {TupleToUnion} from 'type-fest';
import {Bank, Cash, Wallet} from '@components/Icon/Expensicons';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import type {BankAccountMenuItem} from '@components/Search/types';
import {isCurrencySupportedForDirectReimbursement} from '@libs/actions/Policy/Policy';
import {isCurrencySupportedForGlobalReimbursement} from '@libs/actions/Policy/Policy';
import Navigation from '@libs/Navigation/Navigation';
import {formatPaymentMethods} from '@libs/PaymentUtils';
import {hasRequestFromCurrentAccount} from '@libs/ReportActionsUtils';
Expand Down Expand Up @@ -174,7 +174,7 @@ function useBulkPayOptions({
}

if (isInvoiceReport) {
const isCurrencySupported = isCurrencySupportedForDirectReimbursement(currency as CurrencyType);
const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const getInvoicesOptions = (payAsBusiness: boolean) => {
const addBankAccountItem = {
text: translate('bankAccount.addBankAccount'),
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/usePaymentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
isInvoiceReport as isInvoiceReportUtil,
} from '@libs/ReportUtils';
import Navigation from '@navigation/Navigation';
import {isCurrencySupportedForDirectReimbursement} from '@userActions/Policy/Policy';
import {isCurrencySupportedForGlobalReimbursement} from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {BankAccountList, FundList, LastPaymentMethod} from '@src/types/onyx';
Expand Down Expand Up @@ -139,7 +139,7 @@ function usePaymentOptions({
value: CONST.IOU.REPORT_ACTION_TYPE.APPROVE,
disabled: !!shouldDisableApproveButton,
};
const canUseWallet = !isExpenseReport && !isInvoiceReport && currency === CONST.CURRENCY.USD;
const canUseWallet = !isExpenseReport && !isInvoiceReport && isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);

// Only show the Approve button if the user cannot pay the expense
if (shouldHidePaymentOptions && shouldShowApproveButton) {
Expand All @@ -163,7 +163,7 @@ function usePaymentOptions({

if (isInvoiceReport) {
const formattedPaymentMethods = formatPaymentMethods(bankAccountList, fundList, styles, translate);
const isCurrencySupported = isCurrencySupportedForDirectReimbursement(currency as CurrencyType);
const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const getPaymentSubitems = (payAsBusiness: boolean) =>
formattedPaymentMethods.map((formattedPaymentMethod) => ({
text: formattedPaymentMethod?.title ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type CreateWorkspaceFromIOUPaymentParams = {
memberData: string;
reportActionID: string | undefined;
expenseMovedReportActionID: string | undefined;
currency: string;
};

export default CreateWorkspaceFromIOUPaymentParams;
5 changes: 3 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
};

const deprecatedAllPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 209 in src/libs/actions/Policy/Policy.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,
callback: (val, key) => {
if (!key) {
Expand All @@ -222,7 +222,7 @@
});

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

Check warning on line 225 in src/libs/actions/Policy/Policy.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 All @@ -231,7 +231,7 @@
});

let deprecatedAllReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 234 in src/libs/actions/Policy/Policy.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_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -241,7 +241,7 @@

let deprecatedSessionEmail = '';
let deprecatedSessionAccountID = 0;
Onyx.connect({

Check warning on line 244 in src/libs/actions/Policy/Policy.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.SESSION,
callback: (val) => {
deprecatedSessionEmail = val?.email ?? '';
Expand All @@ -250,25 +250,25 @@
});

let deprecatedAllPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 253 in src/libs/actions/Policy/Policy.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: (val) => (deprecatedAllPersonalDetails = val),
});

let deprecatedAllRecentlyUsedCurrencies: string[];
Onyx.connect({

Check warning on line 259 in src/libs/actions/Policy/Policy.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.RECENTLY_USED_CURRENCIES,
callback: (val) => (deprecatedAllRecentlyUsedCurrencies = val ?? []),
});

let deprecatedActivePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 265 in src/libs/actions/Policy/Policy.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.NVP_ACTIVE_POLICY_ID,
callback: (value) => (deprecatedActivePolicyID = value),
});

let deprecatedIntroSelected: OnyxEntry<IntroSelected>;
Onyx.connect({

Check warning on line 271 in src/libs/actions/Policy/Policy.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.NVP_INTRO_SELECTED,
callback: (value) => (deprecatedIntroSelected = value),
});
Expand Down Expand Up @@ -3520,8 +3520,8 @@
ownerAccountID: deprecatedSessionAccountID,
isPolicyExpenseChatEnabled: true,

// Setting the currency to USD as we can only add the VBBA for this policy currency right now
outputCurrency: CONST.CURRENCY.USD,
// Setting the new workspace currency to the currency of the iouReport
outputCurrency: iouReport.currency ?? CONST.CURRENCY.USD,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
autoReporting: true,
autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.IMMEDIATE,
Expand Down Expand Up @@ -3936,6 +3936,7 @@
memberData: JSON.stringify(memberData),
reportActionID: movedReportAction.reportActionID,
expenseMovedReportActionID: movedIouReportAction.reportActionID,
currency: iouReport.currency ?? CONST.CURRENCY.USD,
};

API.write(WRITE_COMMANDS.CREATE_WORKSPACE_FROM_IOU_PAYMENT, params, {optimisticData, successData, failureData});
Expand Down
9 changes: 6 additions & 3 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import isEmpty from 'lodash/isEmpty';
import Onyx from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {TupleToUnion, ValueOf} from 'type-fest';
import type {FormOnyxValues} from '@components/Form/types';
import type {ContinueActionParams, PaymentMethod, PaymentMethodType} from '@components/KYCWall/types';
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
Expand Down Expand Up @@ -50,6 +50,7 @@ import type Nullable from '@src/types/utils/Nullable';
import SafeString from '@src/utils/SafeString';
import {setPersonalBankAccountContinueKYCOnSuccess} from './BankAccounts';
import {prepareRejectMoneyRequestData, rejectMoneyRequest} from './IOU';
import {isCurrencySupportedForGlobalReimbursement} from './Policy/Policy';
import {setOptimisticTransactionThread} from './Report';
import {saveLastSearchParams} from './ReportNavigation';

Expand Down Expand Up @@ -1061,13 +1062,15 @@ function handleBulkPayItemSelected(
confirmPayment?.(paymentType as PaymentMethodType, item?.additionalData);
}

type CurrencyType = TupleToUnion<typeof CONST.DIRECT_REIMBURSEMENT_CURRENCIES>;

/**
* Return true if selected reports/transactions have the same USD currency.
*/
function isCurrencySupportWalletBulkPay(selectedReports: SelectedReports[], selectedTransactions: SelectedTransactions) {
return selectedReports?.length > 0
? Object.values(selectedReports).every((report) => report?.currency === CONST.CURRENCY.USD)
: Object.values(selectedTransactions).every((transaction) => transaction.currency === CONST.CURRENCY.USD);
? Object.values(selectedReports).every((report) => isCurrencySupportedForGlobalReimbursement(report?.currency as CurrencyType))
: Object.values(selectedTransactions).every((transaction) => isCurrencySupportedForGlobalReimbursement(transaction.currency as CurrencyType));
}

/**
Expand Down
Loading