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

Ticket attestation fetch #14

Merged
merged 8 commits into from
Aug 11, 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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
]
}
],
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-unused-vars": [
"error",
{
Expand Down
40 changes: 40 additions & 0 deletions apps/contract/src/PuchaseTicket.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract PurchaseTicket {
error AlreadyPurchased();
error AlreadyIssued();

address private paymentAddress;

mapping(string => mapping(string => uint256)) private prices;
mapping(string => mapping(string => bool)) private proofs;
mapping(string => mapping(string => bool)) private tickets;

constructor(address _paymentAddress) {
paymentAddress = _paymentAddress;
}

function purchase(
string memory eventId,
string memory uniqueEventId,
string memory seat,
string memory ticketType,
string memory worldProof
) external payable {
bool purchased = proofs[uniqueEventId][worldProof];
if (purchased == true) {
revert AlreadyPurchased();
}

bool issued = tickets[uniqueEventId][seat];
if (issued == true) {
revert AlreadyIssued();
}

uint256 price = prices[eventId][ticketType];
proofs[uniqueEventId][worldProof] = true;
tickets[uniqueEventId][seat] = true;
payable(paymentAddress).transfer(price);
}
}
24 changes: 19 additions & 5 deletions apps/haus/src/app/api/attestation/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ export async function POST(request: Request) {
}
}

interface WhereType {
schemaId: {
equals: string | undefined
}
recipient?: {
equals: string | undefined
}
}

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const query = `
Expand All @@ -87,19 +96,24 @@ export async function GET(request: NextRequest) {
`

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

if (!uid) {
return NextResponse.json({ message: 'Schema UID is required' }, { status: 400 })
const where: WhereType = {
schemaId: {
equals: SCHEMA_UID,
},
}

// schema recipient: ?recipient=xxxxxxxxxxxxxxxxxxxxxx
const recipient = searchParams.get('recipient')
if (recipient) where.recipient = { equals: searchParams.get('recipient') || undefined }

const response = await axios.post(
QUERY_ENDPOINT,
{
query,
variables: {
where: { schemaId: { equals: uid } },
where,
orderBy: [{ timeCreated: 'desc' }],
},
},
Expand Down
9 changes: 0 additions & 9 deletions apps/haus/src/app/event/[id]/complate/page.tsx

This file was deleted.

9 changes: 9 additions & 0 deletions apps/haus/src/app/event/[id]/complete/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

import CompleteTicket from '@/components/complete-ticket'

function Completepage() {
return <CompleteTicket />
}

export default Completepage
36 changes: 35 additions & 1 deletion apps/haus/src/app/ticket/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
'use client'
import { useEffect, useState } from 'react'
import { useAccount } from 'wagmi'

import Tickets from '@/components/tickets'
import { LoadingPage } from '@/components/loading-page'

function TicketPage() {
return <Tickets />
const { address } = useAccount()
const [data, setData] = useState<any>(null)
const [loading, setLoading] = useState(true)

useEffect(() => {
async function fetchData() {
try {
setLoading(true)
const response = await fetch(`/api/attestation?recipient=${address}`)
const result = await response.json()
setData(result)
} catch (error) {
console.error('Error fetching attestations:', error)
} finally {
setLoading(false)
}
}

if (address) {
fetchData()
}
}, [address])

if (loading) return <LoadingPage />

return (
<>
<Tickets attestations={data ? data.data.attestations : []} />
</>
)
}

export default TicketPage
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Box, Link, Typography } from '@mui/material'
import Image from 'next/image'

const ComplateTicket: React.FC = () => {
const CompleteTicket: React.FC = () => {
return (
<Box
display="flex"
Expand Down Expand Up @@ -49,4 +49,4 @@ const ComplateTicket: React.FC = () => {
)
}

export default ComplateTicket
export default CompleteTicket
20 changes: 10 additions & 10 deletions apps/haus/src/components/confirm-ticket/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
'use client'

import React, { useContext } from 'react'
import Image from 'next/image'
import { useParams, useRouter } from 'next/navigation'
import { useAccount, useEnsName } from 'wagmi'
import Typography from '@mui/material/Typography'
import Stack from '@mui/material/Stack'
import IconButton from '@mui/material/IconButton'
import Divider from '@mui/material/Divider'
import Container from '@mui/material/Container'
import Box from '@mui/material/Box'
import React, { useContext } from 'react'
import Image from 'next/image'
import { useParams } from 'next/navigation'
import ArrowBackIcon from '@mui/icons-material/ArrowBack'
import LocationOnIcon from '@mui/icons-material/LocationOn'
import EventIcon from '@mui/icons-material/Event'
import { useMutation } from '@tanstack/react-query'

import { getEventById } from '@/utils/helper'
import { TicketContext } from '@/store/ticket'
// import { useConnect, useAccount, useEnsName } from 'wagmi'
import { useAccount, useEnsName } from 'wagmi'
import { useMutation } from '@tanstack/react-query'
import VerifyWorldId from '../verify-world-id'
import api from '@/services/api'
import { useRouter } from 'next/router'
import VerifyWorldId from '../verify-world-id'

function generateSeatNumber() {
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Expand Down Expand Up @@ -50,7 +50,7 @@ function ConfirmTicket({ setStep }: { setStep: (step: number) => void }) {
return api.post<{ attestation_id: string }>(`/attestation/`, payload)
},
onSuccess: () => {
router.push(`/event/${id}/complate`)
router.push(`/event/${id}/complete`)
},
})
return (
Expand Down Expand Up @@ -170,7 +170,7 @@ function ConfirmTicket({ setStep }: { setStep: (step: number) => void }) {
id: event?.id || '',
eventId: event?.id || '',
worldProof: item.proof,
holderName: ensName || address || '',
holderName: ensName || 'Anonymous',
type: event?.tickets[0].type || '',
seatNumber: generateSeatNumber(),
entryFor: 1,
Expand Down
25 changes: 25 additions & 0 deletions apps/haus/src/components/loading-page/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import CircularProgress from '@mui/material/CircularProgress'
import Box from '@mui/material/Box'
import Typography from '@mui/material/Typography'

export const LoadingPage = ({ minHeight }: any) => {
return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
minHeight: minHeight || '480px',
}}
>
<CircularProgress />
<Typography
variant="caption"
sx={{ mt: 4 }}
>
Loading
</Typography>
</Box>
)
}
Loading
Loading