Skip to content

Comments

Min amount warning and paying tokens fix#421

Merged
RanaBug merged 1 commit intostagingfrom
fix/PRO-3743/PW-fix-Pulse
Oct 3, 2025
Merged

Min amount warning and paying tokens fix#421
RanaBug merged 1 commit intostagingfrom
fix/PRO-3743/PW-fix-Pulse

Conversation

@RanaBug
Copy link
Collaborator

@RanaBug RanaBug commented Oct 3, 2025

Description

  • Min amount warning and paying tokens fix

How Has This Been Tested?

  • Existing Unit Tests and Manual testing

Screenshots (if appropriate):

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 buy amount of $0.50.
    • Displays a clear inline message: “Min. amount 0.5 USD.”
    • Buy button now disables when below minimum, low liquidity, or insufficient balance.
  • Bug Fixes

    • Resets error messages when editing the USD amount.
    • Avoids misleading liquidity errors for amounts below the minimum.
    • More consistent updates to available assets, chains, and payment options during input.

@RanaBug RanaBug requested a review from IAmKio October 3, 2025 10:43
@RanaBug RanaBug self-assigned this Oct 3, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

Adds a minimum USD amount check (0.5) to the Buy flow, introducing a belowMinimumAmount state. Resets error flags on input. Debounced handler short-circuits liquidity checks when below minimum; otherwise updates tokens/chains/assets unconditionally. Error rendering prioritizes the new flag, and BuyButton receives combined not-enough conditions.

Changes

Cohort / File(s) Summary
Buy flow min-amount and error-state handling
src/apps/pulse/components/Buy/Buy.tsx
Adds belowMinimumAmount state; resets error flags on input; debounced handler enforces min 0.5 USD and skips liquidity checks if below; otherwise clears belowMinimumAmount and always updates dispensableAssets, permittedChains, payingTokens, and parent data; error rendering prioritizes min-amount; BuyButton receives combined not-enough condition.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant B as Buy.tsx
  participant D as Debounced Handler
  participant L as Liquidity/Asset Fetch

  U->>B: Type USD amount
  B->>B: Clear belowMinimumAmount, notEnoughLiquidity, insufficientWalletBalance

  Note over B: Debounce
  B->>D: Pass parsed USD amount

  alt amount < 0.5
    D->>B: Set belowMinimumAmount=true<br/>Clear other error flags
    Note over B: Skip liquidity checks
  else amount >= 0.5
    D->>B: belowMinimumAmount=false
    D->>L: Fetch/update tokens, chains, dispensable assets
    L-->>D: Results
    D->>B: Update payingTokens, permittedChains,<br/>dispensableAssets, parent data
  end

  B->>B: Render error message (min amount prioritized)
  B->>B: Compute notEnough for BuyButton (min/liquidity/wallet)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • IAmKio
  • mightyboothkl

Poem

A nibble of coins, a hop to buy,
I sniff the breeze—0.5 is nigh.
Below that floor, I pause my cart,
Above, I bound with token heart.
Errors cleared, my whiskers twitch—
Liquidity checks? I’m quick!
Thump-thump—approve, then switch. 🐇💸

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly captures the two primary changes introduced by this pull request—the minimum amount warning and the fix to paying tokens—making it directly relevant and easily understandable at a glance. It avoids unnecessary detail and correctly reflects the main update without ambiguity.
Description Check ✅ Passed The description follows the repository template by providing a concise summary under Description, specifying testing approaches in How Has This Been Tested, including the optional Screenshots header, and marking the Types of changes checklist appropriately. All required sections are present and filled with relevant information, making the overall description complete and aligned with expectations.
✨ 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 fix/PRO-3743/PW-fix-Pulse

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.

@cloudflare-workers-and-pages
Copy link

Deploying x with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6083353
Status: ✅  Deploy successful!
Preview URL: https://d559780e.x-e62.pages.dev
Branch Preview URL: https://fix-pro-3743-pw-fix-pulse.x-e62.pages.dev

View logs

@RanaBug RanaBug merged commit 1931973 into staging Oct 3, 2025
5 of 6 checks passed
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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 67f8ded and 6083353.

📒 Files selected for processing (1)
  • src/apps/pulse/components/Buy/Buy.tsx (7 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 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/Buy/Buy.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: unit-tests
  • GitHub Check: lint
  • GitHub Check: build
🔇 Additional comments (5)
src/apps/pulse/components/Buy/Buy.tsx (5)

111-111: LGTM!

The state declaration is correct and follows React conventions.


158-160: LGTM!

Resetting all error flags on input change is appropriate to clear stale error states and is consistent with the existing pattern.


176-188: LGTM!

The minimum amount check (0.5 USD) is correctly implemented and short-circuits further liquidity checks when the amount is below the threshold, preventing unnecessary API calls.


575-586: LGTM!

The error rendering logic correctly prioritizes belowMinimumAmount and displays a clear, informative message ("Min. amount 0.5 USD").


696-700: LGTM!

The composite condition correctly disables the BuyButton when any of the three error conditions (belowMinimumAmount, notEnoughLiquidity, or insufficientWalletBalance) are true, ensuring consistent behavior with the error rendering logic.

Comment on lines +201 to +206
// Always update payingTokens to ensure correct USD amounts are passed to PreviewBuy
setDispensableAssets(dAssets);
setPermittedChains(pChains);
setPayingTokens(pTokens);
setParentDispensableAssets(dAssets);
setParentUsdAmount(usdAmount);
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

🧩 Analysis chain

Verify that input amount resets when tokens change.

The comment indicates this change ensures correct USD amounts are passed to PreviewBuy by always updating payingTokens. However, verify that the Buy component resets the input amount when tokens change, similar to the Sell component, to prevent stale state issues.

Based on learnings

Run the following script to verify if the Buy component resets the input amount when tokens change:


🏁 Script executed:

#!/bin/bash
# Description: Check if Buy component resets input amount when token changes.

# Search for token change handlers or effects that reset usdAmount
rg -n -A5 -B5 'setBuyToken|setToken' src/apps/pulse/components/Buy/Buy.tsx

# Search for effects that depend on token and reset usdAmount
ast-grep --pattern $'useEffect(() => {
  $$$
  setUsdAmount($$$)
  $$$
}, [$$$token$$$])'

Length of output: 1737


🏁 Script executed:

#!/bin/bash
# Search for any usage of setUsdAmount beyond its declaration
rg -n 'setUsdAmount' -C3 src/apps/pulse/components/Buy/Buy.tsx

# Locate useEffect blocks that reference setUsdAmount
rg -nP 'useEffect\s*\(' -C5 src/apps/pulse/components/Buy/Buy.tsx | rg -B5 -A5 'setUsdAmount'

Length of output: 1440


Reset usdAmount on token change
The Buy component doesn’t clear usdAmount when token updates, allowing stale USD values in PreviewBuy. Add a useEffect in src/apps/pulse/components/Buy/Buy.tsx to call setUsdAmount('') on token change.

🤖 Prompt for AI Agents
In src/apps/pulse/components/Buy/Buy.tsx around lines 201 to 206, usdAmount is
not cleared when the selected token changes which can leave stale USD values
shown in PreviewBuy; add a useEffect that listens to changes of the token
variable and calls setUsdAmount('') inside it (ensure you import useEffect if
not already) so usdAmount is reset whenever token updates.

This was referenced Oct 7, 2025
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