mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-10 11:05:47 +00:00
31912c0f83
* 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.
39 lines
860 B
TypeScript
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;
|
|
}
|
|
}
|