coinforbarter-react-native
Version:
CoinForBarter ReactNative Library - Integrate cryptocurrency payments for goods and services in your Mobile App
40 lines (39 loc) • 1.32 kB
JavaScript
import { PaymentTypeOptions, PaymentStatus } from './types';
export const initialState = () => {
return {
payment: {
isCurrencyLocked: false,
sourceAddressInformation: [],
customerDetails: {
email: '',
fullName: '',
phoneNumber: '',
},
customer: '',
totalDue: 0,
transactionFees: 0,
currencies: [''],
baseCurrency: '',
baseAmount: 0,
sourceDetails: {},
description: '',
status: PaymentStatus.Null,
_id: '',
id: '',
},
};
};
export const paymentReducer = (state = initialState(), action) => {
switch (action.type) {
case PaymentTypeOptions.UPDATE:
const updatedState = Object.assign(Object.assign({}, state), { payment: Object.assign(Object.assign({}, state.payment), action.payload) });
return updatedState;
case PaymentTypeOptions.CREATE:
const newState = Object.assign(Object.assign({}, state), action.payload);
return newState;
case PaymentTypeOptions.CLEAR:
return initialState();
default:
return state;
}
};