Skip to content

Refactor/evidence refactors #1634

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 8 commits into from
Jul 19, 2024
Merged

Refactor/evidence refactors #1634

merged 8 commits into from
Jul 19, 2024

Conversation

tractorss
Copy link
Contributor

@tractorss tractorss commented Jun 28, 2024

⚠️ Will need contract redeploys, natspec has been updated for EvidenceModule.

  • Older frontends will not crash, but newer frontends will not display the evidences uploaded before this change.

more info and context : https://hackmd.io/@-cmxt73kRVi2uFMhhabm4A/BkGylT58R

To be done :-

  • Redeploy contracts, natspecs have been updated. We should redeploy since we were alrd discussing about doing this for devnet.
  • Updated subgraphs with the new contracts

PR-Codex overview

This PR updates the Kleros v2 subgraph, adds full-text search feature, improves evidence submission handling, and enhances UI components.

Detailed summary

  • Added fullTextSearch feature to subgraphs
  • Updated subgraph version to 0.7.0
  • Modified evidence submission parameters
  • Added new fields to evidence schema
  • Updated SVG icon
  • Implemented JSONValueToMaybeString function
  • Updated EvidenceSearch component
  • Updated useEvidences query hook
  • Updated EvidenceDetails fragment
  • Updated EvidenceCard component

The following files were skipped due to too many changes: web/src/components/EvidenceCard.tsx, web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx, subgraph/core/src/EvidenceModule.ts, web/src/pages/Cases/CaseDetails/Evidence/index.tsx

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

Summary by CodeRabbit

  • New Features

    • Introduced full-text search functionality for evidence.
    • Added detailed evidence fields (name, description, fileURI, fileTypeExtension) to evidence handling.
    • Implemented a new EvidenceSearch component for enhanced evidence search and submission.
  • Refactor

    • Updated evidence submission to use a stringified evidence object instead of an IPFS path.
    • Refactored EvidenceCard and related components to utilize new evidence fields.
  • Chores

    • Increased the version of @kleros/kleros-v2-subgraph from 0.5.1 to 0.7.0.

Copy link
Contributor

coderabbitai bot commented Jun 28, 2024

Walkthrough

The changes across various modules and files center around updating the way evidence is handled in the arbitration system. Instead of using IPFS paths, the system now expects a stringified JSON object containing fields like "name", "description", and "fileURI". Additionally, full-text search capabilities have been introduced, and several components were refactored to support these updates.

Changes

File Path Summary of Changes
contracts/src/arbitration/.../EvidenceModule.sol Changed submitEvidence to accept a stringified evidence object instead of an IPFS path.
contracts/src/arbitration/.../ModeratedEvidenceModule.sol Updated event and function parameter descriptions to use a stringified evidence object format.
contracts/src/arbitration/.../IEvidence.sol Modified Evidence event parameter to accept a stringified evidence object.
subgraph/core/schema.graphql Added fields like name, description, fileURI, fileTypeExtension to Evidence and ClassicEvidence types.
subgraph/core-neo/subgraph.yaml, subgraph/core-university/subgraph.yaml, subgraph/core/subgraph.yaml Introduced fullTextSearch feature and added KlerosCore data source for Ethereum.
subgraph/core/src/EvidenceModule.ts Enhanced handleEvidenceEvent to parse and extract fields from stringified evidence objects, with added error handling.
subgraph/package.json Updated project version from 0.5.1 to 0.7.0.
web/src/components/EvidenceCard.tsx Refactored EvidenceCard component to use new props for rendering evidence, removing reliance on useIPFSQuery.
web/src/hooks/queries/useEvidences.ts Updated evidencesQuery to include new evidence fields and specified type parameter for useQuery.
web/src/pages/Cases/CaseDetails/.../SubmitEvidenceModal.tsx Refactored submitEvidence function to handle evidence submission more efficiently and improved error handling.
web/src/pages/Cases/CaseDetails/.../index.tsx Refactored evidence display logic, added scroll-to-latest feature, and replaced several hooks and components.
web/src/pages/Cases/CaseDetails/.../EvidenceSearch.tsx Introduced EvidenceSearch component for searching evidence with dynamic filtering and blockchain connectivity checks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant SmartContract
    participant IPFS

    User->>Frontend: SubmitEvidence (name, description, fileURI)
    Frontend->>IPFS: Upload file
    IPFS-->>Frontend: fileURI
    Frontend->>SmartContract: submitEvidence(externalDisputeID, evidenceJSON)
    SmartContract->>Frontend: Emit Evidence Event
    Frontend->>Frontend: handleEvidenceEvent
    Frontend->>Database: Save Evidence (parsed JSON)
Loading

Poem

A change in code, so swift and bright,
Evidence now in JSON light.
Fields of name, and description too,
Full-text search to find what's true.
A bunny hops with joy, delight,
For updates come and bugs take flight.
🌟🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@tractorss tractorss requested review from kemuru and alcercu June 28, 2024 12:25
Copy link

netlify bot commented Jun 28, 2024

Deploy Preview for kleros-v2 ready!

Name Link
🔨 Latest commit d1b6fe2
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2/deploys/66992be2b15ba90008e05caa
😎 Deploy Preview https://deploy-preview-1634--kleros-v2.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 Jun 28, 2024

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit d1b6fe2
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/66992be2bd7df80008b18163
😎 Deploy Preview https://deploy-preview-1634--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 Jun 28, 2024

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit d1b6fe2
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/66992be2e03865000889387a
😎 Deploy Preview https://deploy-preview-1634--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: 2

Outside diff range and nitpick comments (1)
web/src/components/EvidenceCard.tsx (1)

Line range hint 140-166: Optimize rendering and add error handling for file links.

The EvidenceCard component can be optimized to prevent unnecessary re-renders and should handle potential errors or edge cases, such as missing or malformed fileURI.

- {fileURI && (
-   <StyledLink to={`attachment/?url=${getIpfsUrl(fileURI)}`}>
-     <AttachmentIcon />
-     <AttachedFileText />
-   </StyledLink>
- )}

+ {fileURI ? (
+   <StyledLink to={`attachment/?url=${getIpfsUrl(fileURI)}`}>
+     <AttachmentIcon />
+     <AttachedFileText />
+   </StyledLink>
+ ) : (
+   <p>No file attached</p>
+ )}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9ea71a5 and 7cf0b1e.

Files selected for processing (11)
  • contracts/src/arbitration/evidence/EvidenceModule.sol (1 hunks)
  • contracts/src/arbitration/evidence/ModeratedEvidenceModule.sol (2 hunks)
  • contracts/src/arbitration/interfaces/IEvidence.sol (1 hunks)
  • subgraph/core/schema.graphql (2 hunks)
  • subgraph/core/src/EvidenceModule.ts (1 hunks)
  • subgraph/package.json (1 hunks)
  • subgraph/utils/index.ts (1 hunks)
  • web/src/components/EvidenceCard.tsx (3 hunks)
  • web/src/hooks/queries/useEvidences.ts (2 hunks)
  • web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx (2 hunks)
  • web/src/pages/Cases/CaseDetails/Evidence/index.tsx (1 hunks)
Files not reviewed due to errors (2)
  • subgraph/core/schema.graphql (no review received)
  • contracts/src/arbitration/evidence/ModeratedEvidenceModule.sol (no review received)
Files skipped from review due to trivial changes (1)
  • subgraph/package.json
Additional comments not posted (6)
contracts/src/arbitration/interfaces/IEvidence.sol (1)

10-10: Updated event parameter to handle structured data.

The change from an IPFS path to a JSON string for _evidence is a significant improvement as it allows for richer data handling. However, it would be beneficial to update the natspec comments further to explain the expected structure of the JSON object in more detail.

subgraph/utils/index.ts (1)

3-26: Robust handling of JSON values to strings.

The introduction of JSONValueToMaybeString improves security by addressing potential vulnerabilities where crafted JSON objects could bypass UI checks. This is a crucial update for maintaining data integrity in the subgraph.

web/src/hooks/queries/useEvidences.ts (1)

18-21: Enhanced GraphQL query to include new evidence fields.

The inclusion of name, description, fileURI, and fileTypeExtension in the GraphQL query allows for richer data to be fetched and displayed, enhancing the user experience significantly.

web/src/pages/Cases/CaseDetails/Evidence/index.tsx (1)

65-71: UI Enhancement to display additional evidence properties.

Passing new properties like name, description, and fileURI to the EvidenceCard component improves the display and accessibility of evidence details, enhancing user interaction.

subgraph/core/src/EvidenceModule.ts (1)

24-59: Robust parsing and handling of JSON structured evidence.

The update to parse and handle JSON structured evidence effectively addresses potential data integrity issues. Consider enhancing the error messages to include more details about the failure, which would aid in debugging and maintenance.

contracts/src/arbitration/evidence/EvidenceModule.sol (1)

67-67: Ensure JSON string is properly formatted and escaped.

The function now accepts a JSON string for evidence. It's crucial to ensure that the input is properly formatted and escaped to prevent injection attacks or parsing errors.

@tractorss tractorss mentioned this pull request Jul 2, 2024
alcercu
alcercu previously approved these changes Jul 5, 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

kemuru
kemuru previously approved these changes Jul 5, 2024
@alcercu alcercu dismissed stale reviews from kemuru and themself via 653f505 July 18, 2024 14:44
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7cf0b1e and 653f505.

Files selected for processing (1)
  • web/src/hooks/queries/useEvidences.ts (2 hunks)
Additional comments not posted (2)
web/src/hooks/queries/useEvidences.ts (2)

31-31: Type parameter added to useQuery.

The addition of the type parameter <EvidencesQuery> to useQuery improves type safety and developer experience.


19-22: New fields added to the GraphQL query.

