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: clear transaction data after submission or cancellation #30546

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions ui/pages/confirmations/components/confirm/footer/footer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { TransactionMeta } from '@metamask/transaction-controller';
import { providerErrors, serializeError } from '@metamask/rpc-errors';
import { TransactionMeta } from '@metamask/transaction-controller';
import React, { useCallback, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { MetaMetricsEventLocation } from '../../../../../../shared/constants/metametrics';
import { isCorrectDeveloperTransactionType } from '../../../../../../shared/lib/confirmation.utils';
import { ConfirmAlertModal } from '../../../../../components/app/alert-system/confirm-alert-modal';
import {
Button,
Expand All @@ -10,13 +12,15 @@ import {
IconName,
} from '../../../../../components/component-library';
import { Footer as PageFooter } from '../../../../../components/multichain/pages/page';
import { Alert } from '../../../../../ducks/confirm-alerts/confirm-alerts';
import { clearConfirmTransaction } from '../../../../../ducks/confirm-transaction/confirm-transaction.duck';
import { Severity } from '../../../../../helpers/constants/design-system';
import useAlerts from '../../../../../hooks/useAlerts';
import { useI18nContext } from '../../../../../hooks/useI18nContext';
import {
doesAddressRequireLedgerHidConnection,
getCustomNonceValue,
} from '../../../../../selectors';

import useAlerts from '../../../../../hooks/useAlerts';
import {
rejectPendingApproval,
resolvePendingApproval,
Expand All @@ -26,14 +30,10 @@ import {
///: END:ONLY_INCLUDE_IF
updateCustomNonce,
} from '../../../../../store/actions';
import { isSignatureTransactionType } from '../../../utils';
import { useConfirmContext } from '../../../context/confirm';
import { getConfirmationSender } from '../utils';
import { MetaMetricsEventLocation } from '../../../../../../shared/constants/metametrics';
import { Alert } from '../../../../../ducks/confirm-alerts/confirm-alerts';
import { Severity } from '../../../../../helpers/constants/design-system';
import { isCorrectDeveloperTransactionType } from '../../../../../../shared/lib/confirmation.utils';
import { useOriginThrottling } from '../../../hooks/useOriginThrottling';
import { isSignatureTransactionType } from '../../../utils';
import { getConfirmationSender } from '../utils';
import OriginThrottleModal from './origin-throttle-modal';

export type OnCancelHandler = ({
Expand Down Expand Up @@ -178,6 +178,12 @@ const Footer = () => {
(!isScrollToBottomCompleted && !isSignature) ||
hardwareWalletRequiresConnection;

const resetTransactionState = () => {
dispatch(updateCustomNonce(''));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, unit tests would be nice but I appreciate this is high priority.

dispatch(setNextNonce(''));
dispatch(clearConfirmTransaction());
};

const onCancel = useCallback(
({ location }: { location?: MetaMetricsEventLocation }) => {
if (!currentConfirmation) {
Expand All @@ -190,8 +196,7 @@ const Footer = () => {
dispatch(
rejectPendingApproval(currentConfirmation.id, serializeError(error)),
);
dispatch(updateCustomNonce(''));
dispatch(setNextNonce(''));
resetTransactionState();
},
[currentConfirmation],
);
Expand Down Expand Up @@ -223,8 +228,7 @@ const Footer = () => {
} else {
dispatch(resolvePendingApproval(currentConfirmation.id, undefined));
}
dispatch(updateCustomNonce(''));
dispatch(setNextNonce(''));
resetTransactionState();
}, [currentConfirmation, customNonceValue]);

const handleFooterCancel = useCallback(() => {
Expand Down
Loading