Skip to content

Commit

Permalink
fix: Estimated fee in redesigned screens
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronfigueiredo committed Sep 18, 2024
1 parent 1a6f212 commit c862835
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion shared/modules/conversion.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { addHexPrefix, BN } from 'ethereumjs-util';
import { EtherDenomination } from '../constants/common';
import { Numeric, NumericValue } from './Numeric';

export function decGWEIToHexWEI(decGWEI: number) {
export function decGWEIToHexWEI(decGWEI: number | string | BigNumber | BN) {
return new Numeric(decGWEI, 10, EtherDenomination.GWEI)
.toBase(16)
.toDenomination(EtherDenomination.WEI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ describe('Contract Interaction Confirmation', () => {
expect(editGasFeesRow).toHaveTextContent('Network fee');

const firstGasField = within(editGasFeesRow).getByTestId('first-gas-field');
expect(firstGasField).toHaveTextContent('0.0084 ETH');
expect(firstGasField).toHaveTextContent('0.0001 ETH');
const editGasFeeNativeCurrency =
within(editGasFeesRow).getByTestId('native-currency');
expect(editGasFeeNativeCurrency).toHaveTextContent('$28.50');
expect(editGasFeeNativeCurrency).toHaveTextContent('$0.47');
expect(editGasFeesRow).toContainElement(
screen.getByTestId('edit-gas-fee-icon'),
);
Expand Down Expand Up @@ -394,8 +394,8 @@ describe('Contract Interaction Confirmation', () => {
const maxFee = screen.getByTestId('gas-fee-details-max-fee');
expect(gasFeesSection).toContainElement(maxFee);
expect(maxFee).toHaveTextContent('Max fee');
expect(maxFee).toHaveTextContent('0.2313 ETH');
expect(maxFee).toHaveTextContent('$787.37');
expect(maxFee).toHaveTextContent('0.0023 ETH');
expect(maxFee).toHaveTextContent('$7.72');

const nonceSection = screen.getByTestId('advanced-details-nonce-section');
expect(nonceSection).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { useSelector } from 'react-redux';
import { EtherDenomination } from '../../../../../../../shared/constants/common';
import {
addHexes,
decGWEIToHexWEI,
decimalToHex,
getEthConversionFromWeiHex,
getValueFromWeiHex,
multiplyHexes,
Expand All @@ -15,9 +17,9 @@ import { useFiatFormatter } from '../../../../../../hooks/useFiatFormatter';
import { useGasFeeEstimates } from '../../../../../../hooks/useGasFeeEstimates';
import { getCurrentCurrency } from '../../../../../../selectors';
import { HEX_ZERO } from '../shared/constants';
import { useTransactionGasFeeEstimate } from './useTransactionGasFeeEstimate';
import { useEIP1559TxFees } from './useEIP1559TxFees';
import { useSupportsEIP1559 } from './useSupportsEIP1559';
import { useTransactionGasFeeEstimate } from './useTransactionGasFeeEstimate';

const EMPTY_FEE = '';
const EMPTY_FEES = {
Expand Down Expand Up @@ -94,7 +96,7 @@ export function useFeeCalculations(transactionMeta: TransactionMeta) {

const maxFee = useMemo(() => {
return multiplyHexes(
supportsEIP1559 ? (maxFeePerGas as Hex) : (gasPrice as Hex),
supportsEIP1559 ? (decimalToHex(maxFeePerGas) as Hex) : (gasPrice as Hex),
gasLimit as Hex,
);
}, [supportsEIP1559, maxFeePerGas, gasLimit, gasPrice]);
Expand All @@ -113,8 +115,8 @@ export function useFeeCalculations(transactionMeta: TransactionMeta) {

// Logic for any network without L1 and L2 fee components
const minimumFeePerGas = addHexes(
estimatedBaseFee || HEX_ZERO,
maxPriorityFeePerGas,
decGWEIToHexWEI(estimatedBaseFee) || HEX_ZERO,
decimalToHex(maxPriorityFeePerGas),
);

const estimatedFee = multiplyHexes(
Expand Down

0 comments on commit c862835

Please sign in to comment.