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

Atlas integration for file uploads to IPFS #1687

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

Harman-singh-waraich
Copy link
Contributor

@Harman-singh-waraich Harman-singh-waraich commented Sep 12, 2024

  • does not include hashing yet

PR-Codex overview

This PR focuses on refactoring file upload functionality to IPFS by introducing a new uploadToIpfs utility and integrating it into various components. It also removes obsolete files and updates environment variables.

Detailed summary

  • Deleted uploadToIPFS.ts and authMiddleware.ts.
  • Added uploadToIpfs export in web/src/utils/atlas/index.ts.
  • Updated environment variables to remove /graphql from REACT_APP_ATLAS_URI.
  • Integrated uploadFile from useAtlasProvider in Policy and SubmitEvidenceModal.
  • Refactored file upload logic in Policy and SubmitEvidenceModal components.
  • Created uploadToIpfs utility with error handling and toast notifications.
  • Updated AtlasProvider to manage file upload state and logic.

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

Summary by CodeRabbit

  • New Features

    • Introduced a new file upload mechanism to IPFS with user feedback notifications.
    • Enhanced evidence submission process to streamline file handling.
    • Added functionality for uploading files using the new context provider method.
    • Updated the application endpoint for improved connectivity.
  • Bug Fixes

    • Improved error handling during evidence submission.
  • Refactor

    • Simplified file upload logic across various components by integrating a new context-based approach.
  • Documentation

    • Updated context provider to include new upload functionality.

Copy link
Contributor

coderabbitai bot commented Sep 12, 2024

Walkthrough

The changes involve updates to multiple environment configuration files, specifically modifying the REACT_APP_ATLAS_URI variable by removing the /graphql endpoint from its value across various environments. Additionally, the AtlasProvider component has been enhanced with a new uploadFile function for handling file uploads to IPFS, along with a new state variable isUploadingFile. The SubmitEvidenceModal and Policy components have been refactored to utilize this new upload functionality, streamlining the evidence submission process. A new utility file, uploadToIpfs.ts, has also been introduced to manage file uploads.

Changes

Files Change Summary
web/.env.devnet-neo.public, web/.env.devnet-university.public, web/.env.devnet.public, web/.env.local.public, web/.env.mainnet-neo.public, web/.env.testnet.public Updated REACT_APP_ATLAS_URI from http://localhost:3000/graphql to http://localhost:3000 in multiple environment files.
web/src/context/AtlasProvider.tsx Added uploadFile method and isUploadingFile state to manage file uploads within the context.
web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx Updated to use uploadFile for evidence submission, improving error handling and code clarity.
web/src/pages/Resolver/Policy/index.tsx Refactored to utilize uploadFile from AtlasProvider, simplifying the upload process.
web/src/utils/atlas/index.ts Added export for uploadToIpfs module to enhance modularity.
web/src/utils/atlas/uploadToIpfs.ts Introduced functionality for uploading files to IPFS using a structured payload and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AtlasProvider
    participant IPFS
    participant GraphQL

    User->>AtlasProvider: uploadFile(file)
    AtlasProvider->>GraphQL: getPreSignedUrl(filename)
    GraphQL-->>AtlasProvider: return presigned URL
    AtlasProvider->>IPFS: PUT request to upload file
    IPFS-->>AtlasProvider: return upload status
    AtlasProvider-->>User: return upload result
Loading

🐇 In the meadow, files take flight,
To IPFS, they soar with delight.
With tokens and URLs, they find their way,
A hop, a skip, in the tech ballet!
Error logs fade, clarity reigns,
As uploads dance through digital lanes! 🌟

Possibly related PRs

  • Add REACT_APP_DEVTOOLS_URL to the court #1708: The changes in this PR involve the addition of the REACT_APP_DEVTOOLS_URL variable across multiple environment configuration files, which is related to the modifications made to the REACT_APP_ATLAS_URI variable in the main PR, as both involve updates to environment variables in similar files.

Suggested labels

Type: Enhancement :sparkles:

Suggested reviewers

  • alcercu
  • kemuru

🪧 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 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

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

Outside diff range and nitpick comments (1)
web/src/utils/atlas/uploadToIpfs.ts (1)

