Skip to content

Commit

Permalink
fix: Estimated fee in redesigned screens (#27250)
Browse files Browse the repository at this point in the history
cherry-pick: (#27247)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

`maxFeePerGas`, `maxPriorityFeePerGas` and `estimatedBaseFee` are
decimal values that should be converted before being used inside
`multiplyHexes` and `addHexes`. `estimatedBaseFee` also needs to be
converted to wei.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution? -->

[![Open in GitHub

Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27247?quickstart=1)

Fixes:

1. Go to this page... 2.
3.

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

<img width="320" alt="Screenshot 2024-09-18 at 13 40 13"
src="https://github.com/user-attachments/assets/cf06ac39-6ab7-46c9-af84-951efbb37fd1">

<img width="320" alt="Screenshot 2024-09-18 at 13 39 49"
src="https://github.com/user-attachments/assets/15c8ff6b-6277-4f7f-b290-68adb21d845a">

<img width="320" alt="Screenshot 2024-09-18 at 13 37 13"
src="https://github.com/user-attachments/assets/6d4e3500-972e-4196-8041-8a16436daaf7">

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding

Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.


<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27250?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
pedronfigueiredo authored Sep 18, 2024
1 parent 3373b9a commit 29094e0
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 26 deletions.
1 change: 0 additions & 1 deletion app/scripts/controllers/swaps/swaps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,6 @@ describe('SwapsController', function () {
const swapsQuotePrefetchingRefreshTime = 0;
const swapsStxBatchStatusRefreshTime = 0;
const swapsStxGetTransactionsRefreshTime = 0;
const swapsStxStatusDeadline = 0;
swapsController.__test__updateState({
swapsState: {
...swapsController.state.swapsState,
Expand Down
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

0 comments on commit 29094e0

Please sign in to comment.