Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ function SearchAutocompleteList({
translate,
getReportByID,
rules,
bankAccountList,
},
);

Expand Down Expand Up @@ -375,6 +376,7 @@ function SearchAutocompleteList({
getReportByID,
rules,
formatPhoneNumber,
bankAccountList,
}).options;
const optionsByReportID = new Map(options.recentReports.map((option) => [option.reportID, option]));
serverReportsOptions = orderedReportIDs.map((reportID) => optionsByReportID.get(reportID)).filter((option): option is OptionData => !!option && !option.isSelfDM);
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useAutocompleteSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ function useAutocompleteSuggestions({
translate,
getReportByID,
rules,
bankAccountList,
}).options.personalDetails.filter((participant) => participant.text && !alreadyAutocompletedKeys.has(participant.text.toLowerCase()));

return participants.map((participant) => ({
Expand Down Expand Up @@ -359,6 +360,7 @@ function useAutocompleteSuggestions({
translate,
getReportByID,
rules,
bankAccountList,
}).options.recentReports.filter((chat) => {
if (!chat.text) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useSearchSelector/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function useSearchSelectorBase<TSelected extends Option = OptionData>({
const currentUserEmail = currentUserPersonalDetails.email ?? '';
const personalDetails = usePersonalDetails();
const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const [isTrackIntentUser] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {selector: isTrackIntentUserSelector});
const [rules] = useOnyx(ONYXKEYS.COLLECTION.RULE);
Expand Down Expand Up @@ -413,6 +414,7 @@ function useSearchSelectorBase<TSelected extends Option = OptionData>({
formatPhoneNumber,
isTrackIntentUser,
getReportByID,
bankAccountList,
...appliedGetValidOptionsConfig,
},
{translate, formatPhoneNumber},
Expand Down
15 changes: 15 additions & 0 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import CONST from '@src/CONST';
import IntlStore from '@src/languages/IntlStore';
import ONYXKEYS from '@src/ONYXKEYS';
import type {
BankAccountList,
Locale,
Login,
OnyxInputOrEntry,
Expand Down Expand Up @@ -236,6 +237,7 @@ type GetAlternateTextConfig = {
localeCompare?: LocaleContextProps['localeCompare'];
formatPhoneNumber?: LocaleContextProps['formatPhoneNumber'];
rules: OnyxCollection<Rule>;
bankAccountList?: OnyxEntry<BankAccountList>;
};

/**
Expand Down Expand Up @@ -280,6 +282,7 @@ function getAlternateText(
localeCompare,
formatPhoneNumber,
rules,
bankAccountList,
}: GetAlternateTextConfig,
) {
const report = getReportOrDraftReport({reportID: option.reportID});
Expand Down Expand Up @@ -326,6 +329,7 @@ function getAlternateText(
convertToDisplayString,
convertToDisplayStringWithoutCurrency: convertToDisplayStringWithoutCurrency ?? fallbackConvertToDisplayStringWithoutCurrency,
rules,
bankAccountList,
});
}
if (option.lastMessageText) {
Expand Down Expand Up @@ -2201,6 +2205,7 @@ function prepareReportOptionsForDisplay(
formatPhoneNumber?: LocaleContextProps['formatPhoneNumber'];
transactionThreadIDs?: Record<string, string | undefined>;
lastActions: Record<string, ReportAction> | undefined;
bankAccountList?: OnyxEntry<BankAccountList>;
},
conciergeReportID: string | undefined,
sortedActions: Record<string, ReportAction[]> | undefined,
Expand Down Expand Up @@ -2233,6 +2238,7 @@ function prepareReportOptionsForDisplay(
formatPhoneNumber,
transactionThreadIDs,
lastActions,
bankAccountList,
} = config;

const validOptions: Array<SearchOption<Report>> = [];
Expand Down Expand Up @@ -2260,6 +2266,7 @@ function prepareReportOptionsForDisplay(
localeCompare,
formatPhoneNumber,
translate,
bankAccountList,
]);

for (let i = 0; i < options.length; i++) {
Expand Down Expand Up @@ -2308,6 +2315,7 @@ function prepareReportOptionsForDisplay(
localeCompare,
formatPhoneNumber,
rules,
bankAccountList,
},
),
);
Expand Down Expand Up @@ -2418,6 +2426,7 @@ function getValidOptions(
sortedActions,
transactionThreadIDs,
lastActions,
bankAccountList,
currentUserLogin,
localeCompare,
isTrackIntentUser,
Expand Down Expand Up @@ -2559,6 +2568,7 @@ function getValidOptions(
formatPhoneNumber,
transactionThreadIDs,
lastActions,
bankAccountList,
},
conciergeReportID,
sortedActions,
Expand Down Expand Up @@ -2593,6 +2603,7 @@ function getValidOptions(
formatPhoneNumber,
transactionThreadIDs,
lastActions,
bankAccountList,
},
conciergeReportID,
sortedActions,
Expand Down Expand Up @@ -2623,6 +2634,7 @@ function getValidOptions(
formatPhoneNumber,
transactionThreadIDs,
lastActions,
bankAccountList,
},
conciergeReportID,
sortedActions,
Expand Down Expand Up @@ -2809,6 +2821,7 @@ type SearchOptionsConfig = {
/** @see GetValidReportsConfig['getReportByID'] */
getReportByID: GetOptionsConfig['getReportByID'];
rules: OnyxCollection<Rule>;
bankAccountList?: OnyxEntry<BankAccountList>;
};

/**
Expand Down Expand Up @@ -2851,6 +2864,7 @@ function getSearchOptions({
convertToDisplayString,
convertToDisplayStringWithoutCurrency,
rules,
bankAccountList,
}: SearchOptionsConfig): OptionsResult {
const optionList = getValidOptions(
options,
Expand Down Expand Up @@ -2896,6 +2910,7 @@ function getSearchOptions({
excludeFromSuggestionsOnly,
isTrackIntentUser,
getReportByID,
bankAccountList,
},
{translate, formatPhoneNumber},
rules,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OptionsListUtils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {AvatarSource} from '@libs/UserAvatarUtils';

import type {IOUAction} from '@src/CONST';
import type {
BankAccountList,
Login,
PersonalDetails,
PersonalDetailsList,
Expand Down Expand Up @@ -301,6 +302,7 @@ type GetOptionsConfig = {
localeCompare?: LocaleContextProps['localeCompare'];
formatPhoneNumber?: LocaleContextProps['formatPhoneNumber'];
isTrackIntentUser?: boolean;
bankAccountList?: OnyxEntry<BankAccountList>;
/** The user's default workspace. Its expense chat is ranked first in the separated workspace chats so the result limit can't drop it */
activePolicyID?: OnyxEntry<string>;
/** TODO: Should be required field in the future. Refactor issue: https://github.com/Expensify/App/issues/66407 */
Expand Down
10 changes: 4 additions & 6 deletions src/libs/PolicyUtils/members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
*/
import type {PersonalDetailsByLogin} from '@components/PersonalDetailsByLoginProvider';

import {getBankAccountFromID} from '@libs/actions/BankAccounts';
import {getIsOffline} from '@libs/NetworkState';
import {generateAccountID} from '@libs/UserUtils';

import CONST from '@src/CONST';
import type {PersonalDetailsList, Policy, PolicyEmployeeList} from '@src/types/onyx';
import type {BankAccount, PersonalDetailsList, Policy, PolicyEmployeeList} from '@src/types/onyx';
import type PolicyEmployee from '@src/types/onyx/PolicyEmployee';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

Expand All @@ -22,12 +21,11 @@ import {getActivePolicies, shouldShowPolicy} from './policy';
type MemberEmailsToAccountIDs = Record<string, number>;

/** Return the emails that can receive a shared bank account from the current user. */
function getEligibleBankAccountShareRecipientEmails(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined, bankAccountID: string | undefined): string[] {
function getEligibleBankAccountShareRecipientEmails(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined, currentBankAccount: OnyxEntry<BankAccount>): string[] {
if (!currentUserLogin) {
return [];
}

const currentBankAccount = getBankAccountFromID(Number(bankAccountID));
const isOffline = getIsOffline();
const activePolicies = getActivePolicies(policies, currentUserLogin).filter(
(policy) => shouldShowPolicy(policy, isOffline, currentUserLogin) && canMemberWrite(policy, currentUserLogin, CONST.POLICY.POLICY_FEATURE.WORKFLOWS_PAYMENTS),
Expand Down Expand Up @@ -57,8 +55,8 @@ function getEligibleBankAccountShareRecipientEmails(policies: OnyxCollection<Pol
}

/** Return whether the current user has someone they can share a bank account with. */
function hasEligibleBankAccountShareRecipient(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined, bankAccountID: string | undefined): boolean {
return getEligibleBankAccountShareRecipientEmails(policies, currentUserLogin, bankAccountID).length > 0;
function hasEligibleBankAccountShareRecipient(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined, currentBankAccount: OnyxEntry<BankAccount>): boolean {
return getEligibleBankAccountShareRecipientEmails(policies, currentUserLogin, currentBankAccount).length > 0;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ import type {LastVisibleMessage} from './ReportActionsUtils';
import type {AvatarSource} from './UserAvatarUtils';

import {isIntuitEnterpriseSuiteConnection} from './AccountingUtils';
import {getBankAccountFromID} from './actions/BankAccounts';
import hasCreditBankAccount from './actions/ReimbursementAccount/hasCreditBankAccount';
import {getAnchorHref, isAttachmentAnchorTag, isOwnAttachmentURL} from './AttachmentAnchorUtils';
import {convertAttendeesToArray, normalizeAttendees} from './AttendeeUtils';
Expand Down Expand Up @@ -7073,7 +7072,7 @@ type GetReportPreviewMessageBaseParams = {
/** This can be either a report preview action or the IOU action. This will be the original report preview action in cases where `iouReportAction` was unwrapped from a report preview action. Otherwise, it will be the same as `iouReportAction`. */
originalReportAction?: OnyxInputOrEntry<ReportAction>;
/** The current user's bank accounts, used to name the account a report was paid with. */
bankAccountList?: OnyxEntry<BankAccountList>;
bankAccountList: OnyxEntry<BankAccountList>;
personalDetails?: OnyxEntry<PersonalDetailsList>;
/** The transaction of `iouReportAction`. Pass it from a subscription so a memoized caller doesn't read an outdated module-level copy. Split and track actions rely on it, since their transaction isn't part of `reportOrID`. */
linkedTransaction?: OnyxEntry<Transaction>;
Expand Down Expand Up @@ -7263,7 +7262,7 @@ function getReportPreviewMessage(

if (isFromInvoice) {
translatePhraseKey = originalMessage?.payAsBusiness ? 'iou.settleInvoiceBusiness' : 'iou.settleInvoicePersonal';
const currentBankAccount = getBankAccountFromID(originalMessage?.bankAccountID);
const currentBankAccount = originalMessage?.bankAccountID ? bankAccountList?.[originalMessage.bankAccountID] : undefined;
return translate(translatePhraseKey, formattedAmount, currentBankAccount?.accountData?.accountNumber?.slice(-4) ?? '');
}
}
Expand Down Expand Up @@ -7389,6 +7388,7 @@ function getReportPreviewReportActionMessage(
| 'isPreviewMessageForParentChatReport'
| 'isForListPreview'
| 'linkedTransaction'
| 'bankAccountList'
> & {
policy?: OnyxInputOrEntry<Policy>;
iouReportAction?: OnyxInputOrEntry<ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW>>;
Expand Down
11 changes: 0 additions & 11 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1963,16 +1963,6 @@ function shareBankAccountAndSetPayer(bankAccountID: number, shareeAccountID: num
API.write(WRITE_COMMANDS.SHARE_BANK_ACCOUNT_AND_UPDATE_POLICY_REIMBURSER, parameters, onyxData);
}

/**
* Get bank account from bankAccountID
*/
function getBankAccountFromID(bankAccountID: number | undefined) {
if (!bankAccountID) {
return undefined;
}
return bankAccountList?.[bankAccountID];
}

function openBankAccountSharePage() {
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.IS_LOADING_SHARE_BANK_ACCOUNTS>> = [
{
Expand Down Expand Up @@ -2198,7 +2188,6 @@ export {
sendReminderForCorpaySignerInformation,
clearPersonalBankAccountErrors,
clearReimbursementAccountSendReminderForCorpaySignerInformation,
getBankAccountFromID,
openBankAccountSharePage,
clearShareBankAccountErrors,
updatePersonalBankAccountInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';

import {bankAccountByIDSelector} from '@selectors/BankAccount';
import React, {useEffect} from 'react';

import type {BusinessInfoSubPageProps} from './types';
Expand All @@ -47,7 +48,7 @@ const pages = [
function EnableGlobalReimbursementsBusinessPage({route}: EnableGlobalReimbursementsBusinessPageProps) {
const {translate} = useLocalize();
const bankAccountID = route.params?.bankAccountID;
const [bankAccount] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {selector: (list) => list?.[bankAccountID]});
const [bankAccount] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {selector: bankAccountByIDSelector(bankAccountID)});
const country = (route.params?.bankCountry ?? bankAccount?.bankCountry ?? '') as Country;
const currency = route.params?.bankCurrency ?? bankAccount?.bankCurrency ?? '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/EnableGlobalReimbursementsForm';

import {bankAccountByIDSelector} from '@selectors/BankAccount';
import React, {useEffect} from 'react';

type EnableGlobalReimbursementsSignPageProps = PlatformStackScreenProps<
Expand All @@ -23,7 +24,7 @@ type EnableGlobalReimbursementsSignPageProps = PlatformStackScreenProps<
function EnableGlobalReimbursementsSignPage({route}: EnableGlobalReimbursementsSignPageProps) {
const {getAgreementsRoute, isDynamic} = useEnableGlobalReimbursementsNavigation();
const bankAccountID = route.params?.bankAccountID;
const [bankAccount] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {selector: (list) => list?.[bankAccountID]});
const [bankAccount] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {selector: bankAccountByIDSelector(bankAccountID)});
const currency = route.params?.bankCurrency ?? bankAccount?.bankCurrency ?? '';
const country = route.params?.bankCountry ?? bankAccount?.bankCountry;
const [enableGlobalReimbursements] = useOnyx(ONYXKEYS.FORMS.ENABLE_GLOBAL_REIMBURSEMENTS);
Expand Down
3 changes: 2 additions & 1 deletion src/pages/settings/Wallet/LinkPlaidToBankAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {DYNAMIC_ROUTES} from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

import {bankAccountByIDSelector} from '@selectors/BankAccount';
import React, {useEffect} from 'react';
import {View} from 'react-native';

Expand All @@ -61,7 +62,7 @@ function LinkPlaidToBankAccountInner({bankAccountID, backPath}: LinkPlaidToBankA

const [plaidLinkToken] = useOnyx(ONYXKEYS.RAM_ONLY_PLAID_LINK_TOKEN);
const [isPlaidDisabled] = useOnyx(ONYXKEYS.IS_PLAID_DISABLED);
const [bankAccount] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {selector: (list) => list?.[bankAccountID]});
const [bankAccount] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {selector: bankAccountByIDSelector(bankAccountID)});

const latestErrorMessage = getLatestErrorMessage(bankAccount);
const isWrongAccountError = !isEmptyObject(getLatestErrorField(bankAccount, CONST.BANK_ACCOUNT.PLAID_WRONG_ACCOUNT_ERROR_FIELD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';

import {bankAccountByIDSelector} from '@selectors/BankAccount';
import React, {useEffect, useState} from 'react';

type ShareBankAccountProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.WALLET.SHARE_BANK_ACCOUNT>;
Expand All @@ -53,13 +54,14 @@ function ShareBankAccount({route}: ShareBankAccountProps) {
const isLoading = sharedBankAccountData?.isLoading ?? false;

const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [currentBankAccount] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {selector: bankAccountByIDSelector(bankAccountID)});
const {login: currentUserLogin} = useCurrentUserPersonalDetails();
const [selectedOptions, setSelectedOptions] = useState<MemberForList[]>([]);
const [isAlertVisible, setIsAlertVisible] = useState<boolean>(false);

const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
const {translate} = useLocalize();
const adminEmails = getEligibleBankAccountShareRecipientEmails(allPolicies, currentUserLogin, bankAccountID);
const adminEmails = getEligibleBankAccountShareRecipientEmails(allPolicies, currentUserLogin, currentBankAccount);
const adminPersonalDetails = usePersonalDetailsByLogins(adminEmails);
const admins = adminEmails.flatMap((email) => {
const personalDetails = adminPersonalDetails[email];
Expand Down
3 changes: 2 additions & 1 deletion src/pages/settings/Wallet/WalletPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ function WalletPage() {
const shouldShowGBDisclaimer = countryByIp === CONST.COUNTRY.GB;
const isPendingOnfidoResult = userWallet?.isPendingOnfidoResult ?? false;
const hasFailedOnfido = userWallet?.hasFailedOnfido ?? false;
const hasEligibleShareRecipient = hasEligibleBankAccountShareRecipient(allPolicies, currentUserLogin, paymentMethod?.selectedPaymentMethod?.bankAccountID?.toString());
const selectedBankAccountID = paymentMethod?.selectedPaymentMethod?.bankAccountID;
const hasEligibleShareRecipient = hasEligibleBankAccountShareRecipient(allPolicies, currentUserLogin, selectedBankAccountID ? bankAccountList[selectedBankAccountID] : undefined);
const paidGroupPolicy = Object.values(allPolicies ?? {}).find(isPaidGroupPolicy);

const updateShouldShowLoadingSpinner = () => {
Expand Down
6 changes: 4 additions & 2 deletions src/selectors/BankAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import type {BankAccountList} from '@src/types/onyx';

import type {OnyxEntry} from 'react-native-onyx';

const bankAccountByIDSelector = (bankAccountID: string | number | undefined) => (bankAccountList: OnyxEntry<BankAccountList>) =>
bankAccountID ? bankAccountList?.[bankAccountID] : undefined;

/**
* Returns a selector that picks the methodID of the bank account connected to the given workspace.
*/
const connectedBankAccountIDSelector = (policyID: string | undefined) => (bankAccountList: OnyxEntry<BankAccountList>) =>
Object.values(bankAccountList ?? {}).find((bankAccount) => bankAccount?.accountData?.additionalData?.policyID === policyID)?.methodID;

// eslint-disable-next-line import/prefer-default-export -- additional selectors may be added here
export {connectedBankAccountIDSelector};
export {bankAccountByIDSelector, connectedBankAccountIDSelector};
Loading
Loading