Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.

Fix: Prevented infinity swap tx sending on user rejection#204

Merged
Andrew718PLTS merged 1 commit intomainfrom
fix/SUP-6-infinity-swap-tx-sending
Mar 10, 2025
Merged

Fix: Prevented infinity swap tx sending on user rejection#204
Andrew718PLTS merged 1 commit intomainfrom
fix/SUP-6-infinity-swap-tx-sending

Conversation

@Andrew718PLTS
Copy link
Copy Markdown
Contributor

@Andrew718PLTS Andrew718PLTS commented Mar 7, 2025

Description

It prevents infinity swap tx sending on user rejection by adding the swapRejectedRef setting when it's been rejected by the user (checking via error message).

Additionally, to read:
The useState doesn't work in this case because the React state updates asynchronously, so useEffect does not immediately pick up the change in isSwapRejected during the first rejection (that's why I had a case when the first rejection is ignored).

Other changes

None

Tested

Reject when there's an approval and a swap TXs.

  1. Select tokens to have an approval TX first (the eXOF would be a good choice).
  2. Click the 'Continue' button.
  3. Wait until the 'Approve ${token}' button is enabled to click.
  4. Click the 'Approve ${token}' button.
  5. Approve the approval TX.
  6. Reject the swap TX.

Reject when there's no approval TX.

  1. Select tokens to avoid an approval TX (a precondition is to swap some tokens before).
  2. Click the 'Continue' button.
  3. Wait until the 'Swap' button is enabled to click.
  4. Click the 'Swap' button.
  5. Reject the swap TX.

Related issues

  • Fixes #issue number here

Checklist before requesting a review

  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • The PR title follows the conventions
  • I have run the regression tests

Copilot AI review requested due to automatic review settings March 7, 2025 14:20
@linear
Copy link
Copy Markdown

linear bot commented Mar 7, 2025

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mento-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 7, 2025 2:20pm

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR fixes an issue where a rejected swap transaction could result in an infinite loop by adding a reference flag (swapRejectedRef) to prevent resubmission after a user rejection.

  • Introduces a swapRejectedRef to track user rejections and prevent duplicate swap transactions.
  • Updates the success toast message wording for clarity.
  • Adjusts the useEffect condition to include the swap rejection flag.

Reviewed Changes

File Description
src/features/swap/SwapConfirm.tsx Added a swapRejectedRef check in the useEffect to block further txs

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Copy link
Copy Markdown
Contributor

@nvtaveras nvtaveras left a comment

Choose a reason for hiding this comment

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

Tested it on the preview and works fine for me. I was wondering tho, do you know why this doesn't happen for the approval tx? If I reject the initial approval the popup doesn't come up again. Why is it different for the swap?

Copy link
Copy Markdown
Contributor

@chapati23 chapati23 left a comment

Choose a reason for hiding this comment

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

tested: works
lgtm

@Andrew718PLTS
Copy link
Copy Markdown
Contributor Author

Andrew718PLTS commented Mar 10, 2025

@nvtaveras It was triggering the swap TX repeatedly because of the useEffect - when some of its dependencies were changing that was trying to send a swap TX.
On approval, it works differently - it has a trigger onSubmit, so it performs only once.
image

@Andrew718PLTS Andrew718PLTS merged commit acdc35a into main Mar 10, 2025
7 checks passed
@Andrew718PLTS Andrew718PLTS deleted the fix/SUP-6-infinity-swap-tx-sending branch March 10, 2025 13:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants