1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 18:41:38 +01:00
metamask-extension/ui/components/app/advanced-gas-fee-popover/context/advancedGasFeePopover.js

52 lines
1.4 KiB
JavaScript

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],
);
const [baseFeeMultiplier, setBaseFeeMultiplier] = useState();
return (
<AdvancedGasFeePopoverContext.Provider
value={{
gasLimit,
hasErrors: errors.maxFeePerGas || errors.maxPriorityFeePerGas,
maxFeePerGas,
maxPriorityFeePerGas,
setErrorValue,
baseFeeMultiplier,
setGasLimit,
setMaxPriorityFeePerGas,
setMaxFeePerGas,
setBaseFeeMultiplier,
}}
>
{children}
</AdvancedGasFeePopoverContext.Provider>
);
};
export function useAdvancedGasFeePopoverContext() {
return useContext(AdvancedGasFeePopoverContext);
}
AdvancedGasFeePopoverContextProvider.propTypes = {
children: PropTypes.node.isRequired,
};