William O'Beirne 31912c0f83 Gas Price Estimates API (#1050)
* Setup api / reducers / actions for gas.

* Implement gas price saga, fetch from component, and loading states. Blocked on CORS.

* Implement caching mechanism.

* Add tests for gas saga and reducer.

* More testing.

* Indicate that gas price is recommended when fetched from API.

* Hide track while loading.

* Fix tscheck.

* Check gas estimate before assuming its ok.

* Check for correct logical order of gas prices.

* Tscheck fixes.
2018-02-16 13:01:39 -06:00

39 lines
860 B
TypeScript

import { SetGasEstimatesAction, GasAction, TypeKeys } from 'actions/gas';
import { GasEstimates } from 'api/gas';
export interface State {
estimates: GasEstimates | null;
isEstimating: boolean;
}
export const INITIAL_STATE: State = {
estimates: null,
isEstimating: false
};
function fetchGasEstimates(state: State): State {
return {
...state,
isEstimating: true
};
}
function setGasEstimates(state: State, action: SetGasEstimatesAction): State {
return {
...state,
estimates: action.payload,
isEstimating: false
};
}
export function gas(state: State = INITIAL_STATE, action: GasAction): State {
switch (action.type) {
case TypeKeys.GAS_FETCH_ESTIMATES:
return fetchGasEstimates(state);
case TypeKeys.GAS_SET_ESTIMATES:
return setGasEstimates(state, action);
default:
return state;
}
}