Daniel Ternyak af84a589c5 Redux promise middleware (v2) (#233)
* add redux-promise-middleware to package.json and update package-lock.json

* intergrate redux-promise-middleware and simplify rates by replacing saga with promise

* fix unrelated breaking test

* -improve user messaging when network request fails. \n Clean up rates actions and reducers

* Address tslint errors
2017-09-25 20:41:11 -07:00

46 lines
1.0 KiB
TypeScript

import {
FetchCCRatesSucceeded,
FetchCCRatesFailed,
RatesAction,
CCResponse
} from 'actions/rates';
import { TypeKeys } from 'actions/rates/constants';
import { Optional } from 'utils/types';
// SYMBOL -> PRICE TO BUY 1 ETH
export interface State {
rates?: Optional<CCResponse>;
ratesError?: string | null;
}
export const INITIAL_STATE: State = {};
function fetchCCRatesSucceeded(
state: State,
action: FetchCCRatesSucceeded
): State {
return { ...state, rates: action.payload };
}
function fetchCCRatesFailed(state: State, action: FetchCCRatesFailed): State {
// TODO: Make library for error messages
return {
...state,
ratesError: 'Sorry. We were unable to fetch equivalent rates.'
};
}
export function rates(
state: State = INITIAL_STATE,
action: RatesAction
): State {
switch (action.type) {
case TypeKeys.RATES_FETCH_CC_SUCCEEDED:
return fetchCCRatesSucceeded(state, action);
case TypeKeys.RATES_FETCH_CC_FAILED:
return fetchCCRatesFailed(state, action);
default:
return state;
}
}