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/hooks/gasFeeInput/useTransactionFunctions.js

50 lines
1.3 KiB

import { useCallback } from 'react';
import { useDispatch } from 'react-redux';
import {
decGWEIToHexWEI,
decimalToHex,
} from '../../helpers/utils/conversions.util';
import { updateTransaction as updateTransactionFn } from '../../store/actions';
export const useTransactionFunctions = ({
defaultEstimateToUse,
gasLimit,
gasFeeEstimates,
transaction,
}) => {
const dispatch = useDispatch();
const updateTransaction = useCallback(
(estimateType) => {
const newGasSettings = {
gas: decimalToHex(gasLimit),
gasLimit: decimalToHex(gasLimit),
estimateSuggested: defaultEstimateToUse,
estimateUsed: estimateType,
};
newGasSettings.maxFeePerGas = decGWEIToHexWEI(
gasFeeEstimates[estimateType].suggestedMaxFeePerGas,
);
newGasSettings.maxPriorityFeePerGas = decGWEIToHexWEI(
gasFeeEstimates[estimateType].suggestedMaxPriorityFeePerGas,
);
const updatedTxMeta = {
...transaction,
userFeeLevel: estimateType || 'custom',
txParams: {
...transaction.txParams,
...newGasSettings,
},
};
dispatch(updateTransactionFn(updatedTxMeta));
},
[defaultEstimateToUse, dispatch, gasLimit, gasFeeEstimates, transaction],
);
return { updateTransaction };
};