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

added reject status #173

Open
wants to merge 3 commits into
base: testnets
Choose a base branch
from
Open

added reject status #173

wants to merge 3 commits into from

Conversation

madhurMongia
Copy link
Contributor

@madhurMongia madhurMongia commented Dec 29, 2024

Summary by CodeRabbit

  • New Features

    • Added support for tracking request rejection status.
    • Enhanced request status display logic to show "Rejected" state.
  • Bug Fixes

    • Improved status representation for resolved requests without winning claims.
  • Refactor

    • Updated status handling across multiple components to support new rejection state.
    • Modified utility function to handle more complex status scenarios.
    • Streamlined expiration logic for resolved requests.
  • Style

    • Introduced new color definitions and CSS classes for "rejected" status in light and dark themes.

Copy link
Contributor

coderabbitai bot commented Dec 29, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/app/[pohid]/[chain]/[request]/ActionBar.tsx

Oops! Something went wrong! :(

ESLint: 9.18.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

Walkthrough

The pull request introduces a new rejected property to handle request status representation across multiple components. This change modifies the ActionBar, request page, and request card components to conditionally display status messages based on whether a request has been resolved without a winning claim. The camelToTitle utility function has been updated to support this new status condition, providing more nuanced status reporting throughout the application. Additionally, the Tailwind CSS configuration has been updated to include new color definitions for the "rejected" status, along with corresponding CSS classes.

Changes

File Change Summary
src/app/[pohid]/[chain]/[request]/ActionBar.tsx Added rejected prop to ActionBarProps interface
src/app/[pohid]/[chain]/[request]/page.tsx Introduced rejected variable to determine request resolution status
src/components/Request/Card.tsx Added rejected boolean to modify status display logic
src/utils/case.ts Updated camelToTitle function signature to include rejected parameter
src/config/misc.ts Updated colorForStatus function to include rejected parameter
tailwind.config.cjs Added new colors and safelist entries for rejected status
src/app/globals.css Added new CSS classes for text-status-rejected and bg-status-rejected

Sequence Diagram

sequenceDiagram
    participant Page as Request Page
    participant Card as Request Card
    participant ActionBar as Action Bar
    participant Util as Case Utility

    Page->>Card: Pass request details
    Card->>Util: Call camelToTitle with rejected status
    Util-->>Card: Return formatted status
    Card->>ActionBar: Pass rejected status
    ActionBar->>ActionBar: Render status based on rejected flag
Loading

Poem

🐰 A Rabbit's Ode to Request Status

Rejected or accepted, the tale unfolds,
With flags and statuses, our logic takes hold,
A boolean whisper, a conditional dance,
Transforming requests with a magical glance,
Code hops and skips, with nuanced delight! 🎉


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>, 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 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 Dec 29, 2024

Deploy Preview for proof-of-humanity-v2 ready!

Name Link
🔨 Latest commit 3184edc
🔍 Latest deploy log https://app.netlify.com/sites/proof-of-humanity-v2/deploys/6787b0616e3aef0008869a3f
😎 Deploy Preview https://deploy-preview-173--proof-of-humanity-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.

@madhurMongia madhurMongia linked an issue Dec 29, 2024 that may be closed by this pull request
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

🧹 Nitpick comments (3)
src/utils/case.ts (1)

30-36: Consider refactoring nested ternaries for readability.

While the logic is functionally correct, the layered conditional can be harder to maintain. Consider an if-else chain or a small helper function to improve clarity and maintainability.

src/components/Request/Card.tsx (1)

113-114: Remove or replace direct console log for production.

The console.log(rejected) statement is useful for debugging but might cause noise in production logs. Consider either removing it or wrapping it in a debug-logging mechanism.

src/app/[pohid]/[chain]/[request]/ActionBar.tsx (1)

469-469: Pass rejected parameter explicitly.

Including the rejected argument in disputed status messages is consistent with the newly introduced condition. If no logic changes for disputed statuses, consider whether rejected is relevant here or safe to omit.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e4ac1a and 82a72bd.

📒 Files selected for processing (4)
  • src/app/[pohid]/[chain]/[request]/ActionBar.tsx (5 hunks)
  • src/app/[pohid]/[chain]/[request]/page.tsx (2 hunks)
  • src/components/Request/Card.tsx (2 hunks)
  • src/utils/case.ts (2 hunks)
🔇 Additional comments (6)
src/utils/case.ts (1)

5-5: Ensure optional parameter aligns with naming consistency.

The new rejected parameter is clearly optional, which helps maintain backward compatibility. However, confirm that its naming is consistent with other optional parameters (e.g., revocation vs. rejected) so that future readers can easily understand the logical grouping.

src/components/Request/Card.tsx (1)

128-128: Confirm consistent usage of rejected across the app.

Adding rejected to camelToTitle is consistent with the new status logic. Ensure all calls to this function in the codebase correctly handle or pass the rejected argument.

src/app/[pohid]/[chain]/[request]/ActionBar.tsx (3)

63-63: Interface updated correctly to include rejected.

This aligns with the new logic introduced in other components. Good job maintaining a single source of truth for the props needed to display statuses.


307-307: Use the new parameter consistently.

The addition of rejected to the camelToTitle call ensures a consistent display across components. Confirm calls to camelToTitle match the same signature to avoid potential runtime errors.


506-508: Status text enhancements look correct.

Conditionally displaying “Request was accepted” or “Request was rejected” clarifies the resolved state to users. If you plan to localize or further customize these strings, consider a centralized solution for status messages.

src/app/[pohid]/[chain]/[request]/page.tsx (1)

85-86: Check for edge cases in rejected logic.

The condition request.status.id === "resolved" combined with a missing winning claim is valid. However, if winnerClaim is empty or undefined in edge scenarios, verify that no runtime errors occur.

@madhurMongia madhurMongia linked an issue Dec 30, 2024 that may be closed by this pull request
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

🧹 Nitpick comments (2)
src/config/misc.ts (1)

33-33: Use nested ternaries sparingly for better readability.

While the logic is correct, consider refactoring to a clear if-else chain or a switch statement for better readability.

-case "resolved":
-  return revocation ? "removed" : expired ? "expired" : rejected ? "rejected" : "registered";
+case "resolved": {
+  if (revocation) return "removed";
+  if (expired) return "expired";
+  if (rejected) return "rejected";
+  return "registered";
+}
src/components/Request/Grid.tsx (1)

101-103: Simplify the resolved expiration logic.

Multiple consecutive return false; statements may be simplified. For instance, combining them into a single return statement or clarifying conditions can improve readability.

-      return false;
-    }
-  return false;
...
-  return false;
+      return false; // Provide a single consolidated exit path if conditions fail

