Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): stake-input-error-display #1797

Merged
merged 2 commits into from
Dec 17, 2024
Merged

fix(web): stake-input-error-display #1797

merged 2 commits into from
Dec 17, 2024

Conversation

Harman-singh-waraich
Copy link
Contributor

@Harman-singh-waraich Harman-singh-waraich commented Dec 17, 2024

PR-Codex overview

This PR focuses on enhancing the StakeWithdrawPopup and related components by introducing loading states and managing popup visibility. It improves user experience by controlling error messages and popup states during staking and withdrawal actions.

Detailed summary

  • Added isLoading state to StakeWithdrawPopup.
  • Updated condition to display info based on isLoading.
  • Introduced isPopupOpen state in InputDisplay.
  • Modified error message handling in InputDisplay based on isPopupOpen.
  • Updated StakeWithdrawButton to accept isPopupOpen and setIsPopupOpen props.
  • Removed local isPopupOpen state from StakeWithdrawButton.
  • Cleared error message on closing the popup.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Enhanced error handling and user interaction in the input display with the addition of a popup for better visibility.
    • Updated stake withdrawal button to manage popup visibility externally.
  • Bug Fixes

    • Improved conditional rendering in the withdrawal popup to prevent messages during loading states.
  • Documentation

    • Updated interface definitions to reflect new properties for better integration with the popup functionality.

Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ast-grep (0.31.1)
web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx

An unexpected error occurred while running ast-grep.

Walkthrough

The pull request introduces state management improvements for the stake and withdraw functionality in the Courts module. Changes are focused on the InputDisplay, StakeWithdrawButton, and StakeWithdrawPopup components, primarily enhancing popup visibility control and error handling. The modifications involve adding a new isPopupOpen state, updating component interfaces, and refining the logic for displaying error messages and loading states.

Changes

File Change Summary
web/src/pages/Courts/.../InputDisplay.tsx - Added isPopupOpen state variable
- Updated StyledField component's message and variant props
- Modified StakeWithdrawButton props to include popup state management
web/src/pages/Courts/.../StakeWithdrawButton.tsx - Updated IActionButton interface to make setErrorMsg optional
- Added isPopupOpen and setIsPopupOpen props
- Refactored popup state management
web/src/pages/Courts/.../StakeWithdrawPopup/index.tsx - Integrated isLoading state from useSortitionModulePhase
- Updated conditional rendering for informational message

Possibly related PRs

  • Refactor/stake abort controller #1783: The changes in StakeWithdrawButton.tsx regarding the management of the popup state and the introduction of the AbortController are directly related to the modifications made in the main PR, which also updates the StakeWithdrawButton to accept isPopupOpen and setIsPopupOpen props.
  • fix(web): fix-overlay-scroll-lock #1788: The integration of the useLockOverlayScroll hook in StakeWithdrawButton.tsx to manage scroll behavior when the popup is open is relevant to the changes in the main PR, which also involves the popup state management in the same component.

Suggested reviewers

  • kemuru

Poem

🐰 A Rabbit's Ode to Popup State

In Courts of code, a state takes flight,
isPopupOpen shines so bright.
Buttons dance, errors hide with grace,
A popup's journey, a digital embrace! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b72384 and 24a9c9c.

📒 Files selected for processing (1)
  • web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for kleros-v2-testnet failed. Why did it fail? →

Name Link
🔨 Latest commit 24a9c9c
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/676181f79d716f0008714d3e

Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit 24a9c9c
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/676181f789a69300087dd29a
😎 Deploy Preview https://deploy-preview-1797--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit 24a9c9c
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/676181f752e5840008bce2cc
😎 Deploy Preview https://deploy-preview-1797--kleros-v2-university.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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: 0

🔭 Outside diff range comments (1)
web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx (1)

Line range hint 249-260: Add cleanup to prevent stale error messages.

