mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Transaction updates methods return whole tx meta (#14147)
* Transaction updates methods return whole tx meta * Fix unit test Co-authored-by: Dan Miller <danjm@pop-os.localdomain>
This commit is contained in:
parent
67ef1ce51e
commit
5fec2b53a7
@ -373,6 +373,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* updates the params that are editible in the send edit flow
|
||||||
*
|
*
|
||||||
* @param {string} txId - transaction id
|
* @param {string} txId - transaction id
|
||||||
* @param {object} editableParams - holds the editable parameters
|
* @param {object} editableParams - holds the editable parameters
|
||||||
@ -380,10 +381,13 @@ export default class TransactionController extends EventEmitter {
|
|||||||
* @param {string} editableParams.from
|
* @param {string} editableParams.from
|
||||||
* @param {string} editableParams.to
|
* @param {string} editableParams.to
|
||||||
* @param {string} editableParams.value
|
* @param {string} editableParams.value
|
||||||
|
* @returns {TransactionMeta} the txMeta of the updated transaction
|
||||||
*/
|
*/
|
||||||
updateEditableParams(txId, { data, from, to, value }) {
|
updateEditableParams(txId, { data, from, to, value }) {
|
||||||
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
||||||
return;
|
throw new Error(
|
||||||
|
'Cannot call updateEditableParams on a transaction that is not in an unapproved state',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const editableParams = {
|
const editableParams = {
|
||||||
@ -399,6 +403,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
editableParams.txParams = pickBy(editableParams.txParams);
|
editableParams.txParams = pickBy(editableParams.txParams);
|
||||||
const note = `Update Editable Params for ${txId}`;
|
const note = `Update Editable Params for ${txId}`;
|
||||||
this._updateTransaction(txId, editableParams, note);
|
this._updateTransaction(txId, editableParams, note);
|
||||||
|
return this._getTransaction(txId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -415,6 +420,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
* @param {string} txGasFees.defaultGasEstimates
|
* @param {string} txGasFees.defaultGasEstimates
|
||||||
* @param {string} txGasFees.gas
|
* @param {string} txGasFees.gas
|
||||||
* @param {string} txGasFees.originalGasEstimate
|
* @param {string} txGasFees.originalGasEstimate
|
||||||
|
* @returns {TransactionMeta} the txMeta of the updated transaction
|
||||||
*/
|
*/
|
||||||
updateTransactionGasFees(
|
updateTransactionGasFees(
|
||||||
txId,
|
txId,
|
||||||
@ -431,7 +437,9 @@ export default class TransactionController extends EventEmitter {
|
|||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
||||||
return;
|
throw new Error(
|
||||||
|
'Cannot call updateTransactionGasFees on a transaction that is not in an unapproved state',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let txGasFees = {
|
let txGasFees = {
|
||||||
@ -453,6 +461,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
txGasFees = pickBy(txGasFees);
|
txGasFees = pickBy(txGasFees);
|
||||||
const note = `Update Transaction Gas Fees for ${txId}`;
|
const note = `Update Transaction Gas Fees for ${txId}`;
|
||||||
this._updateTransaction(txId, txGasFees, note);
|
this._updateTransaction(txId, txGasFees, note);
|
||||||
|
return this._getTransaction(txId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -462,13 +471,16 @@ export default class TransactionController extends EventEmitter {
|
|||||||
* @param {object} txEstimateBaseFees - holds the estimate base fees parameters
|
* @param {object} txEstimateBaseFees - holds the estimate base fees parameters
|
||||||
* @param {string} txEstimateBaseFees.estimatedBaseFee
|
* @param {string} txEstimateBaseFees.estimatedBaseFee
|
||||||
* @param {string} txEstimateBaseFees.decEstimatedBaseFee
|
* @param {string} txEstimateBaseFees.decEstimatedBaseFee
|
||||||
|
* @returns {TransactionMeta} the txMeta of the updated transaction
|
||||||
*/
|
*/
|
||||||
updateTransactionEstimatedBaseFee(
|
updateTransactionEstimatedBaseFee(
|
||||||
txId,
|
txId,
|
||||||
{ estimatedBaseFee, decEstimatedBaseFee },
|
{ estimatedBaseFee, decEstimatedBaseFee },
|
||||||
) {
|
) {
|
||||||
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
||||||
return;
|
throw new Error(
|
||||||
|
'Cannot call updateTransactionEstimatedBaseFee on a transaction that is not in an unapproved state',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let txEstimateBaseFees = { estimatedBaseFee, decEstimatedBaseFee };
|
let txEstimateBaseFees = { estimatedBaseFee, decEstimatedBaseFee };
|
||||||
@ -477,6 +489,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
const note = `Update Transaction Estimated Base Fees for ${txId}`;
|
const note = `Update Transaction Estimated Base Fees for ${txId}`;
|
||||||
this._updateTransaction(txId, txEstimateBaseFees, note);
|
this._updateTransaction(txId, txEstimateBaseFees, note);
|
||||||
|
return this._getTransaction(txId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -487,10 +500,13 @@ export default class TransactionController extends EventEmitter {
|
|||||||
* @param {object} swapApprovalTransaction - holds the metadata and token symbol
|
* @param {object} swapApprovalTransaction - holds the metadata and token symbol
|
||||||
* @param {string} swapApprovalTransaction.type
|
* @param {string} swapApprovalTransaction.type
|
||||||
* @param {string} swapApprovalTransaction.sourceTokenSymbol
|
* @param {string} swapApprovalTransaction.sourceTokenSymbol
|
||||||
|
* @returns {TransactionMeta} the txMeta of the updated transaction
|
||||||
*/
|
*/
|
||||||
updateSwapApprovalTransaction(txId, { type, sourceTokenSymbol }) {
|
updateSwapApprovalTransaction(txId, { type, sourceTokenSymbol }) {
|
||||||
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
||||||
return;
|
throw new Error(
|
||||||
|
'Cannot call updateSwapApprovalTransaction on a transaction that is not in an unapproved state',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let swapApprovalTransaction = { type, sourceTokenSymbol };
|
let swapApprovalTransaction = { type, sourceTokenSymbol };
|
||||||
@ -499,6 +515,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
const note = `Update Swap Approval Transaction for ${txId}`;
|
const note = `Update Swap Approval Transaction for ${txId}`;
|
||||||
this._updateTransaction(txId, swapApprovalTransaction, note);
|
this._updateTransaction(txId, swapApprovalTransaction, note);
|
||||||
|
return this._getTransaction(txId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -516,6 +533,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
* @param {string} swapTransaction.swapTokenValue
|
* @param {string} swapTransaction.swapTokenValue
|
||||||
* @param {string} swapTransaction.estimatedBaseFee
|
* @param {string} swapTransaction.estimatedBaseFee
|
||||||
* @param {string} swapTransaction.approvalTxId
|
* @param {string} swapTransaction.approvalTxId
|
||||||
|
* @returns {TransactionMeta} the txMeta of the updated transaction
|
||||||
*/
|
*/
|
||||||
updateSwapTransaction(
|
updateSwapTransaction(
|
||||||
txId,
|
txId,
|
||||||
@ -532,7 +550,9 @@ export default class TransactionController extends EventEmitter {
|
|||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
||||||
return;
|
throw new Error(
|
||||||
|
'Cannot call updateSwapTransaction on a transaction that is not in an unapproved state',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let swapTransaction = {
|
let swapTransaction = {
|
||||||
sourceTokenSymbol,
|
sourceTokenSymbol,
|
||||||
@ -551,6 +571,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
const note = `Update Swap Transaction for ${txId}`;
|
const note = `Update Swap Transaction for ${txId}`;
|
||||||
this._updateTransaction(txId, swapTransaction, note);
|
this._updateTransaction(txId, swapTransaction, note);
|
||||||
|
return this._getTransaction(txId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -560,10 +581,13 @@ export default class TransactionController extends EventEmitter {
|
|||||||
* @param {object} userSettings - holds the metadata
|
* @param {object} userSettings - holds the metadata
|
||||||
* @param {string} userSettings.userEditedGasLimit
|
* @param {string} userSettings.userEditedGasLimit
|
||||||
* @param {string} userSettings.userFeeLevel
|
* @param {string} userSettings.userFeeLevel
|
||||||
|
* @returns {TransactionMeta} the txMeta of the updated transaction
|
||||||
*/
|
*/
|
||||||
updateTransactionUserSettings(txId, { userEditedGasLimit, userFeeLevel }) {
|
updateTransactionUserSettings(txId, { userEditedGasLimit, userFeeLevel }) {
|
||||||
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
if (!this._checkIfTxStatusIsUnapproved(txId)) {
|
||||||
return;
|
throw new Error(
|
||||||
|
'Cannot call updateTransactionUserSettings on a transaction that is not in an unapproved state',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let userSettings = { userEditedGasLimit, userFeeLevel };
|
let userSettings = { userEditedGasLimit, userFeeLevel };
|
||||||
@ -572,6 +596,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
const note = `Update User Settings for ${txId}`;
|
const note = `Update User Settings for ${txId}`;
|
||||||
this._updateTransaction(txId, userSettings, note);
|
this._updateTransaction(txId, userSettings, note);
|
||||||
|
return this._getTransaction(txId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================================================================================================================================
|
// ====================================================================================================================================================
|
||||||
|
@ -2170,7 +2170,7 @@ describe('Transaction Controller', function () {
|
|||||||
assert.equal(result.userFeeLevel, 'high');
|
assert.equal(result.userFeeLevel, 'high');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not update if status is not unapproved', function () {
|
it('throws error if status is not unapproved', function () {
|
||||||
txStateManager.addTransaction({
|
txStateManager.addTransaction({
|
||||||
id: '4',
|
id: '4',
|
||||||
status: TRANSACTION_STATUSES.APPROVED,
|
status: TRANSACTION_STATUSES.APPROVED,
|
||||||
@ -2184,14 +2184,14 @@ describe('Transaction Controller', function () {
|
|||||||
estimateUsed: '0x009',
|
estimateUsed: '0x009',
|
||||||
});
|
});
|
||||||
|
|
||||||
txController.updateTransactionGasFees('4', { maxFeePerGas: '0x0088' });
|
try {
|
||||||
let result = txStateManager.getTransaction('4');
|
txController.updateTransactionGasFees('4', { maxFeePerGas: '0x0088' });
|
||||||
assert.equal(result.txParams.maxFeePerGas, '0x008');
|
} catch (e) {
|
||||||
|
assert.equal(
|
||||||
// test update estimate used
|
e.message,
|
||||||
txController.updateTransactionGasFees('4', { estimateUsed: '0x0099' });
|
'Cannot call updateTransactionGasFees on a transaction that is not in an unapproved state',
|
||||||
result = txStateManager.getTransaction('4');
|
);
|
||||||
assert.equal(result.estimateUsed, '0x009');
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not update unknown parameters in update method', function () {
|
it('does not update unknown parameters in update method', function () {
|
||||||
|
@ -673,8 +673,9 @@ const updateMetamaskStateFromBackground = () => {
|
|||||||
|
|
||||||
export function updateSwapApprovalTransaction(txId, txSwapApproval) {
|
export function updateSwapApprovalTransaction(txId, txSwapApproval) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
|
let updatedTransaction;
|
||||||
try {
|
try {
|
||||||
await promisifiedBackground.updateSwapApprovalTransaction(
|
updatedTransaction = await promisifiedBackground.updateSwapApprovalTransaction(
|
||||||
txId,
|
txId,
|
||||||
txSwapApproval,
|
txSwapApproval,
|
||||||
);
|
);
|
||||||
@ -685,14 +686,18 @@ export function updateSwapApprovalTransaction(txId, txSwapApproval) {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return txSwapApproval;
|
return updatedTransaction;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateEditableParams(txId, editableParams) {
|
export function updateEditableParams(txId, editableParams) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
|
let updatedTransaction;
|
||||||
try {
|
try {
|
||||||
await promisifiedBackground.updateEditableParams(txId, editableParams);
|
updatedTransaction = await promisifiedBackground.updateEditableParams(
|
||||||
|
txId,
|
||||||
|
editableParams,
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(txError(error));
|
dispatch(txError(error));
|
||||||
dispatch(goHome());
|
dispatch(goHome());
|
||||||
@ -700,14 +705,18 @@ export function updateEditableParams(txId, editableParams) {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return editableParams;
|
return updatedTransaction;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateTransactionGasFees(txId, txGasFees) {
|
export function updateTransactionGasFees(txId, txGasFees) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
|
let updatedTransaction;
|
||||||
try {
|
try {
|
||||||
await promisifiedBackground.updateTransactionGasFees(txId, txGasFees);
|
updatedTransaction = await promisifiedBackground.updateTransactionGasFees(
|
||||||
|
txId,
|
||||||
|
txGasFees,
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(txError(error));
|
dispatch(txError(error));
|
||||||
dispatch(goHome());
|
dispatch(goHome());
|
||||||
@ -715,14 +724,18 @@ export function updateTransactionGasFees(txId, txGasFees) {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return txGasFees;
|
return updatedTransaction;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateSwapTransaction(txId, txSwap) {
|
export function updateSwapTransaction(txId, txSwap) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
|
let updatedTransaction;
|
||||||
try {
|
try {
|
||||||
await promisifiedBackground.updateSwapTransaction(txId, txSwap);
|
updatedTransaction = await promisifiedBackground.updateSwapTransaction(
|
||||||
|
txId,
|
||||||
|
txSwap,
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(txError(error));
|
dispatch(txError(error));
|
||||||
dispatch(goHome());
|
dispatch(goHome());
|
||||||
@ -730,7 +743,7 @@ export function updateSwapTransaction(txId, txSwap) {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return txSwap;
|
return updatedTransaction;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user