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 #116

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions src/app/[pohid]/[chain]/[request]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import { EvidenceFile, MetaEvidenceFile, RegistrationFile } from "types/docs";
import { ipfs, ipfsFetch } from "utils/ipfs";
import { SupportedChainId, paramToChain, supportedChains } from "config/chains";
import ActionBar from "./ActionBar";
import Evidence from "./Evidence";
import { getOffChainVouches, getRequestData } from "data/request";
import { getContractData } from "data/contract";
import { getArbitrationCost } from "data/costs";
import { machinifyId, prettifyId } from "utils/identifier";
import { Hash } from "@wagmi/core";
import Attachment from "components/Attachment";
import ChainLogo from "components/ChainLogo";
import ExternalLink from "components/ExternalLink";
import Identicon from "components/Identicon";
import { explorerLink } from "config/chains";
import Image from "next/image";
import Previewed from "components/Previewed";
import Label from "components/Label";
import Previewed from "components/Previewed";
import TimeAgo from "components/TimeAgo";
import Link from "next/link";
import Attachment from "components/Attachment";
import ChainLogo from "components/ChainLogo";
import Info from "./Info";
import { Address } from "viem";
import { Hash } from "@wagmi/core";
import { getClaimerData } from "data/claimer";
import { ClaimerQuery, Request, Vouch as VouchQuery } from "generated/graphql";
import Vouch from "components/Vouch";
import {
SupportedChainId,
explorerLink,
paramToChain,
supportedChains,
} from "config/chains";
import { getClaimerData } from "data/claimer";
import { getContractData } from "data/contract";
import { getArbitrationCost } from "data/costs";
import { getOffChainVouches, getRequestData } from "data/request";
import { ValidVouch, isValidOnChainVouch, isValidVouch } from "data/vouch";
import { ClaimerQuery, Request, Vouch as VouchQuery } from "generated/graphql";
import Image from "next/image";
import Link from "next/link";
import { EvidenceFile, MetaEvidenceFile, RegistrationFile } from "types/docs";
import { machinifyId, prettifyId } from "utils/identifier";
import { ipfs, ipfsFetch } from "utils/ipfs";
import { Address } from "viem";
import ActionBar from "./ActionBar";
import Evidence from "./Evidence";
import Info from "./Info";

interface PageProps {
params: { pohid: string; chain: string; request: string };
Expand Down
23 changes: 23 additions & 0 deletions src/data/claimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ import { cache } from "react";
import { Address } from "viem";
import { sanitizeClaimerData } from "./sanitizer";

// This fixes an error in the legacy subgraph were registration has not
// been removed as expected. Once solved the issue at subgraph level this
// function should be removed
const sanitizeRegistration = (res: Record<SupportedChainId, ClaimerQuery>) => {
var regChain: SupportedChainId | undefined = undefined;
supportedChains.map((chain) => {
if (!regChain && res[chain.id].claimer?.registration) regChain = chain.id;
else if (regChain && res[chain.id].claimer?.registration) {
if (
res[regChain].claimer?.registration?.humanity.winnerClaim.at(0)
?.resolutionTime >
res[chain.id].claimer?.registration?.humanity.winnerClaim.at(0)
?.resolutionTime
) {
res[chain.id].claimer!.registration = null;
} else {
res[regChain].claimer!.registration = null;
}
}
});
};

export const getClaimerData = cache(async (id: Address) => {
const res = await Promise.all(
supportedChains.map((chain) => sdk[chain.id].Claimer({ id })),
Expand All @@ -15,5 +37,6 @@ export const getClaimerData = cache(async (id: Address) => {
{} as Record<SupportedChainId, ClaimerQuery>,
);

sanitizeRegistration(out);
return await sanitizeClaimerData(out, id);
Comment on lines +40 to 41
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider error handling for sanitization step.

The integration of sanitizeRegistration looks correct, but consider adding error handling to prevent issues from propagating.

Consider wrapping the sanitization in a try-catch:

-  sanitizeRegistration(out);
+  try {
+    sanitizeRegistration(out);
+  } catch (error) {
+    console.error('Failed to sanitize registration data:', error);
+    // Still proceed with sanitizeClaimerData as the original data might be usable
+  }
   return await sanitizeClaimerData(out, id);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sanitizeRegistration(out);
return await sanitizeClaimerData(out, id);
try {
sanitizeRegistration(out);
} catch (error) {
console.error('Failed to sanitize registration data:', error);
// Still proceed with sanitizeClaimerData as the original data might be usable
}
return await sanitizeClaimerData(out, id);

});
Loading