Also applies to: 111-111

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82a72bd and f6ec16e.

📒 Files selected for processing (7)
  • src/app/[pohid]/[chain]/[request]/ActionBar.tsx (5 hunks)
  • src/app/[pohid]/[chain]/[request]/page.tsx (3 hunks)
  • src/components/Request/Card.tsx (2 hunks)
  • src/components/Request/Grid.tsx (1 hunks)
  • src/config/misc.ts (2 hunks)
  • src/utils/case.ts (2 hunks)
  • tailwind.config.cjs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/utils/case.ts
  • src/components/Request/Card.tsx
  • src/app/[pohid]/[chain]/[request]/ActionBar.tsx
🔇 Additional comments (5)
src/config/misc.ts (1)

20-20: Ensure consistent function signature usage in calling code.

You've introduced a new boolean parameter rejected to colorForStatus. Make sure all call sites include and properly handle this parameter.

tailwind.config.cjs (2)

34-34: Good addition of “rejected” color codes.

Explicitly adding rejected status color tokens in both light and dark themes helps keep the design consistent.

Also applies to: 58-58


112-114: Successfully extending safelist classes for "rejected" status.

This ensures that Tailwind doesn’t purge these classes and that the rejected status is visually represented.

src/components/Request/Grid.tsx (1)

93-93: Validate logic for expired requests.

