Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

limichange
Copy link
Contributor

@limichange limichange commented Oct 22, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved action button behavior to provide visual feedback when clicked without an amount entered, preventing premature navigation.
  • Style

    • Enhanced button styling for better visual clarity and token symbol display.

@limichange limichange enabled auto-merge (squash) October 22, 2025 04:05
@revan-zhang
Copy link
Contributor

revan-zhang commented Oct 22, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 22, 2025

Walkthrough

Updates ActionButton component to display colored styling and token symbol before user input. Introduces hasClickedWithoutAmount state to track initial clicks without an amount. Button stays enabled on first click, providing visual feedback. Adjusts styling props and gates address-creation flow accordingly.

Changes

Cohort / File(s) Summary
Button State Management and Styling
packages/kit/src/views/Market/MarketDetailV2/components/SwapPanel/components/ActionButton.tsx
Adds hasClickedWithoutAmount state to track clicks without amount input. Introduces isButtonDisabled calculation to keep button enabled on first click. Updates conditional styling to apply colored appearance and show token symbol before input. Modifies address-creation flow gating to use new state. Replaces borderWidth with borderColor in styled props. Updates dependency array for press handler.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
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.
Linked Issues Check ❓ Inconclusive The changes clearly address OK-44732 by introducing colored styling adjustments when no amount is entered, including the shouldUseColoredStyle calculation and buttonStyleProps application. However, the linked issue OK-44649 regarding button size inconsistency shows no clear evidence of being addressed in the provided summary. The changes focus on styling and interaction behavior but do not explicitly mention size-related fixes that would resolve the button size inconsistency issue.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Feat/market swap button interaction OK-44732 OK-44649" clearly identifies the modified component and its purpose. The title accurately describes that this change addresses button interaction behavior in the market swap context, which aligns with the actual modifications to the ActionButton component in SwapPanel. The title is concise and includes issue references, making it easy to trace back to the corresponding work items.
Out of Scope Changes Check ✅ Passed All changes are contained within a single file (ActionButton.tsx in SwapPanel) and focus on button state management, styling adjustments, and interaction behavior. The modifications directly relate to the button's visual presentation before user input and its interaction patterns, aligning with the stated objectives in the linked issues.
✨ 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 feat/market-swap-button-interaction

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 38576c6 and 62eefb0.

📒 Files selected for processing (1)
  • packages/kit/src/views/Market/MarketDetailV2/components/SwapPanel/components/ActionButton.tsx (4 hunks)
⏰ 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). (4)
  • GitHub Check: lint (20.x)
  • GitHub Check: unittest (20.x)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (java-kotlin)
🔇 Additional comments (5)
packages/kit/src/views/Market/MarketDetailV2/components/SwapPanel/components/ActionButton.tsx (5)

52-52: State never resets—verify this matches UX intent.

Once hasClickedWithoutAmount is true, it stays true for the component's lifetime. If the user clicks without an amount, then enters and later deletes the amount, the button won't revert to showing "Buy TOKEN" in colored style. Confirm this is the intended behavior.


217-220: LGTM—border color matches button background.

Setting borderColor to match the button's background color creates clean visual consistency for the colored button states.


236-240: Early return prevents action until amount is entered.

The handler sets state on every press, then returns early if there's no amount. First click without amount provides only visual feedback (button text/style change). This is likely intentional, but ensure users understand they need to enter an amount first.


279-291: Dependency array correctly updated.

The new dependencies (hasAmount, shouldCreateAddress?.result, networkId) are all used within the callback and properly included.


297-297: LGTM—uses computed disabled state.

Correctly applies the computed isButtonDisabled value that accounts for all button state conditions.

Comment on lines +195 to +208
let shouldUseColoredStyle =
hasAmount && !shouldDisable && !noAccount && !disabled;

let isButtonDisabled = Boolean(
(shouldDisable || disabled || !hasAmount) &&
!shouldCreateAddress?.result &&
!noAccount,
);

