Skip to content

Commit

Permalink
only show verified profiles on list page
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPereira committed Dec 7, 2023
1 parent 3ceb9a6 commit 0a9339b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/nextjs/pages/profile/[address].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Accounts {
[key: string]: string;
}

const LSP24_SCHEMA_NAME = "LSP24MultichainAddressResolutionPolygon";
export const LSP24_SCHEMA_NAME = "LSP24MultichainAddressResolutionPolygon";

const Profile: NextPage = () => {
const router = useRouter();
Expand Down Expand Up @@ -91,6 +91,8 @@ const Profile: NextPage = () => {
setIsNotVerified(true);
}

console.log("lsp24", lsp24);

setMetadata(profileMetaData.value);
} catch (error) {
console.error("Error fetching ERC725 data:", error);
Expand Down
49 changes: 47 additions & 2 deletions packages/nextjs/pages/profiles.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,60 @@
import { useEffect, useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { LSP24_SCHEMA_NAME } from "./profile/[address]";
import { ERC725, ERC725JSONSchema } from "@erc725/erc725.js";
import type { NextPage } from "next";
import lspSchemas from "~~/LSP3ProfileMetadata.json";
import { ProfileCard } from "~~/components/updev";
import { useScaffoldContractRead } from "~~/hooks/scaffold-eth";

type Profile = {
up: string;
upLukso: string;
keyManager: string;
eoa: string;
};

const Profiles: NextPage = () => {
const [verifiedProfiles, setVerifiedProfiles] = useState<Profile[] | undefined>(undefined);

const { data: profiles } = useScaffoldContractRead({
contractName: "upRegistry",
functionName: "ups",
});

useEffect(() => {
const checkIfVerified = async (profile: Profile): Promise<boolean> => {
try {
const erc725js = new ERC725(lspSchemas as ERC725JSONSchema[], profile.upLukso, "https://rpc.lukso.gateway.fm", {
ipfsGateway: "https://api.universalprofile.cloud/ipfs",
});
const lsp24 = await erc725js.fetchData(LSP24_SCHEMA_NAME);
console.log(lsp24.value, profile.up);
return lsp24.value === profile.up;
} catch (error) {
console.log(error);
return false;
}
};

const verifyProfiles = async () => {
if (profiles) {
const verificationPromises = profiles.map(async profile => {
const isVerified = await checkIfVerified(profile);
return { ...profile, isVerified };
});
const verifiedResults = await Promise.all(verificationPromises);
const verifiedProfiles = verifiedResults.filter(profile => profile.isVerified);
setVerifiedProfiles(verifiedProfiles);
}
};

verifyProfiles();
}, [profiles]);

console.log(profiles);

return (
<div className="px-5 md:px-10 lg:px-20">
<div className="flex justify-center items-center my-20 gap-4">
Expand All @@ -20,8 +65,8 @@ const Profiles: NextPage = () => {
</div>

<div className="grid grid-cols-1 xl:grid-cols-3 gap-10">
{profiles &&
profiles.map((profile: any) => (
{verifiedProfiles &&
verifiedProfiles.map((profile: Profile) => (
<Link href={`/profile/${profile.up}`} key={profile.upLukso}>
<ProfileCard upAddress={profile.upLukso} />
</Link>
Expand Down

0 comments on commit 0a9339b

Please sign in to comment.