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

feat(subgraph,web): fix coherent votes at vote level instead of dispute level #1702

Merged
merged 9 commits into from
Oct 7, 2024

Conversation

kemuru
Copy link
Contributor

@kemuru kemuru commented Oct 4, 2024

works good.

image image

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced user tracking with new metrics: totalCoherentVotes, totalResolvedVotes, and coherenceScore.
    • Introduced a new voting mechanism, ClassicVote, for improved dispute resolution.
  • Improvements

    • Streamlined user dispute resolution process by simplifying parameters and removing unnecessary complexity.
    • Updated various components to reflect new naming conventions for user voting metrics, enhancing clarity.
  • Configuration

    • Updated version of the Kleros v2 core subgraph from 0.7.4 to 0.7.6.

PR-Codex overview

This PR primarily focuses on renaming properties related to user voting metrics from totalCoherent to totalCoherentVotes and updating the associated logic throughout the application. It also enhances the user level calculation by introducing minimum disputes criteria.

Detailed summary

  • Renamed totalCoherent to totalCoherentVotes in various files.
  • Added totalResolvedVotes in multiple components.
  • Updated getUserLevelData to include totalResolvedDisputes.
  • Modified computeCoherenceScore to use totalCoherentVotes and totalResolvedVotes.
  • Adjusted various components to reflect the new properties and ensure proper rendering.
  • Updated resolveUserDispute function to simplify parameters and logic.
  • Enhanced user level criteria with minimum disputes requirements.

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

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The pull request introduces modifications to the GraphQL schema and related TypeScript files, focusing on the User entity and its metrics. New fields totalCoherentVotes, totalResolvedVotes, and coherenceScore are added, while the totalCoherent field is removed. Changes in the KlerosCore.ts file enhance the handling of juror votes, and various components and hooks are updated to reflect the new field names and structures.

Changes

File Path Change Summary
subgraph/core/schema.graphql - Added fields: totalCoherentVotes: BigInt!, totalResolvedVotes: BigInt!, coherenceScore: BigInt! in User.
- Removed field: totalCoherent: BigInt! in User.
subgraph/core/src/KlerosCore.ts - Added import: ClassicVote.
- Enhanced handleNewPeriod function for juror vote processing.
subgraph/core/src/entities/User.ts - Updated createUserFromAddress to use new properties.
- Simplified resolveUserDispute function parameters and logic.
web/src/hooks/queries/useTopUsersByCoherenceScore.ts - Renamed field in query: totalCoherent to totalCoherentVotes, added totalResolvedVotes.
web/src/hooks/queries/useUser.ts - Renamed field in fragment: totalCoherent to totalCoherentVotes, added totalResolvedVotes.
web/src/pages/Dashboard/JurorInfo/Coherency.tsx - Updated ICoherency interface and component props to use new property names.
web/src/pages/Dashboard/JurorInfo/Header.tsx - Updated IHeader interface and component props to use new property names.
web/src/pages/Dashboard/JurorInfo/index.tsx - Renamed variables from totalCoherent to totalCoherentVotes and from totalResolvedDisputes to totalResolvedVotes.
web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx - Updated ICoherency interface and component props to use new property names.
web/src/pages/Home/TopJurors/JurorCard/DesktopCard.tsx - Updated IDesktopCard interface to rename properties.
web/src/pages/Home/TopJurors/JurorCard/MobileCard.tsx - Updated IMobileCard interface to rename properties.
web/src/pages/Home/TopJurors/JurorCard/index.tsx - Updated IJurorCard interface to rename properties.
subgraph/package.json - Version updated from 0.7.4 to 0.7.6.

Possibly related issues

Possibly related PRs

  • feat(web): extra statistic on homepage #1671: The changes in this PR involve modifications to the GraphQL queries to include new fields like totalCoherentVotes and totalResolvedVotes, which directly relate to the changes made in the main PR regarding the User entity in the GraphQL schema.

Suggested labels

Type: Feature🗿, Package: Web

Suggested reviewers

  • Harman-singh-waraich
  • alcercu

Poem

🐰 In the realm of votes and scores,
A rabbit hops through open doors.
With coherent votes now shining bright,
User metrics take their flight!
A new dawn for jurors, clear and true,
Hooray for changes, fresh and new! 🌟


🪧 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

netlify bot commented Oct 4, 2024

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

Name Link
🔨 Latest commit 38efc1b
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/6703cbfa3ae0b30008321b11

Copy link

netlify bot commented Oct 4, 2024

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

Name Link
🔨 Latest commit 38efc1b
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/6703cbfacba3f30008e32b37

Copy link

netlify bot commented Oct 4, 2024

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit 38efc1b
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/6703cbfaaa39670008e270ff
😎 Deploy Preview https://deploy-preview-1702--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
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: 9

🧹 Outside diff range and nitpick comments (8)
web/src/hooks/queries/useTopUsersByCoherenceScore.ts (1)

Line range hint 1-38: Summary: GraphQL query updated, hook remains unchanged

