- 
                Notifications
    
You must be signed in to change notification settings  - Fork 50
 
Court features selection #2117
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
          
     Merged
      
      
    
  
     Merged
                    Court features selection #2117
Changes from 6 commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      baf9695
              
                feat: initial-features-implementation
              
              
                tractorss 83a21bd
              
                feat(web): dynamic-dispute-kit-feature-selection
              
              
                tractorss 0e3fb9c
              
                chore(web): rabbit-review
              
              
                tractorss f77b92f
              
                fix(web): incorrect-feature-selection
              
              
                tractorss e41329b
              
                feat: court features wording, sub-title styling
              
              
                jaybuidl 65f84cf
              
                feat: clear-choice-button
              
              
                tractorss 2842949
              
                Merge branch 'dev' into feat/court-features
              
              
                alcercu File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
          Some comments aren't visible on the classic Files Changed page.
        
There are no files selected for viewing
        
          
  
    
      
          
            33 changes: 33 additions & 0 deletions
          
          33 
        
  web/src/components/DisputeFeatures/Features/ClassicVote.tsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import React from "react"; | ||
| 
     | 
||
| import { Features } from "consts/disputeFeature"; | ||
| import { useNewDisputeContext } from "context/NewDisputeContext"; | ||
| 
     | 
||
| import { useCourtDetails } from "queries/useCourtDetails"; | ||
| 
     | 
||
| import WithHelpTooltip from "components/WithHelpTooltip"; | ||
| 
     | 
||
| import { RadioInput, StyledRadio } from "."; | ||
| 
     | 
||
| const ClassicVote: React.FC<RadioInput> = (props) => { | ||
| const { disputeData } = useNewDisputeContext(); | ||
| const { data: courtData } = useCourtDetails(disputeData.courtId); | ||
| const isCommitEnabled = Boolean(courtData?.court?.hiddenVotes); | ||
| return ( | ||
| <WithHelpTooltip | ||
| tooltipMsg={ | ||
| isCommitEnabled | ||
| ? `The jurors votes are hidden. | ||
| Nobody can see them before the voting period completes. | ||
| It takes place in a two-step commit-reveal process.` | ||
| : `The jurors votes are not hidden. | ||
| Everybody can see the justification and voted choice before the voting period completes.` | ||
| } | ||
| key={Features.ClassicVote} | ||
| > | ||
| <StyledRadio label={isCommitEnabled ? "Two-step commit-reveal" : "Disabled"} small {...props} /> | ||
| </WithHelpTooltip> | ||
| ); | ||
| }; | ||
| 
     | 
||
| export default ClassicVote; | ||
        
          
  
    
      
          
            122 changes: 122 additions & 0 deletions
          
          122 
        
  web/src/components/DisputeFeatures/Features/GatedErc1155.tsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import React, { Fragment, useEffect, useMemo } from "react"; | ||
| import styled from "styled-components"; | ||
| 
     | 
||
| import { Field } from "@kleros/ui-components-library"; | ||
| 
     | 
||
| import { Features } from "consts/disputeFeature"; | ||
| import { IGatedDisputeData, useNewDisputeContext } from "context/NewDisputeContext"; | ||
| import { useERC1155Validation } from "hooks/useTokenAddressValidation"; | ||
| 
     | 
||
| import { isUndefined } from "src/utils"; | ||
| 
     | 
||
| import WithHelpTooltip from "components/WithHelpTooltip"; | ||
| 
     | 
||
| import { RadioInput, StyledRadio } from "."; | ||
| 
     | 
||
| const FieldContainer = styled.div` | ||
| width: 100%; | ||
| padding-left: 32px; | ||
| `; | ||
| 
     | 
||
| const StyledField = styled(Field)` | ||
| width: 100%; | ||
| margin-top: 8px; | ||
| margin-bottom: 32px; | ||
| > small { | ||
| margin-top: 16px; | ||
| } | ||
| `; | ||
| 
     | 
