Skip to content

Commit

Permalink
Merge pull request #16 from hollow-leaf/feat/contract_interacte
Browse files Browse the repository at this point in the history
Feat/contract interacte
  • Loading branch information
LinXJ1204 authored Dec 12, 2023
2 parents 6d9b8bc + f926675 commit 502843b
Show file tree
Hide file tree
Showing 12 changed files with 1,372 additions and 24 deletions.
3 changes: 3 additions & 0 deletions apps/backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
/.pnp
.pnp.js

/__pycahe__
.idea

# testing
/coverage

Expand Down
Binary file modified apps/backend/__pycache__/extension.cpython-310.pyc
Binary file not shown.
Binary file modified apps/backend/__pycache__/websiteconfig.cpython-310.pyc
Binary file not shown.
Binary file modified apps/backend/blockchain/__pycache__/abi.cpython-310.pyc
Binary file not shown.
Binary file modified apps/backend/blockchain/__pycache__/blockchain.cpython-310.pyc
Binary file not shown.
Binary file modified apps/backend/db_operate/__pycache__/db_operate.cpython-310.pyc
Binary file not shown.
Binary file modified apps/backend/db_operate/__pycache__/model.cpython-310.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions apps/web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@heroicons/react": "2.0.18",
"@material-tailwind/react": "2.1.2",
"@rainbow-me/rainbowkit": "^1.3.0",
"@wagmi/core": "^1.4.10",
"next": "13.4.0",
"react": "18",
"react-dom": "18",
Expand Down
9 changes: 6 additions & 3 deletions apps/web3/src/app/donations/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use client";
import React, { useState } from "react";
import { Typography } from "@material-tailwind/react";
import { register } from "@/service/contract";

type NFT = {
mintPrice: number,
maxSupply: number,
Expand All @@ -22,6 +24,7 @@ export default function Donations() {
e.preventDefault();
let data = { name };
console.log(data);
register(data.name)
};

const handleSubmit = async (e: React.FormEvent) => {
Expand Down Expand Up @@ -59,13 +62,13 @@ export default function Donations() {
<div className="flex flex-wrap mx-4 ">
{/* Left Column: Create Contract */}
<div className="w-[80%] md:w-1/2 px-4 py-4 border border-blue-500 rounded-xl">
<h2 className="text-2xl font-bold mb-4 text-center">Create Contract</h2>
<h2 className="text-2xl font-bold mb-4 text-center">Streamer Register</h2>
<form onSubmit={handleSubmitName} className="text-left">
{/* Form elements for creating contract */}
<label>Get Started : </label><br />
<input
type="text"
placeholder="Donantion Name"
placeholder="Your Stream Id"
onChange={(e) => setName(e.target.value)}
className="my-4 text-center"
/>
Expand All @@ -75,7 +78,7 @@ export default function Donations() {
type="submit"
className="mt-4 bg-blue-500 text-white border border-blue-700 hover:bg-blue-600 px-4 py-2 rounded"
>
Create Contract
Streamer Register
</button>
</form>
</div>
Expand Down
84 changes: 84 additions & 0 deletions apps/web3/src/service/contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { writeContract, readContract } from '@wagmi/core';
import { FactoryABI, ERC20ABI, GlobalABI } from './contractAbi';

const FactoryADDRESS = "0xb2d2108Fa30b0a001998474CA7cd1670c85F4f7D"
const ERC20ADDRESS = "0x1E2DCCDfa8a3fc10669f81f2Ce6b7F425983cfE2"
const GlobalADDRESS = "0x0191343b0e4C72B5F3539C5Ed4b3F36B3699bdb0"

export async function eventId2Address(eventId:number){

const data:any = await readContract({
address: FactoryADDRESS,
abi: FactoryABI,
//TODO: enter right function
functionName: 'eventIdToAddr',
args: [eventId],
})

console.log(data)

if(data){
return data
}

return ""
}


export async function buyNftByNftId(minter:string, eventId:number, nftId:number, amount:number, price:number){
alert("Approve transaction on your device!")

const contractAddr = await eventId2Address(eventId)

await ERC20Approve(contractAddr, amount*price)

const { hash } = await writeContract({
address: FactoryADDRESS,
abi: FactoryABI,
functionName: 'mintEventDonateNFT',
args: [eventId, nftId, amount],
})

console.log("Transaction Submit")

return hash
}

export async function ERC20Approve(contract:string, amount:number){
const { hash } = await writeContract({
address: ERC20ADDRESS,
abi: ERC20ABI,
functionName: 'approve',
args: [contract, amount],
})

return hash
}

export async function register(userId:string){
alert("Approve transaction on your device!")

const { hash } = await writeContract({
address: GlobalADDRESS,
abi: GlobalABI,
functionName: 'setValidEventHolder',
args: [userId, true],
})

return hash
}

export async function createNewNft(name:string, eventId:number, supply:number, price:number){
alert("Approve transaction on your device!")

const { hash } = await writeContract({
address: FactoryADDRESS,
abi: FactoryABI,
functionName: 'addNewERC1155',
args: [eventId, price, supply, name, ""],
})

console.log("Transaction Submit")

return hash
}
Loading

0 comments on commit 502843b

Please sign in to comment.