The changes in this file are well-contained and focused:

  1. The GraphQL query has been updated to rename totalCoherent to totalCoherentVotes and add totalResolvedVotes.
  2. The useTopUsersByCoherenceScore hook implementation remains unchanged, which is correct as it doesn't need to be modified to accommodate these query changes.

These updates align with the PR objective of fixing coherent votes at the vote level. The changes improve data clarity without introducing unnecessary complexity.

Consider adding a comment above the useTopUsersByCoherenceScore hook to briefly explain the purpose of the totalCoherentVotes and totalResolvedVotes fields, which could help future developers understand the data structure more easily.

web/src/pages/Dashboard/JurorInfo/index.tsx (2)

47-47: Approve the change with a minor suggestion for readability.

The renaming of totalCoherent to totalCoherentVotes aligns well with the PR objective of fixing coherent votes at the vote level. The use of optional chaining and nullish coalescing is a good practice.

Consider using a default value in the destructuring to simplify the line:

const { totalCoherentVotes = '0' } = data?.user ?? {};
const totalCoherentVotesInt = parseInt(totalCoherentVotes);

This approach can make the code more readable and reduce nesting.


48-48: Approve the change with a suggestion for consistency.

The renaming of totalResolvedDisputes to totalResolvedVotes is consistent with the previous change and aligns with the PR objective.

For consistency with the previous suggestion, consider using the same pattern:

const { totalResolvedVotes = '0' } = data?.user ?? {};
const totalResolvedVotesInt = parseInt(totalResolvedVotes);

This will maintain a consistent style throughout the component.

web/src/pages/Home/TopJurors/JurorCard/MobileCard.tsx (1)

105-105: Updated Coherency component props

The props passed to the Coherency component have been correctly updated to use the new property names. This ensures consistency with the interface changes.

However, consider using a more explicit prop passing syntax for improved readability:

-<Coherency {...{ totalCoherentVotes, totalResolvedVotes }} />
+<Coherency totalCoherentVotes={totalCoherentVotes} totalResolvedVotes={totalResolvedVotes} />

This change would make the code more immediately understandable, especially for developers who might be less familiar with the object spread syntax in JSX.

subgraph/core/schema.graphql (1)

87-89: LGTM! Consider updating documentation for these changes.

The new fields totalCoherentVotes, totalResolvedVotes, and coherenceScore align well with the PR objective of fixing coherent votes at the vote level instead of the dispute level. This change provides more granular and accurate tracking of user voting behavior.

Consider the following suggestions:

  1. Update any existing documentation or comments that explain the User entity to reflect these new fields and the removal of totalCoherent.
  2. Ensure that the subgraph mappings are updated to calculate and populate these new fields correctly.
  3. If there's a README or schema documentation file, update it to explain the significance of these new fields and how they relate to user reputation or voting behavior.
subgraph/core/src/entities/User.ts (1)

Ensure coherenceScore is recalculated after resolving a dispute

The verification confirms that coherenceScore is not being updated in the resolveUserDispute function. To maintain accurate user metrics, please update coherenceScore appropriately when a dispute is resolved.

  • File: subgraph/core/src/entities/User.ts
  • Function: resolveUserDispute
🔗 Analysis chain

Line range hint 58-68: Ensure coherenceScore is recalculated after resolving a dispute

With the changes to resolveUserDispute, the function no longer updates the user's coherence metrics, such as totalCoherentVotes and coherenceScore. To maintain accurate user metrics, ensure that totalCoherentVotes and coherenceScore are updated appropriately when a dispute is resolved.

Run the following script to verify if coherenceScore is being updated elsewhere in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for updates to 'user.coherenceScore' after dispute resolution.

# Expected result: Find code where `user.coherenceScore` is recalculated after disputes are resolved.

rg --type typescript -A 5 'user\.coherenceScore\s*='

Length of output: 89


Script:

#!/bin/bash
# Description: Search for updates to 'user.coherenceScore' after dispute resolution using the correct file type.

# Corrected command with 'ts' as the file type.
rg --type ts -A 5 'user\.coherenceScore\s*='

Length of output: 320

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

148-151: Redundant non-null assertion after null check

In line 148, you check if (vote.choice === null) continue;, ensuring that vote.choice is not null. However, in line 151, you use the non-null assertion operator ! with vote.choice!.equals(dispute.currentRuling). Since you've already confirmed that vote.choice is not null, the ! operator is unnecessary.

Consider removing the non-null assertion operator to clean up the code:

