Skip to content
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
12 changes: 10 additions & 2 deletions app/components/UI/Perps/Views/PerpsOrderView/PerpsOrderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import { useAddToken } from '../../../../Views/confirmations/hooks/tokens/useAdd
import { useAutomaticTransactionPayToken } from '../../../../Views/confirmations/hooks/pay/useAutomaticTransactionPayToken';
import { useTransactionPayMetrics } from '../../../../Views/confirmations/hooks/pay/useTransactionPayMetrics';
import { useTransactionMetadataRequest } from '../../../../Views/confirmations/hooks/transactions/useTransactionMetadataRequest';
import useClearConfirmationOnBackSwipe from '../../../../Views/confirmations/hooks/ui/useClearConfirmationOnBackSwipe';
import AddRewardsAccount from '../../../Rewards/components/AddRewardsAccount/AddRewardsAccount';
import RewardsAnimations, {
RewardAnimationState,
Expand Down Expand Up @@ -147,6 +146,7 @@ import { useTransactionConfirm } from '../../../../Views/confirmations/hooks/tra
import { useTransactionCustomAmount } from '../../../../Views/confirmations/hooks/transactions/useTransactionCustomAmount';
import { useUpdateTokenAmount } from '../../../../Views/confirmations/hooks/transactions/useUpdateTokenAmount';
import DevLogger from '../../../../../core/SDKConnect/utils/DevLogger';
import { useConfirmActions } from '../../../../Views/confirmations/hooks/useConfirmActions';

// Navigation params interface
interface OrderRouteParams {
Expand Down Expand Up @@ -202,7 +202,15 @@ const PerpsOrderViewContentBase: React.FC<PerpsOrderViewContentProps> = ({
tokenAddress: ARBITRUM_USDC.address,
});

useClearConfirmationOnBackSwipe();
// Clear confirmation when leaving the order view
const { onReject } = useConfirmActions();
useEffect(
() => () => {
onReject(undefined, true);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale closure captures outdated onReject callback on unmount

Medium Severity

The useEffect cleanup captures onReject at mount time with an empty dependency array, but onReject from useConfirmActions depends on values like approvalRequest?.id that can change during the component lifecycle. If the approval request changes (e.g., user starts an order creating a new approval), the cleanup will call a stale onReject that may reference outdated or undefined approval state, causing the confirmation to not be properly cleared. The original useClearConfirmationOnBackSwipe hook correctly included onReject in its dependency arrays. A ref pattern would preserve the latest callback while maintaining the unmount-only behavior.

Fix in Cursor Fix in Web


// Disable automatic token selection - we want to show "Perps balance" by default
// User can explicitly select a token from the modal
Expand Down
Loading