From d0df03b89a266850fb3384de0caf0236937e0ac6 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Tue, 26 Jan 2021 17:01:25 -0330 Subject: [PATCH] Cancel transaction when swaps submission is failed because the simulation fails (#10288) * Cancel transaction when swaps submission is failed because the simulation fails * Cleanup --- ui/app/ducks/swaps/swaps.js | 2 ++ ui/app/store/actions.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/app/ducks/swaps/swaps.js b/ui/app/ducks/swaps/swaps.js index bd029d4ef..d67e8c994 100644 --- a/ui/app/ducks/swaps/swaps.js +++ b/ui/app/ducks/swaps/swaps.js @@ -23,6 +23,7 @@ import { setSwapsLiveness, setSelectedQuoteAggId, setSwapsTxGasLimit, + cancelTx, } from '../../store/actions' import { AWAITING_SWAP_ROUTE, @@ -705,6 +706,7 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => { // 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(cancelTx(tradeTxMeta, false)) await dispatch(setSwapsErrorKey(SWAP_FAILED_ERROR)) history.push(SWAPS_ERROR_ROUTE) return diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js index 0dd31dc9f..9cf6196d8 100644 --- a/ui/app/store/actions.js +++ b/ui/app/store/actions.js @@ -1048,9 +1048,9 @@ export function cancelTypedMsg(msgData) { } } -export function cancelTx(txData) { +export function cancelTx(txData, _showLoadingIndication = true) { return (dispatch) => { - dispatch(showLoadingIndication()) + _showLoadingIndication && dispatch(showLoadingIndication()) return new Promise((resolve, reject) => { background.cancelTransaction(txData.id, (error) => { if (error) {