/** * External dependencies */ import { useExpressPaymentMethods, usePaymentMethodInterface, } from '@woocommerce/base-hooks'; import { cloneElement, isValidElement } from '@wordpress/element'; import { useEditorContext } from '@woocommerce/base-context'; const ExpressPaymentMethods = () => { const { isEditor } = useEditorContext(); const paymentMethodInterface = usePaymentMethodInterface(); // not implementing isInitialized here because it's utilized further // up in the tree for express payment methods. We won't even get here if // there's no payment methods after initialization. const { paymentMethods } = useExpressPaymentMethods(); const paymentMethodIds = Object.keys( paymentMethods ); const content = paymentMethodIds.length > 0 ? ( paymentMethodIds.map( ( id ) => { const expressPaymentMethod = isEditor ? paymentMethods[ id ].edit : paymentMethods[ id ].content; return isValidElement( expressPaymentMethod ) ? (
  • { cloneElement( expressPaymentMethod, { ...paymentMethodInterface, } ) }
  • ) : null; } ) ) : (
  • No registered Payment Methods
  • ); return ( ); }; export default ExpressPaymentMethods;