diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index a9f8f3bd5b18a..5516f4fb69827 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -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'; @@ -55,7 +55,6 @@ type KYCFlowEvent = GestureResponderEvent | KeyboardEvent | undefined; type TriggerKYCFlow = (params: ContinueActionParams) => void; type CurrencyType = TupleToUnion; - function SettlementButton({ addDebitCardRoute = ROUTES.IOU_SEND_ADD_DEBIT_CARD, kycWallAnchorAlignment = { @@ -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); @@ -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 ?? ''); diff --git a/src/hooks/useBulkPayOptions.ts b/src/hooks/useBulkPayOptions.ts index 9a197bad3bdd9..f403e81bf1128 100644 --- a/src/hooks/useBulkPayOptions.ts +++ b/src/hooks/useBulkPayOptions.ts @@ -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'; @@ -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'), diff --git a/src/hooks/usePaymentOptions.ts b/src/hooks/usePaymentOptions.ts index 837a7940feeab..142139becfeec 100644 --- a/src/hooks/usePaymentOptions.ts +++ b/src/hooks/usePaymentOptions.ts @@ -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'; @@ -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) { @@ -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 ?? '', diff --git a/src/libs/API/parameters/CreateWorkspaceFromIOUPaymentParams.ts b/src/libs/API/parameters/CreateWorkspaceFromIOUPaymentParams.ts index 78bc040136aaa..2bbd8190b918b 100644 --- a/src/libs/API/parameters/CreateWorkspaceFromIOUPaymentParams.ts +++ b/src/libs/API/parameters/CreateWorkspaceFromIOUPaymentParams.ts @@ -14,6 +14,7 @@ type CreateWorkspaceFromIOUPaymentParams = { memberData: string; reportActionID: string | undefined; expenseMovedReportActionID: string | undefined; + currency: string; }; export default CreateWorkspaceFromIOUPaymentParams; diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 24dc129d1fa4e..cb466142b6fc3 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -3520,8 +3520,8 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF 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, @@ -3936,6 +3936,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF 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}); diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index b326d22ef8081..6ac58609b1a2d 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -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'; @@ -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'; @@ -1061,13 +1062,15 @@ function handleBulkPayItemSelected( confirmPayment?.(paymentType as PaymentMethodType, item?.additionalData); } +type CurrencyType = TupleToUnion; + /** * 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)); } /**