A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/ui/components/app/advanced-gas-fee-popover/context/advancedGasFeePopover.js

49 lines
1.3 KiB

import React, { createContext, useCallback, useContext, useState } from 'react';
import PropTypes from 'prop-types';
export const AdvancedGasFeePopoverContext = createContext({});
export const AdvancedGasFeePopoverContextProvider = ({ children }) => {
const [gasLimit, setGasLimit] = useState();
const [maxFeePerGas, setMaxFeePerGas] = useState();
const [maxPriorityFeePerGas, setMaxPriorityFeePerGas] = useState();
const [errors, setErrors] = useState({
maxFeePerGas: false,
maxPriorityFeePerGas: false,
});
const setErrorValue = useCallback(
(field, value) => {
if (errors[field] !== value) {
setErrors({ ...errors, [field]: value });
}
},
[errors, setErrors],
);
return (
<AdvancedGasFeePopoverContext.Provider
value={{
gasLimit,
hasErrors: errors.maxFeePerGas || errors.maxPriorityFeePerGas,
maxFeePerGas,
maxPriorityFeePerGas,
setErrorValue,
setGasLimit,
setMaxPriorityFeePerGas,
setMaxFeePerGas,
}}
>
{children}
</AdvancedGasFeePopoverContext.Provider>
);
};
export function useAdvancedGasFeePopoverContext() {
return useContext(AdvancedGasFeePopoverContext);
}
AdvancedGasFeePopoverContextProvider.propTypes = {
children: PropTypes.node.isRequired,
};