diff --git a/ui/ducks/send/send.js b/ui/ducks/send/send.js index dc64a83b7..7363dcdca 100644 --- a/ui/ducks/send/send.js +++ b/ui/ducks/send/send.js @@ -381,6 +381,7 @@ export const draftTransactionInitialState = { gasTotal: '0x0', maxFeePerGas: '0x0', maxPriorityFeePerGas: '0x0', + wasManuallyEdited: false, }, history: [], id: null, @@ -1057,19 +1058,15 @@ const slice = createSlice({ draftTransaction.transactionType = TRANSACTION_ENVELOPE_TYPES.FEE_MARKET; } else { - // Until we remove the old UI we don't want to automatically update - // gasPrice if the user has already manually changed the field value. - // When receiving a new estimate the isAutomaticUpdate property will be - // on the payload (and set to true). If isAutomaticUpdate is true, - // then we check if the previous estimate was '0x0' or if the previous - // gasPrice equals the previous gasEstimate. if either of those cases - // are true then we update the gasPrice otherwise we skip it because - // it indicates the user has ejected from the estimates by modifying - // the field. + if (action.payload.manuallyEdited) { + draftTransaction.gas.wasManuallyEdited = true; + } + + // Update the gas price if it has not been manually edited, + // or if this current action is a manual edit. if ( - action.payload.isAutomaticUpdate !== true || - state.gasPriceEstimate === '0x0' || - draftTransaction.gas.gasPrice === state.gasPriceEstimate + !draftTransaction.gas.wasManuallyEdited || + action.payload.manuallyEdited ) { draftTransaction.gas.gasPrice = addHexPrefix( action.payload.gasPrice, @@ -1821,6 +1818,7 @@ export function updateGasPrice(gasPrice) { actions.updateGasFees({ gasPrice, transactionType: TRANSACTION_ENVELOPE_TYPES.LEGACY, + manuallyEdited: true, }), ); }; diff --git a/ui/ducks/send/send.test.js b/ui/ducks/send/send.test.js index 089c5d1be..4d21316e6 100644 --- a/ui/ducks/send/send.test.js +++ b/ui/ducks/send/send.test.js @@ -1410,6 +1410,7 @@ describe('Send Slice', () => { type: 'send/updateGasFees', payload: { gasPrice: '0x0', + manuallyEdited: true, transactionType: TRANSACTION_ENVELOPE_TYPES.LEGACY, }, }, @@ -2453,6 +2454,7 @@ describe('Send Slice', () => { gasLimit: GAS_LIMITS.SIMPLE, gasPrice: '0x3b9aca00', gasTotal: '0x0', + wasManuallyEdited: false, maxFeePerGas: '0x0', maxPriorityFeePerGas: '0x0', }, @@ -2597,6 +2599,7 @@ describe('Send Slice', () => { gasLimit: GAS_LIMITS.BASE_TOKEN_ESTIMATE, gasPrice: '0x3b9aca00', gasTotal: '0x0', + wasManuallyEdited: false, maxFeePerGas: '0x0', maxPriorityFeePerGas: '0x0', }, @@ -2786,6 +2789,7 @@ describe('Send Slice', () => { error: null, gasLimit: '0x186a0', gasPrice: '0x3b9aca00', + wasManuallyEdited: false, gasTotal: '0x0', maxFeePerGas: '0x0', maxPriorityFeePerGas: '0x0',