The fields name, description, fileURI, and fileTypeExtension have been correctly added to the evidencesQuery.

However, ensure that these new fields are used correctly in the codebase.

@alcercu alcercu enabled auto-merge July 18, 2024 14:48
Copy link

codeclimate bot commented Jul 18, 2024

Code Climate has analyzed commit d1b6fe2 and detected 15 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2
Duplication 2
Style 11

View more on Code Climate.

Copy link

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 653f505 and d1b6fe2.

Files ignored due to path filters (1)
  • web/src/assets/svgs/icons/arrow-down.svg is excluded by !**/*.svg
Files selected for processing (10)
  • subgraph/core-neo/subgraph.yaml (1 hunks)
  • subgraph/core-university/subgraph.yaml (1 hunks)
  • subgraph/core/schema.graphql (3 hunks)
  • subgraph/core/src/EvidenceModule.ts (1 hunks)
  • subgraph/core/subgraph.yaml (1 hunks)
  • subgraph/package.json (1 hunks)
  • web/src/components/EvidenceCard.tsx (4 hunks)
  • web/src/hooks/queries/useEvidences.ts (1 hunks)
  • web/src/pages/Cases/CaseDetails/Evidence/EvidenceSearch.tsx (1 hunks)
  • web/src/pages/Cases/CaseDetails/Evidence/index.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • web/src/hooks/queries/useEvidences.ts
Additional comments not posted (20)
web/src/pages/Cases/CaseDetails/Evidence/EvidenceSearch.tsx (4)

1-14: LGTM! Imports are appropriate.

The imports are necessary for the functionality provided in this file.


16-31: LGTM! Styled components are well-defined.

The styled components use responsive design principles and are appropriately defined.


33-37: LGTM! Interface is appropriately defined.

The interface defines the props for the EvidenceSearch component correctly.


39-69: LGTM! Functional component is well-structured.

The EvidenceSearch component is well-structured and uses appropriate hooks and styled components. The logic is clear and concise.

subgraph/core/src/EvidenceModule.ts (2)

1-7: LGTM! Imports are appropriate.

The imports are necessary for the functionality provided in this file.


9-61: LGTM! Function is well-structured.

The handleEvidenceEvent function is well-structured and includes appropriate error handling. The logic for JSON parsing and extracting fields is clear.

web/src/pages/Cases/CaseDetails/Evidence/index.tsx (3)

1-19: LGTM! Imports are appropriate.

The imports are necessary for the functionality provided in this file.


Line range hint 21-55:
LGTM! Styled components are well-defined.

The styled components use responsive design principles and are appropriately defined.


Line range hint 56-118:
LGTM! Functional component is well-structured.

The Evidence component is well-structured and uses appropriate hooks and styled components. The logic is clear and concise.

web/src/components/EvidenceCard.tsx (3)

Line range hint 1-17:
LGTM! Imports are appropriate.

The imports are necessary for the functionality provided in this file.


126-129: LGTM! Interface is appropriately defined.

The interface defines the props for the EvidenceCard component correctly.


Line range hint 131-175:
LGTM! Functional component is well-structured.

The EvidenceCard component is well-structured and uses appropriate hooks and styled components. The logic is clear and concise.

subgraph/core-university/subgraph.yaml (1)

4-6: Addition of fullTextSearch feature looks good.

The fullTextSearch feature has been correctly added to the features section.

subgraph/core-neo/subgraph.yaml (1)

4-6: Addition of fullTextSearch feature looks good.

The fullTextSearch feature has been correctly added to the features section.

subgraph/core/subgraph.yaml (1)

4-6: Addition of fullTextSearch feature looks good.

The fullTextSearch feature has been correctly added to the features section.

subgraph/core/schema.graphql (3)

55-62: Addition of new fields to Evidence type looks good.

The new fields evidenceIndex, senderAddress, name, description, fileURI, and fileTypeExtension have been correctly added to the Evidence type.


301-312: Addition of new fields to ClassicEvidence type and immutability looks good.

The new fields evidenceIndex, senderAddress, name, description, fileURI, and fileTypeExtension have been correctly added to the ClassicEvidence type. The immutability of the ClassicEvidence type has been correctly specified.


327-333: Addition of full-text search schema _Schema_ looks good.

The full-text search schema _Schema_ has been correctly added for searching evidence-related fields.

subgraph/package.json (2)

3-3: Verify the version bump.

The version has been updated from 0.5.1 to 0.7.0. Ensure that this aligns with semantic versioning principles and reflects the scope of changes made.


5-5: LGTM! New script addition.

The new script for updating core components related to Arbitrum Sepolia Devnet is correctly defined and consistent with other similar scripts.

@alcercu alcercu added this pull request to the merge queue Jul 19, 2024
Merged via the queue into dev with commit 53249a7 Jul 19, 2024
18 of 23 checks passed
@jaybuidl jaybuidl deleted the refactor/evidence-refactors branch October 8, 2024 16:19
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