33-37: Consider making the appname argument configurable.

The presignedUrlQuery mutation is correctly defined with the required filename argument. However, the appname argument is hardcoded to KlerosCourt, which might not be flexible for other use cases.

Consider making the appname argument configurable by passing it as a variable to the getPreSignedUrl function. This will make the function more reusable for other applications.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 39cf66d and 3d217da.

Files selected for processing (7)
  • web/netlify/functions/uploadToIPFS.ts (0 hunks)
  • web/netlify/middleware/authMiddleware.ts (0 hunks)
  • web/src/context/AtlasProvider.tsx (7 hunks)
  • web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx (3 hunks)
  • web/src/pages/Resolver/Policy/index.tsx (2 hunks)
  • web/src/utils/atlas/index.ts (1 hunks)
  • web/src/utils/atlas/uploadToIpfs.ts (1 hunks)
Files not reviewed due to no reviewable changes (2)
  • web/netlify/functions/uploadToIPFS.ts
  • web/netlify/middleware/authMiddleware.ts
Additional comments not posted (12)
web/src/utils/atlas/index.ts (1)

7-7: LGTM!

The export statement is correctly implemented and is consistent with the other export statements in the file. Exporting the uploadToIpfs module enhances the functionality of the atlas utility by making it available for import in other parts of the application, contributing to the modularity and reusability of the codebase.

web/src/utils/atlas/uploadToIpfs.ts (2)

6-31: LGTM!

The uploadToIpfs function is well-implemented and handles the file upload to IPFS using a presigned URL correctly. It uses the toast library effectively to display upload progress and error messages. The function returns the IPFS CID of the uploaded file on successful upload, which is the expected behavior.


43-70: LGTM!

The getPreSignedUrl function is well-implemented and fetches the presigned URL for uploading a file to IPFS correctly using a GraphQL mutation. It uses the toast library effectively to display error messages. The function returns the presigned URL on successful response, which is the expected behavior.

web/src/pages/Resolver/Policy/index.tsx (1)

Line range hint 54-67: LGTM! The refactor improves the code quality and aligns with the new upload mechanism.

The changes simplify the file upload process by directly using the uploadFile method from the AtlasProvider context. This enhances the clarity and efficiency of the code while maintaining the core functionality of updating the disputeData with the new policyURI.

Please ensure that the uploadFile method is correctly implemented in the AtlasProvider context to handle the file upload to IPFS and return the appropriate cid.

Run the following script to verify the uploadFile method:

Verification successful

Verification Successful: The uploadFile method is correctly implemented in the AtlasProvider context.

The method handles file uploads to IPFS and returns the appropriate cid. It is well-integrated and used consistently across the codebase.

  • Located in web/src/context/AtlasProvider.tsx.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the `uploadFile` method in the `AtlasProvider` context.

# Test: Search for the `uploadFile` method declaration and implementation.
# Expect: The method should handle the file upload to IPFS and return the `cid`.
ast-grep --lang typescript --pattern $'const AtlasProvider = ({ children }: Props) => {
  $$$
  const uploadFile = async (file: File) => {
    $$$
    return cid;
  };
  $$$
}'

Length of output: 177


Script:

#!/bin/bash
# Description: Search for the `uploadFile` method across the entire codebase to verify its implementation.

# Test: Search for the `uploadFile` method declaration and implementation.
# Expect: The method should handle the file upload to IPFS and return the `cid`.
rg 'uploadFile' -A 10 --type=ts

Length of output: 7821

web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx (4)

10-10: LGTM!

The import statement for the useAtlasProvider hook is correct and follows the proper syntax. It will likely be used to access the uploadFile function for uploading files to IPFS.


64-64: LGTM!

The destructuring assignment for the uploadFile function from the useAtlasProvider hook is correct and follows the proper syntax. It will likely be used to handle file uploads to IPFS.


104-105: LGTM!

The changes to the constructEvidence function to accept the uploadFile function as a parameter align with the AI-generated summary. Declaring the fileURI variable with an initial value of null is a good practice, as it explicitly sets the initial value and avoids potential undefined behavior.


