Skip to content

Commit

Permalink
Add getDisputeFeeFormatted util function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinksi committed Sep 19, 2023
1 parent 4712f3e commit 582655a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
16 changes: 16 additions & 0 deletions client/disputes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
disputeAwaitingResponseStatuses,
disputeUnderReviewStatuses,
} from 'wcpay/disputes/filters/config';
import { formatExplicitCurrency } from 'wcpay/utils/currency';

interface IsDueWithinProps {
dueBy: CachedDispute[ 'due_by' ] | EvidenceDetails[ 'due_by' ];
Expand Down Expand Up @@ -82,3 +83,18 @@ export const getDisputeFee = (
);
return disputeFee;
};

/**
* Returns the dispute fee balance transaction for a dispute if it exists
* formatted as a currency string.
*/
export const getDisputeFeeFormatted = (
dispute: Dispute
): string | undefined => {
const disputeFee = getDisputeFee( dispute );

return (
disputeFee &&
formatExplicitCurrency( disputeFee.fee, disputeFee.currency )
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { Button, CardFooter, Flex, FlexItem } from '@wordpress/components';
import type { Dispute } from 'wcpay/types/disputes';
import wcpayTracks from 'tracks';
import { getAdminUrl } from 'wcpay/utils';
import { getDisputeFee, isInquiry } from 'wcpay/disputes/utils';
import { formatExplicitCurrency } from 'wcpay/utils/currency';
import { getDisputeFeeFormatted, isInquiry } from 'wcpay/disputes/utils';

const DisputeUnderReviewFooter: React.FC< {
dispute: Dispute;
Expand Down Expand Up @@ -171,10 +170,8 @@ const DisputeLostFooter: React.FC< {
} > = ( { dispute } ) => {
const isSubmitted = !! dispute?.metadata.__evidence_submitted_at;
const isAccepted = dispute?.metadata.__closed_by_merchant === '1';
const disputeFee = dispute && getDisputeFee( dispute );
const disputeFeeFormatted = disputeFee
? formatExplicitCurrency( disputeFee.fee, disputeFee.currency )
: '-';
const disputeFeeFormatted = getDisputeFeeFormatted( dispute ) ?? '-';

const closedDateFormatted = dispute?.metadata.__dispute_closed_at
? dateI18n(
'M j, Y',
Expand Down

0 comments on commit 582655a

Please sign in to comment.