Skip to content

Commit

Permalink
Merge pull request #5 from fabriziogianni7/speaker-nft-mint-flow
Browse files Browse the repository at this point in the history
Speaker nft mint flow
  • Loading branch information
fabriziogianni7 authored Nov 18, 2023
2 parents d9eaa66 + f2e7a0e commit 5d95270
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 7 deletions.
76 changes: 76 additions & 0 deletions packages/nextjs/components/record/Recorder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { useState } from "react";
import lighthouse from "@lighthouse-web3/sdk";
import { LoaderIcon } from "react-hot-toast";

export const Recorder = () => {
const [file, setFile] = useState<FileList | null>();
const [isUploadLoading, setIsUploadLoading] = useState<boolean>();
const [fileUploaded, setFileUploaded] = useState<boolean>();
const [price, setPrice] = useState("");
const progressCallback = (progressData: { total: number; uploaded: number }) => {
const percentageDone = 100 - Number(progressData?.total / progressData?.uploaded);
console.log(percentageDone);
};

const uploadFile = async (file: FileList | null | undefined) => {
setIsUploadLoading(true);
if (!file) {
alert("upload file first");
return;
}
const output = await lighthouse.upload(
file,
process.env.NEXT_PUBLIC_LIGHTHOUSE_KEY as string,
false,
undefined,
progressCallback,
);
console.log("File Status:", output);

console.log("Visit at https://gateway.lighthouse.storage/ipfs/" + output.data.Hash);
setIsUploadLoading(false);
setFileUploaded(true);
alert(`File uploaded at ${"https://gateway.lighthouse.storage/ipfs/"}`);
};

return (
<div className="p-4">
{fileUploaded ? ( //TODO remove, jsut for developmnenrt
<>
<div className="flex flex-col items-center justify-center max-w-sm text-black">
<input
type="number"
placeholder={`Enter Price (USDC)`}
value={price}
onChange={e => setPrice(e.target.value)}
className="mt-4 p-2 border border-gray-300 rounded"
/>
<button onClick={() => alert("CAZZO")} className="mt-2 bg-blue-500 text-white p-2 rounded">
Submit
</button>
</div>
</>
) : (
<>
{isUploadLoading ? (
<div className="flex items-center justify-center">
<LoaderIcon />
</div>
) : (
<>
<div className="text-green-500 font-bold">Read this sentence and upload the audio:</div>
<div className="text-red-500 font-bold">
Unlock new possibilities with cutting-edge technology. Experience innovation at your fingertips. Embrace
the future today.
</div>
<input onChange={e => setFile(e.target.files)} type="file" className="mt-4" />
<button className="btn btn-secondary btn-sm" onClick={() => uploadFile(file)}>
Upload
</button>
</>
)}
</>
)}
</div>
);
};
1 change: 1 addition & 0 deletions packages/nextjs/components/record/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Recorder";
3 changes: 3 additions & 0 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@ethersproject/providers": "^5.7.2",
"@heroicons/react": "^2.0.11",
"@lighthouse-web3/sdk": "^0.2.8",
"@rainbow-me/rainbowkit": "1.1.2",
"@uniswap/sdk-core": "^4.0.1",
"@uniswap/v2-sdk": "^3.0.1",
Expand All @@ -29,6 +30,7 @@
"nextjs-progressbar": "^0.0.16",
"qrcode.react": "^3.1.0",
"react": "^18.2.0",
"react-audio-voice-recorder": "^2.2.0",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.0",
Expand All @@ -43,6 +45,7 @@
"@types/node": "^17.0.35",
"@types/react": "^18.0.9",
"@types/react-copy-to-clipboard": "^5.0.4",
"@types/react-mic": "^12",
"@typescript-eslint/eslint-plugin": "^5.39.0",
"autoprefixer": "^10.4.12",
"eslint": "^8.15.0",
Expand Down
15 changes: 8 additions & 7 deletions packages/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Link from "next/link";
import type { NextPage } from "next";
import { MicrophoneIcon } from "@heroicons/react/24/outline";
import { MetaHeader } from "~~/components/MetaHeader";

const Home: NextPage = () => {
Expand Down Expand Up @@ -31,16 +33,15 @@ const Home: NextPage = () => {

<div className="flex-grow bg-base-300 w-full mt-16 px-8 py-12">
<div className="flex justify-center items-center gap-12 flex-col sm:flex-row">
{/* <div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
<BugAntIcon className="h-8 w-8 fill-secondary" />
<div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
<MicrophoneIcon className="h-8 w-8 fill-secondary" />
<p>
Tinker with your smart contract using the{" "}
<Link href="/debug" passHref className="link">
Debug Contract
Record An audio sample to start{" "}
<Link href="/record" passHref className="link">
Start
</Link>{" "}
tab.
</p>
</div> */}
</div>
{/* <div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
<MagnifyingGlassIcon className="h-8 w-8 fill-secondary" />
<p>
Expand Down
58 changes: 58 additions & 0 deletions packages/nextjs/pages/record.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { NextPage } from "next";
import { MicrophoneIcon } from "@heroicons/react/24/outline";
import { MetaHeader } from "~~/components/MetaHeader";
import { Recorder } from "~~/components/record";

const Home: NextPage = () => {
return (
<>
<MetaHeader />
<div className="flex items-center flex-col flex-grow pt-10">
<div className="px-5">
<h1 className="text-center mb-8">
<span className="block text-2xl mb-2">Welcome to</span>
<span className="block text-4xl font-bold">Dub3.ai</span>
</h1>
{/* <p className="text-center text-lg">
Get started by editing{" "}
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
packages/nextjs/pages/index.tsx
</code>
</p>
<p className="text-center text-lg">
Edit your smart contract{" "}
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
YourContract.sol
</code>{" "}
in{" "}
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
packages/hardhat/contracts
</code>
</p> */}
</div>

<div className="flex-grow bg-base-300 w-full max-w-2xl mt-16 px-8 py-12">
<div className="flex justify-center items-center gap-12 flex-col sm:flex-row">
<div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-2xl rounded-3xl">
<MicrophoneIcon className="h-8 w-8 fill-secondary" />
<p>Here we are. LFG </p>
<Recorder />
</div>
{/* <div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
<MagnifyingGlassIcon className="h-8 w-8 fill-secondary" />
<p>
Explore your local transactions with the{" "}
<Link href="/blockexplorer" passHref className="link">
Block Explorer
</Link>{" "}
tab.
</p>
</div> */}
</div>
</div>
</div>
</>
);
};

export default Home;

0 comments on commit 5d95270

Please sign in to comment.