108-109: LGTM!

The changes to call the uploadFile function with the file argument and assign the result to the fileURI variable align with the AI-generated summary. Throwing an error if the fileURI is falsy ensures that the evidence submission process is halted if the file upload fails, and the error message clearly communicates the reason for the error.

web/src/context/AtlasProvider.tsx (4)

16-16: LGTM!

The import statement for uploadToIpfs is correct and necessary for using the function in this file.


30-30: LGTM!

The changes to the IAtlasProvider interface and the AtlasProvider component are consistent and necessary for implementing the file upload functionality in the context.

Also applies to: 36-36, 55-55


130-131: LGTM!

The change to the userExists memoized value is correct and necessary for determining if a user exists based on the presence of the email property.


207-231: LGTM!

The implementation of the uploadFile method in the AtlasProvider component is correct and follows the necessary steps for handling file uploads to IPFS. The method correctly checks for user verification and address, sets the isUploadingFile state variable to track the upload status, handles the response from the uploadToIpfs function, and includes proper error handling and logging.

@jaybuidl jaybuidl changed the title feat(web): atlas-upload-to-ipfs-integration Atlas integration for file uploads to IPFS Sep 13, 2024
@github-actions github-actions bot added the Package: Web Court web frontend label Sep 13, 2024
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 (2)
web/src/pages/Resolver/Policy/index.tsx (1)

61-64: Approve changes with a suggestion for improved error handling.

The updated handleFileUpload function successfully integrates the new uploadFile method from AtlasProvider, simplifying the upload process. The use of Roles.Policy adds structure to the upload functionality.

However, consider enhancing the error handling to provide more specific error messages to the user.

Consider updating the error handling as follows:

 uploadFile(file, Roles.Policy)
   .then(async (cid) => {
     if (!cid) return;
     setDisputeData({ ...disputeData, policyURI: cid });
   })
-  .catch((err) => console.log(err))
+  .catch((err) => {
+    console.error("Policy upload failed:", err);
+    toast.error("Failed to upload policy. Please try again.", toastOptions);
+  })
   .finally(() => setIsPolicyUploading(false));

This change will provide more informative feedback to the user in case of upload failures.

web/src/context/AtlasProvider.tsx (1)

237-237: Use console.error instead of console.log for error messages.

When logging errors, it's best practice to use console.error to clearly differentiate error messages from standard logs.

Apply this diff to update the error logging:

-           console.log("Upload File Error : ", err?.message);
+           console.error("Upload File Error : ", err?.message);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3d217da and 4c21930.

📒 Files selected for processing (11)
  • web/.env.devnet-neo.public (1 hunks)
  • web/.env.devnet-university.public (1 hunks)
  • web/.env.devnet.public (1 hunks)
  • web/.env.local.public (1 hunks)
  • web/.env.mainnet-neo.public (1 hunks)
  • web/.env.testnet.public (1 hunks)
  • web/src/context/AtlasProvider.tsx (8 hunks)
  • web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx (3 hunks)
  • web/src/pages/Resolver/Policy/index.tsx (2 hunks)
  • web/src/utils/atlas/index.ts (1 hunks)
  • web/src/utils/atlas/uploadToIpfs.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • web/.env.local.public
🧰 Additional context used
📓 Learnings (1)
web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx (2)
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1687
File: web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx:67-84
Timestamp: 2024-10-08T16:23:56.291Z
Learning: In the `submitEvidence` function of the SubmitEvidenceModal component, the try-catch block is specifically designed to handle errors from the `constructEvidence` function, which may throw an Error if file upload fails. This ensures that the file is successfully uploaded before proceeding with evidence submission and transaction signing.
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1687
File: web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx:67-84
Timestamp: 2024-09-12T14:45:48.019Z
Learning: In the `submitEvidence` function of the SubmitEvidenceModal component, the try-catch block is specifically designed to handle errors from the `constructEvidence` function, which may throw an Error if file upload fails. This ensures that the file is successfully uploaded before proceeding with evidence submission and transaction signing.
🔇 Additional comments (13)
web/src/utils/atlas/index.ts (1)

