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
13 changes: 6 additions & 7 deletions src/components/KYCWall/BaseKYCWall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function KYCWall({
source,
shouldShowPersonalBankAccountOption = false,
ref,
currency,
}: KYCWallProps) {
const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET, {canBeMissing: true});
const [walletTerms] = useOnyx(ONYXKEYS.WALLET_TERMS, {canBeMissing: true});
Expand Down Expand Up @@ -124,10 +123,10 @@ function KYCWall({
setPositionAddPaymentMenu(position);
}, [getAnchorPosition]);

const canLinkExistingBusinessBankAccount = getEligibleExistingBusinessBankAccounts(bankAccountList, currency, true).length > 0;

const selectPaymentMethod = useCallback(
(paymentMethod?: PaymentMethod, policy?: Policy) => {
const canLinkExistingBusinessBankAccount = getEligibleExistingBusinessBankAccounts(bankAccountList, policy?.outputCurrency, true).length > 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to move this into the memoized function? Can we move it outside like before?

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.

We need the policy that comes as argument provided to selectPaymentMethod


if (paymentMethod) {
onSelectPaymentMethod(paymentMethod);
}
Expand Down Expand Up @@ -201,22 +200,22 @@ function KYCWall({
}
},
[
bankAccountList,
onSelectPaymentMethod,
iouReport,
addDebitCardRoute,
reimbursementAccount?.achData?.state,
canLinkExistingBusinessBankAccount,
addBankAccountRoute,
chatReport,
policies,
introSelected,
formatPhoneNumber,
lastPaymentMethod,
reportPreviewAction,
currentUserEmail,
employeeEmail,
reportTransactions,
isCustomReportNamesBetaEnabled,
introSelected,
formatPhoneNumber,
lastPaymentMethod,
],
);

Expand Down
3 changes: 0 additions & 3 deletions src/components/KYCWall/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ type KYCWallProps = {

/** Reference to the KYCWall component */
ref: ForwardedRef<KYCWallRef>;

/** Currency associated with the payment */
currency?: string;
};

type KYCWallRef = {
Expand Down
1 change: 0 additions & 1 deletion src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@ function SettlementButton({
policy={lastPaymentPolicy}
anchorAlignment={kycWallAnchorAlignment}
shouldShowPersonalBankAccountOption={shouldShowPersonalBankAccountOption}
currency={currency}
>
{(triggerKYCFlow, buttonRef) => (
<ButtonWithDropdownMenu<string>
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ function handleBulkPayItemSelected(params: {
showDelegateNoAccessModal,
confirmPayment,
} = params;
const {paymentType, selectedPolicy, shouldSelectPaymentMethod} = getActivePaymentType(item.key, activeAdminPolicies, latestBankItems);
const {paymentType, selectedPolicy, shouldSelectPaymentMethod} = getActivePaymentType(item.key, activeAdminPolicies, latestBankItems, policy?.id);
// Policy id is also a last payment method so we shouldn't early return here for that case.
if (!isValidBulkPayOption(item) && !selectedPolicy) {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ function ReimbursementAccountPage({route, policy, isLoadingPolicy, navigation}:
case CONST.BANK_ACCOUNT.STEP.VALIDATION:
if ([CONST.BANK_ACCOUNT.STATE.VERIFYING, CONST.BANK_ACCOUNT.STATE.SETUP].some((value) => value === achData?.state)) {
goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.ACH_CONTRACT);
} else if (CONST.BANK_ACCOUNT.STATE.PENDING === achData?.state) {
Navigation.closeRHPFlow();
} else {
Navigation.goBack();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function ConnectExistingBusinessBankAccountPage({route}: ConnectExistingBusiness
if (policyID === undefined) {
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Redundant change

const newReimburserEmail = policy?.achAccount?.reimburser ?? policy?.owner ?? '';
setWorkspaceReimbursement({
policyID,
Expand Down
74 changes: 73 additions & 1 deletion tests/unit/PaymentUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {BankAccountMenuItem} from '@components/Search/types';
import Navigation from '@libs/Navigation/Navigation';
import {handleUnvalidatedAccount} from '@libs/PaymentUtils';
import {getActivePaymentType, handleUnvalidatedAccount} from '@libs/PaymentUtils';
import CONST from '@src/CONST';
import {calculateWalletTransferBalanceFee} from '@src/libs/PaymentUtils';
import type {Report} from '@src/types/onyx';
import createRandomPolicy from '../utils/collections/policies';

jest.mock('@libs/Navigation/Navigation', () => ({
navigate: jest.fn(),
Expand Down Expand Up @@ -58,4 +60,74 @@ describe('PaymentUtils', () => {
expect(mockNavigate).toHaveBeenCalledWith(expectedRoute);
});
});

describe('getActivePaymentType', () => {
const randomPolicyA = createRandomPolicy(1);
const randomPolicyB = createRandomPolicy(2);
const bankItem = {
text: 'Bank Account',
description: 'Test bank',
methodID: 1,
value: CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT,
} as BankAccountMenuItem;

it('should return EXPENSIFY payment type when paymentMethod is PERSONAL_BANK_ACCOUNT', () => {
const result = getActivePaymentType(CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT, [], undefined);

expect(result.paymentType).toBe(CONST.IOU.PAYMENT_TYPE.EXPENSIFY);
expect(result.shouldSelectPaymentMethod).toBe(true);
expect(result.selectedPolicy).toBeUndefined();
});

it('should return VBBA payment type when paymentMethod is BUSINESS_BANK_ACCOUNT', () => {
const result = getActivePaymentType(CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT, [], undefined);

expect(result.paymentType).toBe(CONST.IOU.PAYMENT_TYPE.VBBA);
expect(result.shouldSelectPaymentMethod).toBe(true);
expect(result.selectedPolicy).toBeUndefined();
});

it('should return ELSEWHERE payment type when paymentMethod is DEBIT_CARD', () => {
const result = getActivePaymentType(CONST.PAYMENT_METHODS.DEBIT_CARD, [], undefined);

expect(result.paymentType).toBe(CONST.IOU.PAYMENT_TYPE.ELSEWHERE);
expect(result.shouldSelectPaymentMethod).toBe(true);
expect(result.selectedPolicy).toBeUndefined();
});

it('should return ELSEWHERE payment type when paymentMethod is undefined', () => {
const result = getActivePaymentType(undefined, [], undefined);

expect(result.paymentType).toBe(CONST.IOU.PAYMENT_TYPE.ELSEWHERE);
expect(result.shouldSelectPaymentMethod).toBe(false);
expect(result.selectedPolicy).toBeUndefined();
});

it('should set shouldSelectPaymentMethod to true when latestBankItems is not empty', () => {
const result = getActivePaymentType(undefined, [], [bankItem]);

expect(result.paymentType).toBe(CONST.IOU.PAYMENT_TYPE.ELSEWHERE);
expect(result.shouldSelectPaymentMethod).toBe(true);
});

it('should find selectedPolicy by policyID', () => {
const result = getActivePaymentType(undefined, [randomPolicyA, randomPolicyB], undefined, randomPolicyA.id);

expect(result.selectedPolicy).toEqual(randomPolicyA);
});

it('should find selectedPolicy by paymentMethod when it matches policy id (Pay via workspace scenario)', () => {
const result = getActivePaymentType(randomPolicyB.id, [randomPolicyA, randomPolicyB], undefined);

expect(result.selectedPolicy).toEqual(randomPolicyB);
expect(result.paymentType).toBe(CONST.IOU.PAYMENT_TYPE.ELSEWHERE);
expect(result.shouldSelectPaymentMethod).toBe(false);
});

it('should return undefined selectedPolicy when no matching policy is found', () => {
const result = getActivePaymentType(undefined, [randomPolicyA], undefined, 'non-existent-policy');

expect(result.selectedPolicy).toBeUndefined();
});
});
});
Loading
Loading