Min amount warning and paying tokens fix#421
Conversation
WalkthroughAdds 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
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Deploying x with
|
| 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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
belowMinimumAmountand 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, orinsufficientWalletBalance) are true, ensuring consistent behavior with the error rendering logic.
| // Always update payingTokens to ensure correct USD amounts are passed to PreviewBuy | ||
| setDispensableAssets(dAssets); | ||
| setPermittedChains(pChains); | ||
| setPayingTokens(pTokens); | ||
| setParentDispensableAssets(dAssets); | ||
| setParentUsdAmount(usdAmount); |
There was a problem hiding this comment.
🧩 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.
Description
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Summary by CodeRabbit
New Features
Bug Fixes