8-8: LGTM! Verify the implementation of uploadToIpfs.

The addition of the uploadToIpfs export aligns with the PR objectives of integrating IPFS upload functionality. This change looks good and should make the IPFS upload function available for use in other parts of the application.

To ensure the correctness of this change, let's verify the implementation of the uploadToIpfs module:

This script will help us confirm that the uploadToIpfs module is properly implemented and used in the codebase.

✅ Verification successful

Need to Re-verify the Usage of uploadToIpfs

The previous search for uploadToIpfs usage failed due to an unrecognized file type. Let's rerun the search without specifying file types to ensure all usages are captured.


uploadToIpfs is correctly implemented and properly utilized within the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the uploadToIpfs module

# Test 1: Check if the uploadToIpfs.ts file exists
echo "Checking if uploadToIpfs.ts exists:"
fd --type f "uploadToIpfs.ts" web/src/utils/atlas

# Test 2: Display the content of uploadToIpfs.ts if it exists
echo "Content of uploadToIpfs.ts (if it exists):"
fd --type f "uploadToIpfs.ts" web/src/utils/atlas --exec cat {}

# Test 3: Check for any usage of uploadToIpfs in the codebase
echo "Checking for usage of uploadToIpfs in the codebase:"
rg --type typescript "uploadToIpfs" web/src

Length of output: 1955


Script:

#!/bin/bash
# Description: Re-verify usage of uploadToIpfs in the codebase

echo "Searching for usage of 'uploadToIpfs' in TypeScript files:"
rg "uploadToIpfs" web/src --glob "*.ts" --glob "*.tsx"

Length of output: 514

web/.env.testnet.public (1)

6-6: LGTM. Verify Atlas service interaction and update documentation if needed.

The change to REACT_APP_ATLAS_URI aligns with the PR objectives of integrating IPFS upload logic into the AtlasProvider. However, please ensure the following:

  1. Verify that removing /graphql from the URI doesn't break existing API calls to the Atlas service.
  2. Update any relevant documentation that might reference the old URI structure.
  3. Confirm that this change is consistent across all environment files (e.g., production, development) if applicable.

To verify the consistency of this change across environment files, run the following script:

web/.env.devnet.public (1)

7-7: LGTM. Verify API request construction and update documentation.

The change to REACT_APP_ATLAS_URI looks good and aligns with the PR objectives. However, please ensure the following:

  1. Verify that all API requests in the application code have been updated to append the necessary endpoints (e.g., /graphql if still required) when constructing URLs.
  2. Update any relevant documentation that references the Atlas URI to reflect this change.

To verify the impact of this change, you can run the following script:

This script will help identify areas of the code that might need adjustment due to the ATLAS_URI change.

✅ Verification successful

Verification Successful.

The updates to REACT_APP_ATLAS_URI have been correctly implemented. API requests are appropriately constructed with the /graphql endpoint, ensuring continued functionality.

  • Confirmed that REACT_APP_ATLAS_URI is utilized in AtlasProvider.tsx to initialize the GraphQLClient with /graphql.
  • No Atlas-related API calls were found that require further adjustments.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential issues with Atlas URI usage

# Search for usages of REACT_APP_ATLAS_URI
echo "Searching for REACT_APP_ATLAS_URI usage:"
rg "REACT_APP_ATLAS_URI" --type ts --type tsx

# Search for hardcoded '/graphql' endpoints
echo "Searching for hardcoded '/graphql' endpoints:"
rg "/graphql" --type ts --type tsx

# Search for Atlas-related API calls
echo "Searching for Atlas-related API calls:"
rg "atlas.*api|api.*atlas" --type ts --type tsx

Length of output: 499


Script:

#!/bin/bash
# Description: Check for potential issues with Atlas URI usage using correct file types

# Search for usages of REACT_APP_ATLAS_URI
echo "Searching for REACT_APP_ATLAS_URI usage:"
rg "REACT_APP_ATLAS_URI" --type typescript --type typescriptreact

# Search for hardcoded '/graphql' endpoints
echo "Searching for hardcoded '/graphql' endpoints:"
rg "/graphql" --type typescript --type typescriptreact

