1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Adding gas limit section on advance gas fee modal (#12865)

This commit is contained in:
Jyoti Puri 2021-12-03 21:29:48 +05:30 committed by GitHub
parent 6542d16349
commit cd4ddffd9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 283 additions and 84 deletions

View File

@ -1132,6 +1132,9 @@
"message": "Gas limit must be at least $1", "message": "Gas limit must be at least $1",
"description": "$1 is the custom gas limit, in decimal." "description": "$1 is the custom gas limit, in decimal."
}, },
"gasLimitV2": {
"message": "Gas limit"
},
"gasOption": { "gasOption": {
"message": "Gas option" "message": "Gas option"
}, },

View File

@ -0,0 +1,67 @@
import React, { useEffect, useState } from 'react';
import { useGasFeeContext } from '../../../../contexts/gasFee';
import { TYPOGRAPHY } from '../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import Box from '../../../ui/box';
import Button from '../../../ui/button';
import FormField from '../../../ui/form-field';
import I18nValue from '../../../ui/i18n-value';
import Typography from '../../../ui/typography';
import { useAdvanceGasFeePopoverContext } from '../context';
const AdvancedGasFeeGasLimit = () => {
const t = useI18nContext();
const {
setDirty,
setGasLimit: setGasLimitInContext,
} = useAdvanceGasFeePopoverContext();
const { gasLimit: gasLimitInTransaction } = useGasFeeContext();
const [isEditing, setEditing] = useState(false);
const [gasLimit, setGasLimit] = useState(gasLimitInTransaction);
const updateGasLimit = (value) => {
setGasLimit(value);
setDirty(true);
};
useEffect(() => {
setGasLimitInContext(gasLimit);
}, [gasLimit, setGasLimitInContext]);
if (isEditing) {
return (
<FormField
onChange={updateGasLimit}
titleText={t('gasLimitV2')}
value={gasLimit}
numeric
/>
);
}
return (
<Typography tag={TYPOGRAPHY.Paragraph} variant={TYPOGRAPHY.H7}>
<Box
display="flex"
alignItems="center"
className="advanced-gas-fee-gas-limit"
>
<strong>
<I18nValue messageKey="gasLimitV2" />
</strong>
<span>{gasLimit}</span>
<Button
className="advanced-gas-fee-gas-limit__edit-link"
onClick={() => setEditing(true)}
type="link"
>
<I18nValue messageKey="edit" />
</Button>
</Box>
</Typography>
);
};
export default AdvancedGasFeeGasLimit;

View File

@ -0,0 +1,68 @@
import React from 'react';
import { fireEvent, screen } from '@testing-library/react';
import { GAS_ESTIMATE_TYPES } from '../../../../../shared/constants/gas';
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
import mockEstimates from '../../../../../test/data/mock-estimates.json';
import mockState from '../../../../../test/data/mock-state.json';
import { GasFeeContextProvider } from '../../../../contexts/gasFee';
import configureStore from '../../../../store/store';
import { AdvanceGasFeePopoverContextProvider } from '../context';
import AdvancedGasFeeGasLimit from './advanced-gas-fee-gas-limit';
jest.mock('../../../../store/actions', () => ({
disconnectGasFeeEstimatePoller: jest.fn(),
getGasFeeEstimatesAndStartPolling: jest
.fn()
.mockImplementation(() => Promise.resolve()),
addPollingTokenToAppState: jest.fn(),
removePollingTokenFromAppState: jest.fn(),
}));
const render = (txProps) => {
const store = configureStore({
metamask: {
...mockState.metamask,
accounts: {
[mockState.metamask.selectedAddress]: {
address: mockState.metamask.selectedAddress,
balance: '0x1F4',
},
},
advancedGasFee: { priorityFee: 100 },
featureFlags: { advancedInlineGas: true },
gasFeeEstimates:
mockEstimates[GAS_ESTIMATE_TYPES.FEE_MARKET].gasFeeEstimates,
},
});
return renderWithProvider(
<GasFeeContextProvider
transaction={{
userFeeLevel: 'custom',
txParams: { gas: '0x5208' },
...txProps,
}}
>
<AdvanceGasFeePopoverContextProvider>
<AdvancedGasFeeGasLimit />
</AdvanceGasFeePopoverContextProvider>
</GasFeeContextProvider>,
store,
);
};
describe('AdvancedGasFeeGasLimit', () => {
it('should show GasLimit from transaction', () => {
render();
expect(screen.getByText('21000')).toBeInTheDocument();
});
it('should show input when edit link is clicked', () => {
render();
expect(document.getElementsByTagName('input')).toHaveLength(0);
fireEvent.click(screen.queryByText('Edit'));
expect(document.getElementsByTagName('input')[0]).toHaveValue(21000);
});
});

