2021-06-16 12:44:40 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useShallowEqual } from '@woocommerce/base-hooks';
|
|
|
|
|
2020-01-06 22:28:09 +00:00
|
|
|
/**
|
2021-04-08 12:31:12 +00:00
|
|
|
* Internal dependencies
|
2020-01-06 22:28:09 +00:00
|
|
|
*/
|
2021-04-08 12:31:12 +00:00
|
|
|
import { usePaymentMethodDataContext } from '../../providers/cart-checkout/payment-methods';
|
2020-01-06 22:28:09 +00:00
|
|
|
|
2020-03-26 11:11:46 +00:00
|
|
|
const usePaymentMethodState = ( express = false ) => {
|
|
|
|
const {
|
|
|
|
paymentMethods,
|
|
|
|
expressPaymentMethods,
|
|
|
|
paymentMethodsInitialized,
|
|
|
|
expressPaymentMethodsInitialized,
|
|
|
|
} = usePaymentMethodDataContext();
|
2021-06-16 12:44:40 +00:00
|
|
|
|
|
|
|
const currentPaymentMethods = useShallowEqual( paymentMethods );
|
|
|
|
const currentExpressPaymentMethods = useShallowEqual(
|
|
|
|
expressPaymentMethods
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
paymentMethods: express
|
|
|
|
? currentExpressPaymentMethods
|
|
|
|
: currentPaymentMethods,
|
|
|
|
isInitialized: express
|
|
|
|
? expressPaymentMethodsInitialized
|
|
|
|
: paymentMethodsInitialized,
|
|
|
|
};
|
2020-01-06 22:28:09 +00:00
|
|
|
};
|
|
|
|
|
2020-03-26 11:11:46 +00:00
|
|
|
export const usePaymentMethods = () => usePaymentMethodState();
|
|
|
|
export const useExpressPaymentMethods = () => usePaymentMethodState( true );
|