graycoreio/daffodil

View on GitHub
libs/paypal/state/src/reducers/payment/reducer.ts

Summary

Maintainability
A
0 mins
Test Coverage
import {
  daffPaymentInitialState,
  DaffPaymentReducerState,
  DaffPaymentStateReducerAdapter,
} from '@daffodil/payment/state';

import {
  DaffPaypalActionTypes,
  DaffPaypalActions,
} from '../../actions/paypal.actions';

export function daffPaypalPaymentReducer(
  state = daffPaymentInitialState,
  action: DaffPaypalActions,
): DaffPaymentReducerState {
  const adapter = new DaffPaymentStateReducerAdapter();
  switch (action.type) {
    case DaffPaypalActionTypes.GeneratePaypalExpressTokenAction:
      return adapter.generateToken(state);

    case DaffPaypalActionTypes.GeneratePaypalExpressTokenSuccessAction:
      return adapter.tokenGenerated(state);

    case DaffPaypalActionTypes.GeneratePaypalExpressTokenFailureAction:
      return adapter.storeError([action.payload], state);

    default:
      return state;
  }
}