Line 93 extends the logic for "transferring" status. When transferring, the request is considered expired if (creationTime + humanityLifespan) < currentTime. Then line 100 returns false for non-handled cases. Ensure no status inadvertently skips the expiration check.

Also applies to: 100-100

src/app/[pohid]/[chain]/[request]/page.tsx (1)

85-86: Propagate the “rejected” status carefully.

This new logic identifies requests that are resolved but not the winner claim as “rejected.” Verify all usage sites to ensure the UI & business rules align with the intended behavior.

Comment on lines +101 to +103
return false;
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Double-check default expiration outcomes.

Defaulting to false when not matching “transferring” or a recognized scenario may lead to never-expiring requests if unhandled statuses arise. Revisit your acceptance criteria to confirm this logic.

...
} else if (request.status.id === "transferring") {
    return ...
}
- return false;
+ // Consider an explicit return for each known status,
+ // or handle an unknown status with a default branch if needed.
  return false;

Also applies to: 111-111

@madhurMongia madhurMongia force-pushed the bug/add-reject-status branch from cc14d44 to f832d71 Compare January 15, 2025 09:40
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

🧹 Nitpick comments (1)
src/app/[pohid]/page.tsx (1)

167-173: Simplify the past requests filtering logic.

The filtering condition is complex and could be simplified for better readability.

Consider refactoring to:

-                ) && 
-                (!(
-                  winnerClaimData.request &&
-                  req.index === winnerClaimData.request.index &&
-                  chain.id === winnerClaimData.chainId
-                ) || 
-                  !winnerClaimData.request),
+                ) && (
+                  !winnerClaimData.request || 
+                  req.index !== winnerClaimData.request.index || 
+                  chain.id !== winnerClaimData.chainId
+                ),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc14d44 and 3184edc.

📒 Files selected for processing (9)
  • src/app/[pohid]/[chain]/[request]/ActionBar.tsx (6 hunks)
  • src/app/[pohid]/[chain]/[request]/page.tsx (3 hunks)
  • src/app/[pohid]/page.tsx (1 hunks)
  • src/app/globals.css (2 hunks)
  • src/components/Request/Card.tsx (2 hunks)
  • src/components/Request/Grid.tsx (1 hunks)
  • src/config/misc.ts (2 hunks)
  • src/utils/case.ts (2 hunks)
  • tailwind.config.cjs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/components/Request/Grid.tsx
  • src/app/[pohid]/[chain]/[request]/page.tsx
  • src/config/misc.ts
  • src/components/Request/Card.tsx
  • tailwind.config.cjs
  • src/utils/case.ts
  • src/app/[pohid]/[chain]/[request]/ActionBar.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/app/globals.css

[error] 212-212: Unexpected unknown function: theme

Use a known function instead.
See MDN web docs for more details.

(lint/correctness/noUnknownFunction)


[error] 216-216: Unexpected unknown function: theme

Use a known function instead.
See MDN web docs for more details.

(lint/correctness/noUnknownFunction)


[error] 374-374: Unexpected unknown function: theme

Use a known function instead.
See MDN web docs for more details.

(lint/correctness/noUnknownFunction)


[error] 378-378: Unexpected unknown function: theme

Use a known function instead.
See MDN web docs for more details.

(lint/correctness/noUnknownFunction)

🔇 Additional comments (2)
src/app/globals.css (2)

211-217: LGTM! Text color utilities for rejected status are well implemented.

The implementation follows the established pattern and correctly handles both light and dark themes.

🧰 Tools
🪛 Biome (1.9.4)

[error] 212-212: Unexpected unknown function: theme

Use a known function instead.
See MDN web docs for more details.

(lint/correctness/noUnknownFunction)


[error] 216-216: Unexpected unknown function: theme

Use a known function instead.
See MDN web docs for more details.

(lint/correctness/noUnknownFunction)


373-379: Verify theme color definitions for rejected status.

The background color utilities are well-implemented and follow the established pattern. However, we should ensure that the corresponding color values are properly defined in the theme configuration.

✅ Verification successful

Theme colors for rejected status are properly configured