The useEffect hook should clean up error messages when unmounting to prevent stale states.

   useEffect(() => {
     if (isPopupOpen) return;
     if (
       action === ActionType.stake &&
       targetStake !== 0n &&
       courtDetails &&
       targetStake < BigInt(courtDetails.court?.minStake)
     ) {
       setErrorMsg(`Min Stake in court is: ${formatETH(courtDetails?.court?.minStake)}`);
     } else if (setStakeError || allowanceError) {
       setErrorMsg(parseWagmiError(setStakeError || allowanceError));
     }
+    return () => setErrorMsg(undefined);
   }, [setStakeError, setErrorMsg, targetStake, courtDetails, allowanceError, isPopupOpen, action]);
🧹 Nitpick comments (4)
web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawPopup/index.tsx (1)

Line range hint 124-130: Consider simplifying the conditional rendering.

The condition can be more concise while maintaining the same logic.

-          {phase !== Phases.staking && !isLoading ? (
+          {!isLoading && phase !== Phases.staking && (
             <InfoContainer>
               <Divider />
               <StyledInfoCard
                 msg={`The ${action === ActionType.stake ? "stake" : "withdraw"} might be delayed by ~1 hr.`}
               />
             </InfoContainer>
-          ) : null}
+          )}
web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx (1)

110-111: Consider consolidating error message logic.

The error message and variant logic could be simplified using a single derived value.

+          const fieldError = !isPopupOpen && errorMsg ? errorMsg : undefined;
           <StyledField
             value={uncommify(amount)}
             onChange={(e) => {
               setAmount(e);
             }}
             placeholder={isStaking ? "Amount to stake" : "Amount to withdraw"}
-            message={isPopupOpen ? undefined : (errorMsg ?? undefined)}
-            variant={!isUndefined(errorMsg) && !isPopupOpen ? "error" : "info"}
+            message={fieldError}
+            variant={fieldError ? "error" : "info"}
             formatter={(number: string) => (number !== "" ? commify(roundNumberDown(Number(number))) : "")}
           />
web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx (2)

Line range hint 281-289: Consider using try-finally for cleanup in closePopup.

The cleanup operations should run even if there's an error in any of the state updates.

   const closePopup = () => {
-    setErrorMsg(undefined);
-    setIsPopupOpen(false);
-    setIsSuccess(false);
-    setAmount("");
-    setPopupStepsState(undefined);
-    if (controllerRef.current) {
-      controllerRef.current.abort();
-    }
+    try {
+      setErrorMsg(undefined);
+      setIsPopupOpen(false);
+      setIsSuccess(false);
+      setAmount("");
+      setPopupStepsState(undefined);
+    } finally {
+      if (controllerRef.current) {
+        controllerRef.current.abort();
+      }
+    }
   };

54-62: Props destructuring could be more concise.

Consider using object destructuring in a single line for better readability.

-const StakeWithdrawButton: React.FC<IActionButton> = ({
-  amount,
-  parsedAmount,
-  action,
-  setErrorMsg,
-  setAmount,
-  isPopupOpen,
-  setIsPopupOpen,
-}) => {
+const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, action, setErrorMsg, setAmount, isPopupOpen, setIsPopupOpen }) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 906dd58 and 2b72384.

📒 Files selected for processing (3)
  • web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx (4 hunks)
  • web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx (3 hunks)
  • web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawPopup/index.tsx (2 hunks)

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 17, 2024
Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for kleros-v2-testnet-devtools failed. Why did it fail? →

Name Link
🔨 Latest commit 24a9c9c
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/676181f7c0b47f00081c6dc6

@kemuru kemuru self-requested a review December 17, 2024 09:35
kemuru
kemuru previously approved these changes Dec 17, 2024
alcercu
alcercu previously approved these changes Dec 17, 2024
Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

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

lgtm

@alcercu alcercu dismissed stale reviews from kemuru, coderabbitai[bot], and themself via 24a9c9c December 17, 2024 13:51
Copy link

codeclimate bot commented Dec 17, 2024

Code Climate has analyzed commit 24a9c9c and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 2

View more on Code Climate.

@alcercu alcercu added this pull request to the merge queue Dec 17, 2024
Merged via the queue into dev with commit 20ac82c Dec 17, 2024
20 of 29 checks passed
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