1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 11:28:51 +01:00

Ensure the advanced gas modal displays a zero priority fee if that is how it is set in the transaction (#17559)

Co-authored-by: Pedro Figueiredo <pedro.figueiredo@consensys.net>
This commit is contained in:
Dan J Miller 2023-02-03 08:00:49 -08:00 committed by GitHub
parent 6b076fa346
commit 0c24448037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View File

@ -7,6 +7,8 @@ import { isLegacyTransaction } from '../../helpers/utils/transactions.util';
import { hexWEIToDecGWEI } from '../../../shared/modules/conversion.utils'; import { hexWEIToDecGWEI } from '../../../shared/modules/conversion.utils';
import { feeParamsAreCustom, getGasFeeEstimate } from './utils'; import { feeParamsAreCustom, getGasFeeEstimate } from './utils';
const isNullOrUndefined = (value) => value === null || value === undefined;
const getMaxPriorityFeePerGasFromTransaction = ( const getMaxPriorityFeePerGasFromTransaction = (
transaction, transaction,
gasFeeEstimates, gasFeeEstimates,
@ -17,9 +19,8 @@ const getMaxPriorityFeePerGasFromTransaction = (
} }
const { maxPriorityFeePerGas, maxFeePerGas, gasPrice } = const { maxPriorityFeePerGas, maxFeePerGas, gasPrice } =
transaction?.txParams || {}; transaction?.txParams || {};
return Number( const feeInHexWei = maxPriorityFeePerGas || maxFeePerGas || gasPrice;
hexWEIToDecGWEI(maxPriorityFeePerGas || maxFeePerGas || gasPrice), return feeInHexWei ? Number(hexWEIToDecGWEI(feeInHexWei)) : null;
);
}; };
/** /**
@ -50,17 +51,20 @@ export function useMaxPriorityFeePerGasInput({
const initialMaxPriorityFeePerGas = supportsEIP1559 const initialMaxPriorityFeePerGas = supportsEIP1559
? getMaxPriorityFeePerGasFromTransaction(transaction, gasFeeEstimates) ? getMaxPriorityFeePerGasFromTransaction(transaction, gasFeeEstimates)
: 0; : null;
const [maxPriorityFeePerGas, setMaxPriorityFeePerGas] = useState(() => { const [maxPriorityFeePerGas, setMaxPriorityFeePerGas] = useState(() => {
if (initialMaxPriorityFeePerGas && feeParamsAreCustom(transaction)) { if (
!isNullOrUndefined(initialMaxPriorityFeePerGas) &&
feeParamsAreCustom(transaction)
) {
return initialMaxPriorityFeePerGas; return initialMaxPriorityFeePerGas;
} }
return null; return null;
}); });
useEffect(() => { useEffect(() => {
if (supportsEIP1559 && initialMaxPriorityFeePerGas) { if (supportsEIP1559 && !isNullOrUndefined(initialMaxPriorityFeePerGas)) {
setMaxPriorityFeePerGas(initialMaxPriorityFeePerGas); setMaxPriorityFeePerGas(initialMaxPriorityFeePerGas);
} }
}, [initialMaxPriorityFeePerGas, setMaxPriorityFeePerGas, supportsEIP1559]); }, [initialMaxPriorityFeePerGas, setMaxPriorityFeePerGas, supportsEIP1559]);

View File

@ -102,4 +102,15 @@ describe('useMaxPriorityFeePerGasInput', () => {
}); });
expect(result.current.maxPriorityFeePerGas).toBe(100); expect(result.current.maxPriorityFeePerGas).toBe(100);
}); });
it('returns maxPriorityFeePerGas from transaction if it is 0', () => {
const { result } = renderUseMaxPriorityFeePerGasInputHook({
transaction: {
txParams: {
maxPriorityFeePerGas: '0x0',
},
},
});
expect(result.current.maxPriorityFeePerGas).toBe(0);
});
}); });