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

Testnets #118

Merged
merged 2 commits into from
Oct 28, 2024
Merged

Testnets #118

merged 2 commits into from
Oct 28, 2024

Conversation

martillansky
Copy link
Contributor

@martillansky martillansky commented Oct 28, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced handling of vouches, now supporting off-chain vouches based on request status.
    • Improved UI rendering to accurately display the current state of vouches.
  • Bug Fixes

    • Streamlined logic for checking vouch validity, ensuring better clarity between on-chain and off-chain vouches.
  • Refactor

    • Optimized data retrieval processes and control flow for vouch handling.

Copy link

coderabbitai bot commented Oct 28, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the page.tsx file, focusing on how vouches are handled and retrieved. The logic for processing on-chain and off-chain vouches has been updated, removing previous references to request.claimer.vouchesReceived. Instead, the code now fetches off-chain vouches based on the request's status. The prepareVouchData function has been refined to enhance clarity in vouch validity checks and streamline the rendering of vouches in the UI.

Changes

File Path Change Summary
src/app/[pohid]/[chain]/[request]/page.tsx Updated import statement and modified logic to handle off-chain vouches, streamlining vouch processing and rendering. Adjusted prepareVouchData for clarity in vouch validity checks.

Possibly related PRs

  • Testnets #116: The changes in page.tsx regarding the handling of vouches and the prepareVouchData function are related to the modifications made in the same file in this PR, which also focuses on streamlining vouch handling and improving the clarity of the vouch data preparation process.

Poem

In the burrow where vouches play,
Off-chain whispers lead the way.
With clarity, we fetch and show,
The data flows, a gentle glow.
Hopping through code, we dance and cheer,
For every change, our path is clear! 🐇✨


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 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 Oct 28, 2024

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

Name Link
🔨 Latest commit 2e0cd4d
🔍 Latest deploy log https://app.netlify.com/sites/proof-of-humanity-v2/deploys/671ffa763b68f700083a1c49
😎 Deploy Preview https://deploy-preview-118--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.

Copy link

@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

🧹 Outside diff range and nitpick comments (4)
src/app/[pohid]/[chain]/[request]/page.tsx (4)

Line range hint 75-93: Cleanup commented code and simplify expiration logic

The hasExpired function contains commented-out code and nested conditions that could be simplified for better readability.

Consider refactoring to:

 const hasExpired = () => {
   if (request.status.id === "resolved") {
     if (!request.revocation && request.humanity.winnerClaim.length > 0) {
       if (request.humanity.winnerClaim[0].index === request.index) {
         if (!!contractData.humanityLifespan) {
-          return (
-            /* (Number(request.humanity.winnerClaim[0].resolutionTime) > 0 && 
-              Number(request.humanity.winnerClaim[0].resolutionTime) + Number(contractData.humanityLifespan) < Date.now() / 1000) || 
-              (Number(request.creationTime) + Number(contractData.humanityLifespan) < Date.now() / 1000) ||  */
-            !request.humanity.registration ||
-            Number(request.humanity.registration?.expirationTime) <
-              Date.now() / 1000
-          );
+          return !request.humanity.registration || 
+                 Number(request.humanity.registration?.expirationTime) < Date.now() / 1000;
         }
       } else return true;
     }
   } else if (request.status.id === "transferring") {
     return Number(request.creationTime) + Number(contractData.humanityLifespan) < Date.now() / 1000;
   }
   return true;
 };

Line range hint 146-196: Improve error handling and promise management in vouch preparation

The prepareVouchData function has several areas that could be improved:

  1. Empty catch block silently swallows errors
  2. Complex promise chains could be simplified using async/await
  3. Potential undefined access in chain finding logic

Consider these improvements:

 const prepareVouchData = (
   rawVouches: Record<SupportedChainId, ClaimerQuery>[],
   isOnChain: boolean,
   skipStatusCheck: boolean,
 ): Promise<VouchData>[] => {
   return rawVouches.map(async (rawVoucher) => {
     const out: VouchData = {
       voucher: undefined,
       name: undefined,
       pohId: undefined,
       photo: undefined,
       vouchStatus: undefined,
       isOnChain: isOnChain,
     };
     try {
       const voucherEvidenceChain = supportedChains.find(
         (chain) =>
-          rawVoucher[chain.id].claimer &&
-          rawVoucher[chain.id].claimer?.registration?.humanity.winnerClaim,
+          rawVoucher[chain.id]?.claimer?.registration?.humanity?.winnerClaim?.length > 0
       );
       const relevantChain = voucherEvidenceChain ?? chain;

       const claimer = rawVoucher[relevantChain.id]?.claimer;
       if (!claimer) return out;

       out.name = claimer.name;
       out.voucher = claimer.id;
       out.pohId = claimer.registration?.humanity.id ?? out.voucher;

       const uri = claimer.registration?.humanity.winnerClaim
         ?.at(0)
         ?.evidenceGroup.evidence.at(0)?.uri;

       if (!skipStatusCheck) {
         out.vouchStatus = isOnChain
           ? isValidOnChainVouch(
               request.claimer.vouchesReceived.find(
                 (v) => v.from.id === out.voucher!,
               )! as VouchQuery,
             )
           : await isValidVouch(
               chain.id,
               out.voucher!,
               offChainVouches.find(
                 (vouch) => vouch.voucher === claimer.id,
               )?.expiration,
             );
       }

       if (!uri) return out;

       const evFile = await ipfsFetch<EvidenceFile>(uri);
       if (!evFile?.fileURI) return out;

       const regFile = await ipfsFetch<RegistrationFile>(evFile.fileURI);
       out.photo = regFile.photo;
       return out;
-    } catch {
+    } catch (error) {
+      console.error('Error preparing vouch data:', error);
       return out;
     }
   });
 };

Line range hint 315-316: Add error handling for video playback

The video element should handle potential loading errors gracefully.

Consider adding error handling:

 {registrationFile && (
   <video
     className="w-full"
     src={ipfs(registrationFile.video)}
     controls
+    onError={(e) => {
+      console.error('Error loading video:', e);
+      e.currentTarget.style.display = 'none';
+    }}
   />
 )}

Line range hint 343-362: Clean up policy tooltip and improve readability

The tooltip contains commented-out code and could benefit from better formatting.

Consider this cleanup:

 <div className="text-primaryText group relative flex py-[8px]">
   Policy in force at submission
   <div className="invisible absolute left-1/2 z-10 m-4 mx-auto w-[260px] flex-shrink-0 -translate-x-1/2 transform place-content-center content-between rounded-[3px] border-[1px] border-[solid] bg-[var(--Light-Mode-White-background,_#FFF)] p-[8px] text-justify text-[14px] font-normal not-italic leading-[normal] outline-black transition-opacity ease-in-out [box-shadow:0px_2px_3px_0px_rgba(0,_0,_0,_0.06)] group-hover:visible md:w-[400px]">
     <span>
-      {/* (Policy in force since {new Date(policyUpdate * 1000).toDateString()}) */}
       This is the policy that was in effect when this submission was made...
     </span>
   </div>
 </div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5497fb3 and 2e0cd4d.

📒 Files selected for processing (1)
  • src/app/[pohid]/[chain]/[request]/page.tsx (1 hunks)
🔇 Additional comments (1)
src/app/[pohid]/[chain]/[request]/page.tsx (1)

21-21: LGTM: Import cleanup

The removal of unused Request type from graphql imports aligns with the changes in vouch handling logic.

@martillansky martillansky merged commit d28f57d into master Oct 28, 2024
7 checks passed
This was referenced Oct 29, 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.

1 participant