Skip to content

Comments

PRO-3800 - Added Warning Message on Sell#429

Merged
vignesha22 merged 1 commit intostagingfrom
PRO-3800-WarningMessagesSell
Oct 9, 2025
Merged

PRO-3800 - Added Warning Message on Sell#429
vignesha22 merged 1 commit intostagingfrom
PRO-3800-WarningMessagesSell

Conversation

@vignesha22
Copy link
Contributor

@vignesha22 vignesha22 commented Oct 9, 2025

Description

  • Added min amount of $1 worth of selected token
  • Changed the warning message of 'Not enough liquidity' to 'Not enough balance'

How Has This Been Tested?

  • Tested locally

Screenshots (if appropriate):

Screenshot 2025-10-09 at 8 41 18 PM Screenshot 2025-10-09 at 8 41 29 PM

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Summary by CodeRabbit

  • New Features
    • Enforces a minimum sell amount of $1 (by token USD value).
    • Disables the Sell button when the amount is below the $1 minimum.
    • Displays a clear “Min amount is $1 worth of tokens” message when under the threshold.
    • Improves validation messaging to better distinguish insufficient balance/liquidity from minimum amount constraints.

@vignesha22 vignesha22 requested a review from RanaBug October 9, 2025 15:44
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

Walkthrough

Adds a $1 minimum-value check to the Sell flow by introducing minAmount state, updating input/change validation, extending notEnoughLiquidity gating, and adjusting error and button-disable logic accordingly in Sell.tsx.

Changes

Cohort / File(s) Change summary
Sell flow validation update
src/apps/pulse/components/Sell/Sell.tsx
Added minAmount state; computed based on token.usdValue and input amount; integrated into validity checks; updated error rendering to show “Min amount is $1 worth of tokens”; combined with notEnoughLiquidity to disable SellButton.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Sell as Sell.tsx
  participant Token as Token Data
  participant Button as SellButton

  User->>Sell: Enter token amount
  Sell->>Token: Read token.usdValue
  alt usdValue available
    Sell->>Sell: Compute USD = amount * usdValue
    Sell->>Sell: Set minAmount = (USD < $1)
  else usdValue unavailable
    Sell->>Sell: Set minAmount = false
  end

  Sell->>Sell: Validate balance/liquidity + minAmount
  Sell->>Button: notEnoughLiquidity = liquidityFail || minAmount
  Note over Sell,Button: Render errors:<br/>- Not enough balance (liquidity fail)<br/>- Min amount is $1 worth of tokens (minAmount)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • RanaBug
  • IAmKio

Poem

I nibble code like clover leaves,
A dollar’s floor, the UI weaves.
Hop-stop checks for tiny sums,
The SellButton hums—no oops, no crumbs.
Tokens tall, tokens slight,
Bound by bucks, the math is right. 🐇💸

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly references the introduction of a new warning message in the Sell component and aligns with the code changes. It accurately reflects the changes made, though it could be more specific about the new $1 minimum token requirement. It is concise and not misleading.
Description Check ✅ Passed The pull request description follows the repository’s template by including the Description, How Has This Been Tested, Screenshots, and Types of changes sections. The Description section succinctly outlines the new $1 minimum requirement and updated warning message, and the Screenshots illustrate the changes. Although the testing section is brief, it indicates that functionality was verified locally.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch PRO-3800-WarningMessagesSell

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/apps/pulse/components/Sell/Sell.tsx (1)

67-67: Consider checking minAmount in the offer fetch logic.

The fetchSellOffer function checks !notEnoughLiquidity but doesn't check !minAmount. This means the component will fetch sell offers even when the amount is below the $1 minimum, which is wasteful since the user cannot proceed with the transaction anyway.

Apply this diff to add the minAmount check:

     if (
       debouncedTokenAmount &&
       token &&
       isInitialized &&
       parseFloat(debouncedTokenAmount) > 0 &&
-      !notEnoughLiquidity
+      !notEnoughLiquidity &&
+      !minAmount
     ) {
       setIsLoadingOffer(true);
       try {

And update the dependency array on line 92:

-  }, [debouncedTokenAmount, token, isInitialized, notEnoughLiquidity]);
+  }, [debouncedTokenAmount, token, isInitialized, notEnoughLiquidity, minAmount]);

Also update the else-if condition:

-    } else if (notEnoughLiquidity) {
+    } else if (notEnoughLiquidity || minAmount) {
       setLocalSellOffer(null);
       setIsLoadingOffer(false);
     }

Also applies to: 87-89

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1bff3e and 3767c82.

