All files / app/payment/paymentMethod/PPSDKPaymentMethod PPSDKPaymentMethod.tsx

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 37 38  25x 25x   25x 25x 25x                     25x 20x   10x   10x 10x   10x 6x   6x     4x            
import { CheckoutService, PaymentMethod } from '@bigcommerce/checkout-sdk';
import { noop } from 'lodash';
import React, { FunctionComponent } from 'react';
 
import { initializationComponentMap } from './initializationComponentMap';
import { usePropsToOnMount } from './usePropsToOnMount';
import { Wrapper } from './Wrapper';
 
type CheckoutServiceInstance = InstanceType<typeof CheckoutService>;
 
interface Props {
    method: PaymentMethod;
    deinitializePayment: CheckoutServiceInstance['deinitializePayment'];
    initializePayment: CheckoutServiceInstance['initializePayment'];
    onUnhandledError?(error: Error): void;
}
 
export const PPSDKPaymentMethod: FunctionComponent<Props> = props => {
    const { method, onUnhandledError = noop } = props;
 
    const onMount = usePropsToOnMount(props);
 
    const componentKey = method?.initializationStrategy?.type || '';
    const Component = initializationComponentMap[componentKey];
 
    if (!Component) {
        onUnhandledError(new Error('PPSDK initialization strategy not found'));
 
        return null;
    }
 
    return (
        <Wrapper onMount={ onMount }>
            <Component { ...props } />
        </Wrapper>
    );
};