if (!hasAmount && !hasClickedWithoutAmount) {
shouldUseColoredStyle = true;
buttonText = `${actionText} ${tokenDetail?.symbol || ''}`.trim();
isButtonDisabled = false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider refactoring complex button state logic for clarity.

The button state calculation mutates shouldUseColoredStyle, buttonText, and isButtonDisabled across multiple conditions. This works but is hard to trace. Consider extracting this into a useMemo that returns an object with all button properties, or add inline comments explaining the first-click UX flow.

Example refactor:

-let shouldUseColoredStyle =
-  hasAmount && !shouldDisable && !noAccount && !disabled;
-
-let isButtonDisabled = Boolean(
-  (shouldDisable || disabled || !hasAmount) &&
-    !shouldCreateAddress?.result &&
-    !noAccount,
-);
-
-if (!hasAmount && !hasClickedWithoutAmount) {
-  shouldUseColoredStyle = true;
-  buttonText = `${actionText} ${tokenDetail?.symbol || ''}`.trim();
-  isButtonDisabled = false;
-}
+// Special case: show colored "Buy TOKEN" button before first click
+const isFirstClickWithoutAmount = !hasAmount && !hasClickedWithoutAmount;
+
+const shouldUseColoredStyle = isFirstClickWithoutAmount
+  ? true
+  : hasAmount && !shouldDisable && !noAccount && !disabled;
+
+const isButtonDisabled = isFirstClickWithoutAmount
+  ? false
+  : Boolean(
+      (shouldDisable || disabled || !hasAmount) &&
+        !shouldCreateAddress?.result &&
+        !noAccount,
+    );
+
+if (isFirstClickWithoutAmount) {
+  buttonText = `${actionText} ${tokenDetail?.symbol || ''}`.trim();
+}
📝 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
let shouldUseColoredStyle =
hasAmount && !shouldDisable && !noAccount && !disabled;
let isButtonDisabled = Boolean(
(shouldDisable || disabled || !hasAmount) &&
!shouldCreateAddress?.result &&
!noAccount,
);
if (!hasAmount && !hasClickedWithoutAmount) {
shouldUseColoredStyle = true;
buttonText = `${actionText} ${tokenDetail?.symbol || ''}`.trim();
isButtonDisabled = false;
}
// Special case: show colored "Buy TOKEN" button before first click
const isFirstClickWithoutAmount = !hasAmount && !hasClickedWithoutAmount;
const shouldUseColoredStyle = isFirstClickWithoutAmount
? true
: hasAmount && !shouldDisable && !noAccount && !disabled;
const isButtonDisabled = isFirstClickWithoutAmount
? false
: Boolean(
(shouldDisable || disabled || !hasAmount) &&
!shouldCreateAddress?.result &&
!noAccount,
);
if (isFirstClickWithoutAmount) {
buttonText = `${actionText} ${tokenDetail?.symbol || ''}`.trim();
}

!noAccount,
)}
disabled={isButtonDisabled}
onPress={shouldDisable ? undefined : handlePress}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Remove redundant onPress condition.

When shouldDisable is true, isButtonDisabled is also true (line 199), so the button is already disabled and won't fire press events. Simplify to onPress={handlePress}.

-onPress={shouldDisable ? undefined : handlePress}
+onPress={handlePress}
📝 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
onPress={shouldDisable ? undefined : handlePress}
onPress={handlePress}
🤖 Prompt for AI Agents
In
packages/kit/src/views/Market/MarketDetailV2/components/SwapPanel/components/ActionButton.tsx
around line 298, the onPress prop is conditionally set to undefined when
shouldDisable is true even though isButtonDisabled already prevents presses;
remove the redundant conditional and set onPress to handlePress unconditionally
(onPress={handlePress}) so the prop is always passed while button disabled state
continues to block activation.

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.

3 participants