-
Notifications
You must be signed in to change notification settings - Fork 50
fix(web): disable buttons if insufficient balance #1720
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
Conversation
WalkthroughThe changes introduce new components and modify existing ones to enhance error handling and user feedback in the application. A styled component Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
❌ Deploy Preview for kleros-v2-university failed. Why did it fail? →
|
✅ Deploy Preview for kleros-v2-testnet ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for kleros-v2-neo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for kleros-v2-testnet-devtools ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (4)
web/src/components/ErrorButtonMessage.tsx (1)
1-11: LGTM! Well-structured styled component.The
ErrorButtonMessagecomponent is well-implemented using styled-components. It provides a reusable, themed error message style that can be easily integrated into other components. The use of flexbox for layout and theme-based color is a good practice.Consider adding a
role="alert"attribute to improve accessibility for screen readers. This can be done by modifying the component definition:-export const ErrorButtonMessage = styled.div` +export const ErrorButtonMessage = styled.div.attrs({ role: 'alert' })`This change will ensure that assistive technologies properly announce the error message when it appears.
web/src/components/StyledIcons/ClosedCircleIcon.tsx (2)
1-3: LGTM! Consider using absolute imports for better maintainability.The imports are appropriate for the component's needs. However, consider using absolute imports for the SVG file to improve maintainability and reduce the risk of broken imports if the file structure changes.
You could update the SVG import to use an absolute path:
-import ClosedCircle from "svgs/icons/close-circle.svg"; +import ClosedCircle from "@/svgs/icons/close-circle.svg";This assumes you have configured absolute imports in your project. If not, you may need to set up path aliases in your TypeScript configuration.
11-14: LGTM! Consider adding prop support for enhanced flexibility.The
ClosedCircleIconcomponent is correctly defined and exported. It serves as a simple wrapper for the styled SVG, which is a common and clean pattern.To enhance the component's flexibility, consider allowing it to accept and pass through additional props:
-const ClosedCircleIcon: React.FC = () => { - return <StyledClosedCircle />; +const ClosedCircleIcon: React.FC<React.SVGProps<SVGSVGElement>> = (props) => { + return <StyledClosedCircle {...props} />; };This change would allow users of the component to pass additional SVG properties if needed, making the component more versatile.
web/src/pages/Resolver/NavigationButtons/SubmitDisputeButton.tsx (1)
70-99: Consider providing additional guidance for insufficient balance.To enhance user experience, consider displaying the required arbitration cost and the user's current balance. This additional information can help users understand how much more they need to proceed.
You could update the error message as follows:
{insufficientBalance && ( <ErrorButtonMessage> <ClosedCircleIcon /> Insufficient balance + <div> + Required: {disputeData.arbitrationCost} ETH + <br /> + Your Balance: {userBalance?.formatted} ETH + </div> </ErrorButtonMessage> )}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- web/src/components/ErrorButtonMessage.tsx (1 hunks)
- web/src/components/StyledIcons/ClosedCircleIcon.tsx (1 hunks)
- web/src/pages/Cases/CaseDetails/Appeal/Classic/Fund.tsx (5 hunks)
- web/src/pages/Resolver/NavigationButtons/SubmitDisputeButton.tsx (4 hunks)
🧰 Additional context used
🔇 Additional comments (14)
web/src/components/StyledIcons/ClosedCircleIcon.tsx (2)
5-9: LGTM! Well-structured styled component.The
StyledClosedCirclecomponent is well-defined:
- It correctly uses the theme for dynamic styling, promoting consistency.
- The component name follows the "Styled" prefix convention.
- Targeting the SVG's
pathelement for styling is appropriate.
1-14: Summary: Well-implemented icon component aligning with PR objectivesThe new
ClosedCircleIconcomponent is a well-structured addition that aligns perfectly with the PR's objective of enhancing error handling and user feedback. It provides a consistent way to display error-related icons, which can be used in conjunction with the disabled buttons for insufficient balance mentioned in the PR title.Key points:
- The component uses styled-components effectively for theming.
- It follows React best practices for functional components.
- The implementation is clean and maintainable.
The suggested improvements (absolute imports and prop forwarding) are minor and optional, aimed at enhancing flexibility and maintainability.
Great job on this addition to the UI components!
web/src/pages/Resolver/NavigationButtons/SubmitDisputeButton.tsx (8)
5-5: Imports are correctly added for new hooks and components.The addition of
useAccount,useBalance, andusePublicClientfrom "wagmi" is appropriate for retrieving account and balance information. Similarly, importingErrorButtonMessageandClosedCircleIconensures the error message components are available for use.
37-39: Balance retrieval handles user account correctly.Using
useAccountto get theaddressand thenuseBalanceto retrieve the user's balance is appropriate. This allows the component to access the user's balance information securely.
40-44: Logic for determining insufficient balance is sound.The
useMemohook correctly calculatesinsufficientBalanceby comparing the user's balance to the arbitration cost. This optimization ensures the computation is efficient and only recalculates when dependencies change.
48-48: Simulation is disabled when user has insufficient balance.Including
!insufficientBalancein theenabledcondition prevents unnecessary simulations when the user cannot afford the arbitration cost, optimizing performance.
62-63: Button disabled state appropriately includes balance checks.Updating
isButtonDisabledto considerisBalanceLoadingandinsufficientBalanceensures the button is only enabled when the user's balance is known and sufficient.
70-75: Button loading state reflects submission and balance loading status.The
isLoadingprop correctly uses(isSubmittingCase || isBalanceLoading) && !insufficientBalance, preventing the loading state when the user has insufficient balance.
94-99: Appropriate error message displayed for insufficient balance.Displaying the
ErrorButtonMessagewithClosedCircleIconwheninsufficientBalanceistrueprovides clear feedback to the user about their balance status.
70-99: Verify that the balance updates correctly upon changes.Ensure that the balance information reflects real-time data, especially after transactions that might change the user's balance. This is crucial for accurate validation.
You can run the following script to check if the balance updates as expected:
web/src/pages/Cases/CaseDetails/Appeal/Classic/Fund.tsx (4)
18-19: Imports are correctly addedThe imports for
ErrorButtonMessageandClosedCircleIconare appropriately added and necessary for the new functionality.
108-110: Ensure consistent types when comparing valuesVerify that
balance.valueandparsedAmountare of the same type (bothBigInt) to ensure the comparisonbalance.value < parsedAmountworks correctly without unexpected errors.
134-134: Confirm the loading state logic when balance is insufficientIn the
isLoadingproperty of theStyledButton, the loading state is set tofalsewheninsufficientBalanceistrue:isLoading={(isSending || isLoading) && !insufficientBalance}Please verify if this behavior aligns with the desired user experience. If the loading state should not depend on
insufficientBalance, consider adjusting the condition.
140-141: Ensure correct handling of the transaction responseVerify that accessing
res.statusaccurately determines the success of the transaction. Depending on the structure of the response fromwrapWithToast,resmay not have astatusproperty. Ensure that you are checking the correct property before callingsetIsOpen(true).
kemuru
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
0dc7b17
|
Code Climate has analyzed commit 0dc7b17 and detected 3 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
|
There was a problem hiding this 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 and nitpick comments (3)
web/src/pages/Courts/StakeMaintenanceButton/index.tsx (1)
50-53: Approved with a minor optimization suggestion.The new
useEffecthook successfully implements the ability to open the maintenance buttons by default when the URL contains the "#maintenance" hash. This enhances the component's functionality and improves user experience.Consider optimizing this implementation by using the
useStateinitializer function instead ofuseEffect. This approach is more efficient for setting initial state based on props or global values. Here's how you can refactor it:-const [isOpen, setIsOpen] = useState(false); +const [isOpen, setIsOpen] = useState(() => location.hash.includes("#maintenance")); -useEffect(() => { - const openDefault = location.hash.includes("#maintenance"); - if (openDefault) setIsOpen(true); -}, []);This change eliminates the need for an additional effect and ensures the initial state is set correctly from the start.
web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (2)
26-26: Consider adding styles toStyledLabelor remove if unused.The
StyledLabelcomponent is created but doesn't have any styles defined. If specific styles are intended, please add them. If no custom styling is needed, consider using a regularlabelelement instead.
78-88: LGTM with a suggestion: Consider parameterizing the link destination.The conditional rendering of the
StyledLabelwith informative text and a link is a good addition. It provides clear guidance to users when the phase needs to be changed.However, the link destination "/courts/1/purpose/#maintenance" is hardcoded. Consider parameterizing this to make it flexible for different court IDs:
<Link to={`/courts/${courtId}/purpose/#maintenance`}>here</Link>This assumes
courtIdis available in the component's props or context. If not, you may need to add it.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (3 hunks)
- web/src/pages/Courts/StakeMaintenanceButton/index.tsx (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx (3)
20-20: LGTM: New import for navigation.The addition of the
Linkimport from 'react-router-dom' is appropriate for the new navigation functionality introduced in the component.
45-48: LGTM: Well-implemented memoized variable.The
needToPassPhasevariable is correctly implemented usinguseMemo. It efficiently determines if the current state requires a phase transition for juror drawing. The dependencies are properly specified, ensuring the value is recalculated when necessary.
Line range hint
1-88: Overall assessment: Well-implemented changes with minor suggestions.The modifications to the
DrawButtoncomponent effectively enhance its functionality and user experience. The addition of conditional rendering to guide users when a phase change is needed is particularly valuable. The code is well-structured and follows React best practices.Consider the following minor improvements:
- Add styles to the
StyledLabelcomponent or use a regularlabelif no custom styling is needed.- Parameterize the hardcoded link in the conditional rendering to make it more flexible for different court IDs.
These changes significantly improve the component's usability and provide clear guidance to users.
alcercu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm



PR-Codex overview
This PR introduces new styled components for error messages and modifies various buttons to display warnings for insufficient balance. It enhances user feedback in different components by integrating the
ErrorButtonMessageandClosedCircleIcon.Detailed summary
ErrorButtonMessagestyled component inErrorButtonMessage.tsx.ClosedCircleIconcomponent inClosedCircleIcon.tsx.SubmitDisputeButton.DrawButtonto show a message if conditions are not met.Fundcomponent with balance checks and error messages.Summary by CodeRabbit
New Features
ErrorButtonMessagecomponent for displaying error messages.ClosedCircleIconfor enhanced visual feedback on error states.Fundcomponent to conditionally render error messages based on user balance.SubmitDisputeButtonto display a message when the user's balance is insufficient for dispute submission.StyledLabelinDrawButtonfor improved user guidance during the drawing phase.StakeMaintenanceButtonsto open maintenance buttons based on the URL hash.Bug Fixes