mirror of
https://github.com/0xShay/ticketchain.git
synced 2026-01-11 13:13:25 +00:00
Merge branch 'main' of https://github.com/Ayush272002/Event-Chain into form__submit_handler
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardHeader,
|
CardHeader,
|
||||||
@@ -32,8 +32,10 @@ const EventDescription: React.FC<EventDescriptionProps> = ({
|
|||||||
eventDetails,
|
eventDetails,
|
||||||
}) => {
|
}) => {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
const [numTickets, setNumTickets] = useState(1);
|
||||||
|
|
||||||
const handleBuyNow = () => {
|
const handleBuyNow = () => {
|
||||||
buyHandler(eventDetails.EventID, toast);
|
buyHandler(eventDetails.EventID, numTickets, toast);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -79,7 +81,10 @@ const EventDescription: React.FC<EventDescriptionProps> = ({
|
|||||||
</Button>
|
</Button>
|
||||||
<div className="relative md:left-5">
|
<div className="relative md:left-5">
|
||||||
<NumberPicker
|
<NumberPicker
|
||||||
|
initialCount={numTickets}
|
||||||
|
min={1}
|
||||||
max={eventDetails.capacity - eventDetails.ticketsSold}
|
max={eventDetails.capacity - eventDetails.ticketsSold}
|
||||||
|
onChange={setNumTickets}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
'use client';
|
import React from 'react';
|
||||||
import React, { useState } from 'react';
|
import { Button } from '../ui/button';
|
||||||
import { Button } from '../ui/button'; // Adjust import path to where your shadcn Button component is located
|
|
||||||
|
|
||||||
interface NumberPickerProps {
|
interface NumberPickerProps {
|
||||||
initialCount?: number;
|
initialCount?: number;
|
||||||
@@ -15,25 +14,23 @@ const NumberPicker: React.FC<NumberPickerProps> = ({
|
|||||||
max = 10,
|
max = 10,
|
||||||
onChange,
|
onChange,
|
||||||
}) => {
|
}) => {
|
||||||
const [count, setCount] = useState<number>(initialCount);
|
const [count, setCount] = React.useState(initialCount);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (onChange) {
|
||||||
|
onChange(count);
|
||||||
|
}
|
||||||
|
}, [count, onChange]);
|
||||||
|
|
||||||
const increment = () => {
|
const increment = () => {
|
||||||
if (count < max) {
|
if (count < max) {
|
||||||
const newCount = count + 1;
|
setCount(count + 1);
|
||||||
setCount(newCount);
|
|
||||||
if (onChange) {
|
|
||||||
onChange(newCount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const decrement = () => {
|
const decrement = () => {
|
||||||
if (count > min) {
|
if (count > min) {
|
||||||
const newCount = count - 1;
|
setCount(count - 1);
|
||||||
setCount(newCount);
|
|
||||||
if (onChange) {
|
|
||||||
onChange(newCount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
504
contracts/EventManagerABI.json
Normal file
504
contracts/EventManagerABI.json
Normal file
@@ -0,0 +1,504 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_ticketId",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "_to",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "bool",
|
||||||
|
"name": "_allowed",
|
||||||
|
"type": "bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "approveTicket",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_eventId",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "buyTicket",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_ticketId",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "payable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "string",
|
||||||
|
"name": "_name",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "string",
|
||||||
|
"name": "_description",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_capacity",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_ticketPrice",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_eventDate",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "string[]",
|
||||||
|
"name": "_images",
|
||||||
|
"type": "string[]"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "createEvent",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_eventId",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "constructor"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anonymous": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "eventId",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "string",
|
||||||
|
"name": "name",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "eventDate",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "EventCreated",
|
||||||
|
"type": "event"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anonymous": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "ticketId",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "eventId",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "buyer",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "price",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "TicketPurchased",
|
||||||
|
"type": "event"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anonymous": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "ticketId",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "owner",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "trustee",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "TicketTransferApproved",
|
||||||
|
"type": "event"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anonymous": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "ticketId",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "from",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "to",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "TicketTransferred",
|
||||||
|
"type": "event"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_ticketId",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "_to",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "transferTicket",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_ticketId",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "_to",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "transferTicketFrom",
|
||||||
|
"outputs": [],
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_cents",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "centsToFlare",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_flr",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "eventCounter",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "events",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "string",
|
||||||
|
"name": "name",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "string",
|
||||||
|
"name": "description",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "capacity",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "ticketsSold",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "ticketPrice",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "eventDate",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "address payable",
|
||||||
|
"name": "eventHost",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "feedIds",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "bytes21",
|
||||||
|
"name": "",
|
||||||
|
"type": "bytes21"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_eventId",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "getEventImages",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "string[]",
|
||||||
|
"name": "",
|
||||||
|
"type": "string[]"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_eventId",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "getEventPriceFlare",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_flr",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_eventId",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "getEventTickets",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256[]",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256[]"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "getFlareFeed",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "_feedValue",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "int8",
|
||||||
|
"name": "_decimals",
|
||||||
|
"type": "int8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint64",
|
||||||
|
"name": "_timestamp",
|
||||||
|
"type": "uint64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "getFtsoV2CurrentFeedValues",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256[]",
|
||||||
|
"name": "_feedValues",
|
||||||
|
"type": "uint256[]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "int8[]",
|
||||||
|
"name": "_decimals",
|
||||||
|
"type": "int8[]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint64",
|
||||||
|
"name": "_timestamp",
|
||||||
|
"type": "uint64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [],
|
||||||
|
"name": "ticketCounter",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "tickets",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "holder",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "boughtTime",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "eventId",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "userTickets",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -17,6 +17,7 @@ type ToastFunction = (options: {
|
|||||||
|
|
||||||
export const buyHandler = async (
|
export const buyHandler = async (
|
||||||
eventId: number,
|
eventId: number,
|
||||||
|
numTickets: number,
|
||||||
toast: ToastFunction
|
toast: ToastFunction
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
if (eventId < 0) {
|
if (eventId < 0) {
|
||||||
@@ -24,42 +25,62 @@ export const buyHandler = async (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (numTickets <= 0) {
|
||||||
if (typeof window.ethereum === 'undefined') {
|
|
||||||
toast({
|
|
||||||
title: 'Please install MetaMask or another Ethereum wallet',
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const provider = new ethers.providers.Web3Provider(window.ethereum);
|
|
||||||
const signer = provider.getSigner();
|
|
||||||
const contract = getContract().connect(signer);
|
|
||||||
|
|
||||||
let ticketCost = await contract.getEventPriceFlare(eventId);
|
|
||||||
ticketCost = ticketCost.mul(105).div(100);
|
|
||||||
const balance = await provider.getBalance(await signer.getAddress());
|
|
||||||
|
|
||||||
if (balance.lt(ticketCost)) {
|
|
||||||
toast({
|
|
||||||
title: 'Insufficient balance to cover ticket cost and gas fees.',
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const tx = await contract.buyTicket(eventId, { value: ticketCost });
|
|
||||||
const receipt = await tx.wait();
|
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: `Ticket purchased successfully! Transaction Hash: ${receipt.transactionHash}`,
|
title: 'Please select at least one ticket.',
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error buying ticket:', error);
|
|
||||||
toast({
|
|
||||||
title: 'Transaction failed. Please try again.',
|
|
||||||
variant: 'destructive',
|
variant: 'destructive',
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title:
|
||||||
|
'You might be asked to approve multiple transactions if you buy multiple tickets',
|
||||||
|
});
|
||||||
|
|
||||||
|
while (numTickets > 0) {
|
||||||
|
try {
|
||||||
|
if (typeof window.ethereum === 'undefined') {
|
||||||
|
toast({
|
||||||
|
title: 'Please install MetaMask or another Ethereum wallet',
|
||||||
|
variant: 'destructive',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const provider = new ethers.providers.Web3Provider(window.ethereum);
|
||||||
|
const signer = provider.getSigner();
|
||||||
|
const contract = getContract().connect(signer);
|
||||||
|
|
||||||
|
const singleTicketCost = await contract.getEventPriceFlare(eventId);
|
||||||
|
const totalTicketCost = singleTicketCost
|
||||||
|
.mul(numTickets)
|
||||||
|
.mul(105)
|
||||||
|
.div(100);
|
||||||
|
|
||||||
|
const balance = await provider.getBalance(await signer.getAddress());
|
||||||
|
if (balance.lt(totalTicketCost)) {
|
||||||
|
toast({
|
||||||
|
title: 'Insufficient balance to cover ticket cost and gas fees.',
|
||||||
|
variant: 'destructive',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tx = await contract.buyTicket(eventId, { value: totalTicketCost });
|
||||||
|
const receipt = await tx.wait();
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: `Tickets purchased successfully! Transaction Hash: ${receipt.transactionHash}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
numTickets -= 1;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error buying tickets:', error);
|
||||||
|
toast({
|
||||||
|
title: 'Transaction failed. Please try again.',
|
||||||
|
variant: 'destructive',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
506
lib/ethers.ts
506
lib/ethers.ts
@@ -1,4 +1,5 @@
|
|||||||
import { ethers } from 'ethers';
|
import { ethers } from 'ethers';
|
||||||
|
import EventManagerABI from '../contracts/EventManagerABI.json';
|
||||||
|
|
||||||
const FLARE_TESTNET_RPC_URL = process.env.NEXT_PUBLIC_RPC_URL;
|
const FLARE_TESTNET_RPC_URL = process.env.NEXT_PUBLIC_RPC_URL;
|
||||||
const CONTRACT_ADDRESS = process.env.NEXT_PUBLIC_CONTRACT_ADDRESS;
|
const CONTRACT_ADDRESS = process.env.NEXT_PUBLIC_CONTRACT_ADDRESS;
|
||||||
@@ -12,509 +13,6 @@ export function getFlareProvider() {
|
|||||||
export function getContract() {
|
export function getContract() {
|
||||||
const provider = getFlareProvider();
|
const provider = getFlareProvider();
|
||||||
const contractAddress = CONTRACT_ADDRESS;
|
const contractAddress = CONTRACT_ADDRESS;
|
||||||
const contractABI = [
|
const contractABI = EventManagerABI;
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_ticketId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'address',
|
|
||||||
name: '_to',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'bool',
|
|
||||||
name: '_allowed',
|
|
||||||
type: 'bool',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'approveTicket',
|
|
||||||
outputs: [],
|
|
||||||
stateMutability: 'nonpayable',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_eventId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'buyTicket',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_ticketId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'payable',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'string',
|
|
||||||
name: '_name',
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'string',
|
|
||||||
name: '_description',
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_capacity',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_ticketPrice',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_eventDate',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'string[]',
|
|
||||||
name: '_images',
|
|
||||||
type: 'string[]',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'createEvent',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_eventId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'nonpayable',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [],
|
|
||||||
stateMutability: 'nonpayable',
|
|
||||||
type: 'constructor',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
anonymous: false,
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'eventId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'string',
|
|
||||||
name: 'name',
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'eventDate',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'EventCreated',
|
|
||||||
type: 'event',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
anonymous: false,
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'ticketId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'eventId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'address',
|
|
||||||
name: 'buyer',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'price',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'TicketPurchased',
|
|
||||||
type: 'event',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
anonymous: false,
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'ticketId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'address',
|
|
||||||
name: 'owner',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'address',
|
|
||||||
name: 'trustee',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'TicketTransferApproved',
|
|
||||||
type: 'event',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
anonymous: false,
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'ticketId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'address',
|
|
||||||
name: 'from',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
indexed: false,
|
|
||||||
internalType: 'address',
|
|
||||||
name: 'to',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'TicketTransferred',
|
|
||||||
type: 'event',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_ticketId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'address',
|
|
||||||
name: '_to',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'transferTicket',
|
|
||||||
outputs: [],
|
|
||||||
stateMutability: 'nonpayable',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_ticketId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'address',
|
|
||||||
name: '_to',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'transferTicketFrom',
|
|
||||||
outputs: [],
|
|
||||||
stateMutability: 'nonpayable',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_cents',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'centsToFlare',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_flr',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [],
|
|
||||||
name: 'eventCounter',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'events',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'string',
|
|
||||||
name: 'name',
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'string',
|
|
||||||
name: 'description',
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'capacity',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'ticketsSold',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'ticketPrice',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'eventDate',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'address payable',
|
|
||||||
name: 'eventHost',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'feedIds',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'bytes21',
|
|
||||||
name: '',
|
|
||||||
type: 'bytes21',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_eventId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'getEventImages',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'string[]',
|
|
||||||
name: '',
|
|
||||||
type: 'string[]',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_eventId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'getEventPriceFlare',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_flr',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_eventId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'getEventTickets',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256[]',
|
|
||||||
name: '',
|
|
||||||
type: 'uint256[]',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [],
|
|
||||||
name: 'getFlareFeed',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '_feedValue',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'int8',
|
|
||||||
name: '_decimals',
|
|
||||||
type: 'int8',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint64',
|
|
||||||
name: '_timestamp',
|
|
||||||
type: 'uint64',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [],
|
|
||||||
name: 'getFtsoV2CurrentFeedValues',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256[]',
|
|
||||||
name: '_feedValues',
|
|
||||||
type: 'uint256[]',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'int8[]',
|
|
||||||
name: '_decimals',
|
|
||||||
type: 'int8[]',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint64',
|
|
||||||
name: '_timestamp',
|
|
||||||
type: 'uint64',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [],
|
|
||||||
name: 'ticketCounter',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'tickets',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'address',
|
|
||||||
name: 'holder',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'boughtTime',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: 'eventId',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
internalType: 'address',
|
|
||||||
name: '',
|
|
||||||
type: 'address',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
name: 'userTickets',
|
|
||||||
outputs: [
|
|
||||||
{
|
|
||||||
internalType: 'uint256',
|
|
||||||
name: '',
|
|
||||||
type: 'uint256',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
stateMutability: 'view',
|
|
||||||
type: 'function',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
return new ethers.Contract(contractAddress!, contractABI, provider);
|
return new ethers.Contract(contractAddress!, contractABI, provider);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user