||
| const GatedErc1155: React.FC<RadioInput> = (props) => { | ||
| const { disputeData, setDisputeData } = useNewDisputeContext(); | ||
| 
     | 
||
| const tokenGateAddress = (disputeData.disputeKitData as IGatedDisputeData)?.tokenGate ?? ""; | ||
| const validationEnabled = !isUndefined(tokenGateAddress) && tokenGateAddress.trim() !== ""; | ||
| 
     | 
||
| const { | ||
| isValidating, | ||
| isValid, | ||
| error: validationError, | ||
| } = useERC1155Validation({ | ||
| address: tokenGateAddress, | ||
| enabled: validationEnabled && props.checked, | ||
| }); | ||
| 
     | 
||
| const [validationMessage, variant] = useMemo(() => { | ||
| if (isValidating) return [`Validating ERC-1155 token...`, "info"]; | ||
| else if (validationError) return [validationError, "error"]; | ||
| else if (isValid === true) return [`Valid ERC-1155 token`, "success"]; | ||
| else return [undefined, "info"]; | ||
| }, [isValidating, validationError, isValid]); | ||
| 
     | 
||
| // Update validation state in dispute context | ||
| useEffect(() => { | ||
| // this can clash with erc20 check | ||
| if (!props.checked) return; | ||
| // Only update if isValid has actually changed | ||
| if (disputeData.disputeKitData) { | ||
| const currentData = disputeData.disputeKitData as IGatedDisputeData; | ||
| 
     | 
||
| if (currentData.isTokenGateValid !== isValid) { | ||
| setDisputeData({ | ||
| ...disputeData, | ||
| disputeKitData: { ...currentData, isTokenGateValid: isValid }, | ||
| }); | ||
| } | ||
| } | ||
| }, [isValid, setDisputeData, props.checked]); | ||
                
      
                  tractorss marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| const handleTokenAddressChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
| const currentData = disputeData.disputeKitData as IGatedDisputeData; | ||
| 
     | 
||
| setDisputeData({ | ||
| ...disputeData, | ||
| disputeKitData: { | ||
| ...currentData, | ||
| tokenGate: event.target.value, | ||
| isTokenGateValid: null, // Reset validation state when address changes | ||
| }, | ||
| }); | ||
| }; | ||
| 
     | 
||
| const handleTokenIdChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
| const currentData = disputeData.disputeKitData as IGatedDisputeData; | ||
| // DEV: we only update the tokenGate value here, and the disputeKidID, | ||
| // and type are still handled in Resolver/Court/FeatureSelection.tsx | ||
| setDisputeData({ | ||
| ...disputeData, | ||
| disputeKitData: { ...currentData, tokenId: event.target.value }, | ||
| }); | ||
| }; | ||
| 
     | 
||
| return ( | ||
| <Fragment key={Features.GatedErc1155}> | ||
| <WithHelpTooltip | ||
| tooltipMsg="Only the jurors who possess the specified token or NFT | ||
| can be selected as jurors for this case. Please input the token details below." | ||
| > | ||
| <StyledRadio label="Jurors owning at least 1 token ERC-1155" small {...props} /> | ||
| </WithHelpTooltip> | ||
| {props.checked ? ( | ||
| <FieldContainer> | ||
| <StyledField | ||
| dir="auto" | ||
| onChange={handleTokenAddressChange} | ||
| value={tokenGateAddress} | ||
| placeholder="Eg. 0xda10009cbd5d07dd0cecc66161fc93d7c9000da1" | ||
| variant={variant} | ||
| message={validationMessage} | ||
| /> | ||
| <StyledField | ||
| dir="auto" | ||
| onChange={handleTokenIdChange} | ||
| value={(disputeData.disputeKitData as IGatedDisputeData)?.tokenId ?? "0"} | ||
| placeholder="Eg. 1" | ||
| /> | ||
| </FieldContainer> | ||
| ) : null} | ||
| </Fragment> | ||
| ); | ||
| }; | ||
| 
     | 
||
| export default GatedErc1155; | ||
        
          
  
    
      
          
            106 changes: 106 additions & 0 deletions
          
          106 
        
  web/src/components/DisputeFeatures/Features/GatedErc20.tsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import React, { Fragment, useEffect, useMemo } from "react"; | ||
| import styled from "styled-components"; | ||
| 
     | 
||
| import { Field } from "@kleros/ui-components-library"; | ||
| 
     | 
||
| import { Features } from "consts/disputeFeature"; | ||
| import { IGatedDisputeData, useNewDisputeContext } from "context/NewDisputeContext"; | ||
| import { useERC20ERC721Validation } from "hooks/useTokenAddressValidation"; | ||
| 
     | 
||
| import { isUndefined } from "src/utils"; | ||
| 
     | 
||
| import WithHelpTooltip from "components/WithHelpTooltip"; | ||
| 
     | 
||
| import { RadioInput, StyledRadio } from "."; | ||
| 
     | 
