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

Cancel transaction when swaps submission is failed because the simulation fails (#10288)

* Cancel transaction when swaps submission is failed because the simulation fails

* Cleanup
This commit is contained in:
Dan J Miller 2021-01-26 17:01:25 -03:30 committed by GitHub
parent b441b7cfdc
commit d0df03b89a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import {
setSwapsLiveness, setSwapsLiveness,
setSelectedQuoteAggId, setSelectedQuoteAggId,
setSwapsTxGasLimit, setSwapsTxGasLimit,
cancelTx,
} from '../../store/actions' } from '../../store/actions'
import { import {
AWAITING_SWAP_ROUTE, AWAITING_SWAP_ROUTE,
@ -705,6 +706,7 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => {
// transactions that get published to the blockchain only to fail and thereby // transactions that get published to the blockchain only to fail and thereby
// waste the user's funds on gas. // waste the user's funds on gas.
if (!approveTxParams && tradeTxMeta.simulationFails) { if (!approveTxParams && tradeTxMeta.simulationFails) {
await dispatch(cancelTx(tradeTxMeta, false))
await dispatch(setSwapsErrorKey(SWAP_FAILED_ERROR)) await dispatch(setSwapsErrorKey(SWAP_FAILED_ERROR))
history.push(SWAPS_ERROR_ROUTE) history.push(SWAPS_ERROR_ROUTE)
return return

View File

@ -1048,9 +1048,9 @@ export function cancelTypedMsg(msgData) {
} }
} }
export function cancelTx(txData) { export function cancelTx(txData, _showLoadingIndication = true) {
return (dispatch) => { return (dispatch) => {
dispatch(showLoadingIndication()) _showLoadingIndication && dispatch(showLoadingIndication())
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
background.cancelTransaction(txData.id, (error) => { background.cancelTransaction(txData.id, (error) => {
if (error) { if (error) {