📒 Files selected for processing (1)
  • src/apps/pulse/components/Sell/Sell.tsx (6 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: RanaBug
PR: pillarwallet/x#391
File: src/apps/pulse/components/Sell/Sell.tsx:113-130
Timestamp: 2025-09-09T12:40:15.629Z
Learning: In the Pulse app Sell component, when a user changes/switches tokens, the input amount automatically resets to 0, which means liquidity validation state doesn't become stale when tokens change.
📚 Learning: 2025-09-09T12:40:15.629Z
Learnt from: RanaBug
PR: pillarwallet/x#391
File: src/apps/pulse/components/Sell/Sell.tsx:113-130
Timestamp: 2025-09-09T12:40:15.629Z
Learning: In the Pulse app Sell component, when a user changes/switches tokens, the input amount automatically resets to 0, which means liquidity validation state doesn't become stale when tokens change.

Applied to files:

  • src/apps/pulse/components/Sell/Sell.tsx
🔇 Additional comments (4)
src/apps/pulse/components/Sell/Sell.tsx (4)

54-54: LGTM!

The new minAmount state variable is properly declared to track the $1 minimum requirement.


137-137: LGTM!

Correctly resets minAmount when the input is empty.


315-315: Consider the error message precedence.

The warning condition correctly checks for all three error states. However, the error message rendering uses OR chaining, which means if both notEnoughLiquidity and minAmount are true, only "Not enough balance" will be displayed. While this prioritization may be intentional, consider whether users might benefit from seeing both messages or if a combined message would be clearer.

The change from "Not enough liquidity" to "Not enough balance" aligns with the PR objectives.

Verify this behavior is acceptable: when a user enters an amount that both exceeds their balance AND is below $1 USD, only "Not enough balance" is shown.

Also applies to: 329-330


427-427: LGTM!

Correctly combines both notEnoughLiquidity and minAmount conditions to disable the sell button when either validation fails.

Comment on lines +130 to +134
if (!Number.isNaN(token?.usdValue)) {
setMinAmount(inputAmount * Number(token?.usdValue) < 1);
} else {
setMinAmount(false);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Handle the edge case when usdValue is zero.

If token.usdValue is 0 (price data unavailable or zero-value token), the calculation inputAmount * 0 < 1 will always be true for any positive input, incorrectly blocking valid sell operations.

Apply this diff to properly handle the edge case:

-        if (!Number.isNaN(token?.usdValue)) {
+        if (!Number.isNaN(token?.usdValue) && Number(token?.usdValue) > 0) {
           setMinAmount(inputAmount * Number(token?.usdValue) < 1);
         } else {
           setMinAmount(false);
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!Number.isNaN(token?.usdValue)) {
setMinAmount(inputAmount * Number(token?.usdValue) < 1);
} else {
setMinAmount(false);
}
if (!Number.isNaN(token?.usdValue) && Number(token?.usdValue) > 0) {
setMinAmount(inputAmount * Number(token?.usdValue) < 1);
} else {
setMinAmount(false);
}
🤖 Prompt for AI Agents
In src/apps/pulse/components/Sell/Sell.tsx around lines 130 to 134, the current
logic treats a usdValue of 0 as valid and therefore marks minAmount true for any
positive input; change the condition to first ensure usdValue is a finite number
greater than 0 before computing inputAmount * usdValue < 1, otherwise set
minAmount to false; ensure you coerce token?.usdValue to a Number safely (handle
token undefined), and use Number.isFinite or explicit checks (usdValue !==
undefined && usdValue > 0) to avoid treating zero as causing a minimum amount
restriction.

Comment on lines +159 to +167
if (!Number.isNaN(token?.usdValue)) {
setMinAmount(inputAmount * Number(token?.usdValue) < 1);
} else {
setMinAmount(false);
}
setNotEnoughLiquidity(inputAmount > tokenBalance);
} else {
setNotEnoughLiquidity(false);
setMinAmount(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Handle the edge case when usdValue is zero and eliminate code duplication.

This validation logic has the same critical issue as lines 130-134: if token.usdValue is 0, it will incorrectly block valid operations. Additionally, this logic is duplicated from the input change handler.

Apply this diff to fix the edge case and consider extracting the validation logic into a helper function to eliminate duplication:

-        if (!Number.isNaN(token?.usdValue)) {
+        if (!Number.isNaN(token?.usdValue) && Number(token?.usdValue) > 0) {
           setMinAmount(inputAmount * Number(token?.usdValue) < 1);
         } else {
           setMinAmount(false);
         }
         setNotEnoughLiquidity(inputAmount > tokenBalance);
       } else {
         setNotEnoughLiquidity(false);
         setMinAmount(false);
       }

Consider extracting the validation logic into a helper function:

const calculateMinAmount = (amount: number, usdValue: string | number | undefined): boolean => {
  const numericUsdValue = Number(usdValue);
  return !Number.isNaN(numericUsdValue) && numericUsdValue > 0 && amount * numericUsdValue < 1;
};

@vignesha22 vignesha22 merged commit 7ac9159 into staging Oct 9, 2025
6 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 10, 2025
3 tasks
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