# Search for Atlas-related API calls
echo "Searching for Atlas-related API calls:"
rg "atlas.*api|api.*atlas" --type typescript --type typescriptreact

Length of output: 580


Script:

#!/bin/bash
# Description: Check for potential issues with Atlas URI usage by targeting specific file extensions

# Search for usages of REACT_APP_ATLAS_URI in .ts and .tsx files
echo "Searching for REACT_APP_ATLAS_URI usage in .ts and .tsx files:"
rg "REACT_APP_ATLAS_URI" -g "*.ts" -g "*.tsx"

# Search for hardcoded '/graphql' endpoints in .ts and .tsx files
echo "Searching for hardcoded '/graphql' endpoints in .ts and .tsx files:"
rg "/graphql" -g "*.ts" -g "*.tsx"

# Search for Atlas-related API calls in .ts and .tsx files
echo "Searching for Atlas-related API calls in .ts and .tsx files:"
rg "atlas.*api|api.*atlas" -g "*.ts" -g "*.tsx"

Length of output: 6001

web/.env.mainnet-neo.public (1)

8-8: Approve change, but verify configuration and impact.

The modification of REACT_APP_ATLAS_URI aligns with the PR objectives for integrating IPFS upload logic. However, there are a couple of points to consider:

  1. Using a localhost URL (http://localhost:3000) in a mainnet configuration file is unusual and potentially problematic. Please verify if this is intentional or if it should be replaced with the actual production URL.

  2. The removal of the /graphql endpoint from the URI might affect how the application interacts with the GraphQL service. Ensure that this change is consistent with the updates in the AtlasProvider and other components that use this URI.

To verify the impact of this change, please run the following script:

This script will help identify areas of the codebase that might be affected by the URI change, allowing you to ensure that all GraphQL and Atlas-related functionality is updated accordingly.

✅ Verification successful

Change verified; no issues found.

The modification of REACT_APP_ATLAS_URI has been reviewed, and all usages of atlasUri in the codebase are consistent with the removal of /graphql. The GraphQLClient is correctly configured by appending /graphql to the base URI, ensuring proper interactions with the GraphQL service.

However, using a localhost URL (http://localhost:3000) in a mainnet configuration is unusual and should be verified to ensure it’s intentional and appropriate for the deployment environment.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for GraphQL endpoint usage in the codebase

# Search for GraphQL-related imports and usage
echo "Searching for GraphQL-related code:"
rg --type typescript --type javascript 'import.*from.*@apollo/client' -A 5
rg --type typescript --type javascript 'useQuery|useMutation|gql`' -A 5

# Search for direct usage of REACT_APP_ATLAS_URI
echo "Searching for REACT_APP_ATLAS_URI usage:"
rg --type typescript --type javascript 'process\.env\.REACT_APP_ATLAS_URI' -A 5

# Search for Atlas-related components or providers
echo "Searching for Atlas-related components:"
rg --type typescript --type javascript 'AtlasProvider|useAtlas' -A 5

Length of output: 704


Script:

#!/bin/bash
# Description: Check for GraphQL endpoint usage in the codebase

echo "Searching for GraphQL-related code:"
rg 'import\s+.*\s+from\s+["@'\'']@apollo/client["@'\'']' -A 5 --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx'
rg 'useQuery|useMutation|gql`' -A 5 --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx'

echo "Searching for REACT_APP_ATLAS_URI usage:"
rg 'process\.env\.REACT_APP_ATLAS_URI' -A 5 --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx'

echo "Searching for Atlas-related components:"
rg 'AtlasProvider|useAtlas' -A 5 --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx'

Length of output: 40120


Script:

#!/bin/bash
# Description: Verify how `atlasUri` is used within the codebase to assess the impact of removing `/graphql` from the URI.

echo "Searching for usages of `atlasUri` variable:"
rg 'atlasUri' --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx' -A 5

echo "Checking GraphQL client configurations for potential URI concatenations:"
rg 'ApolloClient' --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx' -A 10
rg 'new ApolloClient' --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.jsx' -A 10

Length of output: 2235

web/.env.devnet-neo.public (1)

8-8: LGTM. Verify Atlas service interaction.

The change to REACT_APP_ATLAS_URI aligns with the PR objectives of refactoring the file upload functionality and integrating IPFS upload logic into the AtlasProvider.

Please ensure that this change doesn't negatively impact the application's interaction with the Atlas service. Run the following script to verify the usage of REACT_APP_ATLAS_URI across the codebase:

This will help identify any places where the removal of /graphql might require additional adjustments.

web/.env.devnet-university.public (1)

8-8: LGTM. Verify impact and update documentation if needed.

The change to REACT_APP_ATLAS_URI aligns with the PR objectives of integrating IPFS upload logic into the AtlasProvider. However, please ensure the following:

  1. Verify that all parts of the codebase that rely on this URI have been updated accordingly.
  2. Check if this change affects any API calls or GraphQL queries in the application.
  3. Update any relevant documentation that references the Atlas URI.

To help verify the impact of this change, you can run the following script:

This script will help identify any places in the codebase that might need to be updated due to this change.

✅ Verification successful

Please run the following updated script to verify the changes:

This script adjusts the search by specifying file patterns using the --glob option instead of the --type flag, which should prevent the "unrecognized file type" error and ensure all relevant files are included in the search.


Verified. No issues found.

The update to REACT_APP_ATLAS_URI has been successfully integrated, and no hardcoded references to the old URI (http://localhost:3000/graphql) were detected in the codebase. All existing usages of REACT_APP_ATLAS_URI correctly reference the environment variable.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for occurrences of REACT_APP_ATLAS_URI in the codebase

# Test: Look for usages of REACT_APP_ATLAS_URI
echo "Searching for REACT_APP_ATLAS_URI usage:"
rg "REACT_APP_ATLAS_URI" --type ts --type tsx --type js --type jsx

# Test: Look for hardcoded references to the old URI
echo "Searching for hardcoded references to the old URI:"
rg "http://localhost:3000/graphql" --type ts --type tsx --type js --type jsx

Length of output: 401


Script:

# 
#!/bin/bash
# Description: Search for occurrences of REACT_APP_ATLAS_URI in the codebase

# Test: Look for usages of REACT_APP_ATLAS_URI
echo "Searching for REACT_APP_ATLAS_URI usage:"
rg "REACT_APP_ATLAS_URI" --glob "*.ts" --glob "*.tsx" --glob "*.js" --glob "*.jsx"

# Test: Look for hardcoded references to the old URI
echo "Searching for hardcoded references to the old URI:"
rg "http://localhost:3000/graphql" --glob "*.ts" --glob "*.tsx" --glob "*.js" --glob "*.jsx"

Length of output: 609

web/src/pages/Resolver/Policy/index.tsx (2)

8-8: LGTM: New imports for AtlasProvider integration.

The new import statements for useAtlasProvider and Roles are correctly added and necessary for the updated file upload implementation using AtlasProvider.

Also applies to: 10-10


55-55: LGTM: AtlasProvider hook integration.

The uploadFile function is correctly extracted from the AtlasProvider context using the useAtlasProvider hook. This is a good use of the new context for file uploads.

web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx (5)

10-10: Importing useAtlasProvider Module

The import statement correctly imports useAtlasProvider from "context/AtlasProvider", which is essential for accessing the uploadFile function needed for file uploads.


12-12: Importing Roles Enum

The Roles enum is imported from "utils/atlas" and is appropriately used to specify the role during file upload in the constructEvidence function.


65-65: Extracting uploadFile from useAtlasProvider

Destructuring uploadFile from useAtlasProvider allows the component to utilize the file upload functionality provided by the Atlas context effectively.


68-86: Enhanced Error Handling in submitEvidence Function

The addition of the try-catch block in the submitEvidence function improves error handling by capturing any errors from constructEvidence. This ensures that isSending state is appropriately reset if an error occurs during evidence construction, preventing the application from remaining in a loading state.


105-114: Passing uploadFile as a Parameter to constructEvidence

By injecting uploadFile as a parameter into the constructEvidence function, the code promotes modularity and enhances testability. This approach decouples the function from external dependencies, making it easier to maintain and test.

@jaybuidl jaybuidl force-pushed the feat/atlas-ipfs-upload branch from 4c21930 to 96a49cc Compare October 15, 2024 16:14
Copy link

netlify bot commented Oct 15, 2024

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 96a49cc
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/670e94eef7a9330008bd7433
😎 Deploy Preview https://deploy-preview-1687--kleros-v2-testnet.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

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4c21930 and 96a49cc.

📒 Files selected for processing (10)
  • web/.env.devnet-neo.public (1 hunks)
  • web/.env.devnet-university.public (1 hunks)
  • web/.env.devnet.public (1 hunks)
  • web/.env.local.public (1 hunks)
  • web/.env.mainnet-neo.public (1 hunks)
  • web/.env.testnet.public (1 hunks)
  • web/src/context/AtlasProvider.tsx (8 hunks)
  • web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx (3 hunks)
  • web/src/pages/Resolver/Policy/index.tsx (2 hunks)
  • web/src/utils/atlas/uploadToIpfs.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • web/.env.devnet-neo.public
  • web/.env.devnet-university.public
  • web/.env.devnet.public
  • web/.env.local.public
  • web/.env.mainnet-neo.public
  • web/.env.testnet.public
  • web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx
  • web/src/pages/Resolver/Policy/index.tsx
🧰 Additional context used
📓 Learnings (1)
web/src/utils/atlas/uploadToIpfs.ts (1)
Learnt from: Harman-singh-waraich
PR: kleros/kleros-v2#1687
File: web/src/utils/atlas/uploadToIpfs.ts:28-61
Timestamp: 2024-10-15T16:16:27.395Z
Learning: In this codebase, the Toast wrappers handle the return value of `toast.promise`, ensuring that functions using it return the expected result.
🔇 Additional comments (10)
web/src/context/AtlasProvider.tsx (5)

17-24: LGTM: New imports and interface updates for IPFS functionality.

The additions to the imports and the IAtlasProvider interface are consistent with the PR objectives. The new isUploadingFile state and uploadFile method are appropriately typed and structured for the IPFS upload functionality.

Also applies to: 35-41


74-74: LGTM: Updated GraphQL endpoint URL.

The addition of /graphql to the endpoint URL is consistent with the PR objectives and ensures that GraphQL requests are sent to the correct endpoint.


140-140: LGTM: Simplified user existence check.

The new implementation provides a more precise way to determine user existence by checking if the user's email is not undefined. This change aligns well with the comment about defining what constitutes an existing user.


282-283: LGTM: Context value updated with new IPFS-related properties.

The addition of isUploadingFile and uploadFile to the context value and the corresponding updates to the useMemo dependency array are consistent with the new IPFS upload functionality. These changes ensure that components consuming this context will have access to the new functionality and will re-render appropriately when these values change.

Also applies to: 297-298


Line range hint 1-314: Overall assessment: Well-implemented IPFS upload functionality.

The changes in this file successfully implement the IPFS upload functionality as described in the PR objectives. The code is clean, well-structured, and follows best practices. The new uploadFile function and related changes are properly integrated into the AtlasProvider component.

There's only one minor suggestion to include atlasUri in the dependency array of the uploadFile function's useCallback hook. Once this is addressed, the implementation will be fully robust and ready for merging.

Great job on this implementation!

web/src/utils/atlas/uploadToIpfs.ts (5)

5-7: Product enum is properly defined

The Products enum is correctly set up, enhancing type safety by specifying allowed product types.


9-14: Roles enum includes all necessary roles

The Roles enum comprehensively covers the possible roles needed for IPFS uploads.


16-21: IpfsUploadPayload type is well-structured

The IpfsUploadPayload type accurately defines all required properties for the upload payload.


23-26: Configuration type is appropriately defined

The Config type includes the necessary configuration parameters for the upload function.


28-61: uploadToIpfs function is correctly implemented

The uploadToIpfs function properly handles the file upload process to IPFS, including error handling and user notifications. Given that the Toast wrappers in this codebase handle the return value of toast.promise, the function is expected to return the correct upload result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Frontend integration with the new Atlas backend for file uploads to IPFS
3 participants