From 582655a99fe6e2e5fbeb251ba9ecec4f8117fe75 Mon Sep 17 00:00:00 2001 From: Eric Jinks <3147296+Jinksi@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:51:48 +1000 Subject: [PATCH] Add getDisputeFeeFormatted util function --- client/disputes/utils.ts | 16 ++++++++++++++++ .../dispute-resolution-footer.tsx | 9 +++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/client/disputes/utils.ts b/client/disputes/utils.ts index 592c63609a8..1051444226e 100644 --- a/client/disputes/utils.ts +++ b/client/disputes/utils.ts @@ -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' ]; @@ -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 ) + ); +}; diff --git a/client/payment-details/dispute-details/dispute-resolution-footer.tsx b/client/payment-details/dispute-details/dispute-resolution-footer.tsx index 0336c5cad98..ecaafdddeeb 100644 --- a/client/payment-details/dispute-details/dispute-resolution-footer.tsx +++ b/client/payment-details/dispute-details/dispute-resolution-footer.tsx @@ -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; @@ -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',