woocommerce/plugins/woocommerce-blocks/assets/js/base/utils/get-icons-from-payment-meth...

25 lines
667 B
TypeScript

/**
* External dependencies
*/
import type {
PaymentMethods,
PaymentMethodIcons as PaymentMethodIconsType,
} from '@woocommerce/type-defs/payments';
/**
* Get the provider icons from payment methods data.
*
* @param {PaymentMethods} paymentMethods Payment Method data
* @return {PaymentMethodIconsType} Payment Method icons data.
*/
export const getIconsFromPaymentMethods = (
paymentMethods: PaymentMethods
): PaymentMethodIconsType => {
return Object.values( paymentMethods ).reduce( ( acc, paymentMethod ) => {
if ( paymentMethod.icons !== null ) {
acc = acc.concat( paymentMethod.icons );
}
return acc;
}, [] as PaymentMethodIconsType );
};