Skip to content

Commit

Permalink
Merge branch 'main' into feature/generate-assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhamsa1 committed Aug 10, 2024
2 parents 71bfcf3 + 693880a commit 052856d
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 39 deletions.
53 changes: 29 additions & 24 deletions apps/haus/src/app/api/attestation/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
import { NextResponse } from 'next/server'
import { EAS } from '@ethereum-attestation-service/eas-sdk'
import { ethers } from 'ethers'
import { EAS_ADDRESS, PROVIDER } from '@/config'
import axios from 'axios'

const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY

const customStringify = (obj) => {
return JSON.stringify(obj, (key, value) => (typeof value === 'bigint' ? value.toString() : value))
}
const QUERY_ENDPOINT =
process.env.QUERY_ENDPOINT_URL || 'https://optimism-sepolia.easscan.org/graphql'

export async function GET(request: Request, context: { params: { id: string } }) {
const query = `
query getAttestationById($where: AttestationWhereUniqueInput!) {
getAttestation(where: $where) {
decodedDataJson
attester
recipient
id
schemaId
}
}
`

try {
const attestationUID = context.params.id

if (!attestationUID) {
return NextResponse.json({ message: 'Attestation UID is required' }, { status: 400 })
}

// Initialize the sdk with the address of the EAS Schema contract address
const easInstance = new EAS(EAS_ADDRESS as string)

// Gets a default provider (in production use something else like infura/alchemy)
const provider = ethers.getDefaultProvider(PROVIDER)
const signer = new ethers.Wallet(PRIVATE_KEY as string, provider)

// Connects an ethers style provider/signingProvider to perform read/write functions.
easInstance.connect(signer)

const attestation = await easInstance.getAttestation(attestationUID)
console.log('Attestation detail: ', attestation)

const data = customStringify(attestation)

return NextResponse.json(data)
const response = await axios.post(
QUERY_ENDPOINT,
{
query,
variables: { where: { id: attestationUID } },
},
{
headers: {
'Content-Type': 'application/json',
},
},
)

return NextResponse.json(response.data)
} catch (error) {
console.error('Error handling GET request', error)
return NextResponse.json({ message: 'Something went wrong' }, { status: 500 })
Expand Down
55 changes: 53 additions & 2 deletions apps/haus/src/app/api/attestation/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { NextResponse } from 'next/server'
import { NextResponse, NextRequest } from 'next/server'
import { EAS, SchemaEncoder } from '@ethereum-attestation-service/eas-sdk'
import { ethers } from 'ethers'
import { EAS_ADDRESS, SCHEMA_UID, PROVIDER } from '@/config'
import axios from 'axios'

const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY
const EAS_ADDRESS = process.env.EAS_CONTRACT_ADDRESS
const SCHEMA_UID = process.env.SCHEMA_UID
const PROVIDER = process.env.EAS_PROVIDER_URL || 'https://sepolia.optimism.io'
const QUERY_ENDPOINT =
process.env.QUERY_ENDPOINT_URL || 'https://optimism-sepolia.easscan.org/graphql'

export async function POST(request: Request) {
try {
Expand Down Expand Up @@ -65,3 +70,49 @@ export async function POST(request: Request) {
return NextResponse.json({ message: 'Something went wrong' }, { status: 500 })
}
}

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const query = `
query Attestations($where: AttestationWhereInput, $orderBy: [AttestationOrderByWithRelationInput!]) {
attestations(where: $where, orderBy: $orderBy) {
attester
id
recipient
schemaId
timeCreated
decodedDataJson
}
}
`

try {
// schema uid: ?uid=xxxxxxxxxxxxxxxxxxxxxx
const uid = searchParams.get('uid')

if (!uid) {
return NextResponse.json({ message: 'Schema UID is required' }, { status: 400 })
}

const response = await axios.post(
QUERY_ENDPOINT,
{
query,
variables: {
where: { schemaId: { equals: uid } },
orderBy: [{ timeCreated: 'desc' }],
},
},
{
headers: {
'Content-Type': 'application/json',
},
},
)

return NextResponse.json(response.data)
} catch (error) {
console.error('Error handling GET request', error)
return NextResponse.json({ message: 'Something went wrong' }, { status: 500 })
}
}
5 changes: 3 additions & 2 deletions apps/haus/src/app/hooks/useEAS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import { EAS } from '@ethereum-attestation-service/eas-sdk'
import { ethers } from 'ethers'
import { useEffect, useState } from 'react'
import { EAS_ADDRESS, PROVIDER } from '@/config'

export const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY
const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY
const EAS_ADDRESS = process.env.EAS_CONTRACT_ADDRESS
const PROVIDER = process.env.EAS_PROVIDER_URL || 'https://sepolia.optimism.io'

export const useEAS = () => {
const [eas, setEAS] = useState<EAS>()
Expand Down
3 changes: 2 additions & 1 deletion apps/haus/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Metadata } from 'next'
import { AppRouterCacheProvider } from '@mui/material-nextjs/v14-appRouter'
import { ThemeProvider } from '@mui/material/styles'
import CssBaseline from '@mui/material/CssBaseline'

import '@coinbase/onchainkit/styles.css'

import BaseProvider from '@/components/provider/base'
Expand All @@ -21,7 +22,7 @@ export default function RootLayout(props: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<AppRouterCacheProvider options={{ enableCssLayer: true }}>
<AppRouterCacheProvider options={{ enableCssLayer: false }}>
<ThemeProvider theme={theme}>
<BaseProvider apiKey={BASE_KEY}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
Expand Down
13 changes: 7 additions & 6 deletions apps/haus/src/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import * as React from 'react'
import Toolbar from '@mui/material/Toolbar'
import Typography from '@mui/material/Typography'
import Container from '@mui/material/Container'
import { Stack } from '@mui/material'
import { Link, Stack } from '@mui/material'

import Login from '../verify-world-id'
import Wallet from '../wallet'
import Account from '../account'

export default function Header() {
return (
Expand All @@ -26,16 +24,19 @@ export default function Header() {
noWrap
sx={{ flex: 1 }}
>
Haus
<Link
href="/"
underline="none"
>
Haus
</Link>
</Typography>
<Stack
gap={2}
direction="row"
alignItems="center"
>
<Wallet />
<Login />
<Account />
</Stack>
</Container>
</Toolbar>
Expand Down
7 changes: 7 additions & 0 deletions apps/haus/src/components/wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { Address, Avatar, Name, Identity, EthBalance } from '@coinbase/onchainkit/identity'
import { color } from '@coinbase/onchainkit/theme'
import { Box } from '@mui/material'
import ConfirmationNumberIcon from '@mui/icons-material/ConfirmationNumber'

const WalletComponents = () => {
return (
Expand All @@ -35,6 +36,12 @@ const WalletComponents = () => {
>
Wallet
</WalletDropdownLink>
<WalletDropdownLink
icon={<ConfirmationNumberIcon />}
href="/ticket"
>
My Ticket
</WalletDropdownLink>
<WalletDropdownDisconnect />
</WalletDropdown>
</Wallet>
Expand Down
4 changes: 0 additions & 4 deletions apps/haus/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,3 @@ export const EVENTS = [
image_url: 'https://example.com/images/berlin-film-festival.jpg',
},
]

export const EAS_ADDRESS = process.env.EAS_CONTRACT_ADDRESS
export const SCHEMA_UID = process.env.SCHEMA_UID
export const PROVIDER = process.env.EAS_PROVIDER_URL || 'https://sepolia.optimism.io'

0 comments on commit 052856d

Please sign in to comment.