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
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 = {
/** Children to build the KYC */
children: (continueAction: (params?: ContinueActionParams) => void, anchorRef: RefObject<View | null>) => void;

/** The policy used for payment */
policy?: Policy;

/** Reference to the KYCWall component */
ref: ForwardedRef<KYCWallRef>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
import {isTrackOnboardingChoice} from '@libs/OnboardingUtils';
import {hasDynamicExternalWorkflow} from '@libs/PolicyUtils';
import {hasHeldExpensesFromTransactions as hasHeldExpensesReportUtils, hasUpdatedTotal, isAllowedToApproveExpenseReport, isInvoiceReport as isInvoiceReportUtil} from '@libs/ReportUtils';
import {isPending} from '@libs/TransactionUtils';
import {hasHeldExpensesFromTransactions as hasHeldExpensesReportUtils, hasUpdatedTotal, isInvoiceReport as isInvoiceReportUtil} from '@libs/ReportUtils';

import {payInvoice, payMoneyRequest} from '@userActions/IOU/PayMoneyRequest';
import {canApproveIOU, canIOUBePaid as canIOUBePaidAction} from '@userActions/IOU/ReportWorkflow';
import {canIOUBePaid as canIOUBePaidAction} from '@userActions/IOU/ReportWorkflow';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -38,7 +37,6 @@ import type {Transaction} from '@src/types/onyx';
import {hasSeenTourSelector} from '@selectors/Onboarding';
import React from 'react';

import useConfirmApproval from './useConfirmApproval';
import useTransactionThreadData from './useTransactionThreadData';

type PayPrimaryActionProps = {
Expand All @@ -47,7 +45,7 @@ type PayPrimaryActionProps = {
};

function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) {
const {isPaidAnimationRunning, isApprovedAnimationRunning, stopAnimation, startAnimation, startApprovedAnimation} = usePaymentAnimationsContext();
const {isPaidAnimationRunning, isApprovedAnimationRunning, stopAnimation, startAnimation} = usePaymentAnimationsContext();
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const {accountID, email, login: currentUserLogin, localCurrencyCode} = useCurrentUserPersonalDetails();
Expand All @@ -69,7 +67,6 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) {
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const [conciergeChat] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${conciergeReportID}`);
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${moneyRequestReport?.reportID}`);

const activePolicy = usePolicy(activePolicyID);
const chatReportPolicy = usePolicy(chatReport?.policyID);
Expand All @@ -84,7 +81,6 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) {

const {transactions: reportTransactionsMap} = useTransactionsAndViolationsForReport(moneyRequestReport?.reportID);
const transactions = Object.values(reportTransactionsMap);
const hasOnlyPendingTransactions = transactions.length > 0 && transactions.every((t) => isPending(t));
const nonPendingDeleteTransactions = transactions.filter((t): t is Transaction => !!t && (isOffline || t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE));

const canIOUBePaid = canIOUBePaidAction(
Expand Down Expand Up @@ -114,8 +110,6 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) {
invoiceReceiverPolicy,
);
const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere;
const shouldShowApproveButton = (canApproveIOU(moneyRequestReport, policy, reportMetadata, accountID, transactions) && !hasOnlyPendingTransactions) || isApprovedAnimationRunning;
const shouldDisableApproveButton = shouldShowApproveButton && !isAllowedToApproveExpenseReport(moneyRequestReport);
const canAllowSettlement = hasUpdatedTotal(moneyRequestReport, policy);
const totalAmount = getTotalAmountForIOUReportPreviewButton(moneyRequestReport, policy, CONST.REPORT.PRIMARY_ACTIONS.PAY, nonPendingDeleteTransactions, convertToDisplayString);
const isAnyTransactionOnHold = hasHeldExpensesReportUtils(transactions);
Expand All @@ -126,8 +120,6 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) {

const {openHoldMenu} = useMoneyReportHeaderModals();

const confirmApproval = useConfirmApproval(reportID, startApprovedAnimation);

const confirmPayment = ({paymentType: type, payAsBusiness, methodID, paymentMethod}: PaymentActionParams) => {
if (!type || !chatReport) {
return;
Expand Down Expand Up @@ -214,15 +206,12 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) {
canIOUBePaid
onlyShowPayElsewhere={onlyShowPayElsewhere}
currency={moneyRequestReport?.currency}
confirmApproval={confirmApproval}
policyID={moneyRequestReport?.policyID}
chatReportID={chatReport?.reportID}
iouReport={moneyRequestReport}
onPress={confirmPayment}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
shouldHidePaymentOptions={!shouldShowPayButton}
shouldShowApproveButton={shouldShowApproveButton}
shouldDisableApproveButton={shouldDisableApproveButton}
isDisabled={isOffline && !canAllowSettlement}
isLoading={!isOffline && !canAllowSettlement}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ import {generateDefaultWorkspaceName} from '@libs/actions/Policy/Policy';
import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
import {isTrackOnboardingChoice} from '@libs/OnboardingUtils';
import {hasDynamicExternalWorkflow} from '@libs/PolicyUtils';
import {
getReportOrDraftReport,
hasHeldExpensesFromTransactions as hasHeldExpensesReportUtils,
hasUpdatedTotal,
hasViolations as hasViolationsReportUtils,
isInvoiceReport as isInvoiceReportUtils,
} from '@libs/ReportUtils';
import {getReportOrDraftReport, hasHeldExpensesFromTransactions as hasHeldExpensesReportUtils, hasUpdatedTotal, isInvoiceReport as isInvoiceReportUtils} from '@libs/ReportUtils';

import {payInvoice, payMoneyRequest} from '@userActions/IOU/PayMoneyRequest';

Expand All @@ -34,15 +28,7 @@ import ROUTES from '@src/ROUTES';
import {hasSeenTourSelector} from '@selectors/Onboarding';
import React from 'react';

import {
useReportPreviewActions,
useReportPreviewActionState,
useReportPreviewAnimationState,
useReportPreviewData,
useReportPreviewTransactionViolations,
useReportPreviewUIState,
} from './MoneyRequestReportPreviewContext';
import useConfirmApproveReportAction from './useConfirmApproveReportAction';
import {useReportPreviewActions, useReportPreviewActionState, useReportPreviewAnimationState, useReportPreviewData, useReportPreviewUIState} from './MoneyRequestReportPreviewContext';
import useReportPreviewActionButtonData from './useReportPreviewActionButtonData';

function PayActionButton() {
Expand Down Expand Up @@ -74,21 +60,17 @@ function PayActionButton() {
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});

const {transactionViolations} = useReportPreviewTransactionViolations();
const isTrackIntentUser = isTrackOnboardingChoice(introSelected?.choice);

const existingB2BInvoiceReport = useParticipantsInvoiceReport(activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS, chatReport?.policyID);
const getChatReportActions = usePayChatReportActions(chatReport, existingB2BInvoiceReport);
const canAllowSettlement = hasUpdatedTotal(iouReport, policy);
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserAccountID, currentUserEmail, undefined, transactions);

const shouldShowOnlyPayElsewhere = !canIOUBePaid && onlyShowPayElsewhere;
const canIOUBePaidAndApproved = canIOUBePaid;

const formattedAmount = getTotalAmountForIOUReportPreviewButton(iouReport, policy, reportPreviewAction, transactions, convertToDisplayString);

const confirmApproval = useConfirmApproveReportAction(actionButtonData, transactions, hasViolations);

const confirmPayment = ({paymentType: type, payAsBusiness, methodID, paymentMethod}: PaymentActionParams) => {
if (!type) {
return;
Expand Down Expand Up @@ -169,7 +151,6 @@ function PayActionButton() {
onPaymentOptionsShow={onPaymentOptionsShow}
onPaymentOptionsHide={onPaymentOptionsHide}
formattedAmount={formattedAmount}
confirmApproval={confirmApproval}

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.

Dead prop. shouldShowApproveButton is not passed as true in this component, so confirmApproval will never be called.

enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
shouldHidePaymentOptions={!shouldShowPayButton}
kycWallAnchorAlignment={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function AnimatedSettlementButton({
<SettlementButton
{...settlementButtonProps}
wrapperStyle={wrapperStyle}
isDisabled={isAnimationRunning || isDisabled}
isDisabled={isDisabled}
sentryLabel={sentryLabel}
/>
)}
Expand Down
Loading
Loading