Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Estimated fee in redesigned screens #27250

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: NumericValue) {
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 @@ -280,10 +280,10 @@ describe('Contract Interaction Confirmation', () => {
expect(editGasFeesRow).toHaveTextContent('Estimated 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(getByTestId('edit-gas-fee-icon'));

const gasFeeSpeed = within(gasFeesSection).getByTestId(
Expand Down Expand Up @@ -375,8 +375,8 @@ describe('Contract Interaction Confirmation', () => {
const maxFee = 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 = getByTestId('advanced-details-nonce-section');
expect(nonceSection).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ exports[`<ContractInteractionInfo /> renders component for contract interaction
class="mm-box mm-text mm-text--body-md mm-box--margin-right-1 mm-box--color-text-default"
data-testid="first-gas-field"
>
0.004 ETH
0.0001 ETH
</p>
<p
class="mm-box mm-text mm-text--body-md mm-box--margin-right-2 mm-box--color-text-alternative"
data-testid="native-currency"
>
$2.20
$0.04
</p>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-sm mm-button-link mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
Expand Down Expand Up @@ -631,13 +631,13 @@ exports[`<ContractInteractionInfo /> renders component for contract interaction
class="mm-box mm-text mm-text--body-md mm-box--margin-right-1 mm-box--color-text-default"
data-testid="first-gas-field"
>
0.004 ETH
0.0001 ETH
</p>
<p
class="mm-box mm-text mm-text--body-md mm-box--margin-right-2 mm-box--color-text-alternative"
data-testid="native-currency"
>
$2.20
$0.04
</p>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-sm mm-button-link mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
Expand Down Expand Up @@ -994,13 +994,13 @@ exports[`<ContractInteractionInfo /> renders component for contract interaction
class="mm-box mm-text mm-text--body-md mm-box--margin-right-1 mm-box--color-text-default"
data-testid="first-gas-field"
>
0.004 ETH
0.0001 ETH
</p>
<p
class="mm-box mm-text mm-text--body-md mm-box--margin-right-2 mm-box--color-text-alternative"
data-testid="native-currency"
>
$2.20
$0.04
</p>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-sm mm-button-link mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ describe('useFeeCalculations', () => {

expect(result.current).toMatchInlineSnapshot(`
{
"estimatedFeeFiat": "$2.20",
"estimatedFeeNative": "0.004 ETH",
"estimatedFeeFiat": "$0.04",
"estimatedFeeNative": "0.0001 ETH",
"l1FeeFiat": "",
"l1FeeNative": "",
"l2FeeFiat": "",
"l2FeeNative": "",
"maxFeeFiat": "$4.23",
"maxFeeNative": "0.0076 ETH",
"maxFeeFiat": "$0.07",
"maxFeeNative": "0.0001 ETH",
}
`);
});
Expand All @@ -77,8 +77,8 @@ describe('useFeeCalculations', () => {
"l1FeeNative": "0.0045 ETH",
"l2FeeFiat": "$0.04",
"l2FeeNative": "0.0001 ETH",
"maxFeeFiat": "$4.23",
"maxFeeNative": "0.0076 ETH",
"maxFeeFiat": "$0.07",
"maxFeeNative": "0.0001 ETH",
}
`);
});
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ exports[`<GasFeesDetails /> renders component for gas fees section 1`] = `
class="mm-box mm-text mm-text--body-md mm-box--margin-right-1 mm-box--color-text-default"
data-testid="first-gas-field"
>
0.004 ETH
0.0001 ETH
</p>
<p
class="mm-box mm-text mm-text--body-md mm-box--margin-right-2 mm-box--color-text-alternative"
data-testid="native-currency"
>
$2.20
$0.04
</p>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-sm mm-button-link mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ exports[`<GasFeesSection /> renders component for gas fees section 1`] = `
class="mm-box mm-text mm-text--body-md mm-box--margin-right-1 mm-box--color-text-default"
data-testid="first-gas-field"
>
0.004 ETH
0.0001 ETH
</p>
<p
class="mm-box mm-text mm-text--body-md mm-box--margin-right-2 mm-box--color-text-alternative"
data-testid="native-currency"
>
$2.20
$0.04
</p>
<button
class="mm-box mm-text mm-button-base mm-button-base--size-sm mm-button-link mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
Expand Down