||
| const FieldContainer = styled.div` | ||
| width: 100%; | ||
| padding-left: 32px; | ||
| `; | ||
| 
     | 
||
| const StyledField = styled(Field)` | ||
| width: 100%; | ||
| margin-top: 8px; | ||
| margin-bottom: 32px; | ||
| > small { | ||
| margin-top: 16px; | ||
| } | ||
| `; | ||
| 
     | 
||
| const GatedErc20: React.FC<RadioInput> = (props) => { | ||
| const { disputeData, setDisputeData } = useNewDisputeContext(); | ||
| 
     | 
||
| const tokenGateAddress = (disputeData.disputeKitData as IGatedDisputeData)?.tokenGate ?? ""; | ||
| const validationEnabled = !isUndefined(tokenGateAddress) && tokenGateAddress.trim() !== ""; | ||
| 
     | 
||
| const { | ||
| isValidating, | ||
| isValid, | ||
| error: validationError, | ||
| } = useERC20ERC721Validation({ | ||
| address: tokenGateAddress, | ||
| enabled: validationEnabled && props.checked, | ||
| }); | ||
| 
     | 
||
| const [validationMessage, variant] = useMemo(() => { | ||
| if (isValidating) return [`Validating ERC-20 or ERC-721 token...`, "info"]; | ||
| else if (validationError) return [validationError, "error"]; | ||
| else if (isValid === true) return [`Valid ERC-20 or ERC-721 token`, "success"]; | ||
| else return [undefined, "info"]; | ||
| }, [isValidating, validationError, isValid]); | ||
| 
     | 
||
| // Update validation state in dispute context | ||
| useEffect(() => { | ||
| // this can clash with erc1155 check | ||
| if (!props.checked) return; | ||
| if (disputeData.disputeKitData) { | ||
| const currentData = disputeData.disputeKitData as IGatedDisputeData; | ||
| 
     | 
||
| if (currentData.isTokenGateValid !== isValid) { | ||
| setDisputeData({ | ||
| ...disputeData, | ||
| disputeKitData: { ...currentData, isTokenGateValid: isValid }, | ||
| }); | ||
| } | ||
| } | ||
| }, [isValid, setDisputeData, props.checked]); | ||
                
      
                  tractorss marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| const handleTokenAddressChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
| const currentData = disputeData.disputeKitData as IGatedDisputeData; | ||
| // DEV: we only update the tokenGate value here, and the disputeKidID, | ||
| // and type are still handled in Resolver/Court/FeatureSelection.tsx | ||
| setDisputeData({ | ||
| ...disputeData, | ||
| disputeKitData: { | ||
| ...currentData, | ||
| tokenGate: event.target.value, | ||
| isTokenGateValid: null, // Reset validation state when address changes | ||
| }, | ||
| }); | ||
| }; | ||
| 
     | 
||
| return ( | ||
| <Fragment key={Features.GatedErc20}> | ||
| <WithHelpTooltip | ||
| tooltipMsg="Only the jurors who possess the specified token or NFT | ||
| can be selected as jurors for this case. Please input the token details below." | ||
| > | ||
| <StyledRadio label="Jurors owning at least 1 token ERC-20 or ERC-721" small {...props} /> | ||
| </WithHelpTooltip> | ||
| {props.checked ? ( | ||
| <FieldContainer> | ||
| <StyledField | ||
| dir="auto" | ||
| onChange={handleTokenAddressChange} | ||
| value={tokenGateAddress} | ||
| placeholder="Eg. 0xda10009cbd5d07dd0cecc66161fc93d7c9000da1" | ||
| variant={variant} | ||
| message={validationMessage} | ||
| /> | ||
| </FieldContainer> | ||
| ) : null} | ||
| </Fragment> | ||
| ); | ||
| }; | ||
| 
     | 
||
| export default GatedErc20; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import React from "react"; | ||
| import styled from "styled-components"; | ||
| 
     | 
||
| import { Radio } from "@kleros/ui-components-library"; | ||
| 
     | 
||
| import { Features } from "consts/disputeFeature"; | ||
| 
     | 
||
| import WithHelpTooltip from "components/WithHelpTooltip"; | ||
| 
     | 
||
| import ClassicVote from "./ClassicVote"; | ||
| import GatedErc1155 from "./GatedErc1155"; | ||
| import GatedErc20 from "./GatedErc20"; | ||
| 
     | 