-if (vote.choice!.equals(dispute.currentRuling)) {
+if (vote.choice.equals(dispute.currentRuling)) {

127-163: Add logging for missing entities

Throughout lines 127-163, the code continues to the next iteration if entities like round, draw, or vote are not found. While this prevents runtime errors, missing entities might indicate data inconsistencies.

Consider adding logging or error handling to capture these cases. This can help in diagnosing issues with data integrity:

if (!round) {
  // Log missing round
  console.warn(`Round not found: ${rounds[i].id}`);
  continue;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 22e1485 and 8613090.

📒 Files selected for processing (15)
  • subgraph/core/schema.graphql (1 hunks)
  • subgraph/core/src/KlerosCore.ts (2 hunks)
  • subgraph/core/src/entities/TokenAndEthShift.ts (1 hunks)
  • subgraph/core/src/entities/User.ts (2 hunks)
  • web/.env.devnet.public (1 hunks)
  • web/src/components/Popup/MiniGuides/JurorLevels.tsx (2 hunks)
  • web/src/hooks/queries/useTopUsersByCoherenceScore.ts (1 hunks)
  • web/src/hooks/queries/useUser.ts (1 hunks)
  • web/src/pages/Dashboard/JurorInfo/Coherency.tsx (2 hunks)
  • web/src/pages/Dashboard/JurorInfo/Header.tsx (2 hunks)
  • web/src/pages/Dashboard/JurorInfo/index.tsx (2 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx (1 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/DesktopCard.tsx (1 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/MobileCard.tsx (2 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/index.tsx (1 hunks)
🔇 Additional comments (28)
web/.env.devnet.public (1)

3-3: Subgraph URL update looks good, but needs verification.

The update to the REACT_APP_CORE_SUBGRAPH URL aligns with the PR objective of fixing coherent votes at the vote level. However, please consider the following points:

  1. Verify that the new subgraph (kleros-v2-test) owned by query ID 44313 is the correct one and has the necessary changes to support the new voting mechanism.
  2. Ensure that changing from "devnet" to "test" in the URL doesn't negatively impact the development workflow.
  3. Check if other parts of the application that depend on the core subgraph need updates to work with the new schema or resolvers.

To help verify the subgraph ownership and get more information about the changes, you can run the following commands:

✅ Verification successful

Subgraph URL update verified successfully.

The new subgraph (kleros-v2-test) is accessible, the schema matches the previous version, and there are no references to the old subgraph URL in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify subgraph ownership and changes

# Test 1: Check if the new subgraph exists and is accessible
echo "Checking new subgraph accessibility:"
curl -s -X POST -H "Content-Type: application/json" -d '{"query":"{_meta{block{number}}}"}' https://api.studio.thegraph.com/query/44313/kleros-v2-test/version/latest

# Test 2: Compare schema changes between old and new subgraphs
echo -e "\n\nComparing schema changes:"
OLD_SCHEMA=$(curl -s -X POST -H "Content-Type: application/json" -d '{"query":"query{__schema{types{name,fields{name}}}}"}' https://api.studio.thegraph.com/query/61738/kleros-v2-core-devnet/version/latest)
NEW_SCHEMA=$(curl -s -X POST -H "Content-Type: application/json" -d '{"query":"query{__schema{types{name,fields{name}}}}"}' https://api.studio.thegraph.com/query/44313/kleros-v2-test/version/latest)
echo "$OLD_SCHEMA" > old_schema.json
echo "$NEW_SCHEMA" > new_schema.json
diff -u old_schema.json new_schema.json || true
rm old_schema.json new_schema.json

# Test 3: Check for references to the old subgraph URL in the codebase
echo -e "\n\nChecking for references to the old subgraph URL:"
rg "https://api.studio.thegraph.com/query/61738/kleros-v2-core-devnet/version/latest" --type ts --type tsx --type js --type jsx

Length of output: 70331


Script:

#!/bin/bash
# Description: Re-verify references to the old subgraph URL using grep

echo "Re-checking for references to the old subgraph URL using grep:"

# Search through all relevant file types without relying on ripgrep's type definitions
grep -rnw '.' -e "https://api.studio.thegraph.com/query/61738/kleros-v2-core-devnet/version/latest" --include=\*.{ts,tsx,js,jsx}

# Alternatively, if grep is not available or for a broader search, omit the --include flag
# grep -rnw '.' -e "https://api.studio.thegraph.com/query/61738/kleros-v2-core-devnet/version/latest"

Length of output: 302

web/src/pages/Home/TopJurors/JurorCard/Coherency.tsx (4)

14-15: Improved clarity in interface property naming.

The renaming of totalCoherent to totalCoherentVotes and totalResolvedDisputes to totalResolvedVotes enhances clarity by explicitly referring to votes. This change aligns well with the PR objective of addressing coherent votes at the vote level instead of the dispute level.


18-18: Consistent update of component parameters.

The destructured parameters in the Coherency component have been correctly updated to match the new interface property names. This change maintains consistency with the interface updates and ensures type safety.


19-19: Coherence ratio calculation updated correctly.

The coherenceRatio calculation has been properly updated to use the new property names totalCoherentVotes and totalResolvedVotes. The calculation logic and format remain unchanged, ensuring consistency with the previous implementation while reflecting the new naming convention.


14-19: Overall improvement in code clarity and consistency.

The changes in this file successfully implement the PR objective of addressing coherent votes at the vote level. The renaming of interface properties and corresponding updates in the component improve code clarity without altering the underlying functionality. The consistency across the interface, component parameters, and ratio calculation demonstrates a thorough and well-executed refactoring.

web/src/pages/Home/TopJurors/JurorCard/index.tsx (1)

14-15: LGTM! Component updated correctly.

The JurorCard component has been properly updated to reflect the interface changes. The use of object shorthand in allProps is a good practice, making the code concise and readable.

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

15-16: LGTM! Verify impact on consuming components.

The changes to the GraphQL query improve clarity and align with the PR objective:

  1. Renaming totalCoherent to totalCoherentVotes is more explicit.
  2. Adding totalResolvedVotes supports the goal of fixing coherent votes at the vote level.

These modifications enhance the data structure without requiring changes to the hook implementation.

To ensure these changes don't introduce any regressions, please run the following script to identify components that might need updates:

✅ Verification successful

Verified! No remaining usages of the old totalCoherent field found in frontend components. The new totalCoherentVotes and totalResolvedVotes fields are correctly implemented across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find components that might be affected by the GraphQL query changes

# Search for components using the old field name
echo "Components potentially using the old 'totalCoherent' field:"
rg --type typescript --type tsx 'totalCoherent'

# Search for components that might need to use the new 'totalResolvedVotes' field
echo "Components that might benefit from using the new 'totalResolvedVotes' field:"
rg --type typescript --type tsx 'coherenceScore|totalCoherentVotes|totalResolvedDisputes'

Length of output: 513


Script:

#!/bin/bash
# Description: Find components that might be affected by the GraphQL query changes

# Search for components using the old field name
echo "Components potentially using the old 'totalCoherent' field:"
rg --glob '*.ts' --glob '*.tsx' 'totalCoherent'

# Search for components that might need to use the new 'totalResolvedVotes' field
echo "Components that might benefit from using the new 'totalResolvedVotes' field:"
rg --glob '*.ts' --glob '*.tsx' 'totalResolvedVotes'

Length of output: 8587

web/src/pages/Home/TopJurors/JurorCard/DesktopCard.tsx (2)

36-37: Improved property naming in IDesktopCard interface

The renaming of totalCoherent to totalCoherentVotes and totalResolvedDisputes to totalResolvedVotes enhances clarity and consistency. This change aligns well with the PR objective of addressing coherent votes at the vote level rather than the dispute level.


44-45: Consistent prop updates in DesktopCard component

The changes in the component's destructured props and the Coherency component prop passing are consistent with the interface updates. The use of the spread operator for passing props to the Coherency component is a clean and maintainable approach.

To ensure that these changes are consistently applied throughout the codebase, let's verify the usage of the DesktopCard component:

Also applies to: 53-53

✅ Verification successful

DesktopCard usage correctly updated with spread props

The usage of the DesktopCard component with spread props has been verified and aligns with the updated interface.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of DesktopCard component with updated prop names

# Test: Search for DesktopCard usage
rg --type typescript -A 5 '<DesktopCard'

Length of output: 1470


Script:

#!/bin/bash
# Description: Verify the usage of DesktopCard component with updated prop names

# Test: Search for DesktopCard usage in .tsx files
rg --type tsx '<DesktopCard'

Length of output: 58


Script:

#!/bin/bash
# Description: Verify the usage of DesktopCard component with updated prop names

# Test: Search for DesktopCard usage in .tsx files using glob pattern
rg '<DesktopCard' --glob '*.tsx'

Length of output: 119

web/src/pages/Dashboard/JurorInfo/Coherency.tsx (4)

33-34: Improved clarity in interface property names.

The renaming of totalCoherent to totalCoherentVotes and totalResolvedDisputes to totalResolvedVotes enhances clarity and precision. This change aligns well with the PR objective of addressing coherent votes at the vote level rather than the dispute level.


38-38: Component signature updated consistently.

The Coherency component signature has been correctly updated to use the new property names totalCoherentVotes and totalResolvedVotes. This change maintains consistency with the updates made to the ICoherency interface.


44-44: Consistent updates in component logic and rendering.

The changes correctly implement the new property names in both the display logic (line 44) and the progress calculation (line 54). The use of Math.max(totalResolvedVotes, 1) in the progress calculation is a good practice as it prevents division by zero when there are no resolved votes.

Also applies to: 54-54


33-34: Summary: Consistent implementation of vote-level coherency.

The changes in this file successfully implement the transition from dispute-level to vote-level coherency tracking. The updates to the interface, component signature, and rendering logic are consistent and improve the clarity of the code. The changes align well with the PR objective and maintain good coding practices, including proper handling of edge cases.

Also applies to: 38-38, 44-44, 54-54

web/src/pages/Dashboard/JurorInfo/index.tsx (2)

Line range hint 1-68: Summary of changes and final thoughts.

The changes in this file successfully implement the renaming of variables from dispute-level to vote-level counting, aligning with the PR objectives. The new names totalCoherentVotes and totalResolvedVotes are more precise and better reflect the data they represent.

A few minor suggestions have been made to improve readability and consistency. Additionally, it's important to ensure that these changes are propagated to the child components (Header and Coherency) if necessary.

Overall, the implementation is sound and improves the clarity of the code. Great job on making these updates!

As a final step, please run the verification script provided earlier to check if the Header and Coherency components need updating. If they do, consider creating a follow-up task to update those components for full consistency across the codebase.


57-57: Approve the changes with a suggestion for verification.

The use of the spread operator to pass the renamed variables to the child components is concise and effective. This change ensures that the new variable names are correctly propagated.

To ensure the changes are fully implemented, please verify that the Header and Coherency components are updated to use the new prop names totalCoherentVotes and totalResolvedVotes. Run the following script to check:

If the script returns results with the old prop names, those components will need to be updated as well.

Also applies to: 61-61

✅ Verification successful

Changes Verified Successfully.

The Header and Coherency components have been updated to use the new prop names totalCoherentVotes and totalResolvedVotes. No references to the old prop names were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that Header and Coherency components use the new prop names

# Test: Search for the old and new prop names in the Header component
echo "Checking Header component:"
rg --type typescript "(totalCoherent|totalResolvedDisputes|totalCoherentVotes|totalResolvedVotes)" web/src/pages/Dashboard/JurorInfo/Header.tsx

# Test: Search for the old and new prop names in the Coherency component
echo "Checking Coherency component:"
rg --type typescript "(totalCoherent|totalResolvedDisputes|totalCoherentVotes|totalResolvedVotes)" web/src/pages/Dashboard/JurorInfo/Coherency.tsx

Length of output: 496


Script:

#!/bin/bash
# Description: Verify that Header and Coherency components use the new prop names

# Test: Search for the old and new prop names in the Header component
echo "Checking Header component:"
rg --type typescriptreact "(totalCoherent|totalResolvedDisputes|totalCoherentVotes|totalResolvedVotes)" web/src/pages/Dashboard/JurorInfo/Header.tsx

# Test: Search for the old and new prop names in the Coherency component
echo "Checking Coherency component:"
rg --type typescriptreact "(totalCoherent|totalResolvedDisputes|totalCoherentVotes|totalResolvedVotes)" web/src/pages/Dashboard/JurorInfo/Coherency.tsx

Length of output: 516


Script:

#!/bin/bash
# Description: Verify that Header and Coherency components use the new prop names

# Test: Search for the old and new prop names in the Header component
echo "Checking Header component:"
rg --type tsx "(totalCoherent|totalResolvedDisputes|totalCoherentVotes|totalResolvedVotes)" web/src/pages/Dashboard/JurorInfo/Header.tsx

# Test: Search for the old and new prop names in the Coherency component
echo "Checking Coherency component:"
rg --type tsx "(totalCoherent|totalResolvedDisputes|totalCoherentVotes|totalResolvedVotes)" web/src/pages/Dashboard/JurorInfo/Coherency.tsx

Length of output: 468


Script:

#!/bin/bash
# Description: Verify that Header and Coherency components use the new prop names

# Test: Search for the old and new prop names in the Header component
echo "Checking Header component:"
rg "(totalCoherent|totalResolvedDisputes|totalCoherentVotes|totalResolvedVotes)" web/src/pages/Dashboard/JurorInfo/Header.tsx

# Test: Search for the old and new prop names in the Coherency component
echo "Checking Coherency component:"
rg "(totalCoherent|totalResolvedDisputes|totalCoherentVotes|totalResolvedVotes)" web/src/pages/Dashboard/JurorInfo/Coherency.tsx

Length of output: 1332

web/src/pages/Home/TopJurors/JurorCard/MobileCard.tsx (3)

78-79: Improved property naming in IMobileCard interface

The renaming of totalCoherent to totalCoherentVotes and totalResolvedDisputes to totalResolvedVotes enhances clarity and consistency. This change aligns well with the PR objective of addressing coherent votes at the vote level instead of the dispute level.


82-88: Updated MobileCard component parameters

The destructured parameters in the MobileCard functional component have been correctly updated to match the new interface property names. This change maintains consistency between the interface and the component implementation.


Line range hint 1-110: Summary of changes in MobileCard.tsx

The changes in this file consistently rename properties related to coherent votes and resolved votes across the IMobileCard interface, MobileCard component parameters, and Coherency component props. These updates improve clarity and align well with the PR objective of addressing coherent votes at the vote level.

The modifications enhance the overall consistency of the code and make the purpose of these properties more explicit. No major issues were identified, and the changes appear to be well-implemented.

web/src/pages/Dashboard/JurorInfo/Header.tsx (5)

68-69: Improved clarity in interface property names

The renaming of totalCoherent to totalCoherentVotes and totalResolvedDisputes to totalResolvedVotes enhances clarity by explicitly indicating that these values represent votes. This change aligns well with the PR objective of addressing coherent votes at the vote level instead of the dispute level.


72-72: Consistent update of component props

The Header component's function signature has been correctly updated to use the new prop names (totalCoherentVotes and totalResolvedVotes). This change maintains consistency with the updated IHeader interface.


75-77: Correct adaptation of calculations and text content

The calculations for coherencePercentage and the content of xPostText have been accurately updated to use the new prop names (totalCoherentVotes and totalResolvedVotes). This ensures that the displayed information correctly reflects the change from disputes to votes, maintaining consistency with the updated data model.


89-89: Consistent update of conditional rendering logic

The conditional rendering logic for the share link has been correctly updated to check totalResolvedVotes > 0 instead of totalResolvedDisputes > 0. This change maintains consistency with the renaming of props and the shift from disputes to votes, ensuring that the share link is only displayed when the user has resolved votes.


Line range hint 68-89: Summary: Successful implementation of vote-level coherence tracking

The changes in this file successfully implement the shift from dispute-level to vote-level coherence tracking. The updates include:

  1. Renaming interface properties for clarity
  2. Updating the component props to match the new interface
  3. Adapting calculations and text content to reflect the new vote-based model
  4. Adjusting conditional rendering logic for consistency

These changes are well-implemented, maintain consistency throughout the component, and align perfectly with the PR objectives. The modifications enhance the clarity and accuracy of the juror dashboard, providing a more precise representation of a juror's performance at the vote level.

subgraph/core/src/entities/TokenAndEthShift.ts (1)

32-32: LGTM! Verify the impact of the resolveUserDispute function change.

The modification to resolveUserDispute aligns with the PR objective of fixing coherent votes at the vote level instead of the dispute level. This change should improve the accuracy of vote coherence calculations.

To ensure this change doesn't introduce any unintended side effects, please run the following verification script:

This script will help ensure that:

  1. There are no remaining calls to resolveUserDispute with 3 parameters.
  2. All calls to resolveUserDispute now use 2 parameters.
  3. There are no pending TODO or FIXME comments related to this change.

Please review the results and make any necessary adjustments.

✅ Verification successful

Verified the resolveUserDispute function change. All usages have been updated to use 2 parameters, and no outstanding TODOs or FIXMEs related to this change were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of resolveUserDispute function across the codebase

# Test 1: Check for any remaining calls to resolveUserDispute with 3 parameters
echo "Checking for calls to resolveUserDispute with 3 parameters:"
rg --type typescript 'resolveUserDispute\([^)]+,[^)]+,[^)]+\)'

# Test 2: Verify that all calls to resolveUserDispute now use 2 parameters
echo "Verifying calls to resolveUserDispute with 2 parameters:"
rg --type typescript 'resolveUserDispute\([^,]+,[^)]+\)'

# Test 3: Check for any TODO or FIXME comments related to this change
echo "Checking for related TODO or FIXME comments:"
rg --type typescript -e 'TODO.*resolveUserDispute' -e 'FIXME.*resolveUserDispute'

Length of output: 663


Script:

#!/bin/bash
# Description: Verify the usage of resolveUserDispute function across the codebase with corrected file type

# Test 1: Check for any remaining calls to resolveUserDispute with 3 parameters
echo "Checking for calls to resolveUserDispute with 3 parameters:"
rg --type ts 'resolveUserDispute\([^)]+,[^)]+,[^)]+\)'

# Test 2: Verify that all calls to resolveUserDispute now use 2 parameters
echo "Verifying calls to resolveUserDispute with 2 parameters:"
rg --type ts 'resolveUserDispute\([^,]+,[^)]+\)'

# Test 3: Check for any TODO or FIXME comments related to this change
echo "Checking for related TODO or FIXME comments:"
rg --type ts -e 'TODO.*resolveUserDispute' -e 'FIXME.*resolveUserDispute'

Length of output: 762

web/src/components/Popup/MiniGuides/JurorLevels.tsx (3)

66-67: Improved property naming in userLevelData

The changes to the property names in the userLevelData array enhance clarity and align with the PR objectives. Renaming totalCoherent to totalCoherentVotes and totalResolvedDisputes to totalResolvedVotes more accurately reflects that these metrics are tracked at the vote level rather than the dispute level.

Also applies to: 72-73, 78-79, 84-85, 90-91


117-118: Consistent property usage in RightContent component

The changes in the RightContent component correctly reflect the updates made to the userLevelData array. The prop names passed to the Coherency component now match the updated property names, ensuring consistency throughout the component.


117-118: Verify changes in related components

While the changes in this file look good, it's important to ensure that the Coherency component and any other parts of the codebase that might be using these properties have been updated accordingly.

Please run the following script to check for any occurrences of the old property names in the codebase:

This will help ensure that all related components and functions have been updated to use the new property names.

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

134-135: Verify that 'drawnJurors.load()' returns the correct data

In line 134, const draws = round.drawnJurors.load();, ensure that drawnJurors.load() returns an array of draw IDs or objects as expected. If not, additional handling may be required to iterate over the drawn jurors correctly.

Run the following script to check the structure of drawnJurors:

✅ Verification successful

Verified: drawnJurors.load() returns the correct data structure

The analysis confirms that drawnJurors.load() consistently returns an array of draw objects, allowing for proper iteration and handling within the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the structure of 'drawnJurors' in 'Round' entities.

# Test: Search for the definition of 'drawnJurors' and check its type.
rg --type typescript 'drawnJurors' -A 5

# Expected: 'drawnJurors' should be a collection that can be loaded and iterated as an array.

Length of output: 74


Script:

#!/bin/bash
# Description: Verify the structure of 'drawnJurors' in 'Round' entities.

# Corrected Test: Search for the definition of 'drawnJurors' in TypeScript files.
rg --type ts 'drawnJurors' -A 5

Length of output: 23891

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 8613090 and 61bffc7.

📒 Files selected for processing (6)
  • web/src/pages/Dashboard/JurorInfo/index.tsx (1 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/DesktopCard.tsx (2 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/JurorLevel.tsx (1 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/MobileCard.tsx (2 hunks)
  • web/src/pages/Home/TopJurors/JurorCard/index.tsx (1 hunks)
  • web/src/utils/userLevelCalculation.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • web/src/pages/Dashboard/JurorInfo/index.tsx
  • web/src/pages/Home/TopJurors/JurorCard/DesktopCard.tsx
  • web/src/pages/Home/TopJurors/JurorCard/MobileCard.tsx
  • web/src/pages/Home/TopJurors/JurorCard/index.tsx
🔇 Additional comments (6)
web/src/pages/Home/TopJurors/JurorCard/JurorLevel.tsx (4)

43-43: LGTM: Addition of totalResolvedDisputes to IJurorLevel interface

The addition of totalResolvedDisputes: number to the IJurorLevel interface is appropriate and aligns with the PR objective to improve juror level calculations.


46-46: LGTM: Updated JurorLevel component props

The JurorLevel component signature has been correctly updated to include the new totalResolvedDisputes prop, maintaining consistency with the interface changes.


Line range hint 1-58: Summary: Changes are well-implemented and align with PR objectives

The modifications to the JurorLevel component, including the interface update, prop changes, and function call adjustment, are consistent and well-implemented. These changes support the PR's objective of improving juror level calculations by incorporating the totalResolvedDisputes data.

To ensure full consistency across the codebase, please run the provided verification script and address any issues it may uncover.


47-47: LGTM: Updated getUserLevelData function call

The getUserLevelData function call has been correctly updated to include the new totalResolvedDisputes argument, which is consistent with the changes to improve juror level calculations.

To ensure the changes are implemented correctly throughout the codebase, please run the following verification script:

This script will help verify that:

  1. The getUserLevelData function has been updated to accept two parameters.
  2. There are no remaining calls to getUserLevelData with only one argument, which would indicate missed updates.
web/src/utils/userLevelCalculation.ts (2)

2-6: Level titles are well-defined and meaningful.

The levelTitles array is appropriately updated with clear and thematic titles.


14-15: Verify that all coherency score ranges are adequately covered.

The condition coherencyScore >= 0 && coherencyScore <= 70 might overlap with other conditions or leave certain score ranges unaccounted for. Ensure that all possible values of coherencyScore are covered without gaps or overlaps to prevent incorrect level assignments.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 7, 2024
@kemuru kemuru marked this pull request as ready for review October 7, 2024 08:31
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)
subgraph/core/src/KlerosCore.ts (1)

Line range hint 269-273: LGTM: Improved tracking of juror drawing completion.

The addition of the jurorsDrawn status check is a valuable improvement. It allows for accurate tracking of when all jurors for a round have been drawn.

Consider a minor optimization to avoid unnecessary saves:

- if (currentRound.nbVotes.toI32() === currentRound.drawnJurors.load().length) {
+ if (!currentRound.jurorsDrawn && currentRound.nbVotes.toI32() === currentRound.drawnJurors.load().length) {
    currentRound.jurorsDrawn = true;
    currentRound.save();
  }

This change ensures that we only update and save the round when the jurorsDrawn status actually changes, potentially reducing unnecessary database writes.

🧰 Tools
🪛 Biome

[error] 28-28: Do not shadow the global "BigInt" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 061b22a and 8c2903e.

📒 Files selected for processing (2)
  • subgraph/core/schema.graphql (1 hunks)
  • subgraph/core/src/KlerosCore.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • subgraph/core/schema.graphql
🧰 Additional context used
🔇 Additional comments (2)
subgraph/core/src/KlerosCore.ts (2)

27-27: LGTM: Import changes are appropriate.

The addition of the ClassicVote import aligns with the new functionality implemented in the handleNewPeriod function. This change is consistent with the PR objectives of updating vote handling at the vote level.


127-128: LGTM: Improved data consistency with earlier dispute save.

Moving the dispute.save() call earlier in the function ensures that the dispute entity is updated with the current ruling information before processing individual votes. This change improves data consistency and adheres to the best practice of updating entities as soon as their properties change.

@kemuru kemuru requested a review from alcercu October 7, 2024 08:45
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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8c2903e and 9ada434.

📒 Files selected for processing (1)
  • subgraph/core/src/KlerosCore.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (1)
subgraph/core/src/KlerosCore.ts (1)

27-27: LGTM: New import aligns with PR objectives

The addition of the ClassicVote import is consistent with the PR's goal of implementing vote-level coherence tracking.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9ada434 and 4b2ab71.

📒 Files selected for processing (2)
  • subgraph/core/schema.graphql (1 hunks)
  • subgraph/core/src/KlerosCore.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • subgraph/core/schema.graphql
🧰 Additional context used
🔇 Additional comments (1)
subgraph/core/src/KlerosCore.ts (1)

27-27: LGTM: Import changes are consistent with new functionality.

The addition of ClassicVote import aligns with its usage in the updated "execution" period handling logic.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 952ccf0 and 3a61b38.

📒 Files selected for processing (3)
  • subgraph/core/src/KlerosCore.ts (2 hunks)
  • subgraph/core/src/entities/User.ts (3 hunks)
  • subgraph/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • subgraph/package.json
🧰 Additional context used
🔇 Additional comments (6)
subgraph/core/src/entities/User.ts (3)

5-9: LGTM! Past review comment addressed.

The computeCoherenceScore function has been successfully updated to use totalCoherentVotes and totalResolvedVotes, addressing the past review comment. The changes are consistent with the PR objectives and maintain the correct logic.


39-40: LGTM! Improved clarity in user metrics.

The changes in createUserFromAddress function align well with the PR objectives:

  1. Renaming totalCoherent to totalCoherentVotes enhances clarity.
  2. Adding totalResolvedVotes provides a more comprehensive set of user metrics.

These modifications will contribute to better tracking and understanding of user performance in dispute resolution.


58-66: LGTM! Simplified dispute resolution logic.

The resolveUserDispute function has been successfully simplified:

  1. Removed previousFeeAmount and feeAmount parameters, streamlining the function signature.
  2. Eliminated fee-based coherence adjustments, aligning with the shift to vote-level coherence scoring.
  3. Maintained core functionality of marking disputes as resolved.

These changes improve clarity and focus of the function. However, it's worth noting that real-time coherence updates during dispute resolution have been removed.

To ensure this change doesn't negatively impact the system, please verify:

  1. The coherence score is still being updated correctly elsewhere in the codebase.
  2. There are no unintended consequences from removing real-time coherence updates during dispute resolution.

You can use the following script to check for coherence score updates in other parts of the codebase:

subgraph/core/src/KlerosCore.ts (3)

22-22: LGTM: Import changes are consistent with new functionality.

The addition of ClassicVote import and computeCoherenceScore function import align well with the new vote processing logic implemented in the handleNewPeriod function.

Also applies to: 27-27


Line range hint 1-164: Summary of review findings

The changes in this file successfully implement vote-level coherence tracking, aligning with the PR objectives. Key points from the review:

  1. The new imports are consistent with the added functionality.
  2. The vote processing logic in handleNewPeriod correctly updates juror statistics but could benefit from performance optimizations.
  3. The vote entity loading mechanism could be more flexible to accommodate future DisputeKit types.
  4. The coherence score calculation needs verification to ensure it includes the necessary smoothing factor.

These changes significantly enhance the voting and dispute resolution processes. Addressing the suggested optimizations and verifications will further improve the code's efficiency and maintainability.


158-160: Verify coherence score calculation includes smoothing factor

The coherence score calculation uses the computeCoherenceScore function, which is a good practice for maintainability. However, a past review comment indicates that a smoothing factor might be missing from this calculation.

Please ensure that the computeCoherenceScore function includes the necessary smoothing factor as mentioned in the linked comment. You can verify this by running the following script:

If the smoothing factor is indeed missing, consider updating the function to include it. The smoothing factor helps to prevent extreme coherence scores for jurors with a low number of votes.

alcercu
alcercu previously approved these changes Oct 7, 2024
Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

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

lgtm

@alcercu alcercu enabled auto-merge October 7, 2024 11:40
@kemuru kemuru disabled auto-merge October 7, 2024 11:52
Copy link

codeclimate bot commented Oct 7, 2024

Code Climate has analyzed commit 38efc1b and detected 17 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 5
Duplication 4
Style 8

View more on Code Climate.

Copy link

sonarqubecloud bot commented Oct 7, 2024

@alcercu alcercu enabled auto-merge October 7, 2024 11:59
@alcercu alcercu added this pull request to the merge queue Oct 7, 2024
Merged via the queue into dev with commit da331f7 Oct 7, 2024
13 of 23 checks passed
@jaybuidl jaybuidl deleted the feat(subgraph,web)/calculate-coherency-at-vote-level branch October 8, 2024 16:17
@coderabbitai coderabbitai bot mentioned this pull request Dec 31, 2024
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.

2 participants