2021-02-04 19:15:23 +01:00
|
|
|
import { cloneDeep } from 'lodash';
|
2021-04-28 21:53:59 +02:00
|
|
|
import {
|
2021-06-23 23:35:25 +02:00
|
|
|
RESET_CUSTOM_DATA,
|
|
|
|
SET_CUSTOM_GAS_LIMIT,
|
|
|
|
SET_CUSTOM_GAS_PRICE,
|
|
|
|
} from './gas-action-constants';
|
2018-08-16 14:28:27 +02:00
|
|
|
|
|
|
|
const initState = {
|
|
|
|
customData: {
|
2018-09-13 10:47:05 +02:00
|
|
|
price: null,
|
2018-12-12 15:54:03 +01:00
|
|
|
limit: null,
|
2018-08-16 14:28:27 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-16 14:28:27 +02:00
|
|
|
|
|
|
|
// Reducer
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function reducer(state = initState, action) {
|
2018-08-16 14:28:27 +02:00
|
|
|
switch (action.type) {
|
|
|
|
case SET_CUSTOM_GAS_PRICE:
|
|
|
|
return {
|
2020-02-06 17:38:14 +01:00
|
|
|
...state,
|
2018-08-16 14:28:27 +02:00
|
|
|
customData: {
|
2020-02-06 17:38:14 +01:00
|
|
|
...state.customData,
|
2018-08-16 14:28:27 +02:00
|
|
|
price: action.value,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-16 14:28:27 +02:00
|
|
|
case SET_CUSTOM_GAS_LIMIT:
|
|
|
|
return {
|
2020-02-06 17:38:14 +01:00
|
|
|
...state,
|
2018-08-16 14:28:27 +02:00
|
|
|
customData: {
|
2020-02-06 17:38:14 +01:00
|
|
|
...state.customData,
|
2018-08-16 14:28:27 +02:00
|
|
|
limit: action.value,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-20 18:06:23 +02:00
|
|
|
case RESET_CUSTOM_DATA:
|
|
|
|
return {
|
2020-02-06 17:38:14 +01:00
|
|
|
...state,
|
2020-07-08 22:17:53 +02:00
|
|
|
customData: cloneDeep(initState.customData),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-16 14:28:27 +02:00
|
|
|
default:
|
2021-02-04 19:15:23 +01:00
|
|
|
return state;
|
2018-08-16 14:28:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setCustomGasPrice(newPrice) {
|
2018-08-16 14:28:27 +02:00
|
|
|
return {
|
|
|
|
type: SET_CUSTOM_GAS_PRICE,
|
|
|
|
value: newPrice,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-16 14:28:27 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setCustomGasLimit(newLimit) {
|
2018-08-16 14:28:27 +02:00
|
|
|
return {
|
|
|
|
type: SET_CUSTOM_GAS_LIMIT,
|
|
|
|
value: newLimit,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-16 14:28:27 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function resetCustomData() {
|
2021-02-04 19:15:23 +01:00
|
|
|
return { type: RESET_CUSTOM_DATA };
|
2018-09-20 18:06:23 +02:00
|
|
|
}
|