update gas fees (#13646)

* Draft methods to brak updateTransaction into smaller more targeted
methods.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* This is a combination of 76 commits.

normalize and validate tx params.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Method to normalize tx and check if it's unapproved.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Move the methods to controllers/transactions/index.js

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Flesh out the methods to update transaction with custom notes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

enforce that only the properties for the specific methid can be updated via the method.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Test update gas fees

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update swap approval transaction

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

use lodash to remove undefined properties
update swap transaction tests

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Updates transaction user settings.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Add more parameters to updateSwapTransaction
    approvalTxId
    estimatedBaseFee

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Add Update Transaction Metrics

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update transaction gas fees actions.js

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update EIP 1559 Params.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint Fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Documentations.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove metrics from this PR

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes: Removed unused variables

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Add more params to updateTransactionGasFees.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update eip1559 method to editableParams.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Fix Mocha tests

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

add gasPrice to updateEditableParams

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove duplicated Params in notes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

A few more tests to cover if
    transaction status is not unapproved
    transaction is passed more parameters than it requires.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update Transaction Gas Fees.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update gas fees in edit-gas-popover.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove metrics.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update gas settings and user settings.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Fix unit tests.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Draft methods to brak updateTransaction into smaller more targeted
methods.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

normalize and validate tx params.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Method to normalize tx and check if it's unapproved.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Move the methods to controllers/transactions/index.js

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Flesh out the methods to update transaction with custom notes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Test update gas fees

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update swap approval transaction

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

use lodash to remove undefined properties
update swap transaction tests

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Updates transaction user settings.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Add Update Transaction Metrics

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update transaction gas fees actions.js

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update EIP 1559 Params.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint Fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Documentations.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove metrics from this PR

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes: Removed unused variables

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Add more params to updateTransactionGasFees.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update eip1559 method to editableParams.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Fix Mocha tests

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

add gasPrice to updateEditableParams

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove duplicated Params in notes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

A few more tests to cover if
    transaction status is not unapproved
    transaction is passed more parameters than it requires.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update Transaction Gas Fees.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove metrics.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update gas settings and user settings.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Fix unit tests.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove dup;icated method from rebase.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

unrelated change

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Force re-run workflow

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fix

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Do not hideLoading since we're not showing it.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

UpdateTransaction should be renamed to updateGasFees

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

updateGasFees in gas-modal-page-container.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

fix:
    update previous gas params update method
    add types to the jsdoc comments.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

updateTransactionGasFees should have been updatePreviousGasParams

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Previous gas fees can be updated for confirmed transactions.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

add updatePreviousGasParams to mocked functions.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* we need to await the first dispatch before we call the second

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* update values to make tests pass

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* More changes to make e2e pass

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Need to wait a bit after save for changes to take effect.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Remove merge comments.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Await one dispatch before calling another

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* We don't need goHome anymore.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Tests must use async...await syntax too since we have await in the
useTranasctionFunction

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Add delay after button click for values to update

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Wait a moment after clicking save for values to update

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Wait after clicking save...

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Merge update transaction gas fees and transaction user settings
Show loading indicator on edit gas popover
Fix tests.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Lint fixes

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Fix JSDoc

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* updatePreviousGasParams should also return updated transaction meta.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
feature/default_network_editable
Olusegun Akintayo 3 years ago committed by GitHub
parent 06e196441a
commit c54f9b3097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      app/scripts/controllers/transactions/index.js
  2. 3
      app/scripts/metamask-controller.js
  3. 5
      test/e2e/metamask-ui.spec.js
  4. 1
      test/e2e/tests/edit-gas-fee.spec.js
  5. 2
      test/e2e/tests/send-edit.spec.js
  6. 1
      test/e2e/tests/send-eth.spec.js
  7. 2
      ui/components/app/cancel-speedup-popover/cancel-speedup-popover.test.js
  8. 15
      ui/components/app/edit-gas-popover/edit-gas-popover.component.js
  9. 4
      ui/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js
  10. 6
      ui/ducks/metamask/metamask.js
  11. 90
      ui/hooks/gasFeeInput/useTransactionFunction.test.js
  12. 18
      ui/hooks/gasFeeInput/useTransactionFunctions.js
  13. 4
      ui/pages/confirm-transaction-base/confirm-transaction-base.container.js
  14. 22
      ui/store/actions.js

@ -378,14 +378,44 @@ export default class TransactionController extends EventEmitter {
* updates the params that are editible in the send edit flow
*
* @param {string} txId - transaction id
* @param {object} editableParams - holds the editable parameters
* @param {object} previousGasParams - holds the parameter to update
* @param {string} previousGasParams.maxFeePerGas
* @param {string} previousGasParams.maxPriorityFeePerGas
* @param {string} previousGasParams.gasLimit
* @returns {TransactionMeta} the txMeta of the updated transaction
*/
updatePreviousGasParams(
txId,
{ maxFeePerGas, maxPriorityFeePerGas, gasLimit },
) {
const previousGasParams = {
previousGas: {
maxFeePerGas,
maxPriorityFeePerGas,
gasLimit,
},
};
// only update what is defined
previousGasParams.previousGas = pickBy(previousGasParams.previousGas);
const note = `Update Previous Gas for ${txId}`;
this._updateTransaction(txId, previousGasParams, note);
return this._getTransaction(txId);
}
/**
*
* @param {string} txId - transaction id
* @param {object} editableParams - holds the eip1559 fees parameters
* @param {object} editableParams.data
* @param {string} editableParams.from
* @param {string} editableParams.to
* @param {string} editableParams.value
* @param {string} editableParams.gas
* @param {string} editableParams.gasPrice
* @returns {TransactionMeta} the txMeta of the updated transaction
*/
updateEditableParams(txId, { data, from, to, value }) {
updateEditableParams(txId, { data, from, to, value, gas, gasPrice }) {
if (!this._checkIfTxStatusIsUnapproved(txId)) {
throw new Error(
'Cannot call updateEditableParams on a transaction that is not in an unapproved state',
@ -398,6 +428,8 @@ export default class TransactionController extends EventEmitter {
from,
to,
value,
gas,
gasPrice,
},
};
@ -422,6 +454,8 @@ export default class TransactionController extends EventEmitter {
* @param {string} txGasFees.defaultGasEstimates
* @param {string} txGasFees.gas
* @param {string} txGasFees.originalGasEstimate
* @param {string} txGasFees.userEditedGasLimit
* @param {string} txGasFees.userFeeLevel
* @returns {TransactionMeta} the txMeta of the updated transaction
*/
updateTransactionGasFees(
@ -436,6 +470,8 @@ export default class TransactionController extends EventEmitter {
estimateSuggested,
defaultGasEstimates,
originalGasEstimate,
userEditedGasLimit,
userFeeLevel,
},
) {
if (!this._checkIfTxStatusIsUnapproved(txId)) {
@ -456,6 +492,8 @@ export default class TransactionController extends EventEmitter {
estimateSuggested,
defaultGasEstimates,
originalGasEstimate,
userEditedGasLimit,
userFeeLevel,
};
// only update what is defined
@ -556,6 +594,7 @@ export default class TransactionController extends EventEmitter {
'Cannot call updateSwapTransaction on a transaction that is not in an unapproved state',
);
}
let swapTransaction = {
sourceTokenSymbol,
destinationTokenSymbol,

@ -1587,6 +1587,9 @@ export default class MetamaskController extends EventEmitter {
txController,
),
updatePreviousGasParams: txController.updatePreviousGasParams.bind(
txController,
),
// messageManager
signMessage: this.signMessage.bind(this),
cancelMessage: this.cancelMessage.bind(this),

@ -278,6 +278,7 @@ describe('MetaMask', function () {
await gasPriceInput.fill('20');
await driver.delay(veryLargeDelayMs);
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(veryLargeDelayMs);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.delay(regularDelayMs);
@ -393,6 +394,7 @@ describe('MetaMask', function () {
await gasPriceInput.fill('100');
await driver.delay(veryLargeDelayMs);
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(veryLargeDelayMs);
});
it('submits the transaction', async function () {
@ -469,6 +471,7 @@ describe('MetaMask', function () {
await gasPriceInput.fill('10');
await driver.delay(veryLargeDelayMs);
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(veryLargeDelayMs);
await driver.findElement({ tag: 'span', text: '0.0006' });
});
@ -595,6 +598,7 @@ describe('MetaMask', function () {
await driver.delay(veryLargeDelayMs);
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(veryLargeDelayMs);
const gasFeeInEth = await driver.findElement(
'.confirm-approve-content__transaction-details-content__secondary-fee',
@ -619,6 +623,7 @@ describe('MetaMask', function () {
await driver.delay(regularDelayMs);
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(veryLargeDelayMs);
// wait for permission modal to be removed from DOM.
await permissionModal.waitForElementState('hidden');

@ -158,6 +158,7 @@ describe('Editing Confirm Transaction', function () {
// Submit gas fee changes
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(largeDelayMs);
// has correct updated value on the confirm screen the transaction
const editedTransactionAmounts = await driver.findElements(

@ -61,6 +61,7 @@ describe('Editing Confirm Transaction', function () {
await driver.delay(largeDelayMs);
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(largeDelayMs);
// has correct updated value on the confirm screen the transaction
const editedTransactionAmounts = await driver.findElements(
@ -170,6 +171,7 @@ describe('Editing Confirm Transaction', function () {
// Submit gas fee changes
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(largeDelayMs);
// has correct updated value on the confirm screen the transaction
const editedTransactionAmounts = await driver.findElements(

@ -245,6 +245,7 @@ describe('Send ETH from dapp using advanced gas controls', function () {
await gasPriceInput.fill('100');
await driver.delay(1000);
await driver.clickElement({ text: 'Save', tag: 'button' });
await driver.delay(1000);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extension);

@ -22,6 +22,8 @@ jest.mock('../../../store/actions', () => ({
addPollingTokenToAppState: jest.fn(),
removePollingTokenFromAppState: jest.fn(),
updateTransaction: () => ({ type: 'UPDATE_TRANSACTION_PARAMS' }),
updateTransactionGasFees: () => ({ type: 'UPDATE_TRANSACTION_PARAMS' }),
updatePreviousGasParams: () => ({ type: 'UPDATE_TRANSACTION_PARAMS' }),
createTransactionEventFragment: jest.fn(),
}));

@ -27,9 +27,11 @@ import {
createCancelTransaction,
createSpeedUpTransaction,
hideModal,
updateTransaction,
updateTransactionGasFees,
updateCustomSwapsEIP1559GasParams,
updateSwapsUserFeeLevel,
hideLoadingIndication,
showLoadingIndication,
} from '../../../store/actions';
import LoadingHeartBeat from '../../ui/loading-heartbeat';
import { checkNetworkAndAccountSupports1559 } from '../../../selectors';
@ -134,7 +136,7 @@ export default function EditGasPopover({
}
}, [onClose, dispatch]);
const onSubmit = useCallback(() => {
const onSubmit = useCallback(async () => {
if (!updatedTransaction || !mode) {
closePopover();
}
@ -187,7 +189,14 @@ export default function EditGasPopover({
);
break;
case EDIT_GAS_MODES.MODIFY_IN_PLACE:
dispatch(updateTransaction(updatedTxMeta));
newGasSettings.userEditedGasLimit = updatedTxMeta.userEditedGasLimit;
newGasSettings.userFeeLevel = updatedTxMeta.userFeeLevel;
dispatch(showLoadingIndication());
await dispatch(
updateTransactionGasFees(updatedTxMeta.id, newGasSettings),
);
dispatch(hideLoadingIndication());
break;
case EDIT_GAS_MODES.SWAPS:
// This popover component should only be used for the "FEE_MARKET" type in Swaps.

@ -58,7 +58,7 @@ import {
TRANSACTION_STATUSES,
} from '../../../../../shared/constants/transaction';
import { GAS_LIMITS } from '../../../../../shared/constants/gas';
import { updateTransactionGasFees } from '../../../../ducks/metamask/metamask';
import { updateGasFees } from '../../../../ducks/metamask/metamask';
import GasModalPageContainer from './gas-modal-page-container.component';
const mapStateToProps = (state, ownProps) => {
@ -209,7 +209,7 @@ const mapDispatchToProps = (dispatch) => {
hideModal: () => dispatch(hideModal()),
useCustomGas: () => dispatch(useCustomGas()),
updateTransactionGasFees: (gasFees) => {
dispatch(updateTransactionGasFees({ ...gasFees, expectHexWei: true }));
dispatch(updateGasFees({ ...gasFees, expectHexWei: true }));
},
updateCustomGasPrice,
updateCustomGasLimit: (newLimit) =>

@ -11,7 +11,7 @@ import {
checkNetworkAndAccountSupports1559,
getAddressBook,
} from '../../selectors';
import { updateTransaction } from '../../store/actions';
import { updateTransactionGasFees } from '../../store/actions';
import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck';
import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util';
@ -209,7 +209,7 @@ const toHexWei = (value, expectHexWei) => {
};
// Action Creators
export function updateTransactionGasFees({
export function updateGasFees({
gasPrice,
gasLimit,
maxPriorityFeePerGas,
@ -239,7 +239,7 @@ export function updateTransactionGasFees({
? addHexPrefix(gasLimit)
: addHexPrefix(gasLimit.toString(16));
dispatch(setCustomGasLimit(customGasLimit));
await dispatch(updateTransaction(updatedTx));
await dispatch(updateTransactionGasFees(updatedTx.id, updatedTx));
};
}

@ -70,50 +70,53 @@ describe('useMaxPriorityFeePerGasInput', () => {
expect(mock).toHaveBeenCalledTimes(1);
});
it('should invoke action updateTransaction with 10% increased fee when updateTransactionToTenPercentIncreasedGasFee callback is invoked', () => {
const mock = jest
.spyOn(Actions, 'updateTransaction')
it('should invoke action updateTransaction with 10% increased fee when updateTransactionToTenPercentIncreasedGasFee callback is invoked', async () => {
const mockUpdateGasFees = jest
.spyOn(Actions, 'updateTransactionGasFees')
.mockImplementation(() => ({ type: '' }));
const { result } = renderUseTransactionFunctions();
result.current.updateTransactionToTenPercentIncreasedGasFee();
expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalledWith({
txParams: {
estimateSuggested: 'tenPercentIncreased',
estimateUsed: 'tenPercentIncreased',
gas: '5208',
gasLimit: '5208',
maxFeePerGas: '0x582c',
maxPriorityFeePerGas: '0x582c',
},
await result.current.updateTransactionToTenPercentIncreasedGasFee();
expect(mockUpdateGasFees).toHaveBeenCalledTimes(1);
expect(mockUpdateGasFees).toHaveBeenCalledWith(undefined, {
estimateSuggested: 'tenPercentIncreased',
estimateUsed: 'tenPercentIncreased',
gas: '5208',
gasLimit: '5208',
maxFeePerGas: '0x582c',
maxPriorityFeePerGas: '0x582c',
userEditedGasLimit: undefined,
userFeeLevel: 'tenPercentIncreased',
});
});
it('should invoke action updateTransaction with estimate gas values fee when updateTransactionUsingEstimate callback is invoked', () => {
const mock = jest
.spyOn(Actions, 'updateTransaction')
it('should invoke action updateTransaction with estimate gas values fee when updateTransactionUsingEstimate callback is invoked', async () => {
const mockUpdateGasFees = jest
.spyOn(Actions, 'updateTransactionGasFees')
.mockImplementation(() => ({ type: '' }));
const { result } = renderUseTransactionFunctions();
result.current.updateTransactionUsingEstimate(GAS_RECOMMENDATIONS.LOW);
expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalledWith({
txParams: {
estimateSuggested: 'medium',
estimateUsed: 'low',
gas: '5208',
gasLimit: '5208',
maxFeePerGas: 'c570bd200',
maxPriorityFeePerGas: 'b2d05e00',
},
await result.current.updateTransactionUsingEstimate(
GAS_RECOMMENDATIONS.LOW,
);
expect(mockUpdateGasFees).toHaveBeenCalledTimes(1);
expect(mockUpdateGasFees).toHaveBeenCalledWith(undefined, {
estimateSuggested: 'medium',
estimateUsed: 'low',
gas: '5208',
gasLimit: '5208',
maxFeePerGas: 'c570bd200',
maxPriorityFeePerGas: 'b2d05e00',
userEditedGasLimit: undefined,
userFeeLevel: 'low',
});
});
it('should invoke action updateTransaction with dappSuggestedValues values fee when updateTransactionUsingDAPPSuggestedValues callback is invoked', () => {
const mock = jest
.spyOn(Actions, 'updateTransaction')
it('should invoke action updateTransaction with dappSuggestedValues values fee when updateTransactionUsingDAPPSuggestedValues callback is invoked', async () => {
const mockUpdateGasFees = jest
.spyOn(Actions, 'updateTransactionGasFees')
.mockImplementation(() => ({ type: '' }));
const { result } = renderUseTransactionFunctions({
transaction: {
userFeeLevel: CUSTOM_GAS_ESTIMATE,
@ -123,21 +126,16 @@ describe('useMaxPriorityFeePerGasInput', () => {
},
},
});
result.current.updateTransactionUsingDAPPSuggestedValues();
expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalledWith({
dappSuggestedGasFees: {
maxFeePerGas: '0x5028',
maxPriorityFeePerGas: '0x5028',
},
txParams: {
estimateSuggested: 'medium',
estimateUsed: 'dappSuggested',
gas: '5208',
gasLimit: '5208',
maxFeePerGas: '0x5028',
maxPriorityFeePerGas: '0x5028',
},
await result.current.updateTransactionUsingDAPPSuggestedValues();
expect(mockUpdateGasFees).toHaveBeenCalledTimes(1);
expect(mockUpdateGasFees).toHaveBeenCalledWith(undefined, {
estimateSuggested: 'medium',
estimateUsed: 'dappSuggested',
gas: '5208',
gasLimit: '5208',
maxFeePerGas: '0x5028',
maxPriorityFeePerGas: '0x5028',
userEditedGasLimit: undefined,
userFeeLevel: 'dappSuggested',
});
});

@ -11,8 +11,9 @@ import {
createCancelTransaction,
createSpeedUpTransaction,
updateCustomSwapsEIP1559GasParams,
updatePreviousGasParams,
updateSwapsUserFeeLevel,
updateTransaction as updateTransactionFn,
updateTransactionGasFees,
} from '../../store/actions';
export const useTransactionFunctions = ({
@ -49,7 +50,7 @@ export const useTransactionFunctions = ({
}, [editGasMode, transaction?.previousGas, transaction?.txParams]);
const updateTransaction = useCallback(
({
async ({
estimateUsed,
gasLimit,
maxFeePerGas,
@ -87,7 +88,18 @@ export const useTransactionFunctions = ({
);
dispatch(updateCustomSwapsEIP1559GasParams(newGasSettings));
} else {
dispatch(updateTransactionFn(updatedTxMeta));
newGasSettings.userEditedGasLimit = updatedTxMeta.userEditedGasLimit;
newGasSettings.userFeeLevel = updatedTxMeta.userFeeLevel;
if (txMeta && txMeta.previousGas) {
await dispatch(
updatePreviousGasParams(updatedTxMeta.id, txMeta.previousGas),
);
}
await dispatch(
updateTransactionGasFees(updatedTxMeta.id, newGasSettings),
);
}
},
[

@ -38,7 +38,7 @@ import {
import { getMostRecentOverviewPage } from '../../ducks/history/history';
import {
isAddressLedger,
updateTransactionGasFees,
updateGasFees,
getIsGasEstimatesLoading,
getNativeCurrency,
} from '../../ducks/metamask/metamask';
@ -287,7 +287,7 @@ export const mapDispatchToProps = (dispatch) => {
setDefaultHomeActiveTabName: (tabName) =>
dispatch(setDefaultHomeActiveTabName(tabName)),
updateTransactionGasFees: (gasFees) => {
dispatch(updateTransactionGasFees({ ...gasFees, expectHexWei: true }));
dispatch(updateGasFees({ ...gasFees, expectHexWei: true }));
},
showBuyModal: () => dispatch(showModal({ name: 'DEPOSIT_ETHER' })),
};

@ -671,6 +671,24 @@ const updateMetamaskStateFromBackground = () => {
});
};
export function updatePreviousGasParams(txId, previousGasParams) {
return async (dispatch) => {
let updatedTransaction;
try {
updatedTransaction = await promisifiedBackground.updatePreviousGasParams(
txId,
previousGasParams,
);
} catch (error) {
dispatch(txError(error));
log.error(error.message);
throw error;
}
return updatedTransaction;
};
}
export function updateSwapApprovalTransaction(txId, txSwapApproval) {
return async (dispatch) => {
let updatedTransaction;
@ -681,7 +699,6 @@ export function updateSwapApprovalTransaction(txId, txSwapApproval) {
);
} catch (error) {
dispatch(txError(error));
dispatch(goHome());
log.error(error.message);
throw error;
}
@ -700,7 +717,6 @@ export function updateEditableParams(txId, editableParams) {
);
} catch (error) {
dispatch(txError(error));
dispatch(goHome());
log.error(error.message);
throw error;
}
@ -719,7 +735,6 @@ export function updateTransactionGasFees(txId, txGasFees) {
);
} catch (error) {
dispatch(txError(error));
dispatch(goHome());
log.error(error.message);
throw error;
}
@ -738,7 +753,6 @@ export function updateSwapTransaction(txId, txSwap) {
);
} catch (error) {
dispatch(txError(error));
dispatch(goHome());
log.error(error.message);
throw error;
}

Loading…
Cancel
Save