||
| export type RadioInput = { | ||
| name: string; | ||
| value: Features; | ||
| checked: boolean; | ||
| disabled: boolean; | ||
| onClick: () => void; | ||
| }; | ||
| 
     | 
||
| export type FeatureUI = React.FC<RadioInput>; | ||
| 
     | 
||
| export const StyledRadio = styled(Radio)` | ||
| font-size: 14px; | ||
| color: ${({ theme, disabled }) => (disabled ? theme.secondaryText : theme.primaryText)}; | ||
| opacity: ${({ disabled }) => (disabled ? "0.7" : 1)}; | ||
| `; | ||
| 
     | 
||
| export const FeatureUIs: Record<Features, FeatureUI> = { | ||
| [Features.ShieldedVote]: (props: RadioInput) => ( | ||
| <WithHelpTooltip | ||
| tooltipMsg={`The jurors votes are hidden. | ||
| Nobody can see them before the voting period completes. | ||
| It takes place in a single step via Shutter Network`} | ||
| key={Features.ShieldedVote} | ||
| > | ||
| <StyledRadio label="Single-step via Shutter Network" small {...props} /> | ||
| </WithHelpTooltip> | ||
| ), | ||
| 
     | 
||
| [Features.ClassicVote]: (props: RadioInput) => <ClassicVote {...props} />, | ||
| 
     | 
||
| [Features.ClassicEligibility]: (props: RadioInput) => ( | ||
| <StyledRadio key={Features.ClassicEligibility} label="All the jurors in this court" small {...props} /> | ||
| ), | ||
| 
     | 
||
| [Features.GatedErc20]: (props: RadioInput) => <GatedErc20 {...props} />, | ||
| 
     | 
||
| [Features.GatedErc1155]: (props: RadioInput) => <GatedErc1155 {...props} />, | ||
| }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import React from "react"; | ||
| import styled from "styled-components"; | ||
| 
     | 
||
| import { Group } from "consts/disputeFeature"; | ||
| 
     | 
||
| import LightButton from "../LightButton"; | ||
| 
     | 
||
| const Container = styled.div` | ||
| width: 100%; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 16px; | ||
| align-items: start; | ||
| padding-bottom: 16px; | ||
| `; | ||
| 
     | 
||
| const HeaderContainer = styled.div` | ||
| width: 100%; | ||
| padding-top: 16px; | ||
| `; | ||
| 
     | 
||
| const Header = styled.h2` | ||
| display: flex; | ||
| font-size: 16px; | ||
| font-weight: 600; | ||
| margin: 0; | ||
| align-items: center; | ||
| gap: 8px; | ||
| `; | ||
| 
     | 
||
| const SubTitle = styled.p` | ||
| font-size: 14px; | ||
| color: ${({ theme }) => theme.secondaryText}; | ||
| padding: 0; | ||
| margin: 0; | ||
| `; | ||
| 
     | 
||
| const StyledLightButton = styled(LightButton)` | ||
| padding: 0 !important; | ||
| .button-text { | ||
| color: ${({ theme }) => theme.primaryBlue}; | ||
| font-size: 14px; | ||
| } | ||
| :hover { | ||
| background-color: transparent !important; | ||
| .button-text { | ||
| color: ${({ theme }) => theme.secondaryBlue}; | ||
| } | ||
| } | ||
| `; | ||
| 
     | 
||
| export type GroupUI = (props: { children: JSX.Element; clearAll: () => void }) => JSX.Element; | ||
| export const GroupsUI: Record<Group, GroupUI> = { | ||
| [Group.Voting]: ({ children, clearAll }) => ( | ||
| <Container key={Group.Voting}> | ||
| <HeaderContainer> | ||
| <Header> | ||
| Shielded Voting <StyledLightButton text="Clear" onClick={clearAll} /> | ||
| </Header> | ||
| <SubTitle>This feature hides the jurors votes until the end of the voting period.</SubTitle> | ||
| </HeaderContainer> | ||
| {children} | ||
| </Container> | ||
| ), | ||
| [Group.Eligibility]: ({ children, clearAll }) => ( | ||
| <Container key={Group.Eligibility}> | ||
| <HeaderContainer> | ||
| <Header> | ||
| Jurors Eligibility <StyledLightButton text="Clear" onClick={clearAll} /> | ||
| </Header> | ||
| <SubTitle>This feature determines who can be selected as a juror.</SubTitle> | ||
| </HeaderContainer> | ||
| {children} | ||
| </Container> | ||
| ), | ||
| }; | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.