Skip to content

Commit

Permalink
feat(backend): add attestation handler
Browse files Browse the repository at this point in the history
refs #34
  • Loading branch information
jo-elimu committed Jul 1, 2024
1 parent 16fad41 commit 1f48a40
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
96 changes: 96 additions & 0 deletions frontend/src/components/Attestations.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Address, Avatar, Badge, Identity, Name, getAttestations } from "@coinbase/onchainkit/identity";
import { useEffect, useState } from "react";

import { base, baseSepolia } from 'wagmi/chains'
import LoadingIndicator from "./LoadingIndicator";
import Link from "next/link";

export default function Attestations({ queueIndex }: any) {
console.debug("Attestations");

console.debug("queueIndex:", queueIndex);

const [data, setData] = useState(null);

useEffect(() => {
fetch("https://base-sepolia.easscan.org/graphql", {
method: "POST",
headers: {
"content-type": "application/json"
},
body: JSON.stringify({
query: `
query AttestationsQuery {
attestations(where: {schemaId: {equals: "0x47ae9f9a75fc6f94927dfcabe6c68ecaad18b8e55db85911b91846017103387e"}}) {
id,
attester,
recipient,
time,
decodedDataJson
}
}
`
})
})
.then(response => response.json())
.then(result => {
console.debug("then");
console.debug("result.data:", result.data);
setData(result.data);
})
.catch(error => {
console.error("error:", error);
// TODO: Handle errors
});
}, []);

if (!data) {
return <LoadingIndicator />
}

const attestationsData: any = data;
console.debug("attestationsData:", attestationsData);

if (!attestationsData.attestations) {
// TODO: Handle errors
}

// const EAS_SCHEMA_ID = "0x47ae9f9a75fc6f94927dfcabe6c68ecaad18b8e55db85911b91846017103387e";
// // const attestationOptions = {
// // schemas: [EAS_SCHEMA_ID]
// // };
// const attestations = getAttestations(address, baseSepolia);
// console.log("attestations:", attestations);
// return (
// <Identity
// address={address}
// schemaId="0x47ae9f9a75fc6f94927dfcabe6c68ecaad18b8e55db85911b91846017103387e"
// >
// <Avatar className="h-8 w-8 border-2 rounded-full" />
// <Name>
// <Badge />
// </Name>
// <Address />
// </Identity>
// )

return (
attestationsData.attestations.map((attestation: any, i: number) => {
return (
<div key={i} className="p-4 bg-zinc-50 dark:bg-zinc-900 rounded-lg">
<Name address={attestation.attester} />
<div className="mt-2">
{new Date(attestation.time * 1_000).toISOString().substring(0,10)} {new Date(attestation.time * 1_000).toISOString().substring(11,16)}
<Link href={`https://base-sepolia.easscan.org/attestation/view/${attestation.id}`} target="_blank" className="ml-2"></Link>
</div>
<div className="mt-2">
{/* {attestation.decodedDataJson.verified} */}
<span className="px-3 py-1 text-sm text-emerald-400 border-emerald-400 bg-emerald-800 border-2 rounded-2xl">
Verified✅
</span>
</div>
</div>
)
})
)
}
3 changes: 1 addition & 2 deletions frontend/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import "@/styles/globals.css";
import type { AppProps } from "next/app";
import { WagmiProvider, createConfig, http } from "wagmi";
import { base, baseSepolia } from 'wagmi/chains'
// import { wagmiConfig } from "@/config";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { RainbowKitProvider, getDefaultConfig, darkTheme, connectorsForWallets } from "@rainbow-me/rainbowkit";
import { RainbowKitProvider, darkTheme, connectorsForWallets } from "@rainbow-me/rainbowkit";
import { metaMaskWallet, coinbaseWallet } from "@rainbow-me/rainbowkit/wallets";

// Rainbowkit 🌈
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/pages/distributions/[queueNumber].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MainHeader from "@/components/MainHeader";
import DistributionSummary from "@/components/DistributionSummary";
import Head from "next/head";
import { useRouter } from "next/router";
import Attestations from "@/components/Attestations";

export default function DistributionDetails() {
console.debug("DistributionDetails");
Expand Down Expand Up @@ -32,6 +33,14 @@ export default function DistributionDetails() {
<div className="mt-8 p-4 text-2xl bg-zinc-50 dark:bg-zinc-900 rounded-lg">
<DistributionSummary queueIndex={queueIndex} />
</div>

<h2 className="mt-8 text-2xl">
Attestations:
</h2>

<div className="mt-8 text-xl space-y-2">
<Attestations queueIndex={queueIndex} />
</div>
</main>
<MainFooter />
</>
Expand Down

0 comments on commit 1f48a40

Please sign in to comment.