2021-12-08 23:56:10 +01:00
|
|
|
import React, { createContext, useCallback, useContext, useState } from 'react';
|
2021-12-01 01:31:21 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2021-12-06 19:47:26 +01:00
|
|
|
export const AdvancedGasFeePopoverContext = createContext({});
|
2021-12-01 01:31:21 +01:00
|
|
|
|
2021-12-06 19:47:26 +01:00
|
|
|
export const AdvancedGasFeePopoverContextProvider = ({ children }) => {
|
2021-12-03 16:59:48 +01:00
|
|
|
const [gasLimit, setGasLimit] = useState();
|
2021-12-01 01:31:21 +01:00
|
|
|
const [maxFeePerGas, setMaxFeePerGas] = useState();
|
|
|
|
const [maxPriorityFeePerGas, setMaxPriorityFeePerGas] = useState();
|
2021-12-08 23:56:10 +01:00
|
|
|
const [errors, setErrors] = useState({
|
|
|
|
maxFeePerGas: false,
|
|
|
|
maxPriorityFeePerGas: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const setErrorValue = useCallback(
|
|
|
|
(field, value) => {
|
|
|
|
if (errors[field] !== value) {
|
|
|
|
setErrors({ ...errors, [field]: value });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[errors, setErrors],
|
|
|
|
);
|
2021-12-21 20:45:28 +01:00
|
|
|
const [baseFeeMultiplier, setBaseFeeMultiplier] = useState();
|
2021-12-01 01:31:21 +01:00
|
|
|
|
|
|
|
return (
|
2021-12-06 19:47:26 +01:00
|
|
|
<AdvancedGasFeePopoverContext.Provider
|
2021-12-01 01:31:21 +01:00
|
|
|
value={{
|
2021-12-03 16:59:48 +01:00
|
|
|
gasLimit,
|
2021-12-08 23:56:10 +01:00
|
|
|
hasErrors: errors.maxFeePerGas || errors.maxPriorityFeePerGas,
|
2021-12-01 01:31:21 +01:00
|
|
|
maxFeePerGas,
|
|
|
|
maxPriorityFeePerGas,
|
2021-12-08 23:56:10 +01:00
|
|
|
setErrorValue,
|
2021-12-21 20:45:28 +01:00
|
|
|
baseFeeMultiplier,
|
2021-12-03 16:59:48 +01:00
|
|
|
setGasLimit,
|
2021-12-01 01:31:21 +01:00
|
|
|
setMaxPriorityFeePerGas,
|
|
|
|
setMaxFeePerGas,
|
2021-12-21 20:45:28 +01:00
|
|
|
setBaseFeeMultiplier,
|
2021-12-01 01:31:21 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children}
|
2021-12-06 19:47:26 +01:00
|
|
|
</AdvancedGasFeePopoverContext.Provider>
|
2021-12-01 01:31:21 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-12-06 19:47:26 +01:00
|
|
|
export function useAdvancedGasFeePopoverContext() {
|
|
|
|
return useContext(AdvancedGasFeePopoverContext);
|
2021-12-01 01:31:21 +01:00
|
|
|
}
|
|
|
|
|
2021-12-06 19:47:26 +01:00
|
|
|
AdvancedGasFeePopoverContextProvider.propTypes = {
|
2021-12-01 01:31:21 +01:00
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
};
|