Update EIP1559 params. (#13652)

* 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 EIP1559 params.

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

* Remove metrics

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

* Add updateTransactionParams to actions.js updateXXX and return txData at the end of updateXXX method

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

* Lint fixes.

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

* change method name to update editable params.

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

* lint fixes.

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

* Editable params should pass in the txParams and not the full tx object

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

* Fix jest tests

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

* lint fixes.

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>

* Proper JSDOCs comments.

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

* Remove gas settings from updateEditableParams since we already have a
dedicated gas update method.

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

* Fix duplicate codes from rebasing.

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

* Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
feature/default_network_editable
Olusegun Akintayo 3 years ago committed by GitHub
parent 4f6eb02854
commit 442edc5a91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 93
      app/scripts/controllers/transactions/index.js
  2. 6
      app/scripts/metamask-controller.js
  3. 6
      ui/ducks/send/send.js
  4. 17
      ui/ducks/send/send.test.js
  5. 40
      ui/store/actions.js

@ -375,15 +375,13 @@ export default class TransactionController extends EventEmitter {
/** /**
* *
* @param {string} txId - transaction id * @param {string} txId - transaction id
* @param {object} editableParams - holds the eip1559 fees parameters * @param {object} editableParams - holds the editable parameters
* @param editableParams.data * @param {object} editableParams.data
* @param editableParams.from * @param {string} editableParams.from
* @param editableParams.to * @param {string} editableParams.to
* @param editableParams.value * @param {string} editableParams.value
* @param editableParams.gas
* @param editableParams.gasPrice
*/ */
updateEditableParams(txId, { data, from, to, value, gas, gasPrice }) { updateEditableParams(txId, { data, from, to, value }) {
if (!this._checkIfTxStatusIsUnapproved(txId)) { if (!this._checkIfTxStatusIsUnapproved(txId)) {
return; return;
} }
@ -394,8 +392,6 @@ export default class TransactionController extends EventEmitter {
from, from,
to, to,
value, value,
gas,
gasPrice,
}, },
}; };
@ -410,23 +406,15 @@ export default class TransactionController extends EventEmitter {
* *
* @param {string} txId - transaction id * @param {string} txId - transaction id
* @param {object} txGasFees - holds the gas fees parameters * @param {object} txGasFees - holds the gas fees parameters
* { * @param {string} txGasFees.gasLimit
* gasLimit, * @param {string} txGasFees.gasPrice
* gasPrice, * @param {string} txGasFees.maxPriorityFeePerGas
* maxPriorityFeePerGas, * @param {string} txGasFees.maxFeePerGas
* maxFeePerGas, * @param {string} txGasFees.estimateUsed
* estimateUsed, * @param {string} txGasFees.estimateSuggested
* estimateSuggested * @param {string} txGasFees.defaultGasEstimates
* } * @param {string} txGasFees.gas
* @param txGasFees.gasLimit * @param {string} txGasFees.originalGasEstimate
* @param txGasFees.gasPrice
* @param txGasFees.maxPriorityFeePerGas
* @param txGasFees.maxFeePerGas
* @param txGasFees.estimateUsed
* @param txGasFees.estimateSuggested
* @param txGasFees.defaultGasEstimates
* @param txGasFees.gas
* @param txGasFees.originalGasEstimate
*/ */
updateTransactionGasFees( updateTransactionGasFees(
txId, txId,
@ -472,12 +460,8 @@ export default class TransactionController extends EventEmitter {
* *
* @param {string} txId - transaction id * @param {string} txId - transaction id
* @param {object} txEstimateBaseFees - holds the estimate base fees parameters * @param {object} txEstimateBaseFees - holds the estimate base fees parameters
* { * @param {string} txEstimateBaseFees.estimatedBaseFee
* estimatedBaseFee, * @param {string} txEstimateBaseFees.decEstimatedBaseFee
* decEstimatedBaseFee
* }
* @param txEstimateBaseFees.estimatedBaseFee
* @param txEstimateBaseFees.decEstimatedBaseFee
*/ */
updateTransactionEstimatedBaseFee( updateTransactionEstimatedBaseFee(
txId, txId,
@ -501,12 +485,8 @@ export default class TransactionController extends EventEmitter {
* *
* @param {string} txId * @param {string} txId
* @param {object} swapApprovalTransaction - holds the metadata and token symbol * @param {object} swapApprovalTransaction - holds the metadata and token symbol
* { * @param {string} swapApprovalTransaction.type
* type, * @param {string} swapApprovalTransaction.sourceTokenSymbol
* sourceTokenSymbol
* }
* @param swapApprovalTransaction.type
* @param swapApprovalTransaction.sourceTokenSymbol
*/ */
updateSwapApprovalTransaction(txId, { type, sourceTokenSymbol }) { updateSwapApprovalTransaction(txId, { type, sourceTokenSymbol }) {
if (!this._checkIfTxStatusIsUnapproved(txId)) { if (!this._checkIfTxStatusIsUnapproved(txId)) {
@ -527,26 +507,15 @@ export default class TransactionController extends EventEmitter {
* *
* @param {string} txId * @param {string} txId
* @param {object} swapTransaction - holds the metadata * @param {object} swapTransaction - holds the metadata
* { * @param {string} swapTransaction.sourceTokenSymbol
* sourceTokenSymbol, * @param {string} swapTransaction.destinationTokenSymbol
* destinationTokenSymbol, * @param {string} swapTransaction.type
* type, * @param {string} swapTransaction.destinationTokenDecimals
* destinationTokenDecimals, * @param {string} swapTransaction.destinationTokenAddress
* destinationTokenAddress, * @param {string} swapTransaction.swapMetaData
* swapMetaData, * @param {string} swapTransaction.swapTokenValue
* swapTokenValue, * @param {string} swapTransaction.estimatedBaseFee
* estimatedBaseFee, * @param {string} swapTransaction.approvalTxId
* approvalTxId
*}
* @param swapTransaction.sourceTokenSymbol
* @param swapTransaction.destinationTokenSymbol
* @param swapTransaction.type
* @param swapTransaction.destinationTokenDecimals
* @param swapTransaction.destinationTokenAddress
* @param swapTransaction.swapMetaData
* @param swapTransaction.swapTokenValue
* @param swapTransaction.estimatedBaseFee
* @param swapTransaction.approvalTxId
*/ */
updateSwapTransaction( updateSwapTransaction(
txId, txId,
@ -565,7 +534,6 @@ export default class TransactionController extends EventEmitter {
if (!this._checkIfTxStatusIsUnapproved(txId)) { if (!this._checkIfTxStatusIsUnapproved(txId)) {
return; return;
} }
let swapTransaction = { let swapTransaction = {
sourceTokenSymbol, sourceTokenSymbol,
destinationTokenSymbol, destinationTokenSymbol,
@ -590,9 +558,8 @@ export default class TransactionController extends EventEmitter {
* *
* @param {string} txId * @param {string} txId
* @param {object} userSettings - holds the metadata * @param {object} userSettings - holds the metadata
* { userEditedGasLimit, userFeeLevel } * @param {string} userSettings.userEditedGasLimit
* @param userSettings.userEditedGasLimit * @param {string} userSettings.userFeeLevel
* @param userSettings.userFeeLevel
*/ */
updateTransactionUserSettings(txId, { userEditedGasLimit, userFeeLevel }) { updateTransactionUserSettings(txId, { userEditedGasLimit, userFeeLevel }) {
if (!this._checkIfTxStatusIsUnapproved(txId)) { if (!this._checkIfTxStatusIsUnapproved(txId)) {

@ -1526,6 +1526,12 @@ export default class MetamaskController extends EventEmitter {
), ),
getTransactions: txController.getTransactions.bind(txController), getTransactions: txController.getTransactions.bind(txController),
updateEditableParams: txController.updateEditableParams.bind(
txController,
),
updateTransactionGasFees: txController.updateTransactionGasFees.bind(
txController,
),
// messageManager // messageManager
signMessage: this.signMessage.bind(this), signMessage: this.signMessage.bind(this),
cancelMessage: this.cancelMessage.bind(this), cancelMessage: this.cancelMessage.bind(this),

@ -53,7 +53,8 @@ import {
hideLoadingIndication, hideLoadingIndication,
showConfTxPage, showConfTxPage,
showLoadingIndication, showLoadingIndication,
updateTransaction, updateEditableParams,
updateTransactionGasFees,
addPollingTokenToAppState, addPollingTokenToAppState,
removePollingTokenFromAppState, removePollingTokenFromAppState,
isCollectibleOwner, isCollectibleOwner,
@ -1700,7 +1701,8 @@ export function signTransaction() {
eip1559support ? eip1559OnlyTxParamsToUpdate : txParams, eip1559support ? eip1559OnlyTxParamsToUpdate : txParams,
), ),
}; };
dispatch(updateTransaction(editingTx)); dispatch(updateEditableParams(id, editingTx.txParams));
dispatch(updateTransactionGasFees(id, editingTx.txParams));
} else if (asset.type === ASSET_TYPES.TOKEN) { } else if (asset.type === ASSET_TYPES.TOKEN) {
// When sending a token transaction we have to the token.transfer method // When sending a token transaction we have to the token.transfer method
// on the token contract to construct the transaction. This results in // on the token contract to construct the transaction. This results in

@ -95,6 +95,12 @@ describe('Send Slice', () => {
jest jest
.spyOn(Actions, 'isCollectibleOwner') .spyOn(Actions, 'isCollectibleOwner')
.mockImplementation(() => Promise.resolve(true)); .mockImplementation(() => Promise.resolve(true));
jest.spyOn(Actions, 'updateEditableParams').mockImplementation(() => ({
type: 'UPDATE_TRANSACTION_EDITABLE_PARAMS',
}));
jest
.spyOn(Actions, 'updateTransactionGasFees')
.mockImplementation(() => ({ type: 'UPDATE_TRANSACTION_GAS_FEES' }));
}); });
describe('Reducers', () => { describe('Reducers', () => {
@ -2070,10 +2076,13 @@ describe('Send Slice', () => {
const actionResult = store.getActions(); const actionResult = store.getActions();
expect(actionResult).toHaveLength(5); expect(actionResult).toHaveLength(2);
expect(actionResult[0].type).toStrictEqual('SHOW_LOADING_INDICATION'); expect(actionResult[0].type).toStrictEqual(
expect(actionResult[1].type).toStrictEqual('UPDATE_TRANSACTION_PARAMS'); 'UPDATE_TRANSACTION_EDITABLE_PARAMS',
expect(actionResult[2].type).toStrictEqual('HIDE_LOADING_INDICATION'); );
expect(actionResult[1].type).toStrictEqual(
'UPDATE_TRANSACTION_GAS_FEES',
);
}); });
}); });

@ -673,6 +673,46 @@ const updateMetamaskStateFromBackground = () => {
}); });
}; };
export function updateEditableParams(txId, editableParams) {
return async (dispatch) => {
try {
await promisifiedBackground.updateEditableParams(txId, editableParams);
} catch (error) {
dispatch(txError(error));
dispatch(goHome());
log.error(error.message);
throw error;
}
dispatch(
updateTransactionParams(editableParams.id, editableParams.txParams),
);
const newState = await updateMetamaskStateFromBackground();
dispatch(updateMetamaskState(newState));
dispatch(showConfTxPage({ id: editableParams.id }));
return editableParams;
};
}
export function updateTransactionGasFees(txId, txGasFees) {
return async (dispatch) => {
try {
await promisifiedBackground.updateTransactionGasFees(txId, txGasFees);
} catch (error) {
dispatch(txError(error));
dispatch(goHome());
log.error(error.message);
throw error;
}
dispatch(updateTransactionParams(txGasFees.id, txGasFees.txParams));
const newState = await updateMetamaskStateFromBackground();
dispatch(updateMetamaskState(newState));
dispatch(showConfTxPage({ id: txGasFees.id }));
return txGasFees;
};
}
export function updateTransaction(txData, dontShowLoadingIndicator) { export function updateTransaction(txData, dontShowLoadingIndicator) {
return async (dispatch) => { return async (dispatch) => {
!dontShowLoadingIndicator && dispatch(showLoadingIndication()); !dontShowLoadingIndicator && dispatch(showLoadingIndication());

Loading…
Cancel
Save