The rejected status colors are correctly defined in both themes:

  • Light theme: #D90429
  • Dark theme: #F25F5F
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the rejected status colors are defined in the theme configuration

# Look for theme color definitions in tailwind config
rg -A 2 "colors.*status.*rejected" tailwind.config.*

Length of output: 56


Script:

#!/bin/bash
# First, find all potential theme configuration files
echo "=== Theme Configuration Files ==="
fd -e js -e cjs -e ts -e mjs "tailwind.config"

# Then, examine the complete theme structure in these files
echo -e "\n=== Theme Color Definitions ==="
rg -A 10 "colors.*=.*{" 

# Specifically look for status-related color definitions
echo -e "\n=== Status Color Definitions ==="
rg -A 5 "status.*[:=]"

Length of output: 36006


Script:

#!/bin/bash
# Get the complete theme configuration section from tailwind.config.cjs
echo "=== Complete Theme Configuration ==="
rg -A 30 "theme.*=.*{" tailwind.config.cjs

# Also search for any "rejected" related configurations
echo -e "\n=== Rejected Related Configurations ==="
rg "rejected" tailwind.config.cjs

Length of output: 492

🧰 Tools
🪛 Biome (1.9.4)

[error] 374-374: Unexpected unknown function: theme

Use a known function instead.
See MDN web docs for more details.

(lint/correctness/noUnknownFunction)


[error] 378-378: Unexpected unknown function: theme

Use a known function instead.
See MDN web docs for more details.

(lint/correctness/noUnknownFunction)

Comment on lines +177 to +185
expired:
req.status.id === "resolved"
? (!req.revocation &&
winnerClaimData?.request?.index === req.index &&
(! humanity[chain.id]!.humanity!.registration ||
Number(humanity[chain.id]!.humanity!.registration?.expirationTime) < Date.now() / 1000))
: req.status.id === "transferring"
? (Number(req.creationTime) + Number(contractData[chain.id].humanityLifespan) < Date.now() / 1000)
: false
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve readability of expiration status calculation.

The nested ternary operators and complex conditions make the code hard to read and maintain.

Consider refactoring to a more readable format:

-              expired: 
-                req.status.id === "resolved" 
-                  ? (!req.revocation && 
-                     winnerClaimData?.request?.index === req.index &&
-                     (! humanity[chain.id]!.humanity!.registration ||
-                      Number(humanity[chain.id]!.humanity!.registration?.expirationTime) < Date.now() / 1000))
-                  : req.status.id === "transferring"
-                    ? (Number(req.creationTime) + Number(contractData[chain.id].humanityLifespan) < Date.now() / 1000)
-                    : false
+              expired: calculateExpiration(req, {
+                status: req.status.id,
+                chainId: chain.id,
+                humanity: humanity[chain.id]!.humanity!,
+                contractData: contractData[chain.id],
+                winnerClaimData
+              })

And create a helper function:

function calculateExpiration(
  req: Request,
  {
    status,
    chainId,
    humanity,
    contractData,
    winnerClaimData
  }: CalculateExpirationParams
): boolean {
  if (status === "resolved") {
    const isWinnerClaim = winnerClaimData?.request?.index === req.index;
    const hasNoRevocation = !req.revocation;
    const isRegistrationExpired = !humanity.registration || 
      Number(humanity.registration.expirationTime) < Date.now() / 1000;
    
    return hasNoRevocation && isWinnerClaim && isRegistrationExpired;
  }
  
  if (status === "transferring") {
    const expirationTime = Number(req.creationTime) + 
      Number(contractData.humanityLifespan);
    return expirationTime < Date.now() / 1000;
  }
  
  return false;
}

}))
: []),
],
[] as PoHRequest[],
),
);

console.log(pastRequests.map(req => req.status.id));
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove debug console.log statement.

Debug logging should not be committed to production code. If logging is needed for debugging purposes, consider using a proper logging framework with appropriate log levels.

-  console.log(pastRequests.map(req => req.status.id));

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.

Rejected claims appear as "expired"
2 participants