| 1 |
import { Donation } from '@givewp/donations/admin/components/types'; |
| 2 |
import { getDonationOptionsWindowData } from '@givewp/donations/utils'; |
| 3 |
import {amountFormatter} from '@givewp/admin/utils'; |
| 4 |
|
| 5 |
/** |
| 6 |
* This hook is used to get the donation amounts and the formatter for the donation amounts. |
| 7 |
* @since 4.6.0 |
| 8 |
*/ |
| 9 |
export default function useDonationAmounts(donation: Donation) { |
| 10 |
const {currency: baseCurrency, eventTicketsEnabled} = getDonationOptionsWindowData(); |
| 11 |
const donationAmountValue = Number(donation?.amount?.value ?? 0); |
| 12 |
const feeAmountRecoveredValue = Number(donation?.feeAmountRecovered?.value ?? 0); |
| 13 |
const eventTicketsAmountValue = Number(donation?.eventTicketsAmount?.value ?? 0); |
| 14 |
const intendedAmountValue = (donationAmountValue - feeAmountRecoveredValue) - (eventTicketsEnabled ? eventTicketsAmountValue : 0); |
| 15 |
const currency = donation?.amount?.currency ?? baseCurrency; |
| 16 |
|
| 17 |
return { |
| 18 |
baseCurrency, |
| 19 |
formatter: amountFormatter(currency), |
| 20 |
amount: donationAmountValue, |
| 21 |
intendedAmount: intendedAmountValue, |
| 22 |
feeAmountRecovered: feeAmountRecoveredValue, |
| 23 |
eventTicketsAmount: eventTicketsAmountValue, |
| 24 |
}; |
| 25 |
} |
| 26 |
|