Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Avoid canceling transactions after submission #4060

Merged
merged 10 commits into from
Jun 9, 2022
27 changes: 26 additions & 1 deletion app/components/Views/Approval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ import AnalyticsV2 from '../../../util/analyticsV2';
import { GAS_ESTIMATE_TYPES } from '@metamask/controllers';
import { KEYSTONE_TX_CANCELED } from '../../../constants/error';
import { ThemeContext, mockTheme } from '../../../util/theme';
import {
TX_CANCELLED,
TX_CONFIRMED,
TX_FAILED,
TX_SUBMITTED,
TX_REJECTED,
} from '../../../constants/transaction';

const REVIEW = 'review';
const EDIT = 'edit';
Expand Down Expand Up @@ -136,12 +143,30 @@ class Approval extends PureComponent {
}
};

isTxStatusCancellable = (transaction) => {
if (
transaction.status === TX_SUBMITTED ||
transaction.status === TX_REJECTED ||
transaction.status === TX_CONFIRMED ||
transaction.status === TX_CANCELLED ||
transaction.status === TX_FAILED
) {
return false;
}
return true;
};

handleAppStateChange = (appState) => {
try {
if (appState !== 'active') {
const { transaction } = this.props;
const { transaction, transactions } = this.props;
const currentTransaction = transactions.find(
(tx) => tx.id === transaction.id,
);

transaction &&
transaction.id &&
this.isTxStatusCancellable(currentTransaction) &&
Engine.context.TransactionController.cancelTransaction(
transaction.id,
);
Expand Down
4 changes: 4 additions & 0 deletions app/constants/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const TX_SUBMITTED = 'submitted';
export const TX_SIGNED = 'signed';
export const TX_PENDING = 'pending';
export const TX_CONFIRMED = 'confirmed';
export const TX_CANCELLED = 'cancelled';
export const TX_APPROVED = 'approved';
export const TX_FAILED = 'failed';
export const TX_REJECTED = 'rejected';

// Values
export const UINT256_BN_MAX_VALUE = new BN(2).pow(new BN(256)).sub(new BN(1));
Expand Down