View File

@ -0,0 +1 @@
export { default } from './advanced-gas-fee-gas-limit';

View File

@ -0,0 +1,14 @@
.advanced-gas-fee-gas-limit {
white-space: nowrap;
> * {
margin-right: 4px;
}
a.advanced-gas-fee-gas-limit__edit-link {
@include H7;
padding: 0;
width: auto;
}
}

View File

@ -7,6 +7,7 @@ import Popover from '../../ui/popover';
import { AdvanceGasFeePopoverContextProvider } from './context'; import { AdvanceGasFeePopoverContextProvider } from './context';
import AdvancedGasFeeInputs from './advanced-gas-fee-inputs'; import AdvancedGasFeeInputs from './advanced-gas-fee-inputs';
import AdvancedGasFeeGasLimit from './advanced-gas-fee-gas-limit';
import AdvancedGasFeeSaveButton from './advanced-gas-fee-save'; import AdvancedGasFeeSaveButton from './advanced-gas-fee-save';
const AdvancedGasFeePopover = () => { const AdvancedGasFeePopover = () => {
@ -28,8 +29,10 @@ const AdvancedGasFeePopover = () => {
onClose={closeAllModals} onClose={closeAllModals}
footer={<AdvancedGasFeeSaveButton />} footer={<AdvancedGasFeeSaveButton />}
> >
<Box className="advanced-gas-fee-popover__wrapper"> <Box className="advanced-gas-fee-popover__wrapper" margin={4}>
<AdvancedGasFeeInputs /> <AdvancedGasFeeInputs />
<div className="advanced-gas-fee-popover__separator" />
<AdvancedGasFeeGasLimit />
</Box> </Box>
</Popover> </Popover>
</AdvanceGasFeePopoverContextProvider> </AdvanceGasFeePopoverContextProvider>

View File

@ -14,16 +14,18 @@ const AdvancedGasFeeSaveButton = () => {
const { updateTransaction } = useGasFeeContext(); const { updateTransaction } = useGasFeeContext();
const { const {
isDirty, isDirty,
gasLimit,
maxFeePerGas, maxFeePerGas,
maxPriorityFeePerGas, maxPriorityFeePerGas,
} = useAdvanceGasFeePopoverContext(); } = useAdvanceGasFeePopoverContext();
const onSave = () => { const onSave = () => {
updateTransaction( updateTransaction({
PRIORITY_LEVELS.CUSTOM, estimateUsed: PRIORITY_LEVELS.CUSTOM,
decGWEIToHexWEI(maxFeePerGas), maxFeePerGas: decGWEIToHexWEI(maxFeePerGas),
decGWEIToHexWEI(maxPriorityFeePerGas), maxPriorityFeePerGas: decGWEIToHexWEI(maxPriorityFeePerGas),
); gasLimit,
});
closeModal('advancedGasFee'); closeModal('advancedGasFee');
}; };

View File

@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
export const AdvanceGasFeePopoverContext = createContext({}); export const AdvanceGasFeePopoverContext = createContext({});
export const AdvanceGasFeePopoverContextProvider = ({ children }) => { export const AdvanceGasFeePopoverContextProvider = ({ children }) => {
const [gasLimit, setGasLimit] = useState();
const [maxFeePerGas, setMaxFeePerGas] = useState(); const [maxFeePerGas, setMaxFeePerGas] = useState();
const [maxPriorityFeePerGas, setMaxPriorityFeePerGas] = useState(); const [maxPriorityFeePerGas, setMaxPriorityFeePerGas] = useState();
const [isDirty, setDirty] = useState(); const [isDirty, setDirty] = useState();
@ -11,10 +12,12 @@ export const AdvanceGasFeePopoverContextProvider = ({ children }) => {
return ( return (
<AdvanceGasFeePopoverContext.Provider <AdvanceGasFeePopoverContext.Provider
value={{ value={{
gasLimit,
isDirty, isDirty,
maxFeePerGas, maxFeePerGas,
maxPriorityFeePerGas, maxPriorityFeePerGas,
setDirty, setDirty,
setGasLimit,
setMaxPriorityFeePerGas, setMaxPriorityFeePerGas,
setMaxFeePerGas, setMaxFeePerGas,
}} }}

View File

@ -7,4 +7,8 @@
border-top: 1px solid $ui-grey; border-top: 1px solid $ui-grey;
margin: 24px 0 16px 0; margin: 24px 0 16px 0;
} }
.form-field__heading-title > h6 {
font-size: $font-size-h7;
}
} }

View File

@ -57,6 +57,7 @@
@import 'loading-network-screen/index'; @import 'loading-network-screen/index';
@import 'flask/experimental-area/index'; @import 'flask/experimental-area/index';
@import 'advanced-gas-fee-popover/index'; @import 'advanced-gas-fee-popover/index';
@import 'advanced-gas-fee-popover/advanced-gas-fee-gas-limit/index';
@import 'advanced-gas-fee-popover/advanced-gas-fee-inputs/index'; @import 'advanced-gas-fee-popover/advanced-gas-fee-inputs/index';
@import 'advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/index'; @import 'advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/index';
@import 'advanced-gas-fee-popover/advanced-gas-fee-input-subtext/index'; @import 'advanced-gas-fee-popover/advanced-gas-fee-input-subtext/index';

View File

@ -9,7 +9,7 @@ import LoadingHeartBeat from '../../ui/loading-heartbeat';
import Popover from '../../ui/popover'; import Popover from '../../ui/popover';
import Typography from '../../ui/typography/typography'; import Typography from '../../ui/typography/typography';
import { COLORS } from '../../../helpers/constants/design-system'; import { COLORS, TYPOGRAPHY } from '../../../helpers/constants/design-system';
import { INSUFFICIENT_FUNDS_ERROR_KEY } from '../../../helpers/constants/error-keys'; import { INSUFFICIENT_FUNDS_ERROR_KEY } from '../../../helpers/constants/error-keys';
import { useGasFeeContext } from '../../../contexts/gasFee'; import { useGasFeeContext } from '../../../contexts/gasFee';
import EditGasItem from './edit-gas-item'; import EditGasItem from './edit-gas-item';
@ -57,7 +57,8 @@ const EditGasFeePopover = () => {
className="edit-gas-fee-popover__know-more" className="edit-gas-fee-popover__know-more"
align="center" align="center"
color={COLORS.UI4} color={COLORS.UI4}
fontSize="12px" tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
> >
<I18nValue <I18nValue
messageKey="learmMoreAboutGas" messageKey="learmMoreAboutGas"

View File

@ -100,7 +100,7 @@ const EditGasItem = ({ priorityLevel }) => {
return ( return (
<button <button
className={classNames('edit-gas-item', { className={classNames('edit-gas-item', {
'edit-gas-item-selected': priorityLevel === estimateUsed, 'edit-gas-item--selected': priorityLevel === estimateUsed,
'edit-gas-item-disabled': 'edit-gas-item-disabled':
priorityLevel === PRIORITY_LEVELS.DAPP_SUGGESTED && priorityLevel === PRIORITY_LEVELS.DAPP_SUGGESTED &&
!dappSuggestedGasFees, !dappSuggestedGasFees,

View File

@ -111,7 +111,7 @@ describe('EditGasItem', () => {
it('should highlight option is priorityLevel is currently selected', () => { it('should highlight option is priorityLevel is currently selected', () => {
renderComponent({ priorityLevel: 'high' }, { userFeeLevel: 'high' }); renderComponent({ priorityLevel: 'high' }, { userFeeLevel: 'high' });
expect( expect(
document.getElementsByClassName('edit-gas-item-selected'), document.getElementsByClassName('edit-gas-item--selected'),
).toHaveLength(1); ).toHaveLength(1);
}); });

View File

@ -11,7 +11,7 @@
height: 32px; height: 32px;
width: 100%; width: 100%;
&-selected { &--selected {
background-color: $ui-1; background-color: $ui-1;
} }

View File

@ -1,6 +1,9 @@
import React from 'react'; import React from 'react';
import { COLORS } from '../../../../helpers/constants/design-system'; import {
COLORS,
TYPOGRAPHY,
} from '../../../../helpers/constants/design-system';
import { useGasFeeContext } from '../../../../contexts/gasFee'; import { useGasFeeContext } from '../../../../contexts/gasFee';
import I18nValue from '../../../ui/i18n-value'; import I18nValue from '../../../ui/i18n-value';
import Typography from '../../../ui/typography/typography'; import Typography from '../../../ui/typography/typography';
@ -14,10 +17,10 @@ const NetworkStatus = () => {
<div className="network-status"> <div className="network-status">
<Typography <Typography
color={COLORS.UI4} color={COLORS.UI4}
fontSize="10px"
fontWeight="bold" fontWeight="bold"
margin={[3, 0]} margin={[3, 0]}
variant="h6" tag={TYPOGRAPHY.H6}
variant={TYPOGRAPHY.H8}
> >
<I18nValue messageKey="networkStatus" /> <I18nValue messageKey="networkStatus" />
</Typography> </Typography>

View File

@ -172,9 +172,7 @@ export default function GasTiming({
toHumanReadableTime(Number(customEstimatedTime?.upperTimeBound), t), toHumanReadableTime(Number(customEstimatedTime?.upperTimeBound), t),
]); ]);
} }
} } else if (supportsEIP1559V2) {
// code below needs to cleaned-up once EIP_1559_V2 flag is removed
else if (supportsEIP1559V2) {
text = t('gasTimingNegative', [ text = t('gasTimingNegative', [
toHumanReadableTime(low.maxWaitTimeEstimate, t), toHumanReadableTime(low.maxWaitTimeEstimate, t),
]); ]);

View File

@ -31,6 +31,7 @@
background: transparent; background: transparent;
border: 0; border: 0;
padding-inline-end: 0; padding-inline-end: 0;
position: relative;
white-space: pre; white-space: pre;
} }
@ -40,7 +41,18 @@
} }
&__icon { &__icon {
font-size: 1rem; @include Paragraph;
line-height: 1;
position: absolute;
left: -16px;
top: 0;
&-custom {
font-size: 1.35rem;
left: -12px;
top: -2px;
}
} }
&__label { &__label {

View File

@ -7,7 +7,7 @@ import InfoTooltip from '../../ui/info-tooltip/info-tooltip';
import Typography from '../../ui/typography/typography'; import Typography from '../../ui/typography/typography';
import TransactionDetailItem from '../transaction-detail-item/transaction-detail-item.component'; import TransactionDetailItem from '../transaction-detail-item/transaction-detail-item.component';
import { COLORS } from '../../../helpers/constants/design-system'; import { COLORS, TYPOGRAPHY } from '../../../helpers/constants/design-system';
import { PRIORITY_LEVEL_ICON_MAP } from '../../../helpers/constants/gas'; import { PRIORITY_LEVEL_ICON_MAP } from '../../../helpers/constants/gas';
import { useI18nContext } from '../../../hooks/useI18nContext'; import { useI18nContext } from '../../../hooks/useI18nContext';
@ -36,7 +36,9 @@ export default function TransactionDetail({
<div className="transaction-detail"> <div className="transaction-detail">
<div className="transaction-detail-edit-V2"> <div className="transaction-detail-edit-V2">
<button onClick={() => openModal('editGasFee')}> <button onClick={() => openModal('editGasFee')}>
<span className="transaction-detail-edit-V2__icon"> <span
className={`transaction-detail-edit-V2__icon transaction-detail-edit-V2__icon-${estimateUsed}`}
>
{`${PRIORITY_LEVEL_ICON_MAP[estimateUsed]} `} {`${PRIORITY_LEVEL_ICON_MAP[estimateUsed]} `}
</span> </span>
<span className="transaction-detail-edit-V2__label"> <span className="transaction-detail-edit-V2__label">
@ -53,19 +55,32 @@ export default function TransactionDetail({
<InfoTooltip <InfoTooltip
contentText={ contentText={
<div className="transaction-detail-edit-V2__tooltip"> <div className="transaction-detail-edit-V2__tooltip">
<Typography fontSize="12px" color={COLORS.GREY}> <Typography
tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
color={COLORS.GREY}
>
{t('dappSuggestedTooltip', [transaction.origin])} {t('dappSuggestedTooltip', [transaction.origin])}
</Typography> </Typography>
<Typography fontSize="12px"> <Typography
<b>{t('maxBaseFee')}</b> tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
>
<strong>{t('maxBaseFee')}</strong>
{maxFeePerGas} {maxFeePerGas}
</Typography> </Typography>
<Typography fontSize="12px"> <Typography
<b>{t('maxPriorityFee')}</b> tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
>
<strong>{t('maxPriorityFee')}</strong>
{maxPriorityFeePerGas} {maxPriorityFeePerGas}
</Typography> </Typography>
<Typography fontSize="12px"> <Typography
<b>{t('gasLimit')}</b> tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
>
<strong>{t('gasLimit')}</strong>
{gasLimit} {gasLimit}
</Typography> </Typography>
</div> </div>

View File

@ -20,7 +20,6 @@ export default function Typography({
children, children,
fontWeight = 'normal', fontWeight = 'normal',
fontStyle = 'normal', fontStyle = 'normal',
fontSize,
align, align,
boxProps = {}, boxProps = {},
margin = [1, 0], margin = [1, 0],
@ -34,7 +33,6 @@ export default function Typography({
{ {
[`typography--align-${align}`]: Boolean(align), [`typography--align-${align}`]: Boolean(align),
[`typography--color-${color}`]: Boolean(color), [`typography--color-${color}`]: Boolean(color),
[`typography--size-${fontSize}`]: Boolean(fontSize),
}, },
); );
@ -69,7 +67,6 @@ Typography.propTypes = {
margin: MultipleSizes, margin: MultipleSizes,
fontWeight: PropTypes.oneOf(Object.values(FONT_WEIGHT)), fontWeight: PropTypes.oneOf(Object.values(FONT_WEIGHT)),
fontStyle: PropTypes.oneOf(Object.values(FONT_STYLE)), fontStyle: PropTypes.oneOf(Object.values(FONT_STYLE)),
fontSize: PropTypes.string,
tag: PropTypes.oneOf([ tag: PropTypes.oneOf([
'p', 'p',
'h1', 'h1',

View File

@ -33,12 +33,6 @@
} }
} }
@each $size in design-system.$font-size {
&--size-#{$size} {
font-size: $size;
}
}
@each $alignment in design-system.$text-align { @each $alignment in design-system.$text-align {
&--align-#{$alignment} { &--align-#{$alignment} {
text-align: $alignment; text-align: $alignment;

View File

@ -82,4 +82,3 @@ $display: block, grid, flex, inline-block, inline-grid, inline-flex, list-item;
$text-align: left, right, center, justify, end; $text-align: left, right, center, justify, end;
$font-weight: bold, normal, 100, 200, 300, 400, 500, 600, 700, 800, 900; $font-weight: bold, normal, 100, 200, 300, 400, 500, 600, 700, 800, 900;
$font-style: normal, italic, oblique; $font-style: normal, italic, oblique;
$font-size: 10px, 12px;

View File

@ -23,9 +23,6 @@ import { useMaxPriorityFeePerGasInput } from './useMaxPriorityFeePerGasInput';
import { useGasEstimates } from './useGasEstimates'; import { useGasEstimates } from './useGasEstimates';
import { useTransactionFunctions } from './useTransactionFunctions'; import { useTransactionFunctions } from './useTransactionFunctions';
// eslint-disable-next-line prefer-destructuring
const EIP_1559_V2 = process.env.EIP_1559_V2;
/** /**
* @typedef {Object} GasFeeInputReturnType * @typedef {Object} GasFeeInputReturnType
* @property {DecGweiString} [maxFeePerGas] - the maxFeePerGas input value. * @property {DecGweiString} [maxFeePerGas] - the maxFeePerGas input value.
@ -85,6 +82,8 @@ export function useGasFeeInputs(
useSelector(checkNetworkAndAccountSupports1559) && useSelector(checkNetworkAndAccountSupports1559) &&
!isLegacyTransaction(transaction?.txParams); !isLegacyTransaction(transaction?.txParams);
const supportsEIP1559V2 = supportsEIP1559 && EIP_1559_V2_ENABLED;
// We need the gas estimates from the GasFeeController in the background. // We need the gas estimates from the GasFeeController in the background.
// Calling this hooks initiates polling for new gas estimates and returns the // Calling this hooks initiates polling for new gas estimates and returns the
// current estimate. // current estimate.
@ -115,27 +114,31 @@ export function useGasFeeInputs(
return PRIORITY_LEVELS.CUSTOM; return PRIORITY_LEVELS.CUSTOM;
}); });
const [gasLimit, setGasLimit] = useState(() =>
Number(hexToDecimal(transaction?.txParams?.gas ?? '0x0')),
);
/** /**
* In EIP-1559 V2 designs change to gas estimate is always updated to transaction * In EIP-1559 V2 designs change to gas estimate is always updated to transaction
* Thus callback setEstimateToUse can be deprecate in favour of this useEffect * Thus callback setEstimateToUse can be deprecate in favour of this useEffect
* so that transaction is source of truth whenever possible. * so that transaction is source of truth whenever possible.
*/ */
useEffect(() => { useEffect(() => {
if (EIP_1559_V2 && transaction?.userFeeLevel) { if (supportsEIP1559V2) {
if (transaction?.userFeeLevel) {
setEstimateUsed(transaction?.userFeeLevel); setEstimateUsed(transaction?.userFeeLevel);
setInternalEstimateToUse(transaction?.userFeeLevel); setInternalEstimateToUse(transaction?.userFeeLevel);
} }
setGasLimit(Number(hexToDecimal(transaction?.txParams?.gas ?? '0x0')));
}
}, [ }, [
setEstimateUsed, setEstimateUsed,
setGasLimit,
setInternalEstimateToUse, setInternalEstimateToUse,
supportsEIP1559V2,
transaction, transaction,
userPrefersAdvancedGas,
]); ]);
const [gasLimit, setGasLimit] = useState(() =>
Number(hexToDecimal(transaction?.txParams?.gas ?? '0x0')),
);
const { const {
gasPrice, gasPrice,
setGasPrice, setGasPrice,
@ -152,7 +155,7 @@ export function useGasFeeInputs(
maxFeePerGasFiat, maxFeePerGasFiat,
setMaxFeePerGas, setMaxFeePerGas,
} = useMaxFeePerGasInput({ } = useMaxFeePerGasInput({
EIP_1559_V2, supportsEIP1559V2,
estimateToUse, estimateToUse,
gasEstimateType, gasEstimateType,
gasFeeEstimates, gasFeeEstimates,
@ -166,7 +169,7 @@ export function useGasFeeInputs(
maxPriorityFeePerGasFiat, maxPriorityFeePerGasFiat,
setMaxPriorityFeePerGas, setMaxPriorityFeePerGas,
} = useMaxPriorityFeePerGasInput({ } = useMaxPriorityFeePerGasInput({
EIP_1559_V2, supportsEIP1559V2,
estimateToUse, estimateToUse,
gasEstimateType, gasEstimateType,
gasFeeEstimates, gasFeeEstimates,
@ -316,7 +319,7 @@ export function useGasFeeInputs(
hasGasErrors, hasGasErrors,
hasSimulationError, hasSimulationError,
supportsEIP1559, supportsEIP1559,
supportsEIP1559V2: supportsEIP1559 && EIP_1559_V2_ENABLED, supportsEIP1559V2,
updateTransaction, updateTransaction,
updateTransactionUsingGasFeeEstimates, updateTransactionUsingGasFeeEstimates,
}; };

View File

@ -34,7 +34,7 @@ const getMaxFeePerGasFromTransaction = (transaction) => {
* method to update the setMaxFeePerGas. * method to update the setMaxFeePerGas.
*/ */
export function useMaxFeePerGasInput({ export function useMaxFeePerGasInput({
EIP_1559_V2, supportsEIP1559V2,
estimateToUse, estimateToUse,
gasEstimateType, gasEstimateType,
gasFeeEstimates, gasFeeEstimates,
@ -67,10 +67,10 @@ export function useMaxFeePerGasInput({
}); });
useEffect(() => { useEffect(() => {
if (EIP_1559_V2) { if (supportsEIP1559V2) {
setMaxFeePerGas(maxFeePerGasFromTransaction); setMaxFeePerGas(maxFeePerGasFromTransaction);
} }
}, [EIP_1559_V2, maxFeePerGasFromTransaction, setMaxFeePerGas]); }, [maxFeePerGasFromTransaction, setMaxFeePerGas, supportsEIP1559V2]);
let gasSettings = { let gasSettings = {
gasLimit: decimalToHex(gasLimit), gasLimit: decimalToHex(gasLimit),

View File

@ -34,7 +34,7 @@ const getMaxPriorityFeePerGasFromTransaction = (transaction) => {
* method to update the maxPriorityFeePerGas. * method to update the maxPriorityFeePerGas.
*/ */
export function useMaxPriorityFeePerGasInput({ export function useMaxPriorityFeePerGasInput({
EIP_1559_V2, supportsEIP1559V2,
estimateToUse, estimateToUse,
gasEstimateType, gasEstimateType,
gasFeeEstimates, gasFeeEstimates,
@ -63,13 +63,13 @@ export function useMaxPriorityFeePerGasInput({
}); });
useEffect(() => { useEffect(() => {
if (EIP_1559_V2) { if (supportsEIP1559V2) {
setMaxPriorityFeePerGas(maxPriorityFeePerGasFromTransaction); setMaxPriorityFeePerGas(maxPriorityFeePerGasFromTransaction);
} }
}, [ }, [
EIP_1559_V2,
maxPriorityFeePerGasFromTransaction, maxPriorityFeePerGasFromTransaction,
setMaxPriorityFeePerGas, setMaxPriorityFeePerGas,
supportsEIP1559V2,
]); ]);
const maxPriorityFeePerGasToUse = const maxPriorityFeePerGasToUse =

View File

@ -11,13 +11,18 @@ import { updateTransaction as updateTransactionFn } from '../../store/actions';
export const useTransactionFunctions = ({ export const useTransactionFunctions = ({
defaultEstimateToUse, defaultEstimateToUse,
gasFeeEstimates, gasFeeEstimates,
gasLimit, gasLimit: gasLimitInTransaction,
transaction, transaction,
}) => { }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const updateTransaction = useCallback( const updateTransaction = useCallback(
(estimateUsed, maxFeePerGas, maxPriorityFeePerGas) => { ({
estimateUsed,
maxFeePerGas,
maxPriorityFeePerGas,
gasLimit = gasLimitInTransaction,
}) => {
const newGasSettings = { const newGasSettings = {
gas: decimalToHex(gasLimit), gas: decimalToHex(gasLimit),
gasLimit: decimalToHex(gasLimit), gasLimit: decimalToHex(gasLimit),
@ -42,7 +47,7 @@ export const useTransactionFunctions = ({
dispatch(updateTransactionFn(updatedTxMeta)); dispatch(updateTransactionFn(updatedTxMeta));
}, },
[defaultEstimateToUse, dispatch, gasLimit, transaction], [defaultEstimateToUse, dispatch, gasLimitInTransaction, transaction],
); );
const updateTransactionUsingGasFeeEstimates = useCallback( const updateTransactionUsingGasFeeEstimates = useCallback(
@ -52,21 +57,21 @@ export const useTransactionFunctions = ({
maxFeePerGas, maxFeePerGas,
maxPriorityFeePerGas, maxPriorityFeePerGas,
} = transaction?.dappSuggestedGasFees; } = transaction?.dappSuggestedGasFees;
updateTransaction( updateTransaction({
PRIORITY_LEVELS.DAPP_SUGGESTED, estimateUsed: PRIORITY_LEVELS.DAPP_SUGGESTED,
maxFeePerGas, maxFeePerGas,
maxPriorityFeePerGas, maxPriorityFeePerGas,
); });
} else { } else {
const { const {
suggestedMaxFeePerGas, suggestedMaxFeePerGas,
suggestedMaxPriorityFeePerGas, suggestedMaxPriorityFeePerGas,
} = gasFeeEstimates[gasFeeEstimateToUse]; } = gasFeeEstimates[gasFeeEstimateToUse];
updateTransaction( updateTransaction({
gasFeeEstimateToUse, estimateUsed: gasFeeEstimateToUse,
decGWEIToHexWEI(suggestedMaxFeePerGas), maxFeePerGas: decGWEIToHexWEI(suggestedMaxFeePerGas),
decGWEIToHexWEI(suggestedMaxPriorityFeePerGas), maxPriorityFeePerGas: decGWEIToHexWEI(suggestedMaxPriorityFeePerGas),
); });
} }
}, },
[gasFeeEstimates, transaction?.dappSuggestedGasFees, updateTransaction], [gasFeeEstimates, transaction?.dappSuggestedGasFees, updateTransaction],

View File

@ -429,9 +429,7 @@ export default class ConfirmTransactionBase extends Component {
) : null; ) : null;
const renderGasDetailsItem = () => { const renderGasDetailsItem = () => {
return EIP_1559_V2_ENABLED && return this.supportsEIP1559V2 ? (
supportsEIP1559 &&
!isLegacyTransaction(txData) ? (
<GasDetailsItem <GasDetailsItem
key="gas_details" key="gas_details"
hexMaximumTransactionFee={hexMaximumTransactionFee} hexMaximumTransactionFee={hexMaximumTransactionFee}
@ -968,6 +966,11 @@ export default class ConfirmTransactionBase extends Component {
this._removeBeforeUnload(); this._removeBeforeUnload();
} }
supportsEIP1559V2 =
EIP_1559_V2_ENABLED &&
this.props.supportsEIP1559 &&
!isLegacyTransaction(this.props.txData);
render() { render() {
const { t } = this.context; const { t } = this.context;
const { const {
@ -995,7 +998,6 @@ export default class ConfirmTransactionBase extends Component {
gasFeeIsCustom, gasFeeIsCustom,
nativeCurrency, nativeCurrency,
hardwareWalletRequiresConnection, hardwareWalletRequiresConnection,
supportsEIP1559,
} = this.props; } = this.props;
const { const {
submitting, submitting,
@ -1035,6 +1037,7 @@ export default class ConfirmTransactionBase extends Component {
functionType = t('contractInteraction'); functionType = t('contractInteraction');
} }
} }
return ( return (
<TransactionModalContextProvider <TransactionModalContextProvider
actionKey={actionKey} actionKey={actionKey}
@ -1094,11 +1097,7 @@ export default class ConfirmTransactionBase extends Component {
editingGas={editingGas} editingGas={editingGas}
handleCloseEditGas={() => this.handleCloseEditGas()} handleCloseEditGas={() => this.handleCloseEditGas()}
currentTransaction={txData} currentTransaction={txData}
supportsEIP1559V2={ supportsEIP1559V2={this.supportsEIP1559V2}
EIP_1559_V2_ENABLED &&
supportsEIP1559 &&
!isLegacyTransaction(txData)
}
/> />
</TransactionModalContextProvider> </TransactionModalContextProvider>
); );

View File

@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import { COLORS } from '../../../helpers/constants/design-system'; import { COLORS, TYPOGRAPHY } from '../../../helpers/constants/design-system';
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common'; import { PRIMARY, SECONDARY } from '../../../helpers/constants/common';
import { hexWEIToDecGWEI } from '../../../helpers/utils/conversions.util'; import { hexWEIToDecGWEI } from '../../../helpers/utils/conversions.util';
import { useI18nContext } from '../../../hooks/useI18nContext'; import { useI18nContext } from '../../../hooks/useI18nContext';
@ -47,15 +47,15 @@ const GasDetailsItem = ({
<InfoTooltip <InfoTooltip
contentText={ contentText={
<> <>
<Typography fontSize="12px"> <Typography tag={TYPOGRAPHY.Paragraph} variant={TYPOGRAPHY.H7}>
{t('transactionDetailGasTooltipIntro', [ {t('transactionDetailGasTooltipIntro', [
isMainnet ? t('networkNameEthereum') : '', isMainnet ? t('networkNameEthereum') : '',
])} ])}
</Typography> </Typography>
<Typography fontSize="12px"> <Typography tag={TYPOGRAPHY.Paragraph} variant={TYPOGRAPHY.H7}>
{t('transactionDetailGasTooltipExplanation')} {t('transactionDetailGasTooltipExplanation')}
</Typography> </Typography>
<Typography fontSize="12px"> <Typography tag={TYPOGRAPHY.Paragraph} variant={TYPOGRAPHY.H7}>
<a <a
href="https://community.metamask.io/t/what-is-gas-why-do-transactions-take-so-long/3172" href="https://community.metamask.io/t/what-is-gas-why-do-transactions-take-so-long/3172"
target="_blank" target="_blank"

View File

@ -11,6 +11,7 @@ import ActionableMessage from '../../../components/ui/actionable-message/actiona
import ErrorMessage from '../../../components/ui/error-message'; import ErrorMessage from '../../../components/ui/error-message';
import I18nValue from '../../../components/ui/i18n-value'; import I18nValue from '../../../components/ui/i18n-value';
import Typography from '../../../components/ui/typography'; import Typography from '../../../components/ui/typography';
import { TYPOGRAPHY } from '../../../helpers/constants/design-system';
const TransactionAlerts = ({ const TransactionAlerts = ({
userAcknowledgedGasMissing, userAcknowledgedGasMissing,
@ -49,10 +50,11 @@ const TransactionAlerts = ({
<ActionableMessage <ActionableMessage
message={ message={
<Typography <Typography
className="transaction-alerts__pending-transactions"
align="left" align="left"
fontSize="12px" className="transaction-alerts__pending-transactions"
margin={[0, 0]} margin={[0, 0]}
tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
> >
<strong> <strong>
<I18nValue <I18nValue
@ -89,7 +91,12 @@ const TransactionAlerts = ({
{estimateUsed === PRIORITY_LEVELS.LOW && ( {estimateUsed === PRIORITY_LEVELS.LOW && (
<ActionableMessage <ActionableMessage
message={ message={
<Typography align="left" fontSize="12px" margin={[0, 0]}> <Typography
align="left"
margin={[0, 0]}
tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
>
<I18nValue messageKey="lowPriorityMessage" /> <I18nValue messageKey="lowPriorityMessage" />
</Typography> </Typography>
} }