Skip to content

refactor: slippage tolerance form#5676

Merged
therealemjy merged 1 commit into
mainfrom
refactor/min-slippage
Jul 8, 2026
Merged

refactor: slippage tolerance form#5676
therealemjy merged 1 commit into
mainfrom
refactor/min-slippage

Conversation

@therealemjy

Copy link
Copy Markdown
Member

Changes

  • refactor slippage tolerance form to use React Hook form and only allow values of at least 0.01%

@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 997557f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@venusprotocol/evm Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@therealemjy therealemjy requested a review from cuzz-venus July 7, 2026 16:00
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dapp-preview Ready Ready Preview Jul 7, 2026 5:51pm
dapp-testnet Ready Ready Preview Jul 7, 2026 5:51pm
venus.io Ready Ready Preview Jul 7, 2026 5:51pm

Request Review

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refactors the swap slippage tolerance form. The main changes are:

  • Adds a 0.01% minimum slippage tolerance constant.
  • Moves slippage input validation into a shared helper.
  • Reworks the modal input with React Hook Form.
  • Updates persisted settings migration and related tests.

Confidence Score: 4/5

The changed slippage input path needs a small fix before merging.

  • Exponent-format number input can be accepted but saved as a different percentage.
  • Persisted numeric slippage values can keep the wrong runtime shape after migration.
  • The normal decimal validation and store fallback paths are covered by updated tests.

apps/evm/src/containers/SwapDetails/index.tsx and apps/evm/src/store/index.ts

Important Files Changed

Filename Overview
apps/evm/src/containers/SwapDetails/index.tsx Refactors the modal to React Hook Form and updates slippage persistence, with a parsing mismatch for exponent-format number input.
apps/evm/src/containers/SwapDetails/validateSlippageTolerancePercentage/index.ts Adds shared validation for empty, finite, precision, minimum, and maximum slippage values.
apps/evm/src/store/index.ts Expands persisted settings migration to reject invalid slippage values, while preserving the original valid value shape.
apps/evm/src/constants/swap.ts Adds the minimum slippage tolerance constant.
apps/evm/src/containers/SwapDetails/tests/index.spec.tsx Updates modal tests for the new validation behavior and error styling.
apps/evm/src/store/tests/index.spec.ts Adds migration coverage for below-minimum and malformed slippage settings.

Reviews (1): Last reviewed commit: "refactor: slippage tolerance form" | Re-trigger Greptile

if (validateSlippageTolerancePercentage(value)) {
setUserChainSettings({
slippageTolerancePercentage: value,
slippageTolerancePercentage: Number.parseFloat(value).toString(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Exponent Slippage Is Misstored

When the number input emits exponent notation like 1e1, validation accepts it as 10%, but this line stores 1 because parseFloat stops before the exponent. The modal accepts the user's value, while later swap quotes use a different slippage tolerance.

Suggested change
slippageTolerancePercentage: Number.parseFloat(value).toString(),
slippageTolerancePercentage: Number(value).toString(),

Context Used: AGENTS.md (source)

Comment on lines +82 to +84
slippageTolerancePercentage: isSlippageTolerancePercentageValid
? settings.slippageTolerancePercentage
: String(DEFAULT_SLIPPAGE_TOLERANCE_PERCENTAGE),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Legacy Numeric Values Persist

If an older persisted setting or manually restored state has slippageTolerancePercentage as a JSON number, the migration validates it but writes the original number back into a field typed and initialized as a string. That value then reaches the React Hook Form default for the modal, so consumers can receive a shape that no longer matches UserChainSettings.

Suggested change
slippageTolerancePercentage: isSlippageTolerancePercentageValid
? settings.slippageTolerancePercentage
: String(DEFAULT_SLIPPAGE_TOLERANCE_PERCENTAGE),
slippageTolerancePercentage: isSlippageTolerancePercentageValid
? String(settings.slippageTolerancePercentage)
: String(DEFAULT_SLIPPAGE_TOLERANCE_PERCENTAGE),

Context Used: AGENTS.md (source)

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for ./apps/evm

Status Category Percentage Covered / Total
🔵 Lines 82.3% 50226 / 61023
🔵 Statements 82.3% 50226 / 61023
🔵 Functions 62.08% 673 / 1084
🔵 Branches 72.99% 5705 / 7816
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
apps/evm/src/constants/swap.ts 100% 0% 100% 100%
apps/evm/src/containers/SwapDetails/index.tsx 100% 92.3% 100% 100%
apps/evm/src/containers/SwapDetails/validateSlippageTolerancePercentage/index.ts 93.33% 33.33% 100% 93.33% 1
apps/evm/src/store/index.ts 98.46% 90.9% 100% 98.46% 1
Generated in workflow #13774 for commit ee031f2 by the Vitest Coverage Report Action

@cuzz-venus cuzz-venus left a comment

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.

looks good to me

@therealemjy therealemjy merged commit 8966a49 into main Jul 8, 2026
5 checks passed
@therealemjy therealemjy deleted the refactor/min-slippage branch July 8, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants