All files / app/cart mapToCartSummaryProps.ts

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36    3x     3x         199x   199x   199x 199x 199x 199x   199x 176x     46x 23x   23x                  
import { CheckoutContextProps } from '../checkout';
 
import mapToRedeemableProps from './mapToRedeemableProps';
import { WithCheckoutCartSummaryProps } from './CartSummary';
 
export default function mapToCartSummaryProps(
    context: CheckoutContextProps
): WithCheckoutCartSummaryProps | null {
    const {
        checkoutState: {
            data: { getConfig, getCustomer, getCheckout },
        },
    } = context;
 
    const checkout = getCheckout();
    const config = getConfig();
    const customer = getCustomer();
    const redeemableProps = mapToRedeemableProps(context);
 
    if (!checkout || !config || !redeemableProps || !customer) {
        return null;
    }
 
    const { isStoreCreditApplied, grandTotal } = checkout;
    const { storeCredit } = customer;
 
    return {
        checkout,
        shopperCurrency: config.shopperCurrency,
        cartUrl: config.links.cartLink,
        storeCurrency: config.currency,
        storeCreditAmount: isStoreCreditApplied ? Math.min(grandTotal, storeCredit) : undefined,
        ...redeemableProps,
    };
}