mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Show advanced options, and hide radio buttons, for advanced gas settings users (#11751)
* Show advanced options, and hide radio buttons, for users with advanced gas settings turned on * Improve naming and copy * lint fix * Lint fix
This commit is contained in:
parent
aa3d1f2341
commit
a950111a19
@ -1935,6 +1935,9 @@
|
|||||||
"showPrivateKeys": {
|
"showPrivateKeys": {
|
||||||
"message": "Show Private Keys"
|
"message": "Show Private Keys"
|
||||||
},
|
},
|
||||||
|
"showRecommendations": {
|
||||||
|
"message": "Show Recommendations"
|
||||||
|
},
|
||||||
"showSeedPhrase": {
|
"showSeedPhrase": {
|
||||||
"message": "Show Secret Recovery Phrase"
|
"message": "Show Secret Recovery Phrase"
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useContext } from 'react';
|
import React, { useContext, useState } from 'react';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
@ -13,6 +13,7 @@ import Typography from '../../ui/typography/typography';
|
|||||||
import {
|
import {
|
||||||
getIsMainnet,
|
getIsMainnet,
|
||||||
checkNetworkAndAccountSupports1559,
|
checkNetworkAndAccountSupports1559,
|
||||||
|
getAdvancedInlineGasShown,
|
||||||
} from '../../../selectors';
|
} from '../../../selectors';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -58,20 +59,29 @@ export default function EditGasDisplay({
|
|||||||
estimatedMaximumFiat,
|
estimatedMaximumFiat,
|
||||||
dappSuggestedGasFeeAcknowledged,
|
dappSuggestedGasFeeAcknowledged,
|
||||||
setDappSuggestedGasFeeAcknowledged,
|
setDappSuggestedGasFeeAcknowledged,
|
||||||
showAdvancedForm,
|
|
||||||
setShowAdvancedForm,
|
|
||||||
warning,
|
warning,
|
||||||
gasErrors,
|
gasErrors,
|
||||||
onManualChange,
|
onManualChange,
|
||||||
minimumGasLimit,
|
minimumGasLimit,
|
||||||
balanceError,
|
balanceError,
|
||||||
estimatesUnavailableWarning,
|
estimatesUnavailableWarning,
|
||||||
|
hasGasErrors,
|
||||||
}) {
|
}) {
|
||||||
const t = useContext(I18nContext);
|
const t = useContext(I18nContext);
|
||||||
const isMainnet = useSelector(getIsMainnet);
|
const isMainnet = useSelector(getIsMainnet);
|
||||||
const networkAndAccountSupport1559 = useSelector(
|
const networkAndAccountSupport1559 = useSelector(
|
||||||
checkNetworkAndAccountSupports1559,
|
checkNetworkAndAccountSupports1559,
|
||||||
);
|
);
|
||||||
|
const showAdvancedInlineGasIfPossible = useSelector(
|
||||||
|
getAdvancedInlineGasShown,
|
||||||
|
);
|
||||||
|
|
||||||
|
const [showAdvancedForm, setShowAdvancedForm] = useState(
|
||||||
|
!estimateToUse || hasGasErrors || !networkAndAccountSupport1559,
|
||||||
|
);
|
||||||
|
const [hideRadioButtons, setHideRadioButtons] = useState(
|
||||||
|
showAdvancedInlineGasIfPossible,
|
||||||
|
);
|
||||||
|
|
||||||
const dappSuggestedAndTxParamGasFeesAreTheSame = areDappSuggestedAndTxParamGasFeesTheSame(
|
const dappSuggestedAndTxParamGasFeesAreTheSame = areDappSuggestedAndTxParamGasFeesTheSame(
|
||||||
transaction,
|
transaction,
|
||||||
@ -84,7 +94,7 @@ export default function EditGasDisplay({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const showTopError = balanceError || estimatesUnavailableWarning;
|
const showTopError = balanceError || estimatesUnavailableWarning;
|
||||||
const showRadioButtons =
|
const radioButtonsEnabled =
|
||||||
networkAndAccountSupport1559 &&
|
networkAndAccountSupport1559 &&
|
||||||
gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET &&
|
gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET &&
|
||||||
!requireDappAcknowledgement &&
|
!requireDappAcknowledgement &&
|
||||||
@ -175,7 +185,22 @@ export default function EditGasDisplay({
|
|||||||
{t('gasDisplayAcknowledgeDappButtonText')}
|
{t('gasDisplayAcknowledgeDappButtonText')}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{showRadioButtons && (
|
{!requireDappAcknowledgement &&
|
||||||
|
radioButtonsEnabled &&
|
||||||
|
showAdvancedInlineGasIfPossible && (
|
||||||
|
<button
|
||||||
|
className="edit-gas-display__advanced-button"
|
||||||
|
onClick={() => setHideRadioButtons(!hideRadioButtons)}
|
||||||
|
>
|
||||||
|
{t('showRecommendations')}{' '}
|
||||||
|
{hideRadioButtons ? (
|
||||||
|
<i className="fa fa-caret-down"></i>
|
||||||
|
) : (
|
||||||
|
<i className="fa fa-caret-up"></i>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{radioButtonsEnabled && !hideRadioButtons && (
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
name="gas-recommendation"
|
name="gas-recommendation"
|
||||||
options={[
|
options={[
|
||||||
@ -200,7 +225,9 @@ export default function EditGasDisplay({
|
|||||||
onChange={setEstimateToUse}
|
onChange={setEstimateToUse}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{!requireDappAcknowledgement && showRadioButtons && (
|
{!requireDappAcknowledgement &&
|
||||||
|
radioButtonsEnabled &&
|
||||||
|
!showAdvancedInlineGasIfPossible && (
|
||||||
<button
|
<button
|
||||||
className="edit-gas-display__advanced-button"
|
className="edit-gas-display__advanced-button"
|
||||||
onClick={() => setShowAdvancedForm(!showAdvancedForm)}
|
onClick={() => setShowAdvancedForm(!showAdvancedForm)}
|
||||||
@ -213,7 +240,8 @@ export default function EditGasDisplay({
|
|||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{!requireDappAcknowledgement && showAdvancedForm && (
|
{!requireDappAcknowledgement &&
|
||||||
|
(showAdvancedForm || showAdvancedInlineGasIfPossible) && (
|
||||||
<AdvancedGasControls
|
<AdvancedGasControls
|
||||||
gasEstimateType={gasEstimateType}
|
gasEstimateType={gasEstimateType}
|
||||||
isGasEstimatesLoading={isGasEstimatesLoading}
|
isGasEstimatesLoading={isGasEstimatesLoading}
|
||||||
@ -271,8 +299,6 @@ EditGasDisplay.propTypes = {
|
|||||||
estimatedMaximumFiat: PropTypes.string,
|
estimatedMaximumFiat: PropTypes.string,
|
||||||
dappSuggestedGasFeeAcknowledged: PropTypes.bool,
|
dappSuggestedGasFeeAcknowledged: PropTypes.bool,
|
||||||
setDappSuggestedGasFeeAcknowledged: PropTypes.func,
|
setDappSuggestedGasFeeAcknowledged: PropTypes.func,
|
||||||
showAdvancedForm: PropTypes.bool,
|
|
||||||
setShowAdvancedForm: PropTypes.func,
|
|
||||||
warning: PropTypes.string,
|
warning: PropTypes.string,
|
||||||
transaction: PropTypes.object,
|
transaction: PropTypes.object,
|
||||||
gasErrors: PropTypes.object,
|
gasErrors: PropTypes.object,
|
||||||
@ -280,4 +306,5 @@ EditGasDisplay.propTypes = {
|
|||||||
minimumGasLimit: PropTypes.number,
|
minimumGasLimit: PropTypes.number,
|
||||||
balanceError: PropTypes.bool,
|
balanceError: PropTypes.bool,
|
||||||
estimatesUnavailableWarning: PropTypes.bool,
|
estimatesUnavailableWarning: PropTypes.bool,
|
||||||
|
hasGasErrors: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
@ -87,10 +87,6 @@ export default function EditGasPopover({
|
|||||||
estimatesUnavailableWarning,
|
estimatesUnavailableWarning,
|
||||||
} = useGasFeeInputs(defaultEstimateToUse, transaction, minimumGasLimit, mode);
|
} = useGasFeeInputs(defaultEstimateToUse, transaction, minimumGasLimit, mode);
|
||||||
|
|
||||||
const [showAdvancedForm, setShowAdvancedForm] = useState(
|
|
||||||
!estimateToUse || hasGasErrors || !networkAndAccountSupport1559,
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporary placeholder, this should be managed by the parent component but
|
* Temporary placeholder, this should be managed by the parent component but
|
||||||
* we will be extracting this component from the hard to maintain modal/
|
* we will be extracting this component from the hard to maintain modal/
|
||||||
@ -213,8 +209,6 @@ export default function EditGasPopover({
|
|||||||
<EditGasDisplay
|
<EditGasDisplay
|
||||||
showEducationButton={showEducationButton}
|
showEducationButton={showEducationButton}
|
||||||
warning={warning}
|
warning={warning}
|
||||||
showAdvancedForm={showAdvancedForm}
|
|
||||||
setShowAdvancedForm={setShowAdvancedForm}
|
|
||||||
dappSuggestedGasFeeAcknowledged={dappSuggestedGasFeeAcknowledged}
|
dappSuggestedGasFeeAcknowledged={dappSuggestedGasFeeAcknowledged}
|
||||||
setDappSuggestedGasFeeAcknowledged={
|
setDappSuggestedGasFeeAcknowledged={
|
||||||
setDappSuggestedGasFeeAcknowledged
|
setDappSuggestedGasFeeAcknowledged
|
||||||
@ -245,6 +239,7 @@ export default function EditGasPopover({
|
|||||||
minimumGasLimit={minimumGasLimitDec}
|
minimumGasLimit={minimumGasLimitDec}
|
||||||
balanceError={balanceError}
|
balanceError={balanceError}
|
||||||
estimatesUnavailableWarning={estimatesUnavailableWarning}
|
estimatesUnavailableWarning={estimatesUnavailableWarning}
|
||||||
|
hasGasErrors={hasGasErrors}
|
||||||
{...editGasDisplayProps}
|
{...editGasDisplayProps}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
checkNetworkAndAccountSupports1559,
|
checkNetworkAndAccountSupports1559,
|
||||||
getShouldShowFiat,
|
getShouldShowFiat,
|
||||||
getSelectedAccount,
|
getSelectedAccount,
|
||||||
|
getAdvancedInlineGasShown,
|
||||||
} from '../selectors';
|
} from '../selectors';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -249,8 +250,18 @@ export function useGasFeeInputs(
|
|||||||
Number(hexToDecimal(transaction?.txParams?.gas ?? minimumGasLimit)),
|
Number(hexToDecimal(transaction?.txParams?.gas ?? minimumGasLimit)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const userPrefersAdvancedGas = useSelector(getAdvancedInlineGasShown);
|
||||||
|
const dontDefaultToAnEstimateLevel =
|
||||||
|
userPrefersAdvancedGas &&
|
||||||
|
transaction?.txParams?.maxPriorityFeePerGas &&
|
||||||
|
transaction?.txParams?.gasPrice;
|
||||||
|
|
||||||
|
const initialEstimateToUse = transaction
|
||||||
|
? initialMatchingEstimateLevel
|
||||||
|
: defaultEstimateToUse;
|
||||||
|
|
||||||
const [estimateToUse, setInternalEstimateToUse] = useState(
|
const [estimateToUse, setInternalEstimateToUse] = useState(
|
||||||
transaction ? initialMatchingEstimateLevel : defaultEstimateToUse,
|
dontDefaultToAnEstimateLevel ? null : initialEstimateToUse,
|
||||||
);
|
);
|
||||||
|
|
||||||
// We specify whether to use the estimate value by checking if the state
|
// We specify whether to use the estimate value by checking if the state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user