1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Do not publish swaps transaction if the estimateGas call made when adding the tx fails. (#9947)

This commit is contained in:
Dan J Miller 2021-01-22 17:44:57 -03:30 committed by GitHub
parent 9e7a799583
commit 7f1f68399a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -694,6 +694,21 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => {
addUnapprovedTransaction(usedTradeTxParams, 'metamask'),
)
dispatch(setTradeTxId(tradeTxMeta.id))
// The simulationFails property is added during the transaction controllers
// addUnapprovedTransaction call if the estimateGas call fails. In cases
// when no approval is required, this indicates that the swap will likely
// fail. There was an earlier estimateGas call made by the swaps controller,
// but it is possible that external conditions have change since then, and
// a previously succeeding estimate gas call could now fail. By checking for
// the `simulationFails` property here, we can reduce the number of swap
// transactions that get published to the blockchain only to fail and thereby
// waste the user's funds on gas.
if (!approveTxParams && tradeTxMeta.simulationFails) {
await dispatch(setSwapsErrorKey(SWAP_FAILED_ERROR))
history.push(SWAPS_ERROR_ROUTE)
return
}
const finalTradeTxMeta = await